Repository navigation
Fix packed document boundaries in Qwen PLE - #14011
danielhanchen merged 4 commits into
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b3fe0e33a
ℹ️ 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".
| torch_varlen_only = bool(mixers) and all(kind in ("short_conv", "ple") for _, kind in mixers) | ||
| mode = _hybrid_packing_mode() | ||
| auto_eligible = bool(mixers) and all(kind in _HYBRID_AUTO_KINDS for _, kind in mixers) | ||
| if not short_conv_only: | ||
| if not torch_varlen_only: | ||
| if mode == "off" or (mode == "auto" and not auto_eligible): |
There was a problem hiding this comment.
Honor the packing kill switch for PLE-only models
When a model's detected mixers are all PLE/short-conv, this condition makes torch_varlen_only true and skips the subsequent mode == "off" check. Thus UNSLOTH_EXPERIMENTAL_HYBRID_PACKING=0 still patches a PLE-only model and lets the trainer enable packing; it also makes the first-forward dispatch error's advertised fallback ineffective for that model shape. Check the explicit off mode before applying the torch-only auto-enable exemption.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable: every published model with Qwen4ExpTextPLELayer (Qwen3.8-Flash-Next) also has Qwen4ExpTextGatedDeltaNet mixers, so torch_varlen_only is false and the off switch is honoured; the short-conv exemption from the kill switch is unchanged from main (LFM2).
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
…-check (unslothai#18611) Follow-up to unslothai#18313 and unslothai#17738. ## Why ROCm was opt-in unslothai#13383 made hybrid packing (Qwen3.5, Qwen3.5-MoE, Qwen3-Next, and the PLE layers from unslothai#14011) default-on for CUDA only. At the time `UNSLOTH_EXPERIMENTAL_HYBRID_PACKING=1` failed closed on gfx1151 because the boundary-aware causal conv was not allowed on HIP (unsloth-zoo unslothai#2503 fixed that), and once it worked, the full attention layers still ran SDPA over a dense `(T, T)` mask on ROCm, so packing was a wash (unslothai#17738). unslothai#18313 moved ROCm packed rows onto torch's flash varlen behind a one-time self-check, which removes that cost. ## Change With the variable unset, `_auto_hybrid_device_ok` now also accepts a ROCm GPU when the unslothai#18313 self-check (`hf_packed_attention._torch_varlen`) passes on that device. The check runs once per device (about 0.3 s on gfx1151) and is cached. Everything else is unchanged: - The same mixer kinds as CUDA (gated delta and PLE), and the existing exactness probe still runs before any packing. - A ROCm build whose flash varlen fails the self-check keeps the padded path, with the reason logged. - `=0` still turns packing off and `=1` still opts in Mamba2 / split QKV mixers and other devices. - CUDA is unchanged. The opt-in note from unslothai#17751 now says the path is "not on by default on this device" instead of naming CUDA only. ## gfx1151, Linux, torch 2.11.0+rocm7.13, transformers 5.5.4 Fake Qwen3.5-4B shaped model (real 4B layer sizes, 4 layers, random weights), LoRA r=16, `packing = True`, `max_length 2048`, batch 4, variable unset vs `=0`. Two runs per arm. | arm | packed | median useful tok/s | median s/step | first losses | |---|---|---|---|---| | main, unset | no (padded) | 1691 | 2.96 | 12.9115, 12.9003, 12.9244 | | main, `=0` | no | 1687 | 2.95 | 12.9115, 12.9003, 12.9244 | | this PR, unset | yes | 2417 | 3.38 | 12.9344, 12.8879, 12.9011 | | this PR, `=0` | no | 1699 | 2.97 | 12.9115, 12.9003, 12.9244 | Default ROCm runs now pack and train at about 1.42x the padded throughput. The packed losses are the same values unslothai#18313 measured for the opt-in path, and `=0` is unchanged. ## Tests `tests/utils/test_hybrid_packing_default.py` adds a case with a ROCm GPU weight where the self-check passes (default-on) and fails (padded, reported as an opt-in device). Reverting the change fails the passing case.
Packed Qwen3.8-Flash-Next text training can pass the gated-delta checks while
Qwen4ExpTextPLELayerstill mixes documents through its dilated convolution. The mixer detector currently overlooks PLE. EOS resets the n-gram hashes but does not reset the convolution; without EOS, n-gram history also crosses packing boundaries.Recognize PLE as a stateful mixer and keep packing enabled by isolating both operations:
short_conv_state_len(9 for the published configuration).context_len(2 for that configuration), so isolation also works without EOS in the actual documents.Each operation remains a single packed call using the native implementation and autograd. Temporary positions stay local to these two PLE operations; attention and the training labels keep their original packed layout. The added work scales with the finite history per document boundary, with no per-document Python loop or additional device-scalar readback. This change is limited to
unsloth/utils/packing.py.Validation:
torch.compile(fullgraph=True), and a CPU-offloaded embedding table. The tested cross-document hidden-state gradients are exactly zero.test_hybrid_packing_default.pyandtest_packing.py: 142 passed, 1 skipped, 2 model-download tests deselected.git diff --checkpassed.The component checks execute the unchanged upstream PLE, n-gram and RMSNorm method bodies from Transformers
23292ca5b82012ee1a1fd620069fd5e659ecf1be, with small random parameters and real autograd. They do not load the pretrained checkpoint or run full-model SFT; no end-to-end speedup or model-quality improvement is claimed.