Skip to content

llama : Inkling 2 DSpark with both drafter layouts (ggml-org#32218 head e4b1cb531 plus the 0a9105de4 fused path) - #405

Open
danielhanchen wants to merge 8 commits into
base/upstream-cbb1c1c50from
inkling2-dspark-0a9105de4
Open

danielhanchen wants to merge 8 commits into
base/upstream-cbb1c1c50from
inkling2-dspark-0a9105de4

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Inkling 2 DSpark drafter support that loads both drafter layouts: the current upstream one from ggml-org#32218 (head e4b1cb5, by @pwilkin and @ngxson) and the older padded-vocab one that the drafters already published with unsloth/Inkling-2-Mini-GGUF use (0a9105d).

Why

  • ggml-org#32218 was rewritten after we froze it at 0a9105d. The new head reads markov_w1 at the real vocab size (200058 rows) and adds the markov_ctx_* context head, while the published drafters (dspark-Inkling-2-Mini-Q8_0.gguf and the dspark/ copies) use the padded layout (dspark_fuse, dspark_hidden_out, 201024 rows).
  • Each revision refuses the other layout:
    • 0a9105d with a new-layout drafter: joint_proj.weight has wrong shape; expected 2816, 768, got 5120, 768
    • e4b1cb5 with a published drafter: markov_w1.weight has wrong shape; expected 256, 200058, got 256, 201024
  • Users with the published drafters on disk must keep working without a re-download, and the mainline-layout drafter (Mainline_Support/) should load in the prebuilt too.

What changed

The branch fast-forwards from 0a9105d and now has three commits on top:

  1. A merge of ggml-org#32218 head e4b1cb5. Its tree is byte-identical to e4b1cb5, so the new layout runs upstream's code unchanged.
  2. The 0a9105d fused head added back as a separate path. The drafter's tensors pick the path:
    • dspark_hidden_out.weight: the 0a9105d loader, graph and speculative loop.
    • markov_ctx_norm (f_rnn): upstream's path.
    • anything else: the generic DSpark / DFlash path, unchanged.
  3. Hardening from review:
    • a fused drafter that also carries newer-layout or fc-based tensors, or has no sliding-window layer, is refused at load with a clear error;
    • the fused path reuses upstream's DFLASH_ATTN_*_CTX tensors instead of duplicates;
    • equal-size block check in the fused embedding, as in the markov head;
    • no dummy state on warmup and probe decodes of the fused drafter;
    • upstream's test_logit_bias is kept as is.

The base branch moves to base/upstream-cbb1c1c50, the upstream base of e4b1cb5 (in b12625).

Checks

All on B200, 4 prompts x 384 tokens, greedy and temp 1.0 (seed 1234), root and Mainline_Support UD-Q4_K_XL targets.

Check Result
Published (fused) drafter, Q8_0 and BF16, n_max 2 and 3 output and acceptance identical to the current pin set (for example 729/1258 at n_max 2 greedy)
Mainline (new layout) drafter, Q8_0 and BF16, n_max 2, 3 and 5 output and acceptance identical to a plain e4b1cb5 build
Target, wikitext-2 c512 x 20 chunks KLD 0.000000, top-1 100%, PPL 7.6681 on both targets
Generic DSpark (Qwen3-4B drafter and target) identical to both reference builds
Mixed-layout and no-SWA drafters (5 fixtures) refused at load
llama-server -np 2 and -np 4 with the fused drafter, 4 concurrent requests all complete, no asserts
Pin set merge, b12648 to b12651 clean, 43/43 pins intact
verify --cuda on b12648 and b12651 PASS (feature_matrix 31/31 CPU and GPU, test-chat, MUL_MAT 2897, MUL_MAT_ID 1183, PAD 37, GET_ROWS 361)

Speed on one exclusive B200 with this build (root UD-Q4_K_XL, 3 rounds after a warm-up, tok/s and ratio to no drafter):

Drafter, n_max greedy temp 1.0
none 102.1 93.4
published (fused), 2 126.6 (1.24x) 107.1 (1.15x)
published (fused), 3 127.0 (1.24x) 102.9 (1.10x)
mainline layout, 2 111.6 (1.09x) 96.5 (1.03x)
mainline layout, 3 118.7 (1.16x) 96.1 (1.03x)
mainline layout, 5 106.1 (1.04x) 90.8 (0.97x)

Acceptance is the same for both layouts at the same n_max, so the gap is per-round cost: upstream's path decodes the full 8-token block every round.

Not covered

  • ROCm, Metal, Windows and ARM builds (nightly only).
  • GPUs other than B200 for the drafter checks.
  • Drop the fused path once upstream merges ggml-org#32218 and the published drafters are re-exported, or keep it as long as those files are in use.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T12:18:32.148043Z b5ed9f2 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 22, 2026
## Summary

Studio's Auto speculative decoding launches DSpark with
`--spec-draft-n-max 3` when nothing names a depth. For Inkling 2 on the
current prebuilt, depth 2 is faster under both sampling defaults Studio
uses, because the third draft token is rarely accepted and costs a wider
verify step.

This makes Inkling 2 (both GGUF layouts, `inkling2` and `inkling2_loop`)
default to depth 2:

- The launch (`_emit_dspark`) and the fit pricing (the draft depth used
to size verify rows) share one helper, so the reserve matches what the
child runs.
- A depth the user sets (the settings field, extras or env) still wins.
- Every other DSpark model, for example DeepSeek-V4-Flash, keeps depth
3.
- MTP, DFlash and EAGLE-3 are untouched.

## Measurements

Inkling-2-Mini, current DSpark pin (ggml-org#32218 at 0a9105de4 via
unslothai/llama.cpp#405), `dspark-Inkling-2-Mini-Q8_0.gguf` drafter,
llama-server, exclusive B200, greedy draft (server default), 4 prompts x
384 tokens, seed 1234. Each arm was run twice with the arms interleaved;
the A/A spread is 3.4% or less in every arm.

Studio's Inkling 2 defaults on main (`inference_defaults.json`:
temperature 1.0, top_p 1.0, top_k -1, min_p 0):

| target | no draft tok/s | depth 2 tok/s | depth 3 tok/s |
|---|---|---|---|
| UD-Q4_K_XL | 73.2, 73.6 | 84.1, 85.3 (1.15x) | 79.0, 80.3 (1.09x) |
| UD-IQ1_S | 76.9, 75.7 | 91.7, 89.8 (1.19x) | 80.3, 78.9 (1.04x) |

Studio's generic defaults (temperature 0.6, top_p 0.95, top_k 20, min_p
0.01):

