Skip to content

inkling2_loop: wire speculative drafting (DSpark is dflash-schema; framework exists, loop path unwired) #66

Open

Description

@FoMiN12

Feature: speculative drafting on the inkling2_loop path (DSpark drafter)

What already exists (and is 90% of what's needed)

--draft-model already understands the DFlash/DFlash2 schema (dflash.* keys: block-diffusion drafter reading target hidden states, block verify, auto-conversion of safetensors checkpoints, hybrid ngram cascade, sampling-safe verify). Thinking Machines' dspark-Inkling-2-Mini-Q8_0.gguf (318 M, on unsloth/Inkling-2-Mini-GGUF) carries general.architecture = dflash — i.e. the same schema family, plus:

  • dflash.dspark.markov_rank
  • dflash.target_layers (a layer subset for hidden-state taps)
  • dflash.block_size, dflash.sample_from_anchor, dflash.has_confidence_head
  • dflash.attention.causal + sliding_window_pattern (draft is partly non-causal)

Verified on-file: /home/kirill/models/unsloth/Inkling-2-Mini/dspark-Inkling-2-Mini-Q8_0.gguf, 402,278,560 B.

The gap

main.rs dispatches inkling2_loop to inkling2::chat::generate(&g, &prompt, n) — the decode loop is single-token greedy; the batched-verify machinery (verify_rows, draft-length negotiation, rollback) lives in gpu_model.rs behind the main engine. --draft-model/--mtp are silently unreachable from that path (serve.rs exposes drafts stats only for the main engine).

Why it matters disproportionately for this model

Inkling 2 Mini's loop shape (24 layers, 6-17 x3 = 48 layer-visits/token) makes one decoded token expensive: on an 8 GB card decode sits at the LPDDR roofline (~16-18 t/s) for every token, and 4/5 of it streams from RAM. A drafter that proposes a whole block in one pass converts roofline-bound tokens into one verify batch — on the 12 GB reference, llama.cpp measured mean accept-len 3.78 at 69.7% acceptance (short ctx); at 64K depth it still measured 2.24 (1.93x net). The loop is exactly where batched verify pays most: verify cost per extra row is the loop's marginal cost, drafting skips it entirely.

Suggested shape

  1. Extract the DFlash draft runtime (load, block propose from tapped hidden states) from the main-engine glue so it's callable per decode step.
  2. Give inkling2::forward a multi-row verify entry (its prefill chunk path already computes multi-token forwards layer-first; a K-row decode is a small chunk) + partial-accept rollback for the sliding-window + rel-bias cache and the loop's per-pass message state.
  3. Wire --draft-model (and the ngram cascade as a weightless fallback that works today on repeated agentic text) into inkling2/chat.rs decode.

The markov_rank/confidence_head/non-causal-attention keys may need schema additions in the loader; the block/anchor/verify skeleton should carry over unchanged.

Context

Measured on RTX 5060 Laptop 8 GB + Ryzen mobile: Inkling UD-Q4_K_XL Mainline_Support: decode 15.3-20.1, prefill 33-136 (chunk-dependent); engine is RustingStrata 1.2.6 @ bc3facb native build. llama.cpp oracle (b12588-mix, -cmoe --moe-cache-mib 1536) with DSpark measured net-negative on 8 GB (accept 2.51 < verify 2.8x) — but its verify there runs through the CPU-heavy path; on a GPU-resident decode state the verify economics are a different regime, which is exactly what this engine changes.

Activity

  1. Vasyl-Trefilov commented on Nov 22, 2026

    @Vasyl-Trefilov
    Member

    @FoMiN12 This is on main now, through #65 by ybenyedder plus fixes on top. --draft-model <DSpark file> and --spec-type ... work on inkling2_loop in generate, chat, serve and bench. --mtp and --mtp-model are still ignored (the model has no MTP head), with a warning.

    How it works: the drafter proposes up to 15 tokens (3 a round for a DSpark file unless you set --spec-draft-n-max), one GPU pass checks them (16 rows at most), and the state is cut back to the last accepted token. Drafts need the GPU path.

    Numbers on my card: RTX 3060 12 GB, Inkling-2-Mini-IQ4_NL.gguf (17.6 GB, so 15 of 24 expert layers are in VRAM on CUDA and 16 on Vulkan), bench --pp 512 --tg 128, decode tok/s. "Merge" is #65 as it was merged; "now" has a follow-up that runs the draft check of the layers outside VRAM as one batch (it checked their rows one at a time before).

    CUDA merge CUDA now Vulkan merge Vulkan now
    no drafts 35.2 35.2 24.1 22.8
    --spec-type ngram-simple 36.8 48.5 39.2 51.1
    --draft-model dspark-Inkling-2-Mini-Q8_0.gguf 23.8 35.1 18.4 29.2

    The bench text repeats, so the lookup has nearly every draft accepted; on normal text it drafts less. The DSpark file has 285 of 294 drafts accepted.

    So on this card the DSpark file no longer costs speed, but on CUDA it only breaks even (in a second run it was 35.6 against 31.1 without drafts; the numbers move with what else the machine does). On Vulkan it is about a quarter faster. The limit is the model not fitting: in the 8 or 9 layers outside VRAM the rows of a check share few experts, so each checked row still pays for its own experts. More drafts a round did not help (--spec-draft-n-max 5, 7, 11, 15: the same tok/s). On a card that holds the whole model all layers check in one batch and I expect a larger gain, but I have no such card and no number for it. If you have 24 GB, a bench with and without --draft-model would tell us.

    With STRATA_FIXED_EXPERTS=1 the text with the DSpark file is byte-identical to the text without drafts (70 tokens checked). Without it the expert split adapts, and the text can differ at a near tie, as it does between two runs without drafts.

  2. FoMiN12 commented on Nov 22, 2026

    @FoMiN12
    Author

    @Vasyl-Trefilov @ybenyedder — thanks for #66's answer and for wiring all of this up so quickly. Here is the full drafter matrix measured on 44e63c5 (the numbers below are that commit's), from the 8 GB 5060 rig of the issue body. I have a 24 GB card on another machine and will run the with/without --draft-model bench some time later. The tip work (#72, the GEMM draft check, the inkling2-named files) landed while I was benching this — re-measuring the same grid on current master and will post the follow-up here.

    Every number:

    rustingstrata bench --model Mainline-Inkling-2-Mini-UD-Q4_K_XL.gguf (17.69 GB) \
      [--backend vulkan --device 0|1] --gpu --ctx 32768 --pp 4096 --tg 128 --reps 1 \
      [--draft-model dspark-Inkling-2-Mini-Q8_0.gguf] [--spec-draft-n-max 7|15] [--spec-type ...]
    STRATA_DS_GPU_FRACTION=0.90
    

    Stack: Ubuntu 26.10, kernel 7.3.0-11; CUDA 13.5 (V13.5.37, native build, libs from /usr/local/cuda); NVIDIA driver 620.70.06 (also the Vulkan driver for device 0); Mesa 26.2.4-1ubuntu1 RADV for device 1 (the engine's own header line: radv Mesa 26.2.4-1ubuntu1, device-coherent memory yes, cooperative matrix f16 yes int8 yes); engine 44e63c5, binary sha256 925e5b6ab191….

    Target is the Mainline_Inkling-2-Mini-UD-Q4_K_XL file from the issue; device 0 = the 5060, device 1 = the 780M iGPU (coherent UMA). "prose" = the engine's built-in bench text, "rep" = a 13.4 KB repetitive prompt (a JSON access-log ending in a request to continue the list in the same format — the agentic-repetition shape; under 4096 tokens, the bench repeats it to fill the prefill). Cell format: bench --pp 4096 --tg 128 decode t/s, then (speedup over the no-draft row of that column, accepted/proposed drafts):

    CUDA prose CUDA rep VK5060 prose VK5060 rep VK780M prose VK780M rep
    no drafts 24.1 24.7 16.6 15.8 10.3 10.5
    --draft-model 29.6 (×1.23, 96%) 30.1 (×1.22, 100%) 21.0 (×1.27, 96%) 22.0 (×1.39, 100%) 11.5 (×1.12, 97%) 11.9 (×1.13, 100%)
    + --spec-draft-n-max 7 30.4 (×1.26, 81%) 35.3 (×1.43, 100%) 22.4 (×1.35, 81%) 30.1 (×1.91, 100%) 12.6 (×1.22, 88%) 14.0 (×1.33, 100%)
    + --spec-draft-n-max 15 30.3 (×1.26, 83%) 35.3 (×1.43, 100%) 27.1 (×1.63, 87%) 29.8 (×1.89, 100%) 12.5 (×1.21, 88%) 13.9 (×1.32, 100%)
    --spec-type suffix 54.6 (×2.27, 100%) 50.6 (×2.05, 94%) 47.1 (×2.84, 100%) 43.5 (×2.75, 94%) 20.6 (×2.00, 100%) 18.5 (×1.76, 94%)
    --spec-type ngram-simple 54.9 (×2.28, 100%) 50.1 (×2.03, 94%) 46.9 (×2.83, 100%) 38.5 (×2.44, 94%) 20.6 (×2.00, 100%) 18.0 (×1.71, 94%)
    --spec-type ngram-map-k 54.6 (×2.27, 100%) 50.5 (×2.04, 94%) 47.0 (×2.83, 100%) 43.1 (×2.73, 94%) 20.4 (×1.98, 100%) 18.3 (×1.74, 94%)
    --spec-type ngram-map-k4v 54.2 (×2.25, 100%) 37.5 (×1.52, 75/75) 47.9 (×2.89, 100%) 28.6 (×1.81, 75/75) 20.5 (×1.99, 100%) 13.7 (×1.30, 75/75)
    --spec-type ngram-mod 53.9 (×2.24, 100%) 50.5 (×2.04, 94%) 47.0 (×2.83, 100%) 43.2 (×2.73, 94%) 20.7 (×2.01, 100%) 18.7 (×1.78, 94%)
    --spec-type ngram-cache 54.1 (×2.24, 100%) 50.2 (×2.03, 94%) 47.3 (×2.85, 100%) 43.2 (×2.73, 94%) 20.7 (×2.01, 100%) 18.5 (×1.76, 94%)
    --draft-model --spec-type suffix 51.5 (×2.14, 100%) 47.2 (×1.91, 94%) 44.4 (×2.67, 100%) 42.0 (×2.66, 94%) 18.0 (×1.75, 100%) 18.2 (×1.73, 94%)

    Same file, bench --pp 512 --tg 128, for depth-512 reference:

    CUDA VK5060 VK780M
    no drafts 26.8 17.8 10.8
    ngram-simple 52.0 (×1.94, 93%) 26.6 (×1.49, 100%) 17.6 (×1.63, 100%)
    --draft-model 34.5 (×1.29, 97%) 24.4 (×1.37, 96%) 13.4 (×1.24, 98%)

    Cell format: t/s (speedup vs the no-draft row of the same column, accepted/proposed drafts).

    Prefill from the same 4096-token runs (prose/rep t/s, grouped — the pattern was uniform inside each group):

    group CUDA VK5060 VK780M
    no drafts 148.8 / 146.5 120.3 / 116.6 67.5 / 70.0
    any lookup drafter (all six) 145.7-150.1 (≈0%) 115.2-118.1 (≈−1%) 53.8-77.8 (noisy)
    --draft-model incl. n-max arms 134.2-138.5 (−7%) 106.5-109.1 (−9%) 68.6-73.9 (≈+2%)
    hybrid cascade 135.5-137.7 (−7%) 107.1-109.1 (−9%) 67.4-68.3

    One determinism question. On this build, with --fixed-experts and a short prompt: two undrafted runs are byte-identical to each other (so the flag holds and the run is deterministic), the ngram-simple output is byte-identical to undrafted, but --draft-model output is byte-identical across itself while consistently differing from the undrafted output at around token 20 — a near-tie in a low-confidence region, so ULP-level reassociation on the verify pass flipping an argmax, presumably from the batched out-of-VRAM expert check. Does the 70-token byte check still pass at the current tip?

  3. ybenyedder commented on Nov 22, 2026

    @ybenyedder
    Contributor

    @FoMiN12 Yes, speculative_ngram_and_dspark_match_greedy still passes on current main (tested on Radeon 890M Vulkan). The divergence around token 20 with --draft-model on partial-VRAM UD-Q4_K_XL is expected ULP rounding between batched verify and token-by-token decode at a near-tie logit — that's also why the test checks up to the first near-tie.

    FWIW on Radeon 890M Vulkan with UD-IQ3_XXS (fits in VRAM with #72 graph capture): plain 11.8 tok/s, --draft-model (default) 17.2 tok/s (90.2% accepted), ngram 29.8 tok/s (87.5% accepted).

    (Also, could you add me on TikTok? My username is table5879 🙏)

  4. Vasyl-Trefilov commented on Nov 22, 2026

    @Vasyl-Trefilov
    Member

    @ybenyedder gasdhdasghdghasghdashhadg, wtf, why do you need him on tiktok hahaha

  5. ybenyedder commented on Nov 22, 2026

    @ybenyedder
    Contributor

    @Vasyl-Trefilov Ifk I just want to add the people from the project pls add me too

  6. Vasyl-Trefilov commented on Nov 22, 2026

    @Vasyl-Trefilov
    Member

    hahahha, okay

  7. FoMiN12 commented on Nov 23, 2026

    @FoMiN12
    Author

    Same grid, re-measured on main @ 2a581f1 (#72 graph capture, ≥7-row GEMM draft check, ccf4e2d decoders, #75 softcap skip). Same rig, stack, and commands as my previous comment, engine binary sha256 9e19f8818a4e…. One run per cell: bench --gpu --ctx 32768 --pp 4096 --tg 128 --reps 1, STRATA_DS_GPU_FRACTION=0.90.

    Upstream moves faster than I can test — the tip moved again while this comment sat. This is my last grid on this machine (5060 Laptop, 8 GB); the next one is on an RTX 3090 (24 GB).

    Correction to my previous comment: its CUDA rep k4v cell (50.2) was a bad run, true value ≈39.8 — the 75/75 starvation shows on CUDA too.

    CUDA prose CUDA rep VK5060 prose VK5060 rep VK780M prose VK780M rep
    no drafts 26.1 26.1 15.8 16.8 10.4 10.2
    --draft-model 32.3 (×1.24, 96%) 32.2 (×1.23, 100%) 22.7 (×1.44, 98%) 22.1 (×1.32, 100%) 11.5 (×1.11, 96%) 11.9 (×1.17, 100%)
    + --spec-draft-n-max 7 32.3 (×1.24, 81%) 35.5 (×1.36, 97%) 28.4 (×1.80, 88%) 28.8 (×1.71, 100%) 12.6 (×1.21, 88%) 13.9 (×1.36, 100%)
    + --spec-draft-n-max 15 32.7 (×1.25, 88%) 37.3 (×1.43, 100%) 27.1 (×1.72, 81%) 28.6 (×1.70, 100%) 12.5 (×1.20, 88%) 13.7 (×1.34, 100%)
    --spec-type suffix 64.3 (×2.46, 100%) 58.2 (×2.23, 94%) 49.3 (×3.12, 100%) 42.3 (×2.52, 94%) 20.5 (×1.97, 100%) 18.2 (×1.78, 94%)
    --spec-type ngram-simple 64.8 (×2.48, 100%) 58.4 (×2.24, 94%) 46.3 (×2.93, 100%) 42.0 (×2.50, 94%) 20.3 (×1.95, 100%) 18.5 (×1.81, 94%)
    --spec-type ngram-map-k 65.4 (×2.51, 100%) 58.3 (×2.23, 94%) 46.2 (×2.92, 100%) 42.6 (×2.54, 94%) 20.4 (×1.96, 100%) 18.5 (×1.81, 94%)
    --spec-type ngram-map-k4v 65.0 (×2.49, 100%) 39.8 (×1.52, 75/75) 47.0 (×2.97, 100%) 29.4 (×1.75, 75/75) 20.5 (×1.97, 100%) 15.2 (×1.49, 75/75)
    --spec-type ngram-mod 64.8 (×2.48, 100%) 58.7 (×2.25, 94%) 46.6 (×2.95, 100%) 44.4 (×2.64, 94%) 20.4 (×1.96, 100%) 18.4 (×1.80, 94%)
    --spec-type ngram-cache 64.9 (×2.49, 100%) 58.5 (×2.24, 94%) 46.8 (×2.96, 100%) 44.1 (×2.63, 94%) 20.5 (×1.97, 100%) 18.6 (×1.82, 94%)
    --draft-model --spec-type suffix 58.1 (×2.23, 100%) 52.5 (×2.01, 94%) 57.8 (×3.66, 100%) 52.6 (×3.13, 94%) 20.2 (×1.94, 100%) 18.0 (×1.76, 94%)

    Format: decode t/s (--pp 4096 --tg 128), speedup vs no-draft, accepted/proposed. Hybrid cascade (--draft-model + default lookup), same grid: CUDA 61.6 / 54.9, VK5060 43.1 / 42.1, VK780M 20.3 / 18.2 (prose / rep). Three cells re-run after an external process skewed their timing (acceptance identical): CUDA n-max-15 prose → 32.7, VK780M --draft-model prose → 11.5, CUDA rep-k4v → 39.8; last row measured in the same gated batch.

    bench --pp 512 --tg 128 (maintainer-reference shape):

    CUDA VK5060 VK780M
    no drafts 28.7 18.3 11.4
    ngram-simple 65.8 (×2.29, 100%) 44.8 (×2.45, 100%) 21.3 (×1.87, 93%)
    --draft-model 36.5 (×1.27, 97%) 26.1 (×1.43, 96%) 15.0 (×1.32, 99%)

    Prefill from the 4096-token runs (prose / rep t/s, grouped):

    group CUDA VK5060 VK780M
    no drafts 164.8 / 160.1 56.2 / 113.8 68.8 / 47.8
    any lookup drafter (all six) 150.6-163.5 / 159.9-161.7 105.5-126.8 / 99.7-122.8 51.4-74.1 / 66.0-76.1
    --draft-model incl. n-max arms 147.1-152.1 / 147.1-147.6 99.7-115.6 / 99.7-102.6 62.8-72.2 / 71.4-74.6
    hybrid cascade 144.0 / 149.1 105.5 / 112.6 69.8 / 73.0

    Diff vs 44e63c5: CUDA lookups +11-16% (GEMM draft check), everything else ±3%.

  8. FoMiN12 commented on Nov 23, 2026

    @FoMiN12
    Author

    @ybenyedder well.... I don't even have TikTok currently. I used it maybe 5-6 years ago last time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions