Repository navigation
GKD: never pass a zero generated-token count - #15328
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Oct 26, 2026
# Conflicts: # unsloth/models/rl_replacements.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #15222, which recounts GKD's
num_items_in_batchfrom the generated labels. Merge it after #15222; until then this branch also carries #15222's two commits.On TRL 1.7 and 1.8,
generate_on_policy_outputsmasks every token equal topad_token_id, EOS included when the tokenizer pads with EOS. A gradient accumulation window whose completions are all an immediate EOS therefore has zero supervised tokens, the recount returns 0, and TRL'sgeneralized_jsd_lossreturnsjsd.sum() / 0 = NaN(the dataset count used before #15222 was nonzero, so the loss was 0). Unsloth's chunked JSD divides the same way.This clamps the shared count to at least 1 (tensor or int). The window's JSD sum is 0 in that case, so the loss becomes 0 instead of NaN; any window with supervised tokens is unchanged.
It also adds
tests/python/test_gkd_generated_token_count.py, which rewrites both TRLtraining_steplayouts and the installed TRL's own source and checks:num_items_in_batchequals the generated label count for on-policy and seq_kd, whatever the dataset answers were, including a short final window.lmbda=0.5) draws the same random numbers as stock TRL.training_stepis left alone.generalized_jsd_loss, all labels maskednum_items_in_batch = 0(#15222 alone)nannum_items_in_batch = 1(this PR)0.0num_items_in_batch = 4(before #15222)0.0