Skip to content

[unified-memory] Name the fused KV translate for what it computes (7/7) - #40331

Merged
ch-wan merged 5 commits into
sgl-project:mainfrom
caihuali95:mainline/stride-write-loc-kernel
Oct 2, 2026
Merged

ch-wan merged 5 commits into
sgl-project:mainfrom
caihuali95:mainline/stride-write-loc-kernel

Conversation

@caihuali95

@caihuali95 caihuali95 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

This is one of seven PRs split out of #38592. That PR was +2105/−1366 across 41
files, twelve of them attention backends on the serving hot path, and it interleaved
hardening, a layout change and dead-code deletion in a single diff — a reviewer could not
tell which hunk was safe-by-construction and which changed behaviour. #38592 is retained as the token-major
layout PR (3/7), which is the core of the series.

Stack — each PR is based on the one above it, and every one is green on its own:

# PR what it does size
1 #40326 derive KV row addresses from strides, not shapes 21 files, +733/−118
2 #40327 build paged KV views through one helper 13 files, +704/−47
3 #38592 token-major layout 36 files, +1215/−1108
4 #40328 mark the write loc physical and check it at every write door 45 files, +935/−132
5 #40329 remove the kernel-page multiplier plumbing 17 files, +117/−230
6 #40330 stride the KV translate kernel and route every translate through it 11 files, +361/−159
7 #40331 name the fused KV translate for what it computes 28 files, +119/−121

Review order is the table order. 1 and 2 are no-ops on today's contiguous pools (2 also
fixes how HND pools with more than one KV head are read); 3 is where the behaviour changes
and deserves the most attention; 4 adds the physical write-loc check; 5 is deletion; 6
consolidates the translate; 7 is naming only.

7/7 — name the fused KV translate for what it computes

Base: #40330 (6/7). 5 commits, 28 files, +119/−121.

After 6/7 one kernel serves every KV translate, reads and writes alike, and the kernel-facing
and physical id spaces are the same. The names still said otherwise. This PR renames, with no
behaviour change:

before after
write_loc_to_kernel_ids / write_loc_to_kernel_id_kernel / WRITE_LOC_BLOCK translate_token_ids / translate_token_ids_kernel / TRANSLATE_TOKEN_IDS_BLOCK
translate_write_loc_for_kernel (sub-allocator and composites) translate_write_loc
_assert_kernel_id_bound _assert_physical_id_bound
test_write_loc_to_kernel_ids_strided.py test_translate_token_ids_strided.py

The kernel registry entry, callers and tests follow. The kernel's argument comments now
describe its real inputs (1-D or strided (rows, cols), int32 or int64, widened under DCP), an
unreachable 0-d branch goes, and the allocator docstrings say "physical" where they said
"kernel-facing".

Comments follow the identifiers: every comment, docstring and unified-memory error message
that called these ids "kernel-facing" now says "physical". Left alone are the sites that
state the equivalence on purpose, one that describes a historical bug, and two where the
word means something else (the Mamba checkpoint pool, the communicator). Three
descriptions that were wrong are corrected: the kernel's out under out_width, the
parity test's page-major formula, and the inkling test's account of a re-translated loc.

The first commit is a scripted mechanical rename; the next two are comments and the two
identifier renames; the last two are the corrections and the comment sweep, each
droppable on its own.

Validation

The stack is rebased onto main 047be72; every PR's own diff is unchanged file for file.

Unit and GPU tests on the H200, this head against that main, over every non-e2e test file the stack
touches plus unit/mem_cache, cp, dcp, unit/layers/attention, kernels/ops/memory and
kernels/ops/kvcache: no failure at this head that main does not also have; the extra passes are the
stack's own tests. The server-launching multi-GPU files under cp/ and dcp/ error the same way on
both sides on a one-GPU run.

End to end at this head on the H200, unified memory against a baseline on the same model and flags
(GSM8K 5-shot, n=200):

model backend unified baseline
Qwen3.5-9B, tp1 triton 0.900 0.900
gpt-oss-20b, tp1 fa3 0.540 0.515

Before the rebase, at d509377 — the whole stack — each admitted SM100 backend was run with
unified memory against a baseline on the same model, flags and box (B200, GSM8K 5-shot, n=100):

model backend unified baseline
Qwen3.5-9B, tp1, cuda graphs off trtllm_mha 0.900 0.900
gpt-oss-20b, tp1 fa4 0.570 0.570
Kimi-Linear-48B-A3B, tp2 trtllm_mla 0.900 0.900
Kimi-Linear-48B-A3B, tp2, dcp2, fp8 KV tokenspeed_mla 0.930 0.930

No write was refused by the physical write-loc check and no device-side assert fired. trtllm_mha
without cuda graphs decodes about 7% slower under unified memory, from the translate launches
an eager step adds.

The commits added since that head fix static-pool write doors, tests and comments; none changes a
unified-memory read or write path.


CI States

Latest PR Test (Base): ⏳ Run #36944919905
Latest PR Test (Extra): ⏳ Run #36944919686
Latest PR Test (AMD ROCm 10): ⏳ Run #36944919884

@caihuali95
caihuali95 force-pushed the mainline/stride-write-loc-kernel branch from 5151029 to 47b9fad Compare September 25, 2026 05:49
@github-actions github-actions Bot added the hicache Hierarchical Caching for SGLang label Sep 25, 2026
@ch-wan
ch-wan force-pushed the mainline/stride-write-loc-kernel branch from 47b9fad to 4218b64 Compare September 28, 2026 19:53
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 28, 2026
@ch-wan
ch-wan force-pushed the mainline/stride-write-loc-kernel branch from 4218b64 to f326ac4 Compare September 28, 2026 21:32
@ch-wan ch-wan changed the title [unified-memory] Stride the write-loc kernel, then fold the last translate (7/7) [unified-memory] Name the fused KV translate for what it computes (7/7) Sep 28, 2026
@ch-wan
ch-wan force-pushed the mainline/stride-write-loc-kernel branch 2 times, most recently from bee7c91 to d509377 Compare September 29, 2026 01:33
@ch-wan ch-wan added run-ci CI: run the baseline test suite on this PR bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) parallel-stages CI: stages dispatch together instead of waiting on each other labels Oct 1, 2026
@ch-wan
ch-wan force-pushed the mainline/stride-write-loc-kernel branch from 2a6115c to d794024 Compare October 1, 2026 06:21
@ch-wan

ch-wan commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-group unified memory

@ch-wan

ch-wan commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-group unified-memory

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

⛔ unified: Unknown test group unified.

Known groups: accuracy, amd, attention, backends, basic_perf, bench_fn, chunked_prefill, constrained_decoding, core, cp, cpu, cuda_graph, dcp, debug_utils, disaggregation, dllm, dp_attn, dp_engine, e2e, ep, eplb, expert_pack, function_call, gb300, hicache, hicache-all, hisparse, input_embedding, kernels, kv_canary, layers, lora, mem_cache, mla, mlx, mock_model, model_loading, moe, musa, npu, observability, openai_server, ops, page_major, perf, pp, prefill_only, profiling, radix_cache, reasoning, rl, rotary, rust, rust-server, sampling, scheduler, scripted_runtime, sessions, spec, stress, tokenizer, unified-memory, unit, utils, vlm, xpu

⛔ memory: Unknown test group memory.

Known groups: accuracy, amd, attention, backends, basic_perf, bench_fn, chunked_prefill, constrained_decoding, core, cp, cpu, cuda_graph, dcp, debug_utils, disaggregation, dllm, dp_attn, dp_engine, e2e, ep, eplb, expert_pack, function_call, gb300, hicache, hicache-all, hisparse, input_embedding, kernels, kv_canary, layers, lora, mem_cache, mla, mlx, mock_model, model_loading, moe, musa, npu, observability, openai_server, ops, page_major, perf, pp, prefill_only, profiling, radix_cache, reasoning, rl, rotary, rust, rust-server, sampling, scheduler, scripted_runtime, sessions, spec, stress, tokenizer, unified-memory, unit, utils, vlm, xpu

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-group unified-memory:

🚀 1-gpu-h100 (5 tests): ✅ View workflow run

cd test/ && python3 registered/attention/test_gemma4_unified_swa_virtual_ids.py
cd test/ && python3 registered/attention/test_unified_memory_deterministic.py
cd test/ && python3 registered/e2e/models/test_inkling_unified.py
cd test/ && python3 registered/page_major/test_page_major_gpt_oss.py
cd test/ && python3 registered/page_major/test_page_major_qwen_hybrid.py

🚀 2-gpu-h100 (5 tests): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_disaggregation_unified_memory.py
cd test/ && python3 registered/e2e/disaggregation/test_disaggregation_unified_memory_swa.py
cd test/ && python3 registered/e2e/disaggregation/test_disaggregation_unified_memory_tri.py
cd test/ && python3 registered/e2e/hicache/test_hicache_unified_memory.py
cd test/ && python3 registered/e2e/models/test_kimi_linear_models.py

🚀 4-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_kimi_linear_unified_memory.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_kimi_linear_unified_memory_dcp_blackwell.py

🚀 ubuntu-latest (32 tests): ✅ View workflow run

cd test/ && python3 registered/unit/disaggregation/test_unified_memory_move_gate.py
cd test/ && python3 registered/unit/layers/attention/test_kv_translate_ownership.py
cd test/ && python3 registered/unit/managers/test_prefill_adder.py
cd test/ && python3 registered/unit/managers/test_scheduler_init_req_max_new_tokens.py
cd test/ && python3 registered/unit/mem_cache/test_dsv4_unified_fp8_pool.py
cd test/ && python3 registered/unit/mem_cache/test_flashkda_strided_state_access.py
cd test/ && python3 registered/unit/mem_cache/test_full_loc_fast_path.py
cd test/ && python3 registered/unit/mem_cache/test_hisparse_allocator.py
cd test/ && python3 registered/unit/mem_cache/test_hisparse_max_token_pool_size.py
cd test/ && python3 registered/unit/mem_cache/test_kda_fused_decode_strided_state.py
cd test/ && python3 registered/unit/mem_cache/test_kv_index_translator.py
cd test/ && python3 registered/unit/mem_cache/test_multi_ended_allocator.py
cd test/ && python3 registered/unit/mem_cache/test_pd_envelope_transfer_layout.py
cd test/ && python3 registered/unit/mem_cache/test_prefill_memory_budget.py
cd test/ && python3 registered/unit/mem_cache/test_swa_locked_full_recover_unified.py
cd test/ && python3 registered/unit/mem_cache/test_unified_byte_accounting.py
cd test/ && python3 registered/unit/mem_cache/test_unified_byte_budget_sizing.py
cd test/ && python3 registered/unit/mem_cache/test_unified_capacity_memo.py
cd test/ && python3 registered/unit/mem_cache/test_unified_free_no_host_sync.py
cd test/ && python3 registered/unit/mem_cache/test_unified_hicache_strided_state.py
cd test/ && python3 registered/unit/mem_cache/test_unified_mamba_views.py
cd test/ && python3 registered/unit/mem_cache/test_unified_mha_views.py
cd test/ && python3 registered/unit/mem_cache/test_unified_mla_views.py
cd test/ && python3 registered/unit/mem_cache/test_unified_npool_sweep.py
cd test/ && python3 registered/unit/mem_cache/test_unified_radix_allocation_eviction.py
cd test/ && python3 registered/unit/mem_cache/test_unified_swa_shared_virtual_ids.py
cd test/ && python3 registered/unit/mem_cache/test_unified_tri_pool.py
cd test/ && python3 registered/unit/model_executor/test_pool_configurator.py
cd test/ && python3 registered/unit/server_args/test_page_major_backend_allowlist.py
cd test/ && python3 registered/unit/server_args/test_unified_prefill_cuda_graph_gate.py
cd test/ && python3 registered/unit/server_args/test_unified_tbo_gate.py
cd test/ && python3 registered/unit/test_model_overrides.py

🚀 1-gpu-5090 (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_unified_handout_zeroing.py
cd test/ && python3 registered/unit/mem_cache/test_unified_hicache_regressions.py
cd test/ && python3 registered/unit/mem_cache/test_unified_mla_gpu_parity.py

ch-wan added 5 commits October 1, 2026 17:12
…putes

`write_loc_to_kernel_ids` now serves every KV translate, reads as well as
writes, and returns physical ids. Rename it `translate_token_ids` (kernel
`translate_token_ids_kernel`, block `TRANSLATE_TOKEN_IDS_BLOCK`), with its
kernel-registry entry, callers, test classes and the strided GPU test file.
Pure rename.
…as they are

The kernel's argument comments still said `loc` is a 1-D int64 tensor of
widened ids; it is 1-D or a strided `(rows, cols)` view, int32 or int64, and
widened only under DCP. `_row_col_strides` handled a 0-d tensor that the
strided path, where both tensors are at least 1-D, never sees. The allocator
docstrings that called the translate's result "kernel-facing" or "dense" now
call it what it is, the physical id.
…or physical ids

`translate_write_loc_for_kernel` returns physical ids and `_assert_kernel_id_bound`
bounds them; with the kernel-facing and physical id spaces now the same, call
them `translate_write_loc` and `_assert_physical_id_bound`, and say "physical"
in the bound's message.
- translate_token_ids_kernel: under out_width, `out` is a packed 1-D
  buffer of W lanes, not shaped like `loc`.
- test_unified_mla_gpu_parity.py still gave the page-major formula
  kernel_id(t) = (t//ps)*(ps*L) + t%ps for what the unified pool
  receives; under the token-major views it receives the token's own id.
- test_inkling_unified.py said re-running full->swa on the rebound
  out_cache_loc indexes past the swa v2p table and trips a device
  assert. A full physical page number is a valid swa virtual page, so
  the map silently resolves it to an unrelated token's swa slot.
Under the token-major views the id a kernel indexes the per-layer views
with is the physical token id, and the identifiers now say so. The
comments, docstrings and two unified-memory error messages still called
it "kernel-facing"; they now say "physical". Sites that state the
equivalence on purpose, that describe a historical bug, or where the
word means something else (the Mamba checkpoint pool, the communicator)
are left alone.
@ch-wan
ch-wan force-pushed the mainline/stride-write-loc-kernel branch from d794024 to dfb0dac Compare October 2, 2026 00:13
@ch-wan
ch-wan merged commit 2a3655f into sgl-project:main Oct 2, 2026
31 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd blackwell SM100/SM120 bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang jit-kernel memory-pool parallel-stages CI: stages dispatch together instead of waiting on each other run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants