Skip to content

spec: DFlash2 drafters (port of llama.cpp#27816) + HIP top-k for large rows - #2

Merged
bong-water-water-bong merged 1 commit into
1bit/vulkan-rocmi4from
1bit/dflash2
Sep 28, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/vulkan-rocmi4from
1bit/dflash2

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Ports upstream DFlash2 (ggml-org/llama.cpp#27816) onto this fork's DFlash code, so a single ROCm server can use both the Hadamard W4A4 prompt path (#1) and DFlash2 drafting.

What changes

  • Drafter model (src/models/dflash.cpp):
    • DFlash2 metadata keys.
    • Local convolutions around attention and the FFN.
    • Target logit scale/softcap.
    • The selector lattice, written to the pre-norm output.
  • Draft walk (common/speculative.cpp): a greedy pass over the lattice, with p_min and n_min.
  • HIP top-k: upstream's radix top-k. Before this, TOP_K over the 248k vocab fell back to the CPU, and code decode ran at 11 tok/s instead of 28.
  • Rollback (common/common.cpp): draft-dflash keeps bounded recurrent-state rollback (n_rs_seq), as upstream does. Without it, every partial accept restores a checkpoint and replays the accepted tokens.
  • Graph size: raises the node budget for DFlash2 drafters.

Checks

  • test-backend-ops -o TOP_K -b ROCm0: 445/445, rows up to 524288. CONCAT and FILL also pass.

  • Acceptance: Qwen3.8-27B + Qwen3.8-27B-DFlash2 q8_0, greedy, 256 tokens.

    Prompt This PR Upstream b10f9ca on ROCm
    Code 6.71 6.71
    Prose 4.11 4.25
  • Greedy text vs no drafter: code and short prompts are identical. The prose prompt flips one near-tie word at character 470; that is batched-verification rounding.

  • Speed on gfx1151, with the rotated H32 file and the W4A4 prompt path. The server runs with -ctxcp 0 --spec-draft-n-max 16 --spec-draft-p-min 0. Decode is in tok/s, best of 3; the box is shared, so treat these as indicative.

    Setup Code Prose Short
    No drafter 12.6 12.6 13.0
    This PR 38.3 23.7 12.3

Notes

  • This fork's default --spec-draft-p-min is 0.75, which cuts DFlash2 drafts short (5.4 instead of 6.7 tokens per step). Pass --spec-draft-p-min 0.
  • The M-RoPE part of the upstream commit is not needed here: the Qwen3.8 drafter has a single 64-wide section, which is the same as NEOX.

🤖 Generated with Claude Code

… for large rows

Ports upstream DFlash2 support (b10f9ca, "spec : add DFlash2 support (local
convolution + candidate selector)") onto this fork's DFlash code:

- dflash.cpp: DFlash2 hparams (block/conv/selector keys), per-layer local
  convolutions around attention and FFN, the target's logit scale/softcap on
  the draft logits, and the selector lattice (top-k candidates + pairwise
  transition scores per block position) written to the pre-norm output
  (this fork's name for upstream's h_nextn)
- speculative.cpp: the greedy lattice walk (p_min on the softmax of the
  winning score, n_min); block tokens request no logits for DFlash2
- llama-context: DFlash2 graph node budget
- ggml-cuda: upstream's HIP radix top-k, so TOP_K over a 248k vocab stays on
  the GPU instead of falling back to the CPU (test-backend-ops TOP_K 445/445
  on gfx1151, rows up to 524288)
- common: keep bounded recurrent-state rollback (n_rs_seq) for draft-dflash,
  as upstream does; without it every partial accept restores a checkpoint and
  replays the accepted tokens

M-RoPE handling from the upstream commit is not needed here: the Qwen3.8
drafter has one 64-wide section, identical to NEOX with its positions.

Qwen3.8-27B (Hadamard-rotated Q4_0 + W4A4 prompt path) + Qwen3.8-27B-DFlash2
q8_0 on gfx1151, -ctxcp 0, --spec-draft-p-min 0, 256 tokens greedy: mean
acceptance length 6.71 code / 4.11 prose, matching upstream (6.71 / 4.25).
Greedy output identical to no-draft on code and short prompts; prose flips
one near-tie word at char 470 (batched verification rounding).

Co-authored-by: Zihan Zhang <tiancaizhangdaxian@sjtu.edu.cn>
Co-authored-by: Jian Chen <jianchen0311@gmail.com>
Co-authored-by: Xuan-Son Nguyen <son@huggingface.co>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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