Home Knowledge Base Prompt Tuning and Prefix Tuning

Prompt Tuning and Prefix Tuning are the parameter-efficient fine-tuning methods that prepend small sequences of learnable "soft" token embeddings to the input or intermediate layers — adapting large pretrained models to downstream tasks without updating any model weights, instead learning a compact set of "virtual tokens" whose embeddings are optimized through backpropagation to steer the frozen model's behavior.

Prompt Tuning (Lester et al., 2021)

class SoftPrompt(nn.Module):
    def __init__(self, n_tokens=20, d_model=1024):
        super().__init__()
        # k trainable embeddings (random or vocabulary-initialized)
        self.prompt = nn.Parameter(torch.randn(n_tokens, d_model))

    def forward(self, input_ids, model):
        input_embeds = model.embed_tokens(input_ids)  # [B, L, D]
        prompt = self.prompt.unsqueeze(0).expand(B, -1, -1)  # [B, k, D]
        full_input = torch.cat([prompt, input_embeds], dim=1)  # [B, k+L, D]
        return model(inputs_embeds=full_input)

Prefix Tuning (Li and Liang, 2021)

For each layer l:
  K_l = [P_k^l ; W_k^l · x]     # prefix keys prepended
  V_l = [P_v^l ; W_v^l · x]     # prefix values prepended
  Attention uses augmented K_l, V_l → prefix influences all positions

P-Tuning v1 and v2

Comparison of PEFT Methods

MethodWhere TokensParamsInference Overhead
Prompt tuningInput onlyk × dNone
Prefix tuningAll layers (KV)2 × L × k × dMinor (KV cache)
P-Tuning v2All layersSimilar to prefixMinor
LoRAWeight matricesr × (d_in + d_out)None (merged)
AdapterAfter FFN/Attn2 × d_adapter × dMinor

Advantages and Limitations

Applications

Prompt tuning and prefix tuning are the extreme lightweight end of the parameter-efficient fine-tuning spectrum — by demonstrating that as few as 20 virtual tokens can adapt a frozen trillion-parameter model to new tasks, these methods reveal that pretrained LLMs encode broad latent capabilities that merely need steering, not retraining, offering a glimpse of a future where one set of model weights serves millions of personalized use cases through tiny learned steering vectors rather than millions of separate fine-tuned models.

prompt tuningprefix tuningsoft promptlearnable promptp tuningprompt based fine tuning

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.