You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wire the chunked generalized JSD into the GKD path #11554
unsloth_zoo.rl_replacements.distillation_chunked_jsd is merged (unslothai/unsloth-zoo#1310) and registered in RL_REPLACEMENTS, but nothing in unsloth/ references it, and there are no RL_* entries keyed gkd_trainer or distillation_trainer. It is dead code today.
So the generated GKD trainer still materialises a full (batch, seq, vocab) logits tensor for both the student and the teacher. On a large vocabulary that term dominates peak memory: gemma-4's is 262144 wide, which is what makes distilling it expensive, rather than its parameter count.
Work:
Add RL_PRE_ITEMS / RL_FUNCTIONS entries keyed gkd_trainer so the generated compute_loss routes through the chunked helper instead of the dense one.
Route hidden states through UNSLOTH_RETURN_HIDDEN_STATES and the __UNSLOTH_SUPPORTS_RETURN_HIDDEN_STATES__ capability marker rather than TRL's _get_last_hidden_state, which calls base_model(...).last_hidden_state and does not match how Unsloth's fast forwards return hidden states.
Guard the case where a pre-quantized checkpoint has a Linear4bit output head, since the chunked projection reads lm_head.weight as a dense [V, H] tensor. Unsloth's own 4-bit loader skips lm_head, but a third-party checkpoint loaded outside it may not.
Verify chunked equals unchunked in both value and gradients, and prove the chunk loop is not retaining each chunk's graph with an allocation trace rather than by reading the code.
The peak-memory claim cannot be demonstrated on a B200, so the before/after needs a small-card leg.
Would like to take this if it's not already spoken for — is anyone working on it? I don't want to duplicate effort if the wiring is already in progress somewhere.
Activity
aran-yogesh commentedon Sep 22, 2026
Would like to take this if it's not already spoken for — is anyone working on it? I don't want to duplicate effort if the wiring is already in progress somewhere.