Repository navigation
[AMD] [GLM-5.3-Flash Day 0] Enable zero-RoPE TileLang DSA on gfx950 - #38547
Conversation
e1be1e9 to
eab6b47
Compare
Compile out zero-width tail work and generalize FP8 TileLang/cache layouts so GLM's 256+0 geometry is covered without changing the existing 512+64 path.
eab6b47 to
54624dd
Compare
|
/rerun-failed-ci |
|
/rerun-failed-ci |
Squashed from #38547, which carries the same change against main and remains open there for review. Co-Authored-By: Raiden-Makoto <[email protected]> Co-authored-by: Cursor <[email protected]>
| def _infer_dsa_dims(dim_quant: int) -> tuple[int, int]: | ||
| if dim_quant == 264: | ||
| return 256, 0 | ||
| if dim_quant == 656: | ||
| return 512, 64 | ||
| raise ValueError(f"Unsupported packed DSA KV row width: {dim_quant}") |
There was a problem hiding this comment.
quantize_k_cache_separate now emits widths this cannot read
This PR widens the quant side from dim_nope != 512 -> raise to dim_nope % 128 != 0 -> raise with dim_rope in (0, 64), while dequant stays a two-entry table, so the pair no longer matches:
| quant input | packed width | this function |
|---|---|---|
| 256 + 0 (GLM-5.3 no-PE) | 264 | ✅ |
| 512 + 64 (DeepSeek MLA) | 656 | ✅ |
| 512 + 0 | 528 | ❌ ValueError |
| 256 + 64 | 392 | ❌ ValueError |
Before this PR quant accepted exactly one combination and this accepted exactly one width, so the asymmetry is new rather than pre-existing.
Not urgent: no caller can reach it (dsa_backend, deepseek_v4_backend, forward_mha and hip_flash_mla all pass a cache produced by the paired quant for one of the two real models), and it raises rather than returning wrong numbers. Worth closing anyway because it is cheap and it also un-breaks the dv / dim_nope / dim_rope parameters — _infer_dsa_dims runs unconditionally at lines 74 and 98 before they are consulted, so today they cannot rescue an unsupported width, only reject a supported one. Generalising here fixes all five call sites and leaves lines 74-81 and 98-100 untouched.
The width determines the pair uniquely, so the table can go:
| def _infer_dsa_dims(dim_quant: int) -> tuple[int, int]: | |
| if dim_quant == 264: | |
| return 256, 0 | |
| if dim_quant == 656: | |
| return 512, 64 | |
| raise ValueError(f"Unsupported packed DSA KV row width: {dim_quant}") | |
| def _infer_dsa_dims(dim_quant: int, tile_size: int = 128) -> tuple[int, int]: | |
| """Recover (dim_nope, dim_rope) from a packed row width. | |
| A packed row holds dim_nope fp8 bytes, 4 scale bytes per tile and 2 bytes | |
| per rope element, so | |
| dim_quant = dim_nope * (tile_size + 4) / tile_size + 2 * dim_rope. | |
| With dim_rope constrained to 0 or 64 and dim_nope to a multiple of | |
| tile_size at most one candidate can satisfy that: the two branches differ | |
| by 128 * tile_size / (tile_size + 4), which is not a multiple of tile_size, | |
| so they cannot both land on a multiple of tile_size. | |
| """ | |
| for dim_rope in (0, 64): | |
| numer = (dim_quant - 2 * dim_rope) * tile_size | |
| if numer % (tile_size + 4): | |
| continue | |
| dim_nope = numer // (tile_size + 4) | |
| if dim_nope > 0 and dim_nope % tile_size == 0: | |
| return dim_nope, dim_rope | |
| raise ValueError(f"Unsupported packed DSA KV row width: {dim_quant}") |
I checked this is equivalent rather than a behaviour change: 264 -> (256, 0) and 656 -> (512, 64) as before, every dim_nope in 128..1024 against dim_rope in (0, 64) round-trips, and no width in 1..20000 resolves to two candidates.
There was a problem hiding this comment.
Fixed in 4b55b94f8b: _infer_dsa_dims now derives every valid 128-aligned NoPE width with RoPE 0 or 64 instead of using a two-entry table. Added round-trip coverage for NoPE widths 128–1024 plus invalid-width rejection; the full MI35X file passes 6/6 tests.
| The paged KV cache stores 656 bytes per token: | ||
| [512 nope_fp8 | 16 scales_f32 (4 groups) | 128 rope_bf16_bytes] |
There was a problem hiding this comment.
Docstring still describes the fixed 656/576 layout
Line 345 now resolves the widths through _infer_dsa_dims, so this function already handles the 264 -> (256, 0) case, but the docstring pins the DeepSeek shape in four places:
| line | says | is now |
|---|---|---|
| 316-317 | stores 656 bytes per token: [512 nope_fp8 | 16 scales_f32 (4 groups) | 128 rope_bf16_bytes] |
one of two layouts |
| 331 | quant_k_cache: [total_num_tokens, 1, 656] |
dim_quant, resolved from the input |
| 339 | out: ... [num_tokens + extra_rows, 1, 576] |
dim_nope + dim_rope |
| 342 | output: [num_tokens + extra_rows, 1, 576] |
same |
Line 339 is the one that matters, since out is caller-allocated: someone sizing it from the docstring while running the 264 path allocates 576 instead of 256. That is caught — assert out.numel() == total_rows * out_dim reports both numbers — so this is doc-only rather than a silent corruption, which is why I have not flagged it higher.
Describing the layout symbolically and giving both widths as examples would cover it. No suggestion block here since the wording is yours.
There was a problem hiding this comment.
Fixed in 4b55b94f8b: the docstring now describes the packed layout symbolically, lists both 264-byte and 656-byte examples, and sizes quant_k_cache, out, and the return value from the inferred dimensions. The MI35X regression file passes 6/6 tests.
… it to distinct failure modes The file lived in a new test/registered/e2e/attention/ directory although it launches no server; the registry validator's kernel layout is test/registered/kernels/ops/<group>/. The dim-inference case recomputed the packed width with the implementation's own formula, so it is now a literal table of the four widths quantize_k_cache_separate accepts. The BF16/FP8 zero-RoPE matrices drop from six subcases to the two that compile distinct inner_iter specializations. The scaled-cache round trip moves to its own class so it also runs on the CUDA kernel lane, where the 264-byte layout is consumed by set_mla_kv_buffer. _dequantize_k_cache_fast has one caller, which always passes the resolved dims, so the second _infer_dsa_dims call inside it is removed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Reset quark.py to upstream sgl-project#39779's per-expert fused config resolution and keep only the block-FP8 activation-grouping check. Fused shared experts are CUDA-only, so the removed shared-expert precision matching loses nothing on ROCm. Drop tests whose targets are now upstream code or duplicate upstream coverage: k-pool cache layout and backend dispatch (sgl-project#39341), TileLang zero-RoPE (sgl-project#38547), transform_index widths (sgl-project#39340), mHC HIP dispatch (sgl-project#38545), the NextN name mapper, write-plan multi-pool, negative-slot scatter, and the comment-only AITER runner. Keep one focused test per production change this branch owns.
Summary
Replacement for #37653, which GitHub closed when its deleted support base was merged into main.
GLM-5.3-Flash sparse DSA uses a 256-wide NoPE latent with a zero-width RoPE tail. The HIP TileLang BF16 partial kernel still emits zero-extent tail allocation/copy/gather/GEMM work, while the HIP FP8 kernel and scaled cache helpers are specialized for the existing DeepSeek-style 512+64 layout.
This PR enables GLM's 256+0 geometry without changing the established 512+64 behavior.
d_v=512)d_v=256and retains four ford_v=512512 FP8 + 16 scale + 128 RoPE)256 FP8 + 8 scale + 0 RoPE)Scope
Four production files:
tilelang_kernel.py: compile out HIP BF16 zero-tail work and specialize the HIP FP8 kernel for either 256+0 or 512+64.quant_k_cache.py: infer or accept the NoPE width, derive the number of 128-element scale tiles, and permit an empty RoPE tensor.dequant_k_cache.py: recognize 264-byte and 656-byte packed rows and use their derived dimensions in direct, paged, and gather/dequant/requant paths.memory_pool.py: document the dimension-derived scaled layout and optional RoPE payload at the existing write sites.One MI35x test file directly covers the TileLang kernels and scaled cache helpers. No model loading, server launch, accuracy benchmark, scheduler/backend policy, dense MHA path, mHC path, MoE path, or CUDA TileLang FP8 behavior is changed.
The FP8 kernel keeps the existing 512+64 allocation, GEMM, accumulation, normalization, and store order. The 256+0 specialization emits only the first two 128-wide tiles and no tail operations.
Test plan
Combined main-based integration (
RM/glm53-day0-main-integrationtested at9d0d62b744; current integration head4e2f84ff3c; TP8/TP4 validation predates the above-cap guard, whose below-cap path is unchanged, pinned AITERd9e5ef7ce0, fresh caches): TP8 GSM8K 97.50% in 87.0s with 0.00% errors; TP4 GSM8K 96.97% in 320.2s with 0.00% errors. Decode CUDA graphs were enabled in both runs.Recovery base:
main@30e7a3072d.Recovery validation on MI355X: scoped pre-commit passed; all 4 BF16/FP8 TileLang and cache-layout test groups passed.
Docker:
rocm/sgl-dev:v0.5.18-rocm720-mi35x-20260830.Hardware: one MI350X (
gfx950).Base:
xinyuan/glm-5.3-flash-support@545bd6f839.The same new test file was run in both arms; the four production files are the only variables.
Direct GLM geometry coverage:
[tokens, 64, 256], KV[slots, 1, 256], output BF16[tokens, 64, 256];-1to 2112;256+0) and 656-byte (512+64) scaled-cache round trips and repeated-page gathers;register_amd_ci(suite="stage-b-test-1-gpu-small-amd-mi35x")python/sglang/jit_kernel/tests/test_triton_store_cache_local.py.CI States
Latest PR Test (Base): ❌ Run #35688366857
Latest PR Test (Extra): ❌ Run #35688366669
Latest PR Test (AMD ROCm 10): ❌ Run #35688366761