Repository navigation
Conversation
QIU023
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
September 17, 2026 09:17
|
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 17, 2026 09:17
QIU023
force-pushed
the
k3_pp_offload
branch
5 times, most recently
from
September 25, 2026 05:17
c73e17c to
49117a1
Compare
QIU023
force-pushed
the
k3_pp_offload
branch
5 times, most recently
from
September 29, 2026 10:22
56f4cd3 to
0194621
Compare
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 stacks the list inside the call, so its arithmetic is unchanged. 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.
Each aggregation runs under a torch_remat checkpoint whenever autograd records it and no activation-checkpointing policy already wraps its block, so backward rebuilds the FP32 intermediates instead of keeping them. The output aggregation sits outside every block and always takes its own. KimiK3Model.parallelize marks the blocks that selective, full or region AC wraps, and their residuals run as plain calls inside that checkpoint. RegionAC's block checkpoint is a torch_remat one, which rejects a nested checkpoint; under selective and full AC a second one would only recompute the residual again.
QIU023
force-pushed
the
k3_pp_offload
branch
from
September 29, 2026 18:53
0194621 to
e852c5a
Compare
… last reader Each hop sends one tensor per block, and the model takes and returns its blocks as a list, so the rank store keeps references to the received and committed tensors instead of copies, and no stage stacks its blocks into a fresh leaf. The store drops each block at the backward of the stage that brought it onto the rank, which is its last reader there. Under the action-list runtime a pending send keeps its tensor alive, so the stage waits a forward send at its own backward of that micro-batch and an input-gradient send at the first forward that proves the peer has used it, instead of at the end of the step. Receive buffers stay with torch, which allocates each one right before its receive. PP_ATTN_RES_CACHE.md and the stage figure's legend describe the blocks as one tensor each, held until the backward of the stage that brought them.
QIU023
force-pushed
the
k3_pp_offload
branch
from
September 29, 2026 20:54
e852c5a to
6c9943a
Compare
… ones on host memory
Each tensor a pipeline stage's forward saves gets a torch.utils.checkpoint.CheckpointPolicy
when the forward ends. {MUST,PREFER}_SAVE leaves it with autograd; {MUST,PREFER}_CPU_OFFLOAD
copies it to pinned host memory on a side stream, and backward reads it back
prefetch_n_layers layers ahead. A full host budget keeps the save on the device. The rank
store pins every block it holds, so no policy moves one.
KimiK3Model.Config.pp_memory.cpu_offload = "all" gives MUST_CPU_OFFLOAD to every save outside
the model's last layer, within cpu_offload_budget_gib of host memory; the saves a stage's
backward reads first come back when the rank's previous compute action begins.
QIU023
force-pushed
the
k3_pp_offload
branch
from
September 29, 2026 21:47
6c9943a to
2140058
Compare
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.
Summary
Add
attn_res_cache_offloadtopipeline_kimi_k3: with it on, the blocks a rank keeps for its later stages (RankStore) are parked on pinned host memory from the stage that commits them until a later stage on the rank reads them, instead of staying on the device for that whole span.RankStore(offload=...)(kimi_k3/pipeline_stage.py):putcopies each block to a pinned host tensor on the current stream,blockscopies it back to the device it saw when a later stage assembles its stack.pipeline_kimi_k3(attn_res_cache_offload=...)(kimi_k3/parallelize.py): the switch, passed the way the transport switch is,functools.partial(pipeline_kimi_k3, attn_res_cache_offload=True)as thepipelining_fnof a recipe.Design
Every stored block is detached (its gradient travels through the store's deposits), so the round trip changes values nowhere. Both copies are
non_blockingon the current stream, so stream order alone serializes the D2H of the commit and the H2D of the read; nothing changes in the stage,_assemblestill checks the held set against the routing tables and stacks whatblocks()returns. A store on CPU has nowhere to park and stores the tensor as it is.The switch lives on
pipeline_kimi_k3next toattn_res_cachebecause it is a property of the rank store the pipelining entry builds, not of the model.Test plan
pytest 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_kimi_k3_stage_swap.py tests/unit_tests/cpu/test_kimi_k3_pp_exact_block_grads.py -q(17 passed)