Skip to content

ROCm: accelerate GLM 5.3 prefill and reduce MTP overhead on gfx1151 - #1011

Open
kyuz0 wants to merge 6 commits into
antirez:mainfrom
kyuz0:perf/rocm-gfx1151-glm53-performance
Open

ROCm: accelerate GLM 5.3 prefill and reduce MTP overhead on gfx1151#1011
kyuz0 wants to merge 6 commits into
antirez:mainfrom
kyuz0:perf/rocm-gfx1151-glm53-performance

Conversation

@kyuz0

@kyuz0 kyuz0 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

GLM-5.3-Flash-Q2 prefill improves 2.20–2.46× on Strix Halo (gfx1151), and embedded-MTP decode improves 22.6% on the completed coding example. Ordinary decode is essentially unchanged.

Resident weights, ROCm 10, greedy native benchmark measurements against main 6289c51; MTP uses a benchmark adapter. Rates are tokens/s:

Workload Main This branch Change
Fresh 4K prefill 76.64 168.41 2.20×
Fresh 16K prefill 63.77 156.89 2.46×
Ordinary decode, 4K / 16K 11.82 / 11.17 11.82 / 11.16 ~unchanged
Completed coding turn, MTP decode 12.21 14.97 +22.6%

Single-run measurements. Coding answers contain 241→267 useful tokens, so throughput is not answer latency. Prefill/ordinary figures precede the final MTP-only commit, which leaves those paths unchanged.

Changes:

  • Enable existing IQ2 expert and Q4 projection MMQ paths for measured GLM 5.3 prefill shapes; parallelize grouped-indexer scoring with wave32.
  • Reuse Q8 weights across two-token projections and skip an unused accepted-draft prediction while preserving its KV update. The final change alone improves coding 14.52→14.97 tok/s with identical output.
  • Invalidate private MTP history after target-only append/evaluation to prevent unwritten draft rows entering its cache window.

Quality evidence:

  • Independent kernel references, complete outputs, canaries, boundary sizes and dispatch profiling before model-level tests.
  • Main and the kernel/history stage each pass 138 practical checks spanning ordinary/MTP, greedy/sampled generation, long prompts and tool round trips, plus 12 vision fact checks.
  • Official long-prompt scoring: 8 cases / 740 targets, weighted NLL improves 1.96%; four cases improve and four worsen. Final-head ordinary short scoring matches main exactly over 100 cases / 11,559 targets.
  • The final MTP-only change preserves 717 full-vocabulary state vectors against the preceding candidate, including snapshot/replay and rewind checks, plus tested native IDs/frontiers. Selected DS4F checks preserve logits/output without a material measured slowdown. All five executable help/link checks pass.

CUDA comparison used the identical GGUF and 4,096 raw token IDs at the same context frontier. Across all 154,880 logits:

Difference from CUDA main ROCm main This branch
Full-logit RMS difference 0.3491 0.2769
KL(CUDA ∥ ROCm), nats 0.0403 0.0412

All three select the same top token and top-ten set. Distances are mixed; CUDA also uses approximate arithmetic, so this checks consistency rather than establishing higher precision or quality equivalence.

Limits: gains are workload-specific; a separate raw-text MTP control is 19.3% slower than main MTP. Vision was not rerun after the final MTP-only commit, and its checks grade facts rather than strict formatting. Performance paths are guarded for resident ROCm/gfx1151 GLM 5.3.

Appending a prompt prefix or evaluating an external token can leave the private MTP window spanning target-only rows without draft KV. Invalidate draft history and its minimum position so the next seed starts at a populated row; preserve internal speculative evaluation and equal-length sync.

