Repository navigation
Review follow-ups: fused LoRA dropout/bias under compile and 4-bit, Q-GaLore offload, GRPO truncated support, CP save on transformers 4.x - #14226
Conversation
…o global dequant scratch Before torch 2.11 the fused LoRA Functions run behind torch._dynamo.disable, so routing lora_dropout > 0 or lora_B bias projections into them while compiling replaced a PEFT forward Dynamo could trace with a graph break (fullgraph=True raised). Those configurations now stay on PEFT while compiling there; plain LoRA routing and eager fusion are unchanged. The dropout/bias path (forward, and the MLP down projection backward) also dequantized 4-bit weights into the per-device global scratch, keeping one dense weight resident that PEFT never held. It now dequantizes into a fresh tensor (matmul_lora gains use_global_buffer, default True, so the plain path keeps the scratch).
Unchunked weight_quant Q-GaLore selected the parameters to restore inside the offloader's step pre hook, before step pre hooks registered later had run. A later hook that created a missing gradient left that parameter's projector and moments on the host, and the step then crashed on a device mismatch. Select the active parameters from the step's closure instead, after every pre hook, as the chunked path already does.
…y is not the sampler UNSLOTH_GRPO_TRUNCATED_SUPPORT=1 rebuilds each policy's own top_k / top_p / min_p kept set and always keeps the scored token. With a reference model (beta != 0) or old logps from rollouts reused across optimizer steps, those sets differ from the sampler's, so the implied probabilities do not sum to 1 and the PPO ratio / KL inputs are wrong. Only bind the kept set while every scored policy is the rollout policy; otherwise warn once and score the full vocabulary, which the zoo loss then follows.
… save_model on transformers 4.x Clearing the installed parallelism config sent transformers 4.x save_model to its FSDP branch, which writes nothing for SHARDED_STATE_DICT and otherwise gathers the whole model, frozen base weights included, through Accelerator.get_state_dict. Keep the config and gather the way Unsloth's FSDP2 save does: trainable plus still-saved frozen parameters for an adapter, rank 0 writes, the other ranks skip _save. transformers 5 keeps the previous path.
…; truncated support refuses an unsynced vLLM sampler
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7af734b37b
ℹ️ 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".
| _support_mismatch = _unsloth_grpo_support_mismatch(self) if _support_kwargs else [] | ||
| if _support_mismatch: |
There was a problem hiding this comment.
Gate truncated support before the efficient early return
When UNSLOTH_GRPO_TRUNCATED_SUPPORT=1 is used with beta=0, num_iterations=1, and an unsynced vLLM sampler (for example LoRA or quantized training without fast_inference), this check is never reached: the current-policy call passes compute_efficient=True and returns at line 2532, while there is no reference/old-logprob call to enter this block. Consequently _unsloth_truncated_support_refused remains unset and the accumulated-loss path can continue truncated-support scoring after the policy diverges from the sampler, producing the unnormalized PPO ratios this change intends to prevent. Apply the mismatch gate on the efficient/current-policy path as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7a0f56d, with the zoo side in unslothai/unsloth-zoo#1874 (8dc935801). The compute_efficient branch now calls _unsloth_grpo_refuse_unscored_support before returning. It runs the same mismatch check (an unsynced vLLM sampler, beta != 0, reused rollouts) and marks the trainer refused. The zoo loss used to drop the kept set only when old / ref logps were present, so it now also honours that refusal and scores the full vocabulary. Tests: the unsloth helper test covers the unsynced sampler, a synced sampler and the opt-in being off; the zoo test checks that a refused trainer scores exactly the full-vocabulary logprobs.
…scored policy is not the sampler
|
@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". |
# Conflicts: # tests/test_optimizer_state_offload.py
…rs unsloth's refusal (unslothai#1874) ## Summary Two routing replay (#13916) problems that still reproduce on main: 1. **`probs_renorm` 0 / 0.** When every forced expert's probability underflows to 0, renormalising gave NaN weights and NaN router gradients. Those rows now keep their natural routing and weights. 2. **Recompiles on every compiled call.** The diagnostic counters (`_STATE.stats[...] += 1`) in the router hook, the decoder pre-hook and replay bookkeeping became Dynamo guards, so a compiled router or decoder recompiled on every call. They are now skipped while compiling. They are only used for `routing_replay_stats()`. 3. **GRPO truncated support with no old / ref logps.** With `UNSLOTH_GRPO_TRUNCATED_SUPPORT=1`, `beta = 0` and the efficient path, no old or reference logprobs are scored, so the loss used the current policy's own kept set even when unsloth had found the scored policy is not the sampler (for example vLLM weight sync skipped for a LoRA / quantized model without `fast_inference`). The loss now honours unsloth's `_unsloth_truncated_support_refused` and scores the full vocabulary. Companion: unslothai/unsloth#14226. The matching NaN for `softmax_renorm` (finite logits far below the natural top-k) is fixed in unslothai#1868; this PR merges cleanly with it. Default routing outputs and gradients are unchanged. ## Tests `tests/test_routing_replay_compile.py` (new, CPU): | Test | main | this PR | |---|---|---| | compiled router, 4 calls | recompiles `[2, 1, 1, 1]` | `[2, 0, 0, 0]` | | hooked decoder inside a compiled model | recompiles | no recompile | | underflowed forced probabilities | NaN weights | natural routing, finite gradients | All routing replay test files: 39 passed. `tests/test_grpo_truncated_support_paths.py::test_refused_trainer_scores_the_full_vocabulary`: fails on main, passes here; with the GRPO truncated support tests, 37 passed. ## Not covered here - No vLLM end-to-end GRPO run with routing replay. - The one-time formula detection (`.item()`) and the host-side replay matching still break `fullgraph = True`; this PR only removes the per-call recompiles.
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.
lora_Bbias (Fused LoRA kernels: support lora_dropout and lora_bias #13898).fullgraph = Truefailed. While compiling on torch < 2.11 those projections now run PEFT again, as they did before Fused LoRA kernels: support lora_dropout and lora_bias #13898. Plain LoRA, eager fusion and torch 2.11+ are unchanged.matmul_loragets ause_global_bufferkeyword, defaultTrue, so every other caller is unchanged.beta != 0), with rollouts reused across optimizer steps, or when vLLM weight sync is skipped (LoRA or quantized withoutfast_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 withbeta = 0keep the feature.SHARDED_STATE_DICTthe sharded save wrote no adapter, and withFULL_STATE_DICTit 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
tests/test_fused_lora_dropout_bias_compile_memory.pytests/test_fused_lora_dropout_bias.py(eval keeps the dropout route)tests/test_optimizer_state_offload.pytests/test_grpo_truncated_support_policy_gate.pytests/test_context_parallel_fsdp2_save_gloo.py(transformers 4.57.6, 2 gloo ranks)#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 #13898:
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 #13898 and is left as is.
Not covered here
push_to_hub.