Raise a clear error when GKD student and teacher vocab sizes differ#6252
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
9e2c4d7 to
408920f
Compare
kashif
approved these changes
Jul 2, 2026
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.
What does this PR do?
White-box logit KD in
GKDTrainerrequires the student and teacher to sharevocab_size. When they differ, training failed with a cryptic broadcast error inkl_div(e.g.Qwen2.5-0.5Bis 151936 butQwen2.5-7Bis 152064).GKDTrainernow validates this at init and raises a clear error pointing to GOLD for cross-tokenizer distillation.DistillationTraineralready handles this by resizing the teacher embeddings.Before submitting
AI writing disclosure
Note
Low Risk
Init-time validation only; no change to training logic when vocab sizes already match.
Overview
GKDTrainer now checks that the student and teacher share the same
vocab_sizeright after the teacher is loaded, instead of failing later with an obscurekl_divbroadcast error when logits shapes disagree.On mismatch it raises a
ValueErrorthat states both sizes, notes that GKD needs a shared vocabulary for full next-token distributions, and suggests matching teachers or GOLD for cross-tokenizer distillation (unlike DistillationTrainer, which can resize teacher embeddings).Reviewed by Cursor Bugbot for commit 408920f. Bugbot is set up for automated code reviews on this repo. Configure here.