Repository navigation
kimi_k3: a page for the pipeline cache, with the stage figure and a f… - #4914
Conversation
…orward-only example PP_ATTN_RES_CACHE.md explains the attention residual cache of the pipeline stage, in the shape of models/common/MOE_SHARDING.md. The first figure is one virtual stage on one rank with attn_res_cache on and off, forward and backward, with the P2P boxes and a legend for every symbol. The second is a forward-only example: four ranks with two virtual stages each in loop placement, the blocks each rank holds when each stage starts, the blocks each hop brings, and the per-hop P2P volume with the cache on and off. Both figures are SVGs under assets/images, where the MoE page keeps its figure.
|
|
shuhuayu
left a comment
There was a problem hiding this comment.
thx for adding the figures, left some comments.
| [`stage.py`](stage.py), the rank cache is [`cache.py`](cache.py), and the | ||
| tables that decide what each hop carries are [`layout.py`](layout.py). | ||
|
|
||
| ## Overview |
There was a problem hiding this comment.
for the backward path with cache=on, the received gradient is correctly added to the current rank's deposit, can you also add one line on the changes of
There was a problem hiding this comment.
Added:
| | on (default) | hidden `[T, D]` and the blocks the receiving rank has not seen, `[T, Nd, D]` | every block its earlier stages committed or received, per micro-batch, in `PPRankLocalCache`, released after its last stage's forward | the same values; the cached blocks' gradients are summed in another order, so not bitwise | | ||
| | off | hidden `[T, D]` and the whole stack `[T, N, D]` | nothing between hops | bitwise | | ||
|
|
||
| Plain `1F1B` has one stage per rank, so the rank cache never holds anything |
There was a problem hiding this comment.
it still holds the cache stack temporarily? and both transports carry the whole stack on every hop.
There was a problem hiding this comment.
Yes, until the end of that stage's forward, and both transports carry the whole stack on every hop. Corrected the doc
| - `_assemble_stack`: the received delta and the held blocks become one leaf | ||
| `[T, N, D]` in block order, and the stage's model part runs on it. | ||
| - `_pack_outgoing_delta`: the columns the next rank lacks, `delta_to_send`, | ||
| as views of the model's stack. |
There was a problem hiding this comment.
the packed tensors are not views even they are selected as views.
There was a problem hiding this comment.
Yes, for now torch.stack copies them. Corrected the doc, will have a follow up PR to optimize it to use and store reference, trying to remove any unnecessary copy in followed optimization
…s, no internals The stage figure drew the forward labels and caption in orange while the page calls the forward path black; they are black now. The backward side showed only the deposits collected into the incoming gradient for the blocks the stage committed. The stage also adds the deposits for the blocks it received to the gradient it sends back, after the split; the split box, its arrow from the rank cache and the legend now show that, and the page has one line on it. The 1F1B note says both transports carry the whole stack and the rank cache holds the blocks only during the forward. The sections on the stage's functions and the routing tables are removed, with the figure's note on the tables; the loop placement the cache needs stays as one line.
_pack_outgoing_delta packs the columns the next rank lacks with torch.stack, which copies them; its docstring said views.
Summary
Adds a page for the Kimi K3 pipeline's attention residual cache,
torchtitan/models/kimi_k3/pipeline_parallel/PP_ATTN_RES_CACHE.md, with two figures in the style ofmodels/common/MOE_SHARDING.md, as asked in the review of #4312.assets/images/kimi_k3_pp_attn_res_cache.svg: one virtual stage on one rank withattn_res_cacheon and off, forward and backward, with the P2P sends and receives and a legend for every symbol.assets/images/kimi_k3_pp_attn_res_cache_example.svg: a forward-only example, four ranks with two virtual stages each in loop placement, showing the blocks each rank holds when each stage starts, the blocks each hop brings, and the per-hop P2P volume with the cache on and off.