Repository navigation
Pipeline parallel: keep the frozen-prefix skip off on later stages - #18745
Conversation
…arlier stages got no gradient) On a pipeline parallel stage after the first, the decoder layer list starts with pass-through stand-ins for the layers other stages own. They have no parameters, so the frozen-prefix skip (#18442) saw the stage's first own layer as the first trainable one and cut there: the hidden states the stand-ins return (the previous stage's activations) became a detached leaf, and no gradient reached any earlier stage. Only the last stage trained. Gemma-4 E4B 4-bit, PP=2 on 2x T4: step-1 grad norm 2.78 against 5.12 on one GPU, losses 0.83 above one GPU by step 9 (E2B 1.05 by step 5). DDP, FSDP2 and one GPU train layer 0, so the skip never engaged there. The stand-in now carries `_unsloth_pipeline_stand_in`, and the skip's plan returns None for a stack that holds one. One process and the other parallel modes are unchanged. tests/test_pp_frozen_prefix_gloo.py (CPU, gloo): PP=2 GPipe and 1F1B with gradient checkpointing and the skip installed, every gradient and loss against one process. Main: rank 1 cuts 8 forwards, gradient error 2.11; this branch: no cut, 4.4e-4.
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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: Didn't find any major issues. Delightful! 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". |
…pins the skip on and checks torch pipelining first
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
@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". |
Problem
Under pipeline parallel, the frozen-prefix skip from #18442 cuts the graph at the first activation the later stage receives from the stage before it. Every stage except the last then trains nothing. On Kaggle 2xT4, Gemma-4 PP=2 losses drift from the 1 GPU run after the warmup steps. E4B 4-bit is 0.81 off at step 6 and E2B 4-bit 0.91 off at step 5.
Root cause:
_PPPassThroughstand-ins with no parameters._frozen_prefix._plantherefore sees stage 1's first own layer as "the first trainable layer" and detaches its input. That input is the activation from stage 0.Fix
_PPPassThroughcarries_unsloth_pipeline_stand_in = True._planmakes no cut, on any layer stack, while the model holds a stand-in. A later stage would otherwise cut at the activations it receives, and a non-last stage leaves its forward by raising, past the hook cleanup. This works whether the stages are split before or afterget_peft_model.Results
Kaggle 2xT4, fp16, unsloth main 15a985f / zoo 9b3fccb, 25 steps, same harness / data / seed. Each cell is the max over steps of |PP loss - median 1 GPU loss|, all from one kernel:
UNSLOTH_RETURN_LOGITS=1(no fused CE) drifted the same;Tests
tests/test_pp_frozen_prefix_gloo.py: tiny Gemma-4, PP=2 over CPU gloo, GPipe and 1F1B, against one process. It fails on main (rank 1 cuts 8 forwards, gradient error 2.11) and passes here (0 cuts, gradients within 4.4e-4).Not covered