Repository navigation
GRPO: score old and reference logprobs over the truncated sampling support when opted in - #13900
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 |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
Member
Author
|
pre-commit.ci run |
1 similar comment
Member
Author
|
pre-commit.ci run |
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 19, 2026
…-GaLore offload, GRPO truncated support, CP save on transformers 4.x (unslothai#14226) ## Summary Fixes for four problems found when re-reviewing recently merged PRs. Each one still reproduced on main, and each has a test that fails on main and passes here. Default configs are unchanged. 1. **Fused LoRA with dropout or a `lora_B` bias (unslothai#13898).** - **Graph breaks:** before torch 2.11 the fused LoRA function runs with Dynamo disabled. unslothai#13898 moved dropout and bias projections from PEFT onto that path, so compiling them hit a graph break each and `fullgraph = True` failed. While compiling on torch < 2.11 those projections now run PEFT again, as they did before unslothai#13898. Plain LoRA, eager fusion and torch 2.11+ are unchanged. - **Memory:** on 4-bit weights the dropout and bias path dequantized into the shared global buffer, so one dense weight stayed resident; PEFT never keeps one. That path now dequantizes into a temporary, including in eval, where dropout is a no-op. `matmul_lora` gets a `use_global_buffer` keyword, default `True`, so every other caller is unchanged. 2. **Q-GaLore optimizer state offload (unslothai#14025).** If a step pre-hook registered after the offloader created a gradient, that parameter's state stayed on CPU and the step crashed with a device mismatch. State is now restored inside the step, after every pre-hook has run. 3. **GRPO truncated-support scoring (unslothai#13900).** This needs the scored policy to be the sampler. That is not the case with a reference model (`beta != 0`), with rollouts reused across optimizer steps, or when vLLM weight sync is skipped (LoRA or quantized without `fast_inference`). In those cases the new policy's implied probabilities did not sum to 1, which made the PPO ratio wrong. Those cases now warn once and score the full vocabulary; on-policy runs with `beta = 0` keep the feature. 4. **Context-parallel save on transformers 4.x (unslothai#14028).** With `SHARDED_STATE_DICT` the sharded save wrote no adapter, and with `FULL_STATE_DICT` it gathered the frozen base weights. The save now gathers only the adapter and rank 0 writes it. Transformers 5 is unchanged. The routing replay part of the same review is in unslothai/unsloth-zoo#1874. ## Tests | Test | main | this PR | |---|---|---| | `tests/test_fused_lora_dropout_bias_compile_memory.py` | 18 failed | 18 passed | | `tests/test_fused_lora_dropout_bias.py` (eval keeps the dropout route) | failed | passed | | `tests/test_optimizer_state_offload.py` | 2 failed | 38 passed | | `tests/test_grpo_truncated_support_policy_gate.py` | 4 failed | passed | | `tests/test_context_parallel_fsdp2_save_gloo.py` (transformers 4.57.6, 2 gloo ranks) | 2 failed | passed | unslothai#13898 base vs head, Llama block at 4096 / 11008, 3 arms. "PEFT" is main with fused dropout and bias turned off, i.e. the routing before unslothai#13898: | torch | Graph breaks on dropout / bias configs (main / this PR) | 4-bit dropout / bias peak MiB (main / PEFT / this PR) | |---|---|---| | 2.10, T4 | 6 / 0, fullgraph fails on main | 293.0 to 294.3 / 209.8 to 211.0 / 207.0 to 208.3 | | 2.13, B200 | 0 / 0 | 340.6 to 341.1 / 257.5 to 257.7 / 254.6 to 255.1 | | 2.14, T4 | 0 / 0 | 292.9 to 293.3 / 209.7 to 210.0 / 206.9 to 207.3 | 16-bit and default configs give the same memory and graph break counts in all three arms. Plain LoRA on 2.10 has 6 graph breaks in every arm; that is older than unslothai#13898 and is left as is. ## Not covered here - Torch 2.11 and 2.12 were not run. Items 2 to 4 ran on torch 2.13 only. - No full-model training or throughput run; the unslothai#13898 memory numbers are per block. - No vLLM end-to-end GRPO run, no NCCL multi-GPU save, no `push_to_hub`. - Off-policy truncated support falls back to full-vocabulary scoring rather than the sampler's kept token set.
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.
Companion to unslothai/unsloth-zoo#1797, which adds UNSLOTH_GRPO_TRUNCATED_SUPPORT. When the option is set and rollouts use top_p, top_k or min_p, the old and reference logprobs are scored over the same kept set as the loss, so the PPO ratio and the KL term compare like with like. The trainer is marked so the zoo loss can check that both sides agree. With an older unsloth_zoo, or with the option unset, nothing changes.