Skip to content
module

Adaption Prompt

3 members
lucid.peft.tuners.adaption_prompt

lucid.peft.tuners.adaption_prompt — adaption prompts (LLaMA-Adapter): learned prompts the top attention layers attend to.

LLaMA-Adapter (Zhang et al., 2023, arXiv:2303.16199) freezes a decoder language model and gives each of its top LL attention layers adapter_len learned prompt vectors. The layer's queries attend to keys and values that the layer's own projections make of the prompt, and the result is added to the layer's output through a gate that starts at zero: y=f(x)+g⋅softmax(qKp⊤/d) Vpy = f(x) + g\cdot\mathrm{softmax}(q K_p^\top/\sqrt{d})\,V_p. The adapted model therefore starts as the base, and the first gradients move the gate before the prompt matters. Pick it to steer a decoder with a few thousand parameters when the weights should stay untouched; unlike prompt tuning it acts inside the layers, and unlike LoRA it cannot be folded into the weights.

It needs the attention's keys and values and its queries, which a module does not return, so each supported family is one strategy: the zoo's gpt and gpt2 decoders (fused c_attn projection). Any other model type raises ValueError naming the supported ones. AdaptionPromptConfig and AdaptionPromptModel are here and exported from lucid.peft; AdaptedAttention is the layer. Importing the package registers the method under PeftType.ADAPTION_PROMPT.

Paper

Zhang, Renrui, et al. "LLaMA-Adapter: Efficient Fine-tuning of Language Models with Zero-init Attention." [arXiv:2303.16199](https://arxiv.org/abs/2303.16199), 2023.

Overview

LLaMA-Adapter (Zhang et al., 2023, arXiv:2303.16199) freezes the model and gives each of the top adapter_layers attention layers adapter_len learned prompt vectors. The layer's queries attend to keys and values projected from the prompt, and that attention output is added to the layer's own, scaled by a gate that starts at zero, so the adapted model starts as the base.

Classes