Concepts / Prompt Engineering Versus Finetuning

Prompt Engineering Versus Finetuning

Hard prompts are the ordinary text prompts a person writes.

  • Programming

Steering a Model Without Retraining Everything

Suppose you have a pretrained language model and you want it to behave differently on one particular job. One option is to retrain every parameter in the model. That works, but it is expensive. Parameter-efficient finetuning, usually shortened to PEFT, asks a narrower question: how little trainable machinery can we add and still steer the model?

This section surveys the main answers the field has settled into. Before reading on, it helps to make a prediction about the first of those answers. The word adapter is a hint, so think about what an adapter could plausibly touch.

What do you think happens?

When a PEFT method is described as an adapter method, which part of the system does it change: the input text, or the model's own structure?

  • The input text only

  • The model's own structure, by attaching extra parameters

Reveal answer
Answer:

The model's own structure, by attaching extra parameters

Adapter-based methods do not reach into the input. They add modules or parameters to the model weights, and the adaptation lives in those attached parameters.

The Two PEFT Families

PEFT methods in this section fall into two buckets. Adapter-based methods add modules or parameters to the model weights. Soft prompt-based methods add special trainable tokens to the input. Every technique discussed in this section belongs to one of these two branches, so the split is the first thing to hold onto.

PEFT methodsAdapter-based methodsadd modules or parametersto weightsLoRAPrefix-tuningSoft prompt-basedmethodsadd trainable tokens toinputHoulsby et al. (2019)Prompt tuningP-Tuningbranchbranchmethodmethodtechniquetechniquetechnique
How do the PEFT methods split into the adapter branch and the soft prompt branch, and which named techniques belong to each?

The diagram shows the branches and the techniques named in the reading. It does not list every method that appears in the section's comparison table. The reading also says that many PEFT frameworks implement these techniques out of the box, so in practice you usually choose among them rather than building them from scratch.

Adapters Change the Model's Structure

The word adapter is a useful handle. An adapter-based method does not reach into the input at all. Instead, it changes the model's own structure by attaching extra parameters, and the adaptation lives in those attached parameters. The original model's parameters are the foundation, and the new parameters are where the task-specific change is stored.

The reading gives Houlsby et al. (2019) as an example of an adapter method that set this pattern. The source does not describe that method's internal design, so this article will not describe it either. What we can say is that the attached modules sit alongside the model weights, and the adaptation is stored there rather than in the input.

Soft Prompts Change the Input

Soft prompt-based methods make their change on the input side rather than inside the model's parameters. The model still receives a sequence of tokens, but some of those tokens are special ones whose values were learned during tuning. They are called soft prompts because, like ordinary prompts, they guide the model's behavior. The difference lies in what they are made of.

The reading also describes soft prompting as a kind of crossover between prompt engineering and finetuning. A figure in the source shows that hard prompts and soft prompts can be combined to change a model's behaviors. So the two are not always rival choices. In some settings they work together.

Hard Prompts Versus Soft Prompts

The source separates soft prompts from hard prompts along two lines. Hard prompts are the ordinary text prompts a person writes. Soft prompts are the learned tokens described above. The two properties the source emphasizes are readability and form, and a third property, trainability, follows from them. The comparison below lays out how the two differ.

Human-readableNot human-readableDiscretewords written by a personContinuous vectorslearned numeric valuesStaticnot updated bybackpropagationOptimizableupdated throughbackpropagation
How do hard and soft prompts differ in whether a human can read them, what form they take, and whether gradients can update them?

Read the columns row by row. Readability asks whether a person can look at the prompt and understand it, and hard prompts pass while soft prompts do not. Form asks what the prompt is made of: discrete words for hard prompts, continuous vectors for soft prompts. Trainability asks whether tuning can change the prompt, and that is the key distinction. Hard prompts are static, while soft prompts can be optimized through backpropagation.

Where Soft Prompt Techniques Insert Their Tokens

Soft prompt tuning is a subfield with several techniques whose names sound alike, which can be confusing. The source lists prefix-tuning, P-Tuning, and prompt tuning. They differ mainly in where the soft prompts are inserted, and that location is the most useful thing to remember when telling them apart.

  • Prefix-tuning prepends soft prompt tokens to the input at every transformer layer.
  • Prompt tuning prepends soft prompt tokens only to the embedded input.
  • P-Tuning belongs to the same soft prompt family, but the source does not describe a location for it. It is distinguished from the other two by its own design, not by an insertion point stated in the source.
Input tokensEmbedded inputTransformer layer 1Transformer layer 2Transformer layer NOutputPrompt tuning tokensinserted at embedded inputonlyPrefix-tuning tokensinserted at every layerAdapter modulesattached to model weightsembeddingnextnextnextnextjoinsjoinsjoinsjoinsattaches
At which points in the forward pass do the trainable tokens or adapter modules enter, and which parts of the existing model do they touch?

The diagram is a generated illustration of the source's statements, so read it as a map of insertion points rather than a claim about every implementation. Prompt tuning acts once, at the embedded input. Prefix-tuning acts at each layer. Adapter modules are attached to the model's weights, which is a different kind of change from adding tokens to the stream at all.

Tracing One Task Through Each Approach

Worked example

Locating the adaptation for a single task

