Repository navigation
[Fix] [AMD] memory_pool: Keep K and V in separate allocations on ROCm - #46861
Merged
ch-wan merged 2 commits intoOct 28, 2026
Merged
Conversation
Since sgl-project#32272, MHATokenToKVPool puts K and V of each layer in one allocation, with V at a block offset. Only the CUDA trtllm fmha_v2 prefill reads that layout. On MI35x, the same-node Mooncake PD test test_disaggregation_basic.py now gets GSM8K accuracy 0.0 to 0.01. It passes on each main base before sgl-project#32272 and fails on each base after it. Keep the fused layout off on ROCm. Add a CPU test that patches _is_hip and checks that K and V do not share storage. Co-authored-by: Cursor <cursoragent@cursor.com>
omirosh
marked this pull request as ready for review
October 27, 2026 15:49
omirosh
requested review from
Ying1123,
alphabetc1,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
October 27, 2026 15:49
This was referenced Oct 27, 2026
Closed
1 task done
1am9trash
approved these changes
Oct 28, 2026
1am9trash
left a comment
Collaborator
There was a problem hiding this comment.
LGTM.
Add a guard to resolve PD acc issue.
Only impact on amd code path.
3 tasks done
This was referenced Oct 29, 2026
2 tasks done
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.
Motivation
This ROCm bugfix, with no speed change, turns off the fused K/V allocation from #32272 on ROCm, because with it the MI35x PD disaggregation test
test_disaggregation_basic.pyreturns garbage on every AMD PR.#32272 changed
MHATokenToKVPoolto store each layer's K and V as block-aligned halves of one allocation, sov_buffer[i]now starts inside the allocation ofk_buffer[i]. Only the trtllm_mha fmha_v2 prefill on CUDA reads that layout, but the allocation change has no platform gate. The test serves Qwen3-8B with Mooncake, prefill and decode on one MI35x node. The decode server now returns nonsense with no transfer error:The MI35x 8-GPU disaggregation job ran on many PRs on 2026-10-27. Grouped by the main commit each run merged onto:
test_disaggregation_basic.pydb90f584d2,2b36c718cb,e4d4a9a7de(before #32272)1a120754e0(#32272) and every later base seen (d3a157a2f2,61a676125a,449617bc94,3927a73a34,8a455f1b90,a6f5bd397b)Seven of the nine earlier jobs failed in
test_disaggregation_pp.py, which also fails on main's scheduled runs.test_disaggregation_basic.pypassed in each of them.Three other commits sit between
e4d4a9a7deand1a120754e0. They are #31286 (removes an unused HiCache field), #46366 (gfx1250 diffusion GEMM) and #33743 (flashinfer TRT-LLM MoE weight reload). None of them touches the KV pool or PD. Every job ran on a different runner, so one bad machine does not explain it.Mooncake's HIP transport carries the same-node transfer. It registers each KV buffer with its own
hipIpcGetMemHandleand maps peer addresses asdest - entry.addr + shm_addr. With the fused layout, both handles of a layer point into one allocation. I did not find which step then puts V at the wrong address, so the evidence here is the bisect, not a mechanism.Modifications
memory_pool.py, the fused allocation now also needsnot _is_hip. ROCm gets back the twotorch.zerosper layer it had before [Perf] fmha_v2: use non-interleaved paged KV input for trtllm sm90/120 GQA prefill #32272.test_mha_pool_fused_kv_layout.py, a new CPU test patches_is_hipand checks that K and V do not share storage. The existing fused-layout test still runs on the CPU runner, where_is_hipis false. Both tests build the pool with a shared_make_poolhelper.Off ROCm this change does nothing. On ROCm nothing reads the fused layout, because fmha_v2 runs only on CUDA, so the only effect there is the allocation from before #32272.
Accuracy Tests
I have not run it on MI35x. The AMD disaggregation job of this PR is the end-to-end check, and I will post its result here.
The CPU unit test on this branch and on main:
test_v_is_block_aligned_offset_from_ktest_rocm_keeps_k_and_v_in_separate_allocationsAssertionError: 4573659136 == 4573659136 : layer 0)Untested: same-node PD on CUDA through an IPC transport, which could meet the same layout.
Speed Tests and Profiling
None. ROCm goes back to the allocation it used before #32272. CUDA is unchanged, so it keeps the fmha_v2 speedup from #32272.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ⏳ Run #40656882185
Latest PR Test (Extra): ❌ Run #40656882229
Latest PR Test (AMD ROCm 10): ⏳ Run #40656882098