Skip to content

perf(ggml): reuse ROCmFP4 weights across q=4 columns#534

Draft
davide221 wants to merge 11 commits into
codex/deepseek4-dspark-draftfrom
codex/ds4-q4-weight-reuse
Draft

perf(ggml): reuse ROCmFP4 weights across q=4 columns#534
davide221 wants to merge 11 commits into
codex/deepseek4-dspark-draftfrom
codex/ds4-q4-weight-reuse

Conversation

@davide221

@davide221 davide221 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • decode each packed ROCmFP4_FAST weight fragment once for dense four-column MMVQ
  • reuse the decoded weights across the four q8 activation columns while preserving each column's original DP4A and floating-point accumulation order
  • select the specialization automatically only on gfx1151, with no new runtime setting

The dispatch is shape- and backend-based rather than DS4-specific, so other
models using the same quantized dense four-column path can reuse it. Routed
MUL_MAT_ID, AR (ncols_dst == 1), other widths, and other architectures keep
the existing kernels.

Performance

Measured on lucebox2 (gfx1151, ROCm 7.2.2), pinned to the same 2.9 GHz
performance/high state for both sides. The workload used fixed DSpark q=4,
LUCE_MMVQ_MAX_NCOLS=4, top-k 4, and the accepted ROCmFPX AR specializations.

Stable matched window: the first seven identical GSM+Math requests, totaling
896 generated tokens and 263 verification steps:

Control This PR Delta
Speculative decode 30.15 tok/s 31.51 tok/s +4.50%
Verification step 112.99 ms 108.13 ms -4.30%

The candidate's ten requests ranged from 28.7 to 35.0 tok/s. The control
encountered a host-wide latency stall on requests 9-10, so those requests are
not included in the comparison above.

AR remains unchanged at 26.88 tok/s, 5/5 GSM, and 583 output tokens.

Correctness

  • 76/76 traced q=4 verifier inputs and host logits are byte-identical to control
  • zero missing/extra trace entries and zero byte mismatches
  • AR produced the same aggregate throughput, score, and token count as control

Kernel checks

A full Release HIP/gfx1151 dflash_server build succeeds. The dedicated
specializations have no register spills, private segment, or dynamic stack:

Kernel SGPR VGPR
q=4 fused specialization 47 59
q=4 unfused specialization 28 46
existing q=4 fused kernel 50 67
existing q=4 unfused kernel 32 83

The existing generic q=4 kernel metadata is unchanged from control.

Stack

This is intentionally based on codex/deepseek4-dspark-draft / #496 because
that branch owns the fixed-q=4 DSpark verification path used for validation.

Review in cubic

davide221 and others added 11 commits July 8, 2026 17:23
Ports the ROCmFP4/ROCmFPX ggml work (previously lucebox-ggml #36, on the
old submodule pointer) into the vendored server/deps/llama.cpp tree.

- ROCmFP4/ROCmFPX quant types + CPU reference conversions (ggml/rocmfp4,
  ggml/rocmfpx) and the ggml type-trait registrations.
- CUDA/HIP dequant, copy, getrows, MMVQ vecdot, MMVF, unary and FA paths
  for the new types.
- Fused DS4 hyper-connection op (GGML_OP_DS4_HC) with the register-resident
  sinkhorn kernel; inert unless emitted by the DS4 fused-decode path.
- DS4 SwiGLU split op plumbing for the fused FFN matvec paths.

Layered on current main, so the main-side ggml work is preserved
(fp64 RoPE reduction, #497 RDNA MMQ tile, LUCE_MMQ_DP_MAX_NE1,
MMVQ_MAX_MOE_BATCH_SIZE, fused dual set_rows, raw-span guard).

Review fixes on top of #36:
- ggml_ftype_to_ggml_type: handle the 11 new ROCmFPX ftypes (dominant-type
  mapping) so the enum switch is -Wswitch/-Werror clean.
- FP6 MMVQ vecdot: pad qs[] to avoid a stack over-read of the last window
  (bit-identical; the over-read bits were already masked out).
