Repository navigation
Speed up DeepSeek V4 Flash prefill on ROCm gfx1151 (Strix Halo) - #1339
Open
felix920506 wants to merge 6 commits into
Open
felix920506 wants to merge 6 commits into
felix920506 wants to merge 6 commits into
Conversation
hipcc rejects rsqrtf in host code (HIP's is device-only, unlike CUDA's), so the ROCm build fails at ds4_rocm_deepseek4_vision.cuh. The value feeds a host-side BLAS call, so use 1/sqrtf, which is defined on both.
-ffast-math reassociated the three-factor Q8_0 product differently in the single-matrix and paired kernels, so ./ds4_test --metal-kernels saw ~1 ulp disagreements. Pin the order with an explicit FMA in both.
HIP rejects a host-to-device copy whose source crosses two pinned host registrations. Split those copies at registration edges, so a span that covers the tail of one registered range and the head of the next still copies.
ds4_rocm.o needs symbols from ds4_rocm_compat.o, so make test-mxfp4-rocm and the other ROCm kernel test binaries that linked only ds4_rocm.o and the unavailable stubs failed to link.
The ROCm routed MoE consumes gate/up through moe_swiglu_weighted, which already drops non-finite values at read, so the two whole-buffer sanitize passes (0.8 ms per layer at 2048 tokens) are redundant there.
Prefill in 2048-token steps on Strix Halo goes from 198 tok/s (cold first chunk) / 267 (4K) / 248 (16K) to 342 / 423 / 407, with decode unchanged. Prefill-sized (32+ token) Q8/F16 projections run as an F16 hipBLASLt GEMM. The library's heuristic order is unreliable on gfx1151, so each shape class times the candidates once and keeps the fastest. This replaces the rocBLAS F32 path, the custom WMMA row-tile kernels and the transposed F16 weight cache with its cold per-layer dequant. Smaller batches (decode, DSpark verification) stay on the native kernels. Attention uses one 32-head WMMA kernel for every prefill chunk, including the zero-prefix first chunk. When the MMQ gate/up pair produces every routed mid row, SwiGLU writes them as F16 and the Q2_K down projection runs as one tiled F16 WMMA kernel; the other gate/up routes keep the hot/cold down split. The indexer keeps the weighted head sum in WMMA registers. See speed-bench/gfx1151-prefill-results.md for the sweep and the official-continuation scores before and after.
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.
Prefill on Strix Halo is 58-73% faster from 2K to 16K context. Decode speed is unchanged, and official-continuation quality on the 0731 release GGUF is as good as
mainor slightly better.The first five commits are standalone fixes found along the way, and each builds on its own:
maindoes not build with ROCm 7.14, because HIP'srsqrtfis device-only.-ffast-mathreassociation. Without it,mainfails the paired Q8_0 exactness check in./ds4_teston ROCm.test-mxfp4-rocm,test-glm53-kda-rocmandtest-glm-attention-rocmfailed to link.The sixth commit, Speed up DeepSeek V4 Flash prefill on ROCm gfx1151, is the speedup itself:
The only change outside ROCm is in
ds4.c, where ROCm now gets two things Metal already had:Metal and CUDA behavior is unchanged.
cuda/mmqgains one entry point,ds4_mmq_iq2_xxs_moe_pair_unsanitized, which the CUDA paths do not call.Test setup
rocm/dev-ubuntu-24.04:7.14.0-fullcontainer.DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-0731.gguf, withDeepSeek-V4-Flash-DSpark-support-0731.gguf. Both are checked against their SHA-256 sums.main(b3f5018) plus commit 1, becausemainalone does not build on ROCm.MemAvailable - CmaFreewatchdog that stops the run below 3 GiB.Build gates
make clean && make strix-haloscore_officialmake cpugit diff --checkTests that need no model
All of these pass:
./ds4_test --server,./ds4-eval --self-test-extractorsand./ds4_agent_testtests/test_layer_pack(97/97),tests/test_engine_mgpu_placement(114/114) andtests/test_gpu_argstests/test_gpu_args_cli.sh(86 pass, 0 fail) andtests/test_prompt_prefixq4k-dot-test(4/4),mxfp4-dot-test(4/4) andtest-session-statemake test-linux-memory test-rocm-memorymake test-mxfp4-rocm: zero failures formidandoutat 1, 3, 32, 128 and 512 tokensmake test-glm53-kda-rocm test-glm-attention-rocm, also withDS4_ROCM_GLM_SELECTED_ATTN_HEAD_TILE=1tests/test_deepseek41_rocmandtests/test_mmvq_rocm./ds4_test --metal-kernels, which runs the isolated GPU kernel checks on ROCmFull
./ds4_testwith the 0731 modelCommand:
ds4 tests: ok. Every check passes.logprob-vectors,local-golden-vectors(top5 5/5, top20 20/20),metal-tensor-equivalence,dspark-verify-depth, the session tests,long-contextandserver.mismatches=57/77), which commit 2 fixes.Speed
On the 0731 model:
All numbers are tok/s. The Vision-Exp model gives the same numbers within 1%.
Quality
score_officialon each GGUF, before and after the change:data/flash(100 cases, API logprobs) @4096flash-vision-exp-openrouter-novita-100@4096tests/test-vectors/flash-vision-exp, 5 cases (two are about 5K tokens) @8192DS4_ROCM_MMQ_IQ2=0(non-MMQ gate/up path)compare_scores.pygives an NLL change of -0.81%, and the branch wins 52 of the 100 cases.--quality, the logits are bit-identical tomain(max-abs 0), so the full-FP32 reference path is untouched.DSpark
On the 0731 model:
Both builds pass with
errors=0and no replays. Speeds are tok/s, DSpark first and ordinary decode second:The fixture also passes with the Vision-Exp model and its support GGUF.
Known behavior
logprob-vectorsandlocal-golden-vectorssit at their thresholds and flip between runs, and they flip onmaintoo. Vision-Exp's own FP32--qualityreference agrees with this branch on the case that flips.metal-tensor-equivalencefail on ROCm: two engines in one process pick different top-1 tokens on a 27-token prompt, even when they use the same tuned algorithms.cuda/mmqentry point.🤖 Generated with Claude Code