Skip to content

GRPO: score old and reference logprobs over the truncated sampling support when opted in - #13900

Merged
danielhanchen merged 5 commits into
mainfrom
dh/vllm-truncated-support
Oct 16, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
dh/vllm-truncated-support

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-16T04:49:00.886228Z d969905 New commits
🔒 Security Review ⚠️ Failed 2026-10-15T17:53:39.954908Z 9676afa PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 9676afaf9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen

Copy link
Copy Markdown
Member Author

pre-commit.ci run

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

pre-commit.ci run

@danielhanchen
danielhanchen merged commit 65d1fdb into main Oct 16, 2026
@danielhanchen
danielhanchen deleted the dh/vllm-truncated-support branch October 16, 2026 14:18
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant