feat(ds4): add fused HIP decode for ROCmFPX#503
Conversation
6a8c765 to
00df78f
Compare
6fe5e71 to
a5f1146
Compare
00df78f to
42f1e10
Compare
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Not reviewed (too large): server/src/deepseek4/deepseek4_graph.cpp (~1,745 lines) - if these are generated or fixture files, add them to ignored paths to exclude them from future reviews.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Validation update (2026-07-09): validated on lucebox2 against DeepSeek-V4-Flash ROCmFP2. The env-only expert routing knob DFLASH_DS4_TOPK=4 reduces routed experts from 6 to 4 and renormalizes retained weights. AR validation (GSM n=5 plus Math n=5) reached 26.19 tok/s GSM and 25.16 tok/s Math, both 5/5, versus baseline 23.54 and 22.24 tok/s. DSpark fused speculative decode reached 20.1–20.3 tok/s warm in repeated q=4 runs, with approximately 105–106 ms verify steps. Adaptive width, causal batched verify, fused verify, and interior-boundary compressor emission are wired and producing coherent output. The neuron-magnitude mask preserved the small-screen scores but produced no speedup; the block-sparse follow-up was not quality-safe and is kept out of the validated path. These measurements come from the hub-494 experiment worktree; the final k=4 patch and larger DSpark runtime follow-on still require explicit commit/push if they are to become part of the PR diff. |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="server/src/deepseek4/deepseek4_graph.cpp">
<violation number="1">
P2: `DFLASH_DS4_TOPK` will not reduce expert work for hash-routed DS4 layers: this override only changes `build_moe_routing`, while the hash-routed decode graphs still allocate/upload `w.n_expert_used` expert IDs and run `ggml_mul_mat_id` over that full count. If the knob is intended to be a serving-wide bandwidth lever, it would be worth applying the same reduced count when building and filling `hash_ids`, or documenting that hash-routed layers are excluded.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Semi-Automated review pass.
Codex: Overall this is careful, well-documented work and the risky paths (fused decode, FFN combine variants, GPU HC) are correctly gated behind default-OFF env flags. My comments concentrate on a few changes that land on the default code path plus one likely-dead block. Inline notes below;
Added a few from Codex, all just nits really. Works well, i've been tested it over the last few days and is works well!
Nice work davide!
2598602 to
e943f2a
Compare
b403928 to
a7dee5b
Compare
Use HIP's target-specific warpSize builtin for the two-stage RMSNorm reduction. ROCm 7.2 no longer defines the deprecated AMDGCN wavefront-size preprocessor spellings used by the prior implementation, which prevented clean gfx1151 builds. The device builtin supports wave32 and wave64 without an architecture guess.
Add an explicit single-graph decode mode for single-device HIP deployments and a validated routed-expert top-k policy exposed through server CLI options. Keep the default model policy unchanged unless requested. The fused graph retains HC, attention, MoE, cache updates, and output projection on-device while caching structural compressor variants. Reset all request cache topology, handle raw-ring wraparound, apply expert limits to hash-routed layers, and expose full-graph timing. Add cache and ring regression coverage and document the serving contract.
Specialize the profiled single-column ROCmFP2/FP3 shapes with fixed-K loops, partially unroll the ROCmFP4-fast loop, and decode packed FP3 values with v_perm_b32 on HIP. Dispatch is restricted to gfx1151 and the exact validated shapes; all other devices and dimensions retain the generic kernels. The specializations preserve each lane's K traversal and accumulation order.
Publish the worker-pool generation and shutdown predicates under the same mutex used by the condition-variable wait. Without that synchronization, a worker could miss notify_all between checking the predicate and blocking, leaving the request thread spinning forever. Always notify after publishing and remove the racy sleeper-count optimization.
e943f2a to
d5fae56
Compare
Summary
Add the production DeepSeek V4 Flash decode path on top of the ROCmFPX types
merged in #502:
specialization, restricted to the exact profiled shapes;
--ds4-fused-decodeand--ds4-expert-top-k Nserving options;The branch is rebuilt directly on current
main; it no longer carries thealready-merged #502 changes or the old submodule-era conflicts.
Runtime behavior
--ds4-fused-decodenow requests a monolithic HIP model load because the fusedgraph must reference every expert tensor directly. If that allocation fails,
the backend logs the fallback and disables fused execution for hybrid expert
placement instead of claiming that the fused graph is active.
--ds4-expert-top-k 4keeps and renormalizes four routed experts. It is anexplicit approximate-inference policy;
0retains the model's configuredexpert count.
No performance feature in this PR requires a serving-time environment
variable.
DFLASH_DS4_TIMINGremains optional instrumentation only.Correctness and maintainability
exercises pre-wrap, boundary, and wrapped cases.
the flush topology.
permute + cont + sum_rowspath.mutex used by the condition-variable wait, preventing lost wakeups.
Validation
Hardware and model:
gfx1151, ROCm 7.2.2, 128 GiB RAM / 96 GiB ROCm aperture;DeepSeek-V4-Flash-ROCMFP2-STRIX.gguf, SHA-2568fa6c30d9badd8e72f83c62952fe24b2e8cd647e103aff086bece328cb9c9208.Configuration:
Two consecutive GSM+Math runs produced identical generated text and scores:
The same checked prompt measured 16.10 tok/s when the old 8K initialization
silently selected hybrid/layered execution and 26.56 tok/s after the monolithic
fused path was made reachable.
The strict trace gate compared 64 full-vocabulary F32 logits rows byte for byte
with zero mismatches. The final model-loading fix changes path selection only;
it does not change graph arithmetic. A fresh ROCm build passes all 20 CTest
targets, including ROCmFP reference/tail tests, RMSNorm, HC, DeepSeek4, and
server tests.
Top-k 4 still requires workload-level quality validation beyond this small
regression suite.