Skip to content

fix: use the shifted input form in training session loss input examples - #6584

Merged
jam-jee merged 1 commit into
aws:masterfrom
992X:training-session-weight-mask-fix
Nov 14, 2026
Merged

jam-jee merged 1 commit into
aws:masterfrom
992X:training-session-weight-mask-fix

Conversation

@992X

@992X 992X commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

weights[i] scores target_tokens[i], the token after position i. The loss input examples in the training session README and module docstring fed the full sequence and padded the last target with 0. Some masked from prompt_len, which skipped the first response token, and the quickstart gave the pad target weight 1, which trained the model to predict the pad.

All examples now use the shifted form: model_input=tokens[:-1], target_tokens=tokens[1:], and weights=[0.0] * (prompt_len - 1) + [1.0] * (len(tokens) - prompt_len). Every per-token list is one shorter than tokens, 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 passes batch_to_datum_list input validation.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

@992X
992X force-pushed the training-session-weight-mask-fix branch from ab90724 to 88482b6 Compare November 13, 2026 23:54
@992X 992X changed the title fix: align training session weight mask examples with target_tokens fix: use the shifted input form in training session loss input examples Nov 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

@992X
992X force-pushed the training-session-weight-mask-fix branch from 88482b6 to b8bb6db Compare November 14, 2026 00:17

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@992X
992X force-pushed the training-session-weight-mask-fix branch from b8bb6db to 0079dba Compare November 14, 2026 00:29

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

@haardm haardm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jam-jee
jam-jee merged commit 0318112 into aws:master Nov 14, 2026
25 of 27 checks passed

This branch was previously deployed

1 inactive deployment
auto-approve — 0079dba0 Deployed Nov 14, 2026 by 992X via wait-for-approval #2233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants