Repository navigation
Pass GradScaler to GKD chunked JSD with an older-Zoo fallback - #13190
Conversation
Co-authored-by: Codex <[email protected]>
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. |
|
Under FP16, GKD's chunked JSD now receives the trainer's GradScaler, so gradients computed during the forward pass are scaled before they can underflow. This needs unslothai/unsloth-zoo#1659. With an Unsloth Zoo that has no What changed
Tested on Until unslothai/unsloth-zoo#1659 ships and the Fork CI: Etherll#225 (running). |
|
@codex review |
1 similar comment
|
@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". |
Pass the trainer's active GradScaler to GKD's chunked generalized JSD so FP16 gradients are scaled before the loss precomputes them in its forward pass. Without this, a finite loss can accompany zero LoRA gradients and no adapter update; the later outer
scaler.scale(loss).backward()cannot recover gradients that have already underflowed.Companion loss implementation: unslothai/unsloth-zoo#1659. Merge and release that Zoo change first, then merge this caller update.
When scaling is enabled but the installed Zoo has no
scalerparameter, return through the existing TRL loss fallback before running either model forward. That preserves correct scaling with older Zoo, at the cost of its ordinary full-logits memory use. With an absent or disabled scaler, the existing chunked call remains compatible with old Zoo. No dependency version bump is required for compatibility.Validation
Rebased onto
4527f330.compute_loss, this production helper, and the installed TRL loss/fallback. All six combinations of old/current Zoo and enabled/disabled/absent scaler pass loss and gradient parity. It also verifies that the old-Zoo fallback takes only one student forward and restores the hidden-state environment flag. These local tests are outside this production-only diff.uvx --from ruff==0.15.12 ruff check unsloth/models/rl_replacements.pyandgit diff HEAD^ HEAD --check: passed.CPU validation commands (the last two files are local-only checks):
The command runs from the Zoo checkout with both source repositories on
PYTHONPATH. Full GKDTrainer training and distributed training have not been validated; the local complete trainer-suite import was blocked by environment/package setup, so the caller checks execute the generated production source directly. The CUDA checks are model forward/backward/optimizer comparisons, not a convergence claim.Open-PR searches for GKD, JSD, and GradScaler found no overlapping JSD repair. #13152 fixes scaler attachment for fused cross entropy under plain
transformers.Trainer; it does not pass a scaler to GKD's chunked JSD.Only production code is included. AI assistance was used to prepare the change and run the local validation.