A team has a pretrained language model and wants it to behave differently on one specific job. They compare three options: an adapter-based method, prompt tuning, and prefix-tuning. For each, decide where the task-specific learned values live and what part of the model they touch.

  1. 1
    Identify the family

    The adapter-based option belongs to the adapter branch, since it adds modules or parameters to the model weights. Prompt tuning and prefix-tuning both belong to the soft prompt branch, since they add trainable tokens to the input.

  2. 2
    Locate the adaptation for the adapter option

    The learned values live in the attached parameters. The input text is not altered by the adapter approach, so the adaptation is not stored in any token.

  3. 3
    Locate the adaptation for prompt tuning

    The learned values are soft prompt tokens inserted only at the embedded input. The model's layers receive those tokens once, at the start of processing.

  4. 4
    Locate the adaptation for prefix-tuning

    The learned soft prompt tokens are inserted at every transformer layer, so they touch each layer rather than only the embedded input.

  5. 5
    Compare the touch points

    Prompt tuning touches one place, prefix-tuning touches every layer, and the adapter option touches the model's weights through attached modules. Only the soft prompt options change what enters the input, and of those, only prefix-tuning reaches every layer.

Result

The adapter option stores its adaptation in attached parameters. Prompt tuning stores it in tokens at the embedded input. Prefix-tuning stores it in tokens inserted at every transformer layer.

Reading the Popularity Evidence

Which PEFT methods do practitioners actually use? The source answers with a proxy. Its author analyzed over 1,000 open issues on the GitHub repository huggingface/peft in October 2024. The assumption is that people who use a technique are more likely to report issues or ask questions about it. For P-Tuning, the search covered both 'p_tuning' and 'p tuning' to account for different spellings.

A bar chart in the source reports the number of issues for each technique, and its caption describes this count as a proxy for popularity. The chart is a plot of counts rather than a diagram with parts to label, so the useful content is the conclusion the source draws from it. The source states that LoRA dominates. It also says that soft prompts are less common, but that interest in them appears to be growing among people who want more customization than prompt engineering provides and who do not want to invest in finetuning.

The source uses this evidence to motivate the next section. Because LoRA is so widely used, the following section explains how LoRA works and how it addresses the challenge posed by early adapter-based methods. The source adds that the deep dive should give you a framework for exploring other finetuning methods even if you never use LoRA itself.

Mistakes When Comparing PEFT Methods

  • Common mistake

    Treating all soft prompt techniques as inserting tokens in the same place

    What it looks like

    Assuming prefix-tuning and prompt tuning both add tokens only to the embedded input.

    Why it fails

    The source says they differ mainly in insertion location: prefix-tuning inserts at every transformer layer, while prompt tuning inserts only at the embedded input.

    Do this instead

    Remember insertion location as the key distinguishing feature when you compare soft prompt techniques.

  • Common mistake

    Describing a P-Tuning insertion point as if the source stated one

    What it looks like

    Saying P-Tuning inserts its tokens at every layer because it sounds like prefix-tuning.

    Why it fails

    The source does not detail the internals of P-Tuning and does not give it a location.

    Do this instead

    Say that P-Tuning belongs to the soft prompt family and is distinguished by its own design, which the source does not describe.

  • Common mistake

    Believing a hard prompt can be updated by backpropagation

    What it looks like

    Assuming that a written instruction can be tuned by gradients the way soft prompt vectors can.

    Why it fails

    Hard prompts are discrete and static, while soft prompts are continuous vectors that can be optimized through backpropagation.

    Do this instead

    Use trainability to separate the two: only soft prompts are learned by backpropagation.

  • Common mistake

    Ranking methods by issue counts and calling the top one the best

    What it looks like

    Concluding that LoRA performs best on every task because it has the most issues on the repository.

    Why it fails

    The source states that issue-based popularity does not establish which method performs best on a given task.

    Do this instead

    Treat popularity as evidence of usage, and evaluate methods on your own task to judge performance.

Checking Your Understanding

EASY

A colleague says that prompt tuning and prefix-tuning are the same technique because both add trainable tokens. For each of the two techniques, state where its soft prompt tokens are inserted, then explain why the colleague's claim is incomplete.

Hints
  • Look for the phrase insertion location in the comparison of prefix-tuning and prompt tuning.
  • Both techniques add trainable tokens, but compare the points at which those tokens enter the model.
MEDIUM

Using the hard-versus-soft comparison, describe a case where a person could read and edit a prompt directly, and a case where a learned soft prompt would be needed instead. Name the property from the comparison that separates the two cases.

Hints
  • Think about readability and whether the prompt is written by a person or learned through tuning.
  • The property that separates the two is trainability.

Key Takeaways

  • PEFT methods split into two families: adapter-based methods, which add modules or parameters to the model weights, and soft prompt-based methods, which add trainable tokens to the input.
  • Hard prompts are human-readable, discrete, and static, while soft prompts are continuous vectors that are not human-readable and can be optimized through backpropagation.
  • Prefix-tuning inserts soft prompt tokens at every transformer layer, prompt tuning inserts them only at the embedded input, and P-Tuning's location is not described in the source.
  • LoRA is the most popular adapter-based method according to issue-based evidence, but issue counts do not establish which method performs best on a given task.

More concepts starting with P