The useful part, up front

What you’ll take away

  • Ignoring a prompt target does not automatically remove prompt context from the model.
  • Next-token alignment determines which prediction each retained label actually scores.
  • The selected-target denominator matters as much as the masked loss terms.
  • Assistant roles and prompt-completion boundaries can select different regions of a multi-turn conversation.
  • Compare losses under the same target population and weighting, then evaluate generated answers separately.
01

Which part of the conversation is being graded?

A training example contains a question and an answer. Should the model receive a training penalty for predicting the question's words, the answer's words, or both? That choice changes what the reported loss summarizes. It does not require removing the question from the example. The model can still read the question as context while the training objective scores only its assistant reply. TRL's supervised fine-tuning documentation provides an assistant-only loss option for conversational data and a separate completion-only option for prompt-completion data. [1]

The distinction is easy to miss when a dashboard shows one small loss number. We will use two invented probability tables for the same short sequence. One table looks better when all six target tokens are averaged; the other looks better when only the two answer targets are averaged. No training or model benchmark is performed here. The calculation uses ordinary unweighted next-token cross-entropy with natural logarithms and no label smoothing. Those assumptions let us isolate the effect of selecting targets. They also give a practical question to ask of any training log: which tokens contributed to this number, and what did the averaging rule count?

Three separate controls govern what training does. The comparison distinguishes context visibility, target scoring and parameter updates. They need separate configuration.
The comparison distinguishes context visibility, target scoring and parameter updates. They need separate configuration. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
02

Leaving a question ungraded does not hide it from the model

Picture a teacher reading a student's question and answer but grading only the answer. The question remains necessary for deciding whether the answer fits. In supervised language-model training, prompt tokens can similarly stay in the model's input while their own target positions are excluded from the loss. TRL's collator documentation shows input IDs, an attention mask and labels as separate outputs, and uses the label value -100 for targets excluded by the completion or assistant mask. [1] The labels decide what is scored; the input still supplies the conversation.

An attention mask answers another question: which available input positions can contribute through attention? A causal language model predicts from the permitted earlier context, so the prompt can influence the assistant response. [3][5] Setting an ignored target label does not automatically change that visibility. Nor does assistant-only loss identify a special set of assistant-only weights. Choosing which parameters are trainable is a separate configuration; the same trainer documentation discusses adapter training independently. [1] Keeping context, supervised targets and trainable parameters separate helps explain why an apparently small label change can alter the learning objective without deleting the prompt or selecting a different model architecture.

03

Match each prediction to the next token before applying the mask

Use this abstract seven-token sequence: BOS, P1, P2, P3, P4, A1, A2. BOS marks the beginning, P1 through P4 are prompt tokens, and A1 and A2 are assistant tokens. The prediction at BOS is compared with P1; the prediction at P1 is compared with P2; and so on. In particular, the prediction at P4 is compared with A1, while the prediction at A1 is compared with A2. There are six next-token targets. These symbols stand for token IDs, with no extra role markers, padding or end token in this small example.

If only the answer is scored, retain the A1 and A2 target terms. The prompt can still provide their earlier context. The model is not allowed to see A2 when predicting A2 simply because the full training sequence is stored in one array; causal attention restricts the visible history. [3] Some model interfaces perform the target shift internally. The cited Transformers GPT-2 interface explicitly documents that behavior. [5] Shifting labels manually and then using an interface that shifts them again would change which target matches each prediction. Inspect the actual input, labels and model contract together, rather than assuming that array positions alone reveal the intended prediction task.

Two answer targets remain after the next-token alignment. Original abstract sequence BOS, P1, P2, P3, P4, A1, A2. No extra role, end or padding tokens are included.
Original abstract sequence BOS, P1, P2, P3, P4, A1, A2. No extra role, end or padding tokens are included. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
04

A loss term measures the probability given to the required token

For the simple objective used here, a target token contributes minus the natural logarithm of the probability assigned to that token. Giving the required token probability 0.99 produces a small loss, about 0.01005. Probability 0.20 produces about 1.60944. The penalty is larger when the required token receives less probability. PyTorch documents cross-entropy in terms of logits and the corresponding normalized class probabilities; our table starts from probabilities only to make the arithmetic visible. [2] These probability values should not be confused with the raw logits expected by that API.

Call the first invented table A. At each of the four prompt targets, it gives the correct token probability 0.99. At each of the two assistant targets, it gives the correct token probability 0.20. Table B gives the prompt targets probability 0.50 and the assistant targets probability 0.60. Their per-target losses are therefore approximately 0.01005 and 1.60944 for A, versus 0.69315 and 0.51083 for B. The tables assign probabilities to the same required targets. We have not generated text from them or supplied distributions for every vocabulary item; the assigned target probabilities are enough to calculate these particular negative-log terms.

05

The lower overall loss can belong to the weaker answer probabilities

Average all six target terms for A. Four small prompt losses plus two larger answer losses total about 3.25908; divide by six to obtain 0.54318. For B, the corresponding total is about 3.79424, giving a mean of 0.63237. Under that all-target average, A has the lower loss. Its very strong probabilities on the four prompt targets outweigh its weaker probabilities on the two answer targets. Nothing about the text generation has changed; we are still evaluating the same two invented tables.

Now score only A1 and A2. A's mean is 1.60944, while B's is 0.51083. B has the lower assistant-target loss. The ordering reverses because the objective now focuses on the reply instead of including prompt reconstruction. This does not establish that assistant-only training is always superior. It establishes that the two averages measure different selected prediction tasks. When comparing training runs, retain the masking rule and evaluation target set beside the loss. A lower number under one rule cannot automatically be interpreted as better performance on the answer tokens measured by another rule. The calculation shows exactly where that inference can fail.

06

Ignored targets leave the denominator as well as the sum

For table A, the two assistant losses add to about 3.21888. Dividing by the two scored targets gives the correct assistant mean, 1.60944. If someone instead replaces the four prompt losses with zero but still divides by all six positions, the result is about 0.53648. That much smaller number is not the same mean. Its denominator counts four positions that supplied no loss. PyTorch's class-index ignore_index behavior averages over non-ignored targets in this unweighted case. [2] The averaging rule is as important as which terms were removed.

The value -100 is an instruction for the target-handling convention, not a token the model should produce and not a request to remove a vocabulary class from every prediction. The remaining assistant targets still compare their required token against the model's output distribution. [2][5] Also count how many valid targets remain after formatting and any length processing. If none remain, the selected-target average has a zero denominator. That is a data or configuration case to handle explicitly; it is not evidence of a perfect answer with zero error. A visible valid-target count makes that problem easier to detect than a loss value shown alone.

The same probability tables reverse order under two objectives. Original class-index, unweighted negative-log-loss calculation. Four prompt targets and two assistant targets; no model was trained.
Original class-index, unweighted negative-log-loss calculation. Four prompt targets and two assistant targets; no model was trained. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
07

A token average and a conversation average can disagree

Consider another small example using two conversations. The first has one scored answer token with loss 1.0. The second has three scored answer tokens, each with loss 0.2. Pool all four token losses and the mean is (1.0 + 0.2 + 0.2 + 0.2) divided by four, or 0.4. First average within each conversation and then average those two values, and the result is (1.0 + 0.2) divided by two, or 0.6. The same errors produced different summaries because the conversations received different weights.

Under the pooled token mean, the longer answer contributes three of the four terms. Under the mean of conversation means, each conversation gets half the total weight. Neither label should be shortened to simply average loss when the distinction matters. A training setup can deliberately choose a weighting scheme, but its evaluation and logging need to describe it. PyTorch offers mean, sum and unreduced outputs, while TRL describes its logged loss over non-masked tokens. [1][2] Keep the reduction boundary clear when combining batches or comparing runs with different answer lengths. A changed mix of short and long answers can change the aggregate even when the individual examples have not improved.

08

Assistant-only and completion-only select different regions

Imagine a conversation with four messages: user question U1, assistant reply R1, user follow-up U2 and assistant reply R2. Suppose a training example declares the first three messages as its prompt and R2 as its completion. Selecting all assistant replies in the whole conversation can include both R1 and R2. Selecting only the declared completion includes R2. Applying both selections keeps the assistant tokens that are also inside the completion, which in this example are the tokens of R2. The exact retained token boundaries still depend on the conversation format.

The distinction explains why a role name and a dataset boundary are not interchangeable. R1 is an assistant message, but it is also part of the later prompt. It can remain useful context even when the objective scores only R2. TRL v0.23.1 documents conversational assistant-only training, prompt-completion training and their compatibility. [1] Before choosing either option, identify the intended learning example: are earlier assistant turns also targets, or are they only the history for the final reply? Inspect the masks on an actual multi-turn record. A one-question, one-answer sample may look correct under several policies and fail to reveal the difference.

A prior assistant reply can also be part of the prompt. Declared example: prompt U1,R1,U2; completion R2. Actual control-token inclusion must be inspected in the prepared template.
Declared example: prompt U1,R1,U2; completion R2. Actual control-token inclusion must be inspected in the prepared template. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
09

Check the formatted tokens before starting a long training run

A chat template converts role-tagged messages into the tokenizable format expected by a model. Different models use different markers and arrangements. [4] That means an assistant mask must match the formatted tokens, not just a character range guessed from the original message text. The cited TRL version requires a template capable of returning an assistant-token mask through its generation markers. [1] A setting named assistant-only cannot establish that a particular template marks every intended reply correctly; inspecting a small prepared batch makes the boundary visible.

Look at the first and last scored token in each reply, whether earlier assistant turns are included, and whether padding or control markers have the intended labels. Also check the formatting path. The Transformers template guide warns about duplicating special tokens when formatted text is tokenized again; its documented approach disables additional special tokens in that separate tokenization step. For training on complete conversations, it usually recommends leaving the extra generation prompt off. [4] These checks catch different mistakes: wrong response boundaries, duplicated formatting and an unwanted start-of-next-reply marker. They are easier to diagnose before a long run than from an unexpected loss curve afterward.

10

Keep the scoring rule beside the learning result

A useful record states which targets are scored, how they are aligned with predictions, how their losses are weighted and averaged, and how many valid targets remain. Save the data format, template, tokenizer and model versions alongside the trainable-parameter choice. Then evaluate comparable runs on the same chosen targets and weighting rule. TRL's documentation distinguishes loss, token accuracy and other logged quantities, so keep their definitions rather than treating them as different names for answer quality. [1] A next-token objective measures probabilities assigned to provided targets; it does not by itself show how a complete generated answer will behave.

There is also a difference between scoring a supplied answer and asking the model to write one. During the next-token calculation, each target is evaluated using the provided earlier tokens as context. During generation, the model produces its own earlier tokens. If those differ, the later context differs too. This follows from the next-token setup [3]. A loss on the supplied answer and an assessment of the freely generated answer therefore observe different paths. Keeping both results can reveal a problem that either measurement alone leaves hidden.

The two invented tables leave a memorable check. A has all-target mean loss about 0.543, below B's 0.632, but its answer-only mean is about 1.609, above B's 0.511. The contradiction disappears once the graded tokens are named. Use that habit when reading a real training result: identify the population behind the number before deciding what improved. Generated answers still need task-appropriate evaluation, including whether they follow the question and preserve relevant conditions. Loss selection defines the learning signal. Clear target boundaries and honest evaluation make that signal interpretable instead of letting one smaller number stand in for every property of the assistant.

Keep the objective definition beside the loss curve. Proposed experiment record. A lower number is interpretable only with the scored population and normalization attached.
Proposed experiment record. A lower number is interpretable only with the scored population and normalization attached. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
Follow the evidence

Sources & further reading

Explore the references behind this guide. External pages may change after our review.

  1. SFT Trainer · Hugging Face
    Hugging Face TRL · Accessed 6 Nov 2026
  2. CrossEntropyLoss — PyTorch 2.15 documentation
    PyTorch · Accessed 6 Nov 2026
  3. Causal language modeling · Hugging Face
    Hugging Face Transformers · Accessed 6 Nov 2026
  4. Getting Started with Chat Templates for Text LLMs · Hugging Face
    Hugging Face Transformers · Accessed 6 Nov 2026
  5. OpenAI GPT2 · Hugging Face
    Hugging Face Transformers · Accessed 6 Nov 2026

Article updated 6 Nov 2026.

Found something we should revisit?

Good explanations get better with thoughtful feedback.

Suggest a correction