Skip to content

[Fix] Kimi-K3: Fix derived weight buffers across CUDA graph reloads - #43675

Merged
nvpohanh merged 12 commits into
sgl-project:mainfrom
wolfcomos:fix/kimi-k3-mla-graph-reload
Nov 9, 2026
Merged

nvpohanh merged 12 commits into
sgl-project:mainfrom
wolfcomos:fix/kimi-k3-mla-graph-reload

Conversation

@wolfcomos

@wolfcomos wolfcomos commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Reloading Kimi-K3 weights after CUDA graph capture can leave captured operations reading old derived-weight storage. AttnRes also retains its cached norm/projection product after the underlying weights change, affecting eager execution as well.

Changes

  • Preserve MLA absorbed projection buffers across reloads.
  • Reuse merged MoE front and CUDA BFA buffers, restoring parameter views into the merged storage. Preserve the dequantized BFA projection buffer as well.
  • Reuse the ROCm fused KDA input-projection buffer across reloads, preserving whole-buffer, BFA-tail, and parameter-view addresses.
  • Refresh CUDA KDA fused-decode tensor arguments in place.
  • Refresh both BF16 and FP32 AttnRes cached products in place during post-load processing.
  • Add repeated-reload regressions and replace dynamic attribute access in the MLA test with direct tensor access.

The reload contract assumes unchanged model configuration, shapes, dtypes, and devices. Native ROCm kernels and all quantized loader variants are not covered by this validation. This is not a claim that every K3 hot-update path has been validated.

AMD/ROCm follow-up

The Python buffer-lifecycle fix for the ROCm fused KDA input projection is included and regression-tested on H100 by invoking _merge_kda_inproj_weights_hip() with an eligible fixture. Native AMD/ROCm graph replay, fused kernels, and token-threshold branches still need validation, tracked in #47508. H100 results do not establish ROCm end-to-end hot-update correctness.

Validation

The original MLA regression failed before its fix and passed after it on one H100, with exact graph/eager projection equality after two successive updates.

The four additional regressions exercise front-weight views, dense/dequantized BFA buffer lifetime, CUDA KDA static buffers, and both AttnRes cache dtypes. Each performs two updates after CUDA graph capture, checks changed values, exact replay/eager buffer equality, and stable addresses. The dequantized BFA branch uses a mocked dequantization boundary returning fresh tensors; it does not validate an FP8 quantizer.

On one H100 80GB using PyTorch 2.14.1+cu130 / CUDA 13.0 and lmsysorg/sglang:dev at digest sha256:78142f9f4b7fb3ee27f59065615dc7bb263f643ed256c9299c3861086ade4d47:

  • All four new cases reproduce failures on the previous PR head f05814ad4eaa02f28afd6d86c3b1fc8fd049e098, using the same image and test source.
  • The complete registered test file passes 10/10 in 11.659 seconds with commit cc5159e.
PYTHONPATH=python python test/registered/unit/models/test_kimi_k3_bfa_overlap.py -v

Follow-up commit 810b49e2bc3ee7d80ebc3beb520638f77d2a29fb adds the HIP input-projection storage regression. On one H100 PCIe with PyTorch 2.14.1+cu130 / CUDA 13.0 and image digest sha256:77ff63ee69fd7ebef20df3a6d036ee4b8a4ffe0734efb0028c3b7643386e3ccf:

  • The same new test fails against parent 58a5db50225e8aad6b3a3ee9652b90e122a4e8ea (including stale replay values after the second update) and passes after the fix.
  • The complete registered test file passes 11/11 in 10.802 seconds using full SGLang imports.
  • The regression captures tensor copies, checks exact replay/current-buffer equality and stable addresses across two reloads, verifies parameter aliases and zero padding, and does not execute AMD fused kernels.

Applicable pre-commit checks pass. Full-model accuracy, real rollout weight synchronization, and performance benchmarking are outside this validation.


CI States

Latest PR Test (Base): ✅ Run #42572728289
Latest PR Test (Extra): ❌ Run #42572728267
Latest PR Test (AMD ROCm 10): ⏳ Run #42572728341

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@wolfcomos
wolfcomos marked this pull request as ready for review October 11, 2026 09:56
@wolfcomos wolfcomos changed the title [WIP] Fix Kimi-K3 MLA CUDA graph weight reloads Fix Kimi-K3 MLA CUDA graph weight reloads Oct 11, 2026
@wolfcomos wolfcomos changed the title Fix Kimi-K3 MLA CUDA graph weight reloads [Bug] Fix Kimi-K3 MLA CUDA graph weight reloads Oct 13, 2026

@nvpohanh nvpohanh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[by Claude Code] This review is done by agents. Please feel free to disagree if they do not make sense.

Comment thread python/sglang/srt/models/kimi_k3.py Resolved
@wolfcomos wolfcomos changed the title [Bug] Fix Kimi-K3 MLA CUDA graph weight reloads [Bug] Fix Kimi-K3 derived weight buffers across CUDA graph reloads Oct 29, 2026
@github-actions

This comment has been minimized.

@wolfcomos wolfcomos changed the title [Bug] Fix Kimi-K3 derived weight buffers across CUDA graph reloads [Fix] Fix Kimi-K3 derived weight buffers across CUDA graph reloads Oct 29, 2026
@github-actions

This comment has been minimized.

@wolfcomos
wolfcomos requested a review from nvpohanh October 29, 2026 22:23
@github-actions

This comment has been minimized.

@nvpohanh nvpohanh changed the title [Fix] Fix Kimi-K3 derived weight buffers across CUDA graph reloads [Fix] Kimi-K3: Fix derived weight buffers across CUDA graph reloads Nov 2, 2026
@nvpohanh

nvpohanh commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] @wolfcomos, could you merge the latest main into this branch? The branch does not include 6a39ddf1 yet, which the CI maintenance gate (#21065) requires, so every CI job would fail at the gate before running any tests. If you'd rather not, you can enable "Allow edits by maintainers" on this PR and we'll do the merge. I also updated the title to the required [Type] scope: title format so the PR Title check passes. Thanks!

@wolfcomos

Copy link
Copy Markdown
Contributor Author

[by Claude Code] @wolfcomos, could you merge the latest main into this branch? The branch does not include 6a39ddf1 yet, which the CI maintenance gate (#21065) requires, so every CI job would fail at the gate before running any tests. If you'd rather not, you can enable "Allow edits by maintainers" on this PR and we'll do the merge. I also updated the title to the required [Type] scope: title format so the PR Title check passes. Thanks!

updated

@nvpohanh

nvpohanh commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] @wolfcomos, the remaining relevant CI failure (base-b-test-1-gpu-large (0), test/registered/vlm/test_vision_chunked_prefill.py timing out in llava image preprocessing) is not caused by this PR. It is fixed on main by #48443, which this branch doesn't include yet, so rerunning CI alone won't pick it up.

Could you enable "Allow edits by maintainers" on this PR (checkbox in the right sidebar)? Then I can merge the latest main into the branch and watch the new CI run for you. Alternatively, merging the latest main yourself works too. Thanks!

@wolfcomos

Copy link
Copy Markdown
Contributor Author

[by Claude Code] @wolfcomos, the remaining relevant CI failure (base-b-test-1-gpu-large (0), test/registered/vlm/test_vision_chunked_prefill.py timing out in llava image preprocessing) is not caused by this PR. It is fixed on main by #48443, which this branch doesn't include yet, so rerunning CI alone won't pick it up.

Could you enable "Allow edits by maintainers" on this PR (checkbox in the right sidebar)? Then I can merge the latest main into the branch and watch the new CI run for you. Alternatively, merging the latest main yourself works too. Thanks!

thanks, edits enabled

@nvpohanh

nvpohanh commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest main into this branch, push a small test-only fix, fix the PR title if the title check fails, or post a note here.

Anyone can stop me at any time: just post a comment asking me to stop (for example, stop babysitting). I'll stop at my next check, within 30 minutes, and take no further action on this PR.

@nvpohanh

nvpohanh commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] @wolfcomos, the relevant CI failure appears to be caused by this PR: https://github.com/sgl-project/sglang/actions/runs/42020871324/job/127241401272. The new test test_kimi_k3_bfa_overlap.py::TestKimiK3BfaOverlap::test_fused_decode_reload_preserves_buffers fails with AttributeError: 'types.SimpleNamespace' object has no attribute 'local_num_heads', because KimiK3DeltaAttention._prepare_fused_decode now reads heads = self.local_num_heads (kimi_k3.py:2032), and the test's mock owner doesn't set that attribute. Its shapes imply 12 heads, so adding local_num_heads=12 to the owner SimpleNamespace should be enough. Could you please fix it? Thanks!

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] LGTM.

@BBuf

BBuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

1 similar comment
@BBuf

BBuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@BBuf

BBuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] Could you rebase this onto the latest main? It conflicts with main now.

Resolve the kimi_k3.py import conflict with sgl-project#48781, which split utils.common:
take main's imports and import bind_or_assign from sglang.srt.models.utils.
attn_residual.py now imports bind_or_assign from there too, since
sglang.srt.utils no longer re-exports it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nvpohanh

nvpohanh commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest main into this branch, push a small test-only fix, fix the PR title if the title check fails, or post a note here.

Anyone can stop me at any time: just post a comment asking me to stop (for example, stop babysitting). I'll stop at my next check, within 30 minutes, and take no further action on this PR.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] LGTM.

@BBuf

BBuf commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@nvpohanh

nvpohanh commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] All NV pipelines have passed.

@BBuf

BBuf commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] Could you rebase this onto the latest main? It conflicts with main now.

Resolve the kimi_k3.py conflict by keeping bind_or_assign for w_kc/w_vc
and refreshing main's DCP pre-projected V weights after the update.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nvpohanh

nvpohanh commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest main into this branch, push a small test-only fix, fix the PR title if the title check fails, or post a note here.

Anyone can stop me at any time: just post a comment asking me to stop (for example, stop babysitting). I'll stop at my next check, within 30 minutes, and take no further action on this PR.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] One thing to fix before this can go in.

/ 512
)

attn = SimpleNamespace(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] The registered reload suite now raises AttributeError before graph capture: this fixture lacks _dcp_v_weights, and the MoE fixture also lacks the _front_shard property read by the merged method. Could we update both fixtures for main’s changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed both fixtures in d365f2b. The MLA fixture now initializes _dcp_v_weights=None, and the MoE fixture exposes _front_shard as a property returning None so it remains available after _merge_front_weights() invalidates cached instance attributes. Test-only changes; syntax and cache-invalidation checks passed locally. Full CUDA graph regression validation is pending GPU CI.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] Checked d365f2b: both missing attributes are covered, and the _front_shard property survives cache invalidation. That resolves this fixture issue; I haven’t run the GPU tests.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] LGTM.

@nvpohanh

nvpohanh commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest main into this branch, push a small test-only fix, fix the PR title if the title check fails, or post a note here.

Anyone can stop me at any time: just post a comment asking me to stop (for example, stop babysitting). I'll stop at my next check, within 30 minutes, and take no further action on this PR.

@nvpohanh

nvpohanh commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] All NV pipelines have passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants