Repository navigation
Conversation
QIU023
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
September 30, 2026 07:02
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
QIU023
marked this pull request as draft
September 30, 2026 07:02
QIU023
force-pushed
the
pp_review_optimize
branch
2 times, most recently
from
October 1, 2026 06:39
345e9e0 to
312bc81
Compare
This was referenced Oct 4, 2026
Inside the model the block residual is a list of [T, D] blocks instead of a [T, N, D] stack. A block opening appends to the list; it used to concatenate a longer stack, and every earlier layer's checkpoint kept the shorter stack it had been called with, so each copy lived until backward. The aggregation takes the list of sources it attends over (the blocks, then the partial block), the way FLA's fused_attnres takes its residuals, and stacks it inside the compiled region. Dynamo specializes a list on its length, so the region compiles one graph per source count (5 for the debug flavor, 8 for Kimi-K3) and raises its recompile limit to 32: a fullgraph region fails at the default limit of 8 instead of falling back. The Triton override takes the same list, stacks it for its kernels and keeps the sources, not the stack, for backward. The model's forward still takes and returns the stack, so the pipeline stage is unchanged: the stack it is given is unbound into the list, and the list is stacked on the way out. The multimodal decoder boundary converts no stack any more: the list starts empty and its first block is layer 0's converted input. The block returns its output and the blocks as one flat tuple, since a function under torch_remat region checkpointing (RegionAC) may return only one hop of tensors.
…per rank The stage hands the model its blocks as a list instead of stacking them into a fresh leaf, and a hop sends one tensor per block. A received block is its own receive buffer and a committed block is the model's own tensor, so the rank cache, the stages' inputs and the sends reference the same memory, and each block lives once on the rank until the stage that brought it has run its backward. _assemble_stack, _pack_outgoing_delta and _split_stack_grad keep their roles on per-block lists; the rank cache, the routing tables and the release point are unchanged. The model takes and returns its blocks as a list. Under the action-list runtime a pending send keeps its tensor allocated, so a forward send is waited at the stage's own backward of that micro-batch instead of at the end of the step.
QIU023
force-pushed
the
pp_review_optimize
branch
from
October 12, 2026 17:53
312bc81 to
57790e1
Compare
When nothing upstream of a stage is trainable, as when LoRA adapts only some projections and the first stages hold none of them, the receive metadata marks every input as not needing a gradient and backward produces none. The stage raised "backward produced no gradient for any input" in that case; it now sends nothing upstream, as it already does for its own blocks. The error stays for a stage with an input that needs a gradient. The new test freezes block 0 in the pp4 x vpp2 split and matches the single-device reference bitwise.
This branch has not been deployed
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.
Relation to other PRs
Summary
The Kimi K3 pipeline stage keeps each attention-residual block once per pipeline rank, the memory the Attention Residuals paper states for cross-stage caching ("each block is stored exactly once across all V virtual stages", section 4.1), by passing the blocks as tensors of their own instead of stacking them.
kimi_k3/pipeline_parallel/stage.py:_assemble_stack,_pack_outgoing_deltaand_split_stack_gradwork on per-block lists, so a hop sends one tensor per block and no stage copies its blocks into a fresh leaf; under the action-list runtime, a forward send is waited at the stage's own backward of that micro-batch.kimi_k3/pipeline_parallel/__init__.py: turns the forward send waits on under_PipelineScheduleRuntime.kimi_k3/model.py: the model takes and returns its blocks as a list.kimi_k3/pipeline_parallel/PP_ATTN_RES_CACHE.mdand the stage figure's legend: one[T, D]tensor per block.Design
[T, N, D]leaf that lives until its backward;Results
4 H100s, the Kimi K3 debug model widened to dim 6144 (17 layers in blocks of 4, 8 experts, every width that scales with dim scaled 24 times), 16 micro-batches of 2048 c4 tokens per step, Interleaved1F1B, FullAC, AdamW, seed 42, deterministic, one warm compile cache per layout. #4656 is the two commits below this PR; both trees ran 100 steps. The layouts with two pipeline ranks hold half the model per GPU and run the model at dim 5120, since at 6144 both trees run out of memory.
Loss / grad norm with and without this PR (without it is the tree of the two #4656 commits below, whose pipeline stage is main's), each pair on one shared warm compile cache with the same seed and data; the last column counts the steps of the 100 whose loss and grad norm are identical.
Blocks held in step 5 at each rank's peak, in
[T, D]blocks (24 MiB at dim 6144, 20 MiB at dim 5120): the rank cache, the stages' saved inputs and outputs and the pending forward sends of blocks, counted by storage. The tight bound frees each block at the backward of the stage that brought it onto the rank; the paper's bound keeps every block of a micro-batch until the rank's last backward of that micro-batch. With this PR the blocks equal the tight bound at every forward and backward of the step, except the last stage's forwards at pp4 x vpp2 and in the pp2 layouts, which sit one block below it because the bound also counts the block that stage completes and uses inside its forward.A hidden-state send carries a stage's output, one
[T, D]that is not a block, so it is counted apart (one per forward of a stage other than the last, taken out of the step 5 records); its memory is real and is part of the peaks above. With this PR it is waited at the sender's own backward of that micro-batch; on #4656 it stays until the end of the step.Test plan
pytest tests/unit_tests/cpu/test_kimi_k3_pp_block_grads.py tests/unit_tests/cpu/test_kimi_k3_pp_stage.py tests/unit_tests/cpu/test_kimi_k3_pp_layout.py tests/unit_tests/cpu/test_pipeline_parallel.py tests/unit_tests/cpu/test_kimi_k3_attention_residual_recompute.py -q(70 passed): the four-rank gloo pipelines of [Kimi K3] Pipeline Parallelism support (text LLM side): PP Virtual Stage Cache Adapter for Attention Residual #4312, now with one tensor per block and the forward send waits, under Interleaved1F1B with the cache on and off, every block gradient bitwise with one device, and eval between steps.