The non-HIP fallback of rocmfp4_get_int_from_codebook_16 /
rocmfp4_get_low_int_from_codebook_16 called get_int_from_table_16, which is
defined in vecdotq.cuh. TUs that pull in this header without vecdotq.cuh
(fattn-chunked.cu reaches it via the fattn dequant chain) failed to compile
under nvcc:

  rocmfp4_hip_codebook.cuh: error: identifier "get_int_from_table_16" is undefined

The HIP path never hit this (it uses __builtin_amdgcn_perm), so the ROCm CI
and the Strix build stayed green while the sm_86 CUDA build broke.

Fix: inline the generic table expander (the generic branch of
get_int_from_table_16, verbatim) as a static helper in this header, so the
fallback no longer depends on include order. Bit-identical; the HIP hot path
is unchanged.
Server-side DeepSeek V4 Flash changes from #494, rebased onto the vendored
ROCmFPX ggml tree (no submodule pointer). Byte-identical to the validated
#494 server files.

Correctness (default ON):
- Token-by-token prefill by default; chunked prefill only fits inside the
  raw SWA ring, so long prompts / multi-turn degraded. Chunked stays
  available via DFLASH_DS4_CHUNKED_PREFILL for short-prompt benchmarking.
- Clear the cache buffer at new-sequence prefill (kv_offset==0) so requests
  2..N are byte-stable instead of pooling over leftover compressor state.
- Route non-hybrid (all-hot) placement through the HC-complete layer-range
  path; deepseek4_step's non-hybrid branch is HC-less and generates garbage.
- Key the cached decode-attn graph on the flush pattern; the old key
  collided once the compressed-KV ring filled, reusing a stale-topology
  graph.
- Compressor decode graphs read state/comp-cache through the ggml_set_rows
  result tensors so the current-step writes are explicit graph dependencies.
- Default DeepSeek4 chat prefix when the request has no system message, so
  the ROCmFPX "Src" GGUF stops behaving like a base model under bare prompts
  (explicit caller system prompts are preserved).

Perf, byte-identical default:
- Persistent HC matvec pool (row-split preserves per-row accumulation order)
  and f16c dot kernels with scalar-order adds.
- Per-step decode scalar inputs uploaded in 2 tensor_sets instead of ~430.

Opt-in, default OFF (documented as not bit-identical):
- DFLASH_DS4_FUSED_DECODE single-graph decode with GGML_OP_DS4_HC.
- DFLASH_DS4_FFN_RAW_MMID / DFLASH_DS4_FFN_FUSED_COMBINE accumulation reorder.
- DFLASH_DS4_ROCMFPX_HC_GPU GPU HC pre-mix.
Return confidence scores from the fused Markov graph in the existing token-id synchronization, then select q=2/q=3/q=4 from cumulative prefix confidence. Compatible DSpark artifacts enable the policy automatically; artifacts without a confidence head retain the existing EWMA controller. No new deployment configuration is introduced.\n\nValidated on gfx1151: GSM+Math 10/10 at 29.25 tok/s weighted, within 0.8% of fixed q=4, with adaptive behavior retained on low-acceptance prompts.
Remove the no-op single-wave MMVQ shared reduction, add opt-in fixed-K FP2/FP3 and partially-unrolled FP4FAST q=1 kernels, and use AMD v_perm_b32 for packed FP3 decode.

A fully build-matched Lucebox3 A/B used ROCm 7.2.4, gfx1151, wave32, -O3, FA_ALL_QUANTS=ON, fused DS4 decode, expert top-k 4, and HC-GPU disabled. Five balanced GSM8K runs per binary improved mean AR throughput from 24.270 +/- 0.018 to 25.664 +/- 0.014 tok/s: +5.744% +/- 0.122% at 95% confidence.

All ten measured runs remained 5/5 with exactly 583 output tokens. Generated fused/plain specializations report zero private segment, dynamic stack, SGPR spills, and VGPR spills.
@davide221
davide221 force-pushed the codex/deepseek4-dspark-draft branch from 726cc05 to 415432f Compare July 17, 2026 20:02
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.

1 participant