๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #322

Prompt Tuning

Prompt tuning is prefix tuning's simpler cousin: instead of adding trainable vectors at every layer, add them only at the input embedding layer, once โ€” the leanest, simplest PEFT method covered in this category.

The Core Idea

\[ \text{input} = [\mathbf{p}_1, \mathbf{p}_2, \ldots, \mathbf{p}_L,\ \mathbf{e}_1, \mathbf{e}_2, \ldots, \mathbf{e}_n] \]

\(\mathbf{p}_1,\ldots,\mathbf{p}_L\) are trainable "soft prompt" embedding vectors, prepended directly to the sequence of real token embeddings \(\mathbf{e}_1,\ldots,\mathbf{e}_n\). These soft prompt vectors then flow through the entire frozen model exactly like any other token embedding would โ€” no special mechanism is needed elsewhere in the model.

Prefix Tuning vs Prompt Tuning โ€” Direct Comparison

Prefix TuningPrompt Tuning
Where trainable vectors are addedKey/value pairs at every attention layerOnly at the input embedding layer, once
Number of trainable parameter setsOne set per layerJust one set, total
Trainable parameter countHigher (scales with number of layers)Lower (independent of model depth)
Typical performanceOften slightly stronger, especially on smaller base modelsSimpler, and increasingly competitive as base model scale grows very large

Why Prompt Tuning Becomes More Competitive at Larger Scale

A key empirical finding: as the underlying pretrained model gets larger, the performance gap between prompt tuning and full fine-tuning (or even prefix tuning) tends to shrink substantially โ€” a very large, capable base model apparently needs comparatively little steering to adapt well, making prompt tuning's minimal parameter footprint an increasingly attractive tradeoff specifically for the largest modern LLMs.

Code

from peft import PromptTuningConfig, get_peft_model
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("gpt2")

prompt_config = PromptTuningConfig(
    task_type="CAUSAL_LM",
    num_virtual_tokens=20   # 20 trainable soft-prompt vectors, added ONCE at the input
)
peft_model = get_peft_model(model, prompt_config)
peft_model.print_trainable_parameters()
# trainable params are even fewer than prefix tuning's, since there's only ONE set, not one per layer

Common Mistakes

  • Assuming prompt tuning is always weaker than prefix tuning regardless of model scale โ€” the performance gap narrows significantly, and sometimes closes entirely, on very large base models.
  • Confusing prompt tuning's trainable embedding vectors with discrete prompt engineering (choosing better natural-language wording) โ€” prompt tuning's vectors are continuous, learned parameters with no corresponding actual words, a fundamentally different technique from writing better text prompts.

Interview Relevance

Q: "Why does prompt tuning have far fewer trainable parameters than prefix tuning, even though both prepend trainable vectors?" Prefix tuning adds a separate set of trainable key/value vectors at every attention layer, so its parameter count scales with model depth. Prompt tuning adds trainable vectors only once, at the input embedding layer โ€” those same vectors then pass through every subsequent frozen layer naturally, requiring only one set of parameters regardless of how many layers the model has.

Practice Question

Why might prompt tuning's advantage narrow specifically as the base model gets larger, rather than staying constant across model sizes?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Prompt Tuning โ€“ FAQs

Quick answers about learning Prompt Tuning in Deep Learning.

This free note from CodingNow 2.0 explains Prompt Tuning in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Prompt Tuning, is 100% free with no signup required.
With focused practice, most students grasp Prompt Tuning in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now