The port to vLLM 0.31, and the three things that moved under it¶
Archived: a dated record
This chapter is the state of the work when it was written: its API, numbers and baselines are of that time. Current documentation starts at the docs home; the numbers the project quotes are on the scorecard.
Part of the development record, in the order the work happened. Paths, API names and numbers are those of the time.
Everything before this chapter was measured on the vLLM the pod shipped, 0.16.1.dev0. This chapter moves the integration to the latest release, 0.31.0, built from source for ROCm 7.2.1 with torch 2.13 and triton-rocm 3.7.1. It then measures the integration again.
No hk kernel changed. Three things in vLLM did, and each one would have produced a plausible number that was wrong.
One cache tensor per layer¶
0.31 keeps each layer's KV cache as a single tensor, [blocks, kv_heads,
block, 2 * head], with K and V side by side in the last dimension. Its
logical order is set by a KVCacheLayout that each backend declares.
hk's paged kernels read a head-major cache. The backend therefore declares
LBHNC and slices K and V out of the last dimension. A 5-D cache from an
older vLLM is still split on its leading dimension, so one backend serves
both versions.
The first eager run with the stock layout (LBNHC) failed loudly, because
k_cache was not contiguous where the kernel assumed it was. That was the
easy one.
A compile cache that does not know what was patched¶
0.31 keys the graphs it compiles by its config and its source, not by what is patched into it. Since 0.2x that includes an AOT cache that skips Dynamo entirely.
The first 0.31 run of hk+gemm loaded the graph that the hk arm had
compiled a minute earlier. Every linear layer inside that graph called
vLLM's GEMM. The arm timed exactly like hk alone, to within 1%. The counters
showed 2476 routed calls and 0 during capture, and those 2476 were all the
LM head, which runs outside the graph.
vllm_gemm.apply() now points VLLM_CACHE_ROOT at a hk-linear
subdirectory, so patched and unpatched graphs never share a cache. The rerun
logs compile cache /root/.cache/vllm/hk-linear. Its counters show the
captured graphs calling the decode kernel 3276 times.
The MoE patch of the next chapter has no such problem. vLLM's MoE layer is a custom op that the compiler does not trace into.
A skinny GEMM that now runs on gfx11¶
0.16.1 ran its skinny GEMMs (wvSplitK, LLMM1) on gfx9 only. 0.31 runs
them on gfx11 too, for M ≤ 5. That is one reason stock 0.31 decodes faster:
41.3 ms a step at 1024 x 1 on 0.16.1, 24.5 ms on 0.31.
The routing table had been measured against F.linear, which is
hipBLASLt. Measured against that, the decode kernel won from one token up.
route_tune.py now measures against what the installed vLLM actually runs:
rocm_unquantized_gemm where it is registered, and F.linear without vLLM.
It records which one in the table's engine field.
Remeasured on 0.31: - M of 1-2 stays on vLLM on every shape, and 1-5 on most; - the decode kernel takes 6-64; - above that, the GEMM keeps its comb.
A harness that patched the wrong process¶
With V1 multiprocessing on, which is the default, vLLM's engine core is a second process. It imports vLLM afresh and runs unpatched.
Every earlier number here had been taken with
VLLM_ENABLE_V1_MULTIPROCESSING=0 set by hand. One 0.31 run was started
without it, and every hk arm in it would have timed as stock with nothing to
say so. It was caught during its first arm, by a log line: EngineCore pid=
where MainProcess should have been. vllm_e2e.py now sets the variable
itself. A served engine is patched by the plugin instead, which vLLM loads
in every process.
Two baselines¶
Stock 0.31 on gfx1100 picks ROCM_ATTN. Its custom paged-attention kernel
then refuses the card, and it falls back to a Triton kernel (Cannot use
ROCm custom paged attention kernel, falling back to Triton implementation).
hk's backend registers over TRITON_ATTN, and below 8 requests it runs
TRITON_ATTN's own unified_attention on hk's cache. So the table has two
baselines:
- stock, the engine as it ships;
- TRITON_ATTN, the backend hk replaces.
Against the second, a small-batch gain is hk's own.
Results¶
Qwen3-8B, bf16, vLLM 0.31.0 under its defaults: CUDA graphs, prefix caching and chunked prefill. 72 generated tokens, best of two rounds, one process per arm. Every arm's greedy tokens are identical to stock's.
Total ms per request batch, ratio to stock; then the decode step, in ms.
| ctx x batch | stock | TRITON_ATTN | hk | hk+gemm | hk / TRITON_ATTN | step: stock | TRITON_ATTN | hk | hk+gemm |
|---|---|---|---|---|---|---|---|---|---|
| 1024 x 1 | 1992 | 1702 (1.17x) | 1687 (1.18x) | 1636 (1.22x) | 1.01x | 24.5 | 20.2 | 20.3 | 20.3 |
| 1024 x 4 | 2781 | 2568 (1.08x) | 2496 (1.11x) | 2310 (1.20x) | 1.03x | 26.2 | 22.3 | 22.4 | 22.2 |
| 1024 x 16 | 7493 | 7341 (1.02x) | 7150 (1.05x) | 4932 (1.52x) | 1.03x | 51.1 | 46.2 | 48.3 | 27.8 |
| 1024 x 32 | 12174 | 12272 (0.99x) | 11181 (1.09x) | 8302 (1.47x) | 1.10x | 61.7 | 58.6 | 52.2 | 32.7 |
| 4096 x 1 | 3664 | 2850 (1.29x) | 2468 (1.48x) | 2301 (1.59x) | 1.15x | 36.8 | 21.0 | 21.0 | 21.0 |
| 4096 x 4 | 7180 | 7311 (0.98x) | 5742 (1.25x) | 4990 (1.44x) | 1.27x | 38.5 | 24.5 | 24.6 | 24.8 |
| 4096 x 16 | 26607 | 26211 (1.02x) | 20091 (1.32x) | 15634 (1.70x) | 1.30x | 72.1 | 55.3 | 59.0 | 38.2 |
| 4096 x 32 | 51762 | 51525 (1.00x) | 36969 (1.40x) | 29604 (1.75x) | 1.39x | 112.2 | 104.4 | 71.2 | 51.5 |
Where the time went.
- TRITON_ATTN is 0.98-1.29x stock end to end, and up to 1.75x per decode
step. The backend 0.31 picks on this card is the slower of its two.
- hk is 1.01-1.39x TRITON_ATTN, almost all of it prefill: hk's paged prefill
is 3.6-7.9x Triton's (chapter 17).
- hk+gemm is 1.20-1.75x stock. The linear-layer patch gains nothing at 1 and
4 requests, where the table now leaves M ≤ 5 to wvSplitK. It nearly
halves the step at 16 and 32.
The decode kernel. At 16 requests hk's step was the slower one: 48.3 ms
against TRITON_ATTN's 46.2 at 1024, and 59.0 against 55.3 at 4096.
paged_ab.py on 0.31, with every layer's cache cold (ms per layer, graph
clock, Triton's kernel on hk's cache against hk's walk and merge), says why:
| ctx | 16 requests | 32 | 64 |
|---|---|---|---|
| 1024 | 0.1201 / 0.1264 | 0.1804 / 0.2166 | 0.3505 / 0.3972 |
| 4096 | 0.3738 / 0.4001 | 0.6907 / 0.7587 | (out of memory at 36 layers) |
On 0.16.1 hk's kernel won from 16 requests up. On 0.31, with triton-rocm 3.7.1, Triton's 2-D kernel wins at every batch measured, by 5-20%: 730-780 GB/s against hk's 610-700.
Giving it those batches made the step slower. The backend was changed to send every decode batch to Triton's kernel on hk's cache, and the 16- and 32-request shapes were measured again, end to end, in the same way:
| ctx x batch | step, hk walk at 16+ | step, Triton at 16+ | with gemm, hk walk | with gemm, Triton |
|---|---|---|---|---|
| 1024 x 16 | 48.3 | 50.1 | 27.8 | 29.8 |
| 1024 x 32 | 52.2 | 58.1 | 32.7 | 38.5 |
| 4096 x 16 | 59.0 | 74.2 | 38.2 | 52.0 |
| 4096 x 32 | 71.2 | 103.5 | 51.5 | 84.3 |
TRITON_ATTN measured 55.3 and then 55.9 at 4096 x 16, so the run itself was steady. The kernel-level and step-level measurements disagree. The likely difference is that the 2-D path, called from inside hk's backend, is not captured in vLLM's full decode graph as the walk is, but that was not confirmed. The step is what a server pays, so the boundary went back to 8 requests. This is a negative result, recorded, and the paradox is open.
The step lead hk's walk shows at 32 requests is still not obviously its kernel. The step is inferred from runs of two lengths, and at 4096 x 32 those runs overlap chunked prefill, where hk is 3.6-7.9x.
What is left¶
hk's decode attention loses to Triton's on the latest vLLM, kernel for kernel, at every batch measured. The backend still earns its keep in prefill. The decode kernel is the M1 gate that is not met, and on 0.31 it is missed by a wider margin than on 0.16.1. Why Triton's faster kernel makes for a slower captured step inside hk's backend is the first thing to find.