Read-only GLM 5.3 diagnostics reproduce three unwritten rows on main and none with the fix. Resident and streamed-expert append/ordinary-gap controls pass with exact live/reset vectors. CUDA, Metal, TP and GLM 5.2 are not hardware-qualified; exact-sampling replacement semantics remain outside this correction.
Admit resident GLM 5.3 topology with 288 experts, top-eight routing and 4096/2048/4096 dimensions to the existing IQ2 gate/up MMQ path. Preserve the previous admission for other models, streaming exclusions and token-tail handling.

Production-shape reference/canary checks pass. The isolated candidate improves 4K prefill from 76.61 to 127.58 tok/s; the final combined change passes the official and practical panels. Activation requantization changes arithmetic; quality evidence is model-level, not bit parity.
Route the resident GLM K4096/M8192 Q4 projection through existing MMQ only for 128 to 2048 rows, retaining the original small-prompt path and quality/streaming fallbacks.

Production-layout reference and tail/canary checks pass. The isolated candidate improves 4K prefill from 76.61 to 85.08 tok/s. Combined final short100 scores match main exactly and long8 weighted NLL improves 1.96%, with mixed per-case changes.
Assign one wave per pooled key group for the FP16-key, 32-head, dimension-128 GLM 5.3 indexer on resident gfx1151 bulk prefill. Preserve causal and partial-group masking and existing fallbacks.

Independent full-output boundary/canary checks pass. Actual ISA uses paired FMAs and the comment acknowledges rounding drift. The isolated candidate improves 8K prefill from 70.91 to 77.91 tok/s; final combined model scoring and practical checks pass.
Quantize two activation rows once and reuse packed weights across their accumulators for twelve production shapes on resident, quality-off gfx1151 GLM 5.3. Preserve GLM 5.2 and other-model dispatch and exclude the slower K128/M8192 shape. This also covers ordinary two-token prefill and appended tails.

Full independent references and canaries pass; the fused operator matches the existing prequantized path. Final combined code passes 138 practical checks, 12 vision fact cases and exact-source official panels, with state replay checks intact. Completed coding MTP improves 12.21 to 14.52 tok/s versus main; raw 4K MTP remains slower at 6.25 versus 7.79. Q8 activation arithmetic changes trajectories and acceptance, so this is not a universal MTP speed or distribution-equivalence claim.
@saxs2224

Copy link
Copy Markdown

Tested this independently on my own Strix Halo box (AMD Ryzen AI Max+ 395 / Radeon 8060S, gfx1151, 128GB unified memory, ROCm 10.0 / HIP 7.15) — same GLM-5.3-Flash-Q2.gguf, on top of main 6289c51 as stated.

Speed (ds4-bench --gen-tokens 0, fresh prefill per context length):

ctx main this PR speedup
4096 76.78 169.27 2.20x
8192 71.09 162.6-163.5 (3 runs) 2.29x
16384 63.85 156.7-157.4 (2 runs) 2.46x

Matches your numbers closely (168.41/2.20x @4k, 156.89/2.46x @16k).

Correctness — after getting burned by the non-determinism in #923, I checked this one thoroughly:

  • test-glm-attention-rocm, test-glm53-kda-rocm, test-mxfp4-rocm: all PASS, 0 failures. (Minor build note: all three standalone test targets fail to link against mainundefined symbol: ds4_engine_is_glm53, referenced from ds4_rocm_matmul.cuh but the Makefile test rules don't pull in ds4.o where it's defined. Worked around it locally by stubbing the symbol in the three test .c files; not a code bug, just a Makefile gap worth a follow-up.)
  • Determinism: reran the exact same prefill 3x at ctx=8192 and 2x at ctx=16384 with --dump-frontier-logits-dir, diffed every pairing — 0/154892 differing logits every time.
  • End-to-end: sent the same ~30.6K-token prompt through ds4-server twice (greedy, 150 output tokens), full chat completion — byte-identical output both times.

No issues found. This one looks solid — nice work on tracking down the invalidation bug from the last round.

@kyuz0

kyuz0 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for checking and testing this PR! @antirez , whenever you have a second, this looks like a good one to marge.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants