Repository navigation
fix: use the shifted input form in training session loss input examples - #6584
Conversation
There was a problem hiding this comment.
🤖 AI code review
Documentation-only PR that corrects the weights mask examples in the training_session README and the length-mismatch error hint in _utils.py so they align with target_tokens = tokens[1:] + [pad]. Since weights[i] scores target_tokens[i] (the token after position i), the mask should start at prompt_len - 1 and zero the trailing pad position. The math checks out (total length still equals len(tokens)), all four README occurrences and the error text are updated consistently, and no test asserts on the changed error substring. The change is clean; no issues found.
Reviewed commit ab90724. Automated review; verify before acting.
ab90724 to
88482b6
Compare
There was a problem hiding this comment.
🤖 AI code review
This PR updates documentation (README and module docstring) and one validation error-message hint in the training_session module to use the "shifted" loss-input form: model_input=tokens[:-1], target_tokens=tokens[1:], and weights=[0.0]*(prompt_len-1)+[1.0]*response_len, removing the pad target. The arithmetic across all updated examples is internally consistent (every per-token list ends up length len(tokens)-1, matching the shortened model_input), and the change is docs/error-text only with no behaviour change. My only concern is that some surrounding prose still describes the inputs as "full-sequence," which now contradicts the shifted examples.
Reviewed commit 88482b6. Automated review; verify before acting.
| @@ -546,9 +546,9 @@ Every datum needs loss inputs, and which keys are required depends on the loss: | |||
| | `ppo` / `importance_sampling` / `cispo` | `target_tokens`, `weights`, `logprobs`, `advantages` | | |||
|
|
|||
| Each is **full-sequence**: one value per token of the datum, prompt included. | |||
There was a problem hiding this comment.
🟠 Medium: This prose still describes the loss inputs as "full-sequence: one value per token of the datum, prompt included," but the examples below now use the shifted form (model_input=tokens[:-1], target_tokens=tokens[1:]), so each per-token list is len(tokens) - 1 long, not the full sequence. The same stale "full-sequence" wording also appears at line 595-596 ("Giving response-length values instead of full-sequence ones raises too"). You already updated the make_datum docstring at line 561 away from "full-sequence," so these two spots look like an oversight and now contradict the shifted examples they introduce. Please reconcile the terminology so the narrative matches the code.
88482b6 to
b8bb6db
Compare
There was a problem hiding this comment.
🤖 AI code review
Docs/error-text only PR that switches all training-session loss-input examples to the shifted form (model_input=tokens[:-1], target_tokens=tokens[1:], weights=[0.0]*(prompt_len-1)+[1.0]*response_len), removing the pad target and the off-by-one in the masked-weights examples. The arithmetic is consistent across the README examples, the __init__.py docstring and the _validate_datum_lengths error hint (each per-token list is now len(tokens)-1). No behaviour change. One minor stale comment left behind.
Reviewed commit b8bb6db. Automated review; verify before acting.
| @@ -37,12 +37,12 @@ | |||
| # per token of the datum. | |||
There was a problem hiding this comment.
🟡 Low: The surrounding comment still reads "one value per token of the datum", but after this change the per-token inputs are one per model_input token (tokens[:-1]), not per full tokens. Since the point of this PR is to clarify exactly that distinction (the README now says "one value per model_input token"), consider updating this comment too so it stays consistent with the example it describes.
b8bb6db to
0079dba
Compare
There was a problem hiding this comment.
🤖 AI code review
This PR updates documentation (README, module docstring) and one validation error message in the training session to use the "shifted" loss-input form (model_input=tokens[:-1], target_tokens=tokens[1:], weights/advantages of length len(tokens)-1), replacing the previous full-sequence examples that padded the last target and mislabeled prompt/response boundaries. It is docs and error-text only, with no behavior change. I verified the arithmetic is internally consistent across every changed example (e.g. (prompt_len - 1) + response_len == len(tokens) - 1), that the length-validation set in _utils.py still accepts these lengths, and that no stale old-form examples remain outside the diff. The change looks correct and clean; no issues found.
Reviewed commit 0079dba. Automated review; verify before acting.
weights[i]scorestarget_tokens[i], the token after positioni. The loss input examples in the training session README and module docstring fed the full sequence and padded the last target with0. Some masked fromprompt_len, which skipped the first response token, and the quickstart gave the pad target weight1, which trained the model to predict the pad.All examples now use the shifted form:
model_input=tokens[:-1],target_tokens=tokens[1:], andweights=[0.0] * (prompt_len - 1) + [1.0] * (len(tokens) - prompt_len). Every per-token list is one shorter thantokens, and no pad target is needed. The length-mismatch error hint shows the same form. Docs and error text only. No behaviour change.Testing:
tests/unit/train/training_session, 826 passed. Each changed example passesbatch_to_datum_listinput validation.