[II] Preserve the final Kimi-K3 AttnRes block - #467
voipmonitor wants to merge 1 commit into
Conversation
Signed-off-by: Martin Vit <martin@voipmonitor.org>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe Kimi decoder now identifies the final AttnRes block-write layer and avoids reusing ChangesKimi AttnRes preservation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change preserves the final AttnRes residual block with a localized additional allocation while retaining existing behavior for other paths. No actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Behavior
Kimi-K3 AttnRes output reuse now stops at the boundary that commits the final
residual block. The old prefix remains in the residual bank, while the
post-attention mixture receives separate output storage. Earlier block
boundaries and the remaining KDA, MLA, dense-MLP, and routed-MoE caller-output
paths retain their existing storage reuse.
Status: implemented and qualified.
Technical reason
The official Kimi-K3 text transformer has 93 layers, an AttnRes block size of
12, and eight residual-bank slots. The eighth slot can hold temporary output
before layer 84 because it is not yet a residual source. Layer 84 commits that
slot. Reusing the same storage for the post-attention output then overwrites a
residual source consumed by layers 85 through 92 and the final AttnRes mixture.
The fix identifies the layer that commits the final block and allocates one
separate output tensor at that boundary. A 4,096-token BF16 tensor with hidden
width 7,168 occupies 58,720,256 bytes. No persistent workspace is added.
Compatibility
Models without AttnRes and platforms without AttnRes output reuse are
unchanged. Tensor values, kernels, operation order, cache layout, KDA, MLA,
MoE, DCP, and decode collectives are unchanged. The only additional allocation
occurs when the final AttnRes block becomes live.
Validation
of the final committed block.
[4096, 7168]reproduces the defect:unrestricted reuse changes 7,266,461 of 29,360,128 final-output elements.
output for all 29,360,128 output elements and all 234,881,024 residual-bank
elements in three complete 93-layer repetitions.
complete a captured 208,026-token prompt plus 8,192 greedy output tokens
without the deterministic repetition failure.
physical target-KV tokens.
tok/s median across three runs; the source-locked comparison measured 55.769
tok/s.
ruff check,ruff format --check,git diff --check, and Python bytecodevalidation pass for the changed files.
Qualification artifacts are stored under
/mnt/luke/kimi-k3-runs/merge-lse-alias-fix-20260822/full-r31-attnres-final-block-fix-1m/on the 16-GPU qualification host.
Summary by CodeRabbit