Tutorials

When and How to Train on Completions Only When Fine-tuning LLMs

When and How to Train on Completions Only When Fine-tuning LLMs

When and How to Train on Completions Only When Fine-tuning LLMs

Nov 3, 2025

5 min read

When fine-tuning large language models for instruction-following or conversational tasks, a critical decision is whether to compute the loss on the entire sequence or only on the model's responses. Training on "completions only" (also called response-only or target-only training) means masking the loss calculation for input tokens (user prompts, instructions) and only updating model weights based on the desired outputs. This seemingly small implementation detail can meaningfully impact your model's performance.

Why It Works & Results

The QLoRA paper provides empirical evidence that training on completions only improves model performance. In their experiments (Table 10 of the paper), they found that across four different instruction-tuning datasets, models trained only on target tokens consistently outperformed those trained on both source and target:

  • Unnatural Instructions: 38.0 vs 36.2 MMLU score (~5% improvement)

  • Alpaca: 39.0 vs 38.1 MMLU score (~2% improvement)

  • FLAN v2: 42.9 vs 42.0 MMLU score (~2% improvement)

  • Chip2: 34.5 vs 33.7 MMLU score (~2% improvement)

The intuition behind this approach is straightforward: we want the model to learn to generate high-quality responses, not to predict user inputs. By masking the loss on input tokens, we focus the learning signal entirely on producing the correct completion patterns. This is particularly important for multi-turn conversations where the model shouldn't be learning to predict user behavior but rather to respond appropriately.

The paper notes this is especially beneficial for conversational fine-tuning, where the distinction between what the model should learn to generate (assistant responses) versus what it should condition on (user inputs) is clearest.

Training on Completions Only with Unsloth

Unsloth makes it easy to implement completion-only training. It exposes a wrapper for the trainer called train_on_responses_only. To use it you have to specify what the beginning of the instruction part and response part is per the model template. Here's an example for the Llama 3.x / 4 family of models:

from unsloth.chat_templates import train_on_responses_only
trainer = train_on_responses_only(
    trainer,
    instruction_part = "<|start_header_id|>user<|end_header_id|>\n\n",
    response_part = "<|start_header_id|>assistant<|end_header_id|>\n\n",
)


And here's the same example with Gemma 2 & 3 models:

from unsloth.chat_templates import train_on_responses_only
trainer = train_on_responses_only(
    trainer,
    instruction_part = "<start_of_turn>user\n",
    response_part = "<start_of_turn>model\n",
)


Once you wrap the trainer like so — you can use it as you normally would.

Training on Completions Only with TRL

To train on completion only, use a prompt-completion dataset. By default, the trainer computes the loss on the completion tokens only, ignoring the prompt tokens. If you want to train on the full sequence, set completion_only_loss=False in the SFTConfig.

training_args = SFTConfig(assistant_only_loss=True)

See more details in the official TRL docs.

Training on Completions Only with Datawizz

Datawizz makes it simple to test out training on completions only. When you configure a model training on Datawizz, simply check the "Train on Responses Only" box to activate this feature.

Better yet - if you want to test the impact in your specific use case, make sure to train two models (one with it turned off and one with it turned on) and run an evaluation to benchmark them.

In this post

In this post

In this post