Skip to content

feat(ds4): add fused HIP decode for ROCmFPX#503

Merged
davide221 merged 5 commits into
mainfrom
codex/ds4-rocmfpx-server
Jul 17, 2026
Merged

feat(ds4): add fused HIP decode for ROCmFPX#503
davide221 merged 5 commits into
mainfrom
codex/ds4-rocmfpx-server

Conversation

@davide221

@davide221 davide221 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Add the production DeepSeek V4 Flash decode path on top of the ROCmFPX types
merged in #502:

  • cached, monolithic HIP decode graph covering HC, attention, MoE, and logits;
  • gfx1151 single-column ROCmFP2/FP3 fixed-K kernels and ROCmFP4 loop
    specialization, restricted to the exact profiled shapes;
  • explicit --ds4-fused-decode and --ds4-expert-top-k N serving options;
  • exact tokenwise prefill and cache-reset/ring-wrap correctness fixes;
  • race-free persistent HC worker pool for the layered/hybrid fallback.

The branch is rebuilt directly on current main; it no longer carries the
already-merged #502 changes or the old submodule-era conflicts.

Runtime behavior

--ds4-fused-decode now requests a monolithic HIP model load because the fused
graph 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 4 keeps and renormalizes four routed experts. It is an
explicit approximate-inference policy; 0 retains the model's configured
expert count.

No performance feature in this PR requires a serving-time environment
variable. DFLASH_DS4_TIMING remains optional instrumentation only.

Correctness and maintainability

  • New sequences reset both cache storage and compressed-row topology.
  • Decode after raw-SWA ring wrap reads the correct physical rows; unit coverage
    exercises pre-wrap, boundary, and wrapped cases.
  • Compressed-KV writes are graph dependencies, and cached graph keys include
    the flush topology.
  • Fused timing is included in phase-level telemetry.
  • Default MoE reduction keeps the proven permute + cont + sum_rows path.
  • No implicit system prompt or unsupported chunked-prefill mode is introduced.
  • Dead full-step graph-cache code was removed.
  • The HC worker sequence and stop predicates are synchronized with the same
    mutex used by the condition-variable wait, preventing lost wakeups.

Validation

Hardware and model:

  • Strix Halo gfx1151, ROCm 7.2.2, 128 GiB RAM / 96 GiB ROCm aperture;
  • performance profile with 2900 MHz SCLK observed throughout the run;
  • DeepSeek-V4-Flash-ROCMFP2-STRIX.gguf, SHA-256
    8fa6c30d9badd8e72f83c62952fe24b2e8cd647e103aff086bece328cb9c9208.

Configuration:

--target-device hip:0
--max-ctx 8192
--prefix-cache-slots 0
--prefill-cache-slots 0
--ds4-fused-decode
--ds4-expert-top-k 4

Two consecutive GSM+Math runs produced identical generated text and scores:

Suite Accuracy per run Mean decode Output tokens
GSM 5/5 26.39 tok/s 632
Math 5/5 25.83 tok/s 963
Combined 10/10 26.11 tok/s unweighted; 25.89 token-weighted 1,595

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.

@davide221 davide221 changed the title fix(deepseek4): ROCmFPX byte-safe decode + fused-decode path fix(ds4): ROCmFPX byte-safe decode + fused-decode path Jul 8, 2026
@davide221
davide221 force-pushed the codex/ds4-rocmfpx-server branch from 6a8c765 to 00df78f Compare July 8, 2026 15:14
@davide221
davide221 force-pushed the codex/rocmfpx-ggml-vendor branch from 6fe5e71 to a5f1146 Compare July 8, 2026 15:46
@davide221
davide221 force-pushed the codex/ds4-rocmfpx-server branch from 00df78f to 42f1e10 Compare July 8, 2026 15:46
@davide221
davide221 marked this pull request as ready for review July 9, 2026 08:10

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread server/src/deepseek4/deepseek4_backend.cpp Outdated
Comment thread server/src/deepseek4/deepseek4_internal.h
@davide221

Copy link
Copy Markdown
Contributor Author

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@davide221 davide221 changed the title fix(ds4): ROCmFPX byte-safe decode + fused-decode path fix/feat(ds4): ROCmFPX byte-safe decode + fused-decode path + ds4 optimizations Jul 10, 2026

@DeanoC DeanoC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread server/src/deepseek4/deepseek4_graph.cpp Outdated
Comment thread server/src/server/chat_template.cpp Outdated
Comment thread server/src/deepseek4/deepseek4_graph.cpp Outdated
Comment thread server/src/deepseek4/deepseek4_graph.cpp Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

Not reviewed (too large): server/src/deepseek4/deepseek4_graph.cpp (~1,795 lines) - if these are generated or fixture files, add them to ignored paths to exclude them from future reviews.

Re-trigger cubic

@davide221 davide221 changed the title fix/feat(ds4): ROCmFPX byte-safe decode + fused-decode path + ds4 optimizations fix/feat(ds4): ROCmFPX byte-safe decode + fused-decode path + ds4 AR optimizations Jul 13, 2026
@davide221
davide221 force-pushed the codex/ds4-rocmfpx-server branch from 2598602 to e943f2a Compare July 13, 2026 14:00
@davide221
davide221 force-pushed the codex/rocmfpx-ggml-vendor branch 3 times, most recently from b403928 to a7dee5b Compare July 16, 2026 19:20
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.
@davide221
davide221 force-pushed the codex/ds4-rocmfpx-server branch from e943f2a to d5fae56 Compare July 17, 2026 05:33
@davide221 davide221 changed the title fix/feat(ds4): ROCmFPX byte-safe decode + fused-decode path + ds4 AR optimizations feat(ds4): add fused HIP decode for ROCmFPX Jul 17, 2026
@davide221
davide221 changed the base branch from codex/rocmfpx-ggml-vendor to main July 17, 2026 15:10
@davide221
davide221 merged commit 4bce493 into main Jul 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants