Adaption_Prompt
mindnlp.peft.tuners.adaption_prompt.config.AdaptionPromptConfig
dataclass
¶
Bases: PeftConfig
Stores the configuration of an [AdaptionPromptModel].
Source code in mindnlp/peft/tuners/adaption_prompt/config.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
mindnlp.peft.tuners.adaption_prompt.config.AdaptionPromptConfig.is_adaption_prompt: bool
property
¶
Return True if this is an adaption prompt config.
mindnlp.peft.tuners.adaption_prompt.model.AdaptionPromptModel
¶
Bases: Cell
Implements adaption prompts as described in https://arxiv.org/pdf/2303.16199.pdf.
The top L attention modules are replaced with AdaptedAttention modules that wrap the original ones, but insert trainable prompts with gates (for zero init).
Notes on the multi-adapter pattern: - We store the states of different adapters by keeping a dictionary of AdaptedAttention modules indexed by adapter name. - Every time we switch adapters, we remove the modules of the currently active adapter from the model, store them in the dictionary, and replace them with the modules of the new adapter. - To avoid duplicated and potentially inconsistent state, the currently active adapter is always removed from the dictionary. - Disabling the adapter would also result in the modules being removed from the model.
Source code in mindnlp/peft/tuners/adaption_prompt/model.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
mindnlp.peft.tuners.adaption_prompt.model.AdaptionPromptModel.__getattr__(name)
¶
Forward missing attributes to the wrapped module.
Source code in mindnlp/peft/tuners/adaption_prompt/model.py
142 143 144 145 146 147 148 149 | |
mindnlp.peft.tuners.adaption_prompt.model.AdaptionPromptModel.add_adapter(adapter_name, config)
¶
Add an adapter with the given name and config.
Source code in mindnlp/peft/tuners/adaption_prompt/model.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
mindnlp.peft.tuners.adaption_prompt.model.AdaptionPromptModel.disable_adapter_layers()
¶
Disable adapter layers by swapping out AdaptedAttention modules.
Source code in mindnlp/peft/tuners/adaption_prompt/model.py
105 106 107 108 | |
mindnlp.peft.tuners.adaption_prompt.model.AdaptionPromptModel.enable_adapter_layers()
¶
Enable adapter layers by swapping in cached AdaptedAttention modules.
Source code in mindnlp/peft/tuners/adaption_prompt/model.py
100 101 102 103 | |
mindnlp.peft.tuners.adaption_prompt.model.AdaptionPromptModel.set_adapter(adapter_name)
¶
Set the model to use the adapter with the given name.
Source code in mindnlp/peft/tuners/adaption_prompt/model.py
87 88 89 90 91 92 93 94 95 96 97 98 | |