| target | no draft tok/s | depth 2 tok/s | depth 3 tok/s |
|---|---|---|---|
| UD-Q4_K_XL | 82.1, 81.9 | 103.6, 104.0 (1.27x) | 85.8, 85.9 (1.05x) |
| UD-IQ1_S | 84.6, 85.0 | 106.5, 110.2 (1.28x) | 96.2, 96.2 (1.13x) |

Greedy (temperature 0), UD-IQ1_S: depth 2 1.28x, depth 3 1.19x, depth 5
1.15x, depth 7 1.08x.

## Tests

- New parametrized case in `test_llama_cpp_mtp_detection.py`: Inkling 2
in both layouts emits depth 2, a requested depth 3 stays 3, and
`deepseek4` and an unknown architecture stay at 3. The existing
DeepSeek-V4-Flash case is unchanged.
- `test_llama_cpp_mtp_detection.py`, `test_spec_sidecar_fit_reserve.py`,
`test_mtp_drafter_companion.py` and `test_llama_cpp_placement.py`: 1458
passed. The placement file has teardown errors on a host with visible
GPUs (CUDA device queries in CPU tests); the same test IDs error on
main, and CI runners have no GPU.

## Not covered

- GPUs other than B200. The depth trade-off comes from acceptance (the
third token is rarely kept), which does not depend on the GPU, but the
speed ratio was only measured on B200.
- A future DSpark pin. On the newer upstream head (e4b1cb531) the
drafter decodes its full 8-token block every round and depth 2 is the
slowest setting there, so this default should be revisited when the pin
moves.
The drafters published with unsloth/Inkling-2-Mini-GGUF before the f_rnn
layout (dspark_fuse, dspark_hidden_out, padded markov_w1) keep their own
head: a draft with dspark_hidden_out.weight takes the 0a9105d loader,
graph and speculative loop, a draft with markov_ctx_norm takes the f_rnn
path above, and every other DSpark draft is unchanged. A draft mixing
both layouts is refused at load.
- reject a fused draft that also carries f_rnn (markov_ctx_*, blk.N.ctx_mix/ctx_norm,
  token_embd_norm) or fc-based DFlash tensors, and one without any SWA layer, at load
- reuse the upstream DFLASH_ATTN_*_CTX tensors and layer fields for attn_k_ctx/attn_v_ctx
- equal-size block check in build_inkling2_embd, as in the markov head
- no dummy state on probe and warmup decodes of the fused draft (its state is 3*n_embd)
- keep upstream's test_logit_bias
@danielhanchen
danielhanchen changed the base branch from base/upstream-e50c254a2 to base/upstream-cbb1c1c50 November 23, 2026 12:06
@danielhanchen danielhanchen changed the title llama : Inkling 2 DSpark (ggml-org#32218 at 0a9105de4) for the published drafters llama : Inkling 2 DSpark with both drafter layouts (ggml-org#32218 head e4b1cb531 plus the 0a9105de4 fused path) Nov 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5ed9f2845

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/models/dspark.cpp

ggml_tensor * llama_model_dflash::graph_base::mix_target_features(ggml_tensor * features, int row, ggml_tensor * norm) {
const int64_t count = model.target_layer_ids.size();
auto * weights = ggml_soft_max(ctx0, ggml_view_1d(ctx0, model.dspark_fuse, count, row*model.dspark_fuse->nb[1]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Convert fused mixing weights to F32 before softmax

When a fused-layout drafter is converted with llama-quantize, dspark_fuse.weight is eligible for conversion because it is a 2D weight and has no exclusion in tensor_allows_quantization(). An F16/BF16 conversion changes its type directly, and quantized formats fall back to F16 when the target-layer count is not block-aligned. This view preserves that type, but the CPU softmax implementation in ggml/src/ggml-cpu/ops.cpp only handles F32 and aborts otherwise, so the converted drafter cannot process its context features. Cast the mixing row to F32 before softmax, or preserve this tensor as F32 during quantization.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Already covered in the pin set: #397 keeps dspark_fuse.weight unquantized in llama-quantize (src/llama-quant.cpp, quantize &= name.find("dspark_fuse.weight") == std::string::npos), and #397 is merged before #405 in pr-set.json, so a fused drafter quantized with the prebuilt keeps an F32 fuse. The published drafters also store it as F32. Keeping that fix in #397 where it was born rather than duplicating it here.

Comment thread common/speculative.cpp
// the block attention is non-causal: a draft with a markov context decodes the full trained block, then reads n_max of it
const int32_t n_draft = params.n_max;
const int32_t n_block_tokens = n_draft + (sample_from_anchor ? 0 : 1);
const int32_t n_block_tokens = has_markov_context ? block_size : n_draft + (sample_from_anchor ? 0 : 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound full-block draft batches by the context capacity

For the new Markov-context layout, each drafting sequence now contributes the entire trained block, but all sequences are still passed to one decode without checking the batch or microbatch capacity. For example, two active sequences with an 8-token block, n_max = 3, and a draft microbatch capacity of 8 produce a 16-token non-causal decode. llama_context::decode() asserts that a non-causal batch fits entirely in n_ubatch (src/llama-context.cpp:2254), terminating the process rather than returning the error handled below. The initialization change only enlarges output limits, not these capacities. Decode groups of complete blocks that fit the configured capacities, and reject configurations where even one block cannot fit.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This line is upstream's code from ggml-org#32218 (8ccecab, the f_rnn path), which this pin carries verbatim so the new layout behaves exactly like upstream. Changing how the markov-context path sizes its batches belongs in ggml-org#32218 itself; for the prebuilt the default is the fused drafter, and the multi-slot server checks (-np 2 / -np 4, 4 concurrent requests) passed on this head.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: b5ed9f2845

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

L4TN added a commit to L4TN/qwen3.8-27B-MTP-rtx5060ti that referenced this pull request Nov 24, 2026
…7059d6)

Registra a config validada em hardware real (RTX 5060 Ti 16GB):

- ctx 102400 (100k), KV f16/q8_0, batch 512 / ubatch 128
- DSpark n-max 2 (n-min 0, p-min 0), sem --spec-draft-device
- 15684-15721 MiB usados / 590-627 MiB livres (96.2-96.4%)
- prompt 243.5-256.9 t/s, geracao 58.9-63.6 t/s, aceitacao 46.7-52.3%
- escada de KV a 122880: f16/f16 = 344 MiB livres (reprovado) -> f16/q8_0 = 421 MiB (aprovado)
- 120k com DSpark colapsa para 24.9 t/s; curva 16K/32K/100K/120K documentada
- com ~59k de prompt preenchido: 26.6 t/s (DSpark n=2) vs 34.0 t/s sem drafter

Novo docs/inkling-2-mini.md com versoes exatas: llama.cpp b12651 (commit
d426a3774), release Unsloth b12651-mix-c7059d6, sha256 do zip, CUDA 13.3 do
build + runtime 13.5 (cudart 6.14.11.13050 / cublas 6.14.11.13100), driver
621.24, quant UD-IQ3_XXS e drafter Q8_0 com bytes e sha256 do HF, fix
antecipado do DSpark (unslothai/llama.cpp#405, b5ed9f2) e o script completo.

Novo scripts/start-inkling2-mini-ud-iq3xxs-100k-q8.bat (CRLF, auto-download,
args ctx/ctk/ctv/ubatch/nmax).
@santiago200031

Copy link
Copy Markdown

Tested the 0a9105de4 dspark_f_rnn fused 384M drafter against the #32218 481M drafter on Inkling-2-Mini-AD-Q4_K (2x RX 9060 XT 16 GB, Vulkan, -sm tensor -ub 512, q8_0/q8_0 KV, with #403 applied).

On a coding/prose head-to-head test (16384 ctx, n_max=2 on the 384M fused drafter vs n_max=5 on the 481M drafter):

  • Greedy (temp=0.0): 39.45 tok/s (no draft), 39.21 tok/s (481M, 165/445 accepted), 44.56 tok/s (384M, 143/223 accepted, +13.0%)
  • Sampling (temp=1.0): 41.11 tok/s (no draft), 30.83 tok/s (481M, 135/598), 37.39 tok/s (384M, 114/280)

In multi-hit server benchmarks at temp=1.0 (4096 prefill, 157440 ctx), non-speculative stayed faster than fixed n_max=2 (39.89 vs 36.59 tok/s), while the 384M 0a9105de4 path clearly beat the 481M layout in both greedy and sampled runs.

Also needed two extra fixes for Vulkan -sm tensor (split-mode = tensor):

  1. src/llama-model.cpp: update pattern_kv_weight (attn_(k|v)(_ctx)?) and pattern_qk_norm (attn_(q|k)(_ctx)?_norm) so context injection matches split draft KV caches.
  2. ggml/src/ggml-backend-meta.cpp (handle_view): keep stock nb_next matching first (needed for multi-segment nr[0] > 1 models like Qwen3.6), then fall back to seg_span = nb_next / src_ss[0].nr[0] when nr[0] > 1 && n_segments == 1 && view_offs % seg_span == 0 so build_conv_state_store rollback works on 2-repeat [K|V] cache_r_l*.

This branch has not been deployed

No deployments
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.

4 participants