Skip to content

inkling-2-dflash2:mini: Inkling-2-Mini with the DFlash2 draft (#1176) - #1210

Merged
tawei-amd merged 6 commits into
mainfrom
feat/inkling-2-dflash2
Dec 1, 2026
Merged

tawei-amd merged 6 commits into
mainfrom
feat/inkling-2-dflash2

Conversation

@tawei-amd

@tawei-amd tawei-amd commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Adds inkling-2-dflash2:mini: Inkling-2-Mini decoded with Inco AI's DFlash 2 draft (#1176).

  • Catalog: tag inkling-2-dflash2 / mini, base_model: inkling-2:mini, xclbin_folder: Inkling-2-Mini-NPU2, own draft package Inkling-2-Mini-DFlash2-NPU2 (452 MB: dflash_weight.q4nx, config.json, draft_vocab.txt), flm_min_version 1.0.15. Published on HF FastFlowLM/Inkling-2-Mini-DFlash2-NPU2 and ModelScope amd/Inkling-2-Mini-DFlash2-NPU2; model_info.json is from the HF tree, and flm pull inkling-2-dflash2:mini verifies from both stores.
  • Draft (FLM_Xclbin/Inkling2/dflash2_layer, dflash2.xclbin): 5 sliding-window layers (window 2048) on the NPU in Q4_K, reading features from four layer visits of the main model. It writes a block of 7 tokens in one pass and picks one path through its top 16 candidates per position. Its output projection uses the 65,536 most frequent rows of the target's lm_head (draft_vocab.txt). The converter is in FLM_Q4NX.
  • Check (verify_layer, lm_head8, verify_switches -> verify.xclbin, inkling2_verify.switches): the target checks all 8 positions in one pass with a dedicated 8-row kernel set, driven by control-packet switches. Part of the expert matmul work runs on the CPU at the same time, in a sleeping worker pool. The host reads the verify kernel's capability stamp and refuses (fails closed) a kernel without it. decode_switches gains the VERIFY=1 variant.
  • Engine (FLM_DLL/detail/inkling2_npu): draft / verify / commit / rollback in inkling2_npu; rollback trims K/V and the linear state back to the accepted length. A block is sized to min(7, tokens_left - 1) and is declined when pos + 8 would pass the context (plain decode then). The draft is primed with the prompt features after prefill (~0.1 s). The prefix cache keeps the draft's state with the target's.
  • Wrapper (modeling_inkling2.cpp): every step drafts 7 tokens; speculation never turns itself off. Greedy requests without penalties or constraints take the engine's argmax. Sampling, penalties, response_format / tool grammars and min_tokens choose every checked row with the same _sample_row as plain decoding (exact speculative sampling with a one-hot draft). Logprobs of speculated tokens come from the verify rows.
  • Kill switches: FLM_DFLASH=0 (draft not loaded) and FLM_DISABLE_SPECULATION=1 (loaded, plain decode) both answer exactly like inkling-2:mini. FLM_DFLASH_PATH points at another draft package. Under HRX the tag decodes one token at a time and says so in a warning.
  • CI data: engines.json, build_units.json, kernel_assignment.{json,md}, changes.py (+ tests), builtin_backends / builtin_frontends, rest_handler, test_reasoning, test_model_downloader. The NPU test selection for the tag (PR_CHAT / ALWAYS_THINKS_FAMILIES) went in first as ci(npu-test): pr tier runs inkling-2-dflash2 only when a change touches it #1200. flm.wxs needs no change: it already lists inkling2_npu.dll, and it takes xclbins\** recursively.
  • Fix for inkling-2:mini on Windows (also in v1.0.14): after a long prompt (about 4k tokens), an answer could come back empty or as !!!!. The fused decode and the 8-row verify read each layer's weight buffer by device address only; no run takes it as an argument. On Windows such a buffer can lose its device mapping, and the reads then return NaN. The softcap clamp turns NaN into a flat row, so argmax picks token 0. The engine now checks every NPU decode token and verify for a non-finite hidden state or a non-finite / pinned logit row. When it finds one, it replays the device tokens on the host and binds every layer's weight buffer to a run again (one small o-projection per layer, ~10 ms). It then reloads the device state and reruns once. If the output is still non-finite, decode and verify continue on the host. On a healthy device nothing changes: output is bit-identical and no extra runs are made.

Verification

Local: Linux XRT, Ryzen AI MAX+ 395, NPU power mode Performance.

  • Kernels and engine:
    • Bit-identical gates on the final tree: logits / app hashes on a prose, a 4k and an 8k stream.
    • Teacher-forced KLD against plain decode on every verify row (aggregate 2.75e-4 and 2.00e-4).
    • 8 end-to-end speculation streams, including the 4k-to-8k boundary cases.
    • State keep / restore.
  • Decode tok/s vs inkling-2:mini: code 30.2 vs 12.3 (2.46x), math 25.2 to 33.8 vs 12.4, reasoning (high effort) 27.8 vs 12.4, tool calls 19.8 vs 12.3, JSON schema 18.5 vs 12.5, short chat 15.0 vs 12.4, sampling 14.3 vs 12.5, 4k / 8k-token document 13.5 / 12.1 vs 11.5 / 11.1. A mixed set of 71 requests took 804 s against 1,176 s (-32%), with 0 errors, an identical drift check and bounded RSS.
  • Behaviour matrix (32 cases: multi-turn, tools, JSON, penalties, images, cancel / retry, max_tokens, context limit): all pass on the tag, on the kill switches and on inkling-2:mini. Greedy text with speculation on can split from plain decoding at near-ties: every split traced was a top-2 gap of 0 to 2 bf16 ulps, from the 8-row pass rounding differently.
  • Linux no-hang pressure (one server):
    • Both kill switches 23/23 identical to inkling-2:mini.
    • With speculation and the prefix cache on: references identical across passes. A 300 s 4-thread hammer gave 46/46 identical, with streaming plus mid-prefill and mid-decode cancels.
    • 3 unload/reload cycles via inkling-2:mini were identical after each.
    • --prefix-slots 0 matches the cache-on output: 25/25 identical in a 150 s hammer.
  • Non-finite rerun (Linux, by forcing the check with a temporary test hook, not in this tree): on decode and on verify, at the first token and mid-answer, both the rerun and the host fallback run without a hang. A first-token rerun gives the same text. The weights are bound again in 9 to 14 ms and the state reloads in about 150 ms; host replay costs about 17 ms per token since the last sync. Without the hook, both tags stay 23/23 bit-identical to their references, and no recovery line appears.
  • Windows (XRT, 4 sweep runners; branch engine on a package of the same kernel sources): the long-prompt set (2k to 4.1k tokens, reasoning, image + text) at 8 passes per runner, on inkling-2:mini (2 runners) and the tag (2 runners): 0 empty answers in 448 requests, every pass identical. The non-finite case occurred 8 times (2 decode tokens, 6 verifies); each time the rerun after binding the weights was clean, and the host fallback was never needed. Before the fix, the same set gave empty answers on about 3% of long requests, on inkling-2:mini from the v1.0.14 release as well. Earlier Windows runs of the full pressure set on the tag showed no failure other than these empty answers.
  • devkit_check, check_internal_refs and .github/script/ci unittest (544) pass. test_model_downloader builds and passes.

CI-built artifacts

c00deab swaps in what Build and Test run 46586996276 built from e0e3612 and tested on the NPU (devkit_swap.py fetch):

  • inkling2_npu for Linux and Windows, XRT and HRX;
  • 8 files in Inkling-2-Mini-NPU2, 3 of them new: dflash2.xclbin, verify.xclbin, inkling2_verify.switches.

inkling2.switches and inkling2_decode.switches were byte-identical already.

  • Local check: the CI-built Linux XRT engine and all 10 Inkling-2-Mini-NPU2 kernel files, installed together, were run on the same pressure references as above. inkling-2:mini was 23/23 identical, and inkling-2-dflash2:mini was 23/23 identical, with speculation and the prefix cache on. Each had 0 empty answers in 92 requests, and no recovery line was logged.
  • CI: NPU tests passed on Linux XRT, Linux HRX and Windows XRT. All 4 bench jobs (perf + GSM8K, both tags, Linux XRT and HRX) passed.
    • The first attempt had two failures:
      • The Windows XRT model extension build failed downloading libjpeg-turbo.
      • The inkling-2:mini speed bench on Linux HRX failed with hrx_buffer_allocate at flm bench -c 8192. Its GSM8K passed at 98%.
    • Both passed when re-run. The HRX bench failure is intermittent and not from this PR: the same bench on main's build (run 46606957021) fails the same way, while its GSM8K passes at 98%.

🤖 Generated with Claude Code

tawei-amd and others added 5 commits November 30, 2026 21:26
convert_inkling2_dflash2.py turns the incoai/Inkling-2-Mini-DFlash2 HF
checkpoint into dflash_weight.q4nx: the layer matrices in bfp16 (8 values
per shared exponent, 1.125 B/weight) or, with --q4k, in the FLM Q4_K
block layout of the base model (llama.cpp's quantizer via libggml-base).
Norms, the dynamic-convolution kernels and the candidate-selector
codebooks stay BF16 in their HF layout. The drafter shares the target's
embedding and lm_head, so the package carries neither.

check_inkling2_dflash2_q4nx.py unpacks every tensor and compares it with
the checkpoint (relative L2 for the bfp16 matrices, exact for BF16).

New ModelArch INKLING2_DFLASH2 (config inkling2_dflash2.json); it is
read from safetensors only, never detected from a GGUF.

Co-Authored-By: Claude <noreply@anthropic.com>
Kernels for speculative decoding of Inkling-2-Mini with the DFlash2
drafter:

- Inkling2/verify_layer: the 8-row verify overlay (verify.xclbin). The
  same array layout as decode_layer; the batched ops (OP_PROJ8,
  OP_ROUTER8, OP_TOPK8, OP_EXPERT8) run 8 rows on aie::mmul<8,8,8>
  in bfp16, so each layer application streams its Q4_K weights once
  for the last committed token and the 7 drafted ones. The glue cores
  take the mixes row by row on glue_dn columns 1-7 and a head's
  attention rows in series; the conv rings hold 9 blocks per site so a
  row sees its predecessors' inputs. OP_ATTN cache records are scored
  on the idle row-3 core.
- Inkling2/lm_head8: the lm_head over 8 rows (Q4_K, softcap applied
  on the host).
- Inkling2/verify_switches: builds verify.xclbin and
  inkling2_verify.switches, the warm control-packet switches between
  the verify overlay and the lm_head8 window, via
  decode_switches/build.sh with VERIFY=1. The xclbin is stamped with
  USER:I2V8_CAPS (the glue's VERIFY_CAPS, UUID unchanged) so the host
  only sends the opt-in ops the loaded kernel supports.
- Inkling2/dflash2_layer: dflash2.xclbin, the drafter's matrix products
  (bfp16 or Q4_K, 8 rows) and its context attention.
- decode_layer host test: `mixr` runs OP_MIX for up to 8 independent
  rows in rounds on glue_dn columns 1..7 in one run, checked against
  the fp64 reference.

build_units.json, kernel_assignment.json and kernel_assignment.md list
the new units and the verify.xclbin / inkling2_verify.switches /
dflash2.xclbin slots of Inkling-2-Mini-NPU2.

Co-Authored-By: Claude <noreply@anthropic.com>
inkling2_npu gains the causal_lm speculation hooks. With the drafter
package of the config's draft_model_path loaded, each speculate() cycle
drafts 7 tokens after the last committed one, verifies the block of 8 on
the NPU in one pass and commits the agreeing prefix plus one token.

Engine (flm-dev-kit/FLM_DLL/detail/inkling2_npu):
- inkling2_verify8: the 8-row verify on verify.xclbin. Routing (router,
  top 8, expert union) runs on the host; the expert union is split
  between the NPU (at most 2 rounds per visit) and the host's share,
  run beside it. Attention is batched 4 rows per task so the cache is
  streamed once per 4 rows; the controller regions are fused per
  controller. The conv rings, K/V records and rings go straight into
  the regions the decode uses, so rollback(keep) leaves the state
  exactly as if only the first `keep` rows had run.
- inkling2_pool: the verify's own sleeping worker team (the OpenMP
  team's size; futex on Linux, std::atomic wait elsewhere), with a
  prewake that wakes the workers just before an NPU run ends, so
  spinning threads do not take the SoC power budget from the NPU.
- inkling2_lmh8: the lm_head over the 8 rows on the lm_head8 window,
  reached by warm control-packet switches (inkling2_verify.switches),
  softcap by table.
- inkling2_caps: the opt-in ops of the loaded verify kernel, read from
  the xclbin's USER:I2V8_CAPS key; a missing key means only the ops
  every verify kernel has (fail closed).
- speculate/dflash2_draft: the drafter (5 sliding-window layers with
  two-tap dynamic convolutions, non-causal over the block, then the
  low-rank candidate selector over the top target logits), fed by the
  target's hidden-state taps; its matrix products and context attention
  run on dflash2.xclbin (speculate/dflash2_matmul), the rest on the
  host.
- Taps of the latest positions are kept for the drafter and cut back
  on rollback; restore() of the engine's own checkpoint keeps them.
- Stop tokens end a block; a chooser lets the caller pick each row's
  token (constraints, sampling), asked in order up to the first
  disagreement so it sees exactly the committed tokens.

Environment: FLM_DFLASH=0 skips the drafter (plain decoding),
FLM_DFLASH_PATH overrides the drafter package, INKLING2_NPU_VERIFY=0
runs the verify on the host model, INKLING2_V8_TIME prints a per-stage
timing line of the verify.

Builds: HRX builds compile the verify, lm_head8 and drafter NPU paths
out (the drafter matmul has a stub); MSVC builds take signed OpenMP
loop indices, <array> ahead of npu_utils.hpp and no collapse clauses.

Tools (tools/, all in the Makefile): inkling2_v8_probe (verify vs
forward per stage), inkling2_lmh8_window, inkling2_caps_test,
inkling2_spec_run (rollback / taps checks), inkling2_e2e_run
(end-to-end speculation on the NPU, E2E_FORCED for teacher-forced
acceptance), dflash2_spec_run, dflash2_mm_probe, and near-tie
diagnostics for verify vs forward mismatches.

Wrapper (modeling_inkling2): generate() takes _speculative_generate
when the engine supports speculation and FLM_DISABLE_SPECULATION is not
set. Greedy requests commit the argmax rows; sampled requests use
speculative sampling, so every committed token is distributed as plain
decoding would draw it. show_profile() adds the speculation phase
breakdown; clear_context() zeroes the speculation counters.

Co-Authored-By: Claude <noreply@anthropic.com>
…2 drafter

inkling-2-dflash2:mini is inkling-2:mini (base_model) plus the draft
package FastFlowLM/Inkling-2-Mini-DFlash2-NPU2 (config.json,
dflash_weight.q4nx, draft_vocab.txt). It loads the base's weights and
the Inkling-2-Mini-NPU2 kernel folder; the drafter turns speculative
decoding on in the same inkling2_npu engine and Inkling2 frontend.

- model_list.json / model_info.json: the tag and its download metadata
  (aie2p only, vision, reasoning, tools).
- builtin_backends / builtin_frontends: family inkling-2-dflash2 maps to
  inkling2_npu and Inkling2.
- rest_handler: the inkling-2 reasoning handling also covers the
  dflash2 family; test_reasoning.py detects it as Inkling.
- engines.json, changes.py: the inkling2 engine serves both families,
  so a change to it selects both tags; test_changes.py updated.
- test_model_downloader: the shipped catalog declares the tag with its
  base, kernel folder and draft files, and the base stays draft-free.

Co-Authored-By: Claude <noreply@anthropic.com>
…nding the weight buffers again

The fused decode and the 8-row verify read each layer's weight buffer by
device address only; no run takes it as an argument. On Windows such a
buffer can lose its device mapping after a long prefill, and the reads then
return NaN. The softcap clamp turns NaN into a flat -30 row, so argmax picks
token 0 and the answer comes back as "!!!!" or empty.

Detect the case (non-finite hidden state, or non-finite or mostly pinned
logits), replay the device tokens on the host, run one o-projection per
layer with its weight buffer as a run argument (which restores the
mapping), reload the device state and rerun once. If the output is still
non-finite, decode and verify continue on the host.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Security scan found no critical or high findings on lines changed by this pull request

6 medium, low, or unrated finding(s) are not listed; the scan run has them.

View the security scan run for complete reports.

“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Dev-kit bench

Results of the dev-kit benches in Build and Test run 46586996276 for e0e36127be, as that run reported them (its artifacts hold the per-model reports).

Summary

Dev-kit bench (pr) on e0e36127be

the pull request's staged packages: this run's numbers only, no comparison (to be designed later)

✅ No hard-gate failure and no soft-gate warning.

Linux XRT

Perf (tok/s; dev-kit against the base package on the same runner)

Model Machine Context Decode base → dev-kit Δ Prefill base → dev-kit Δ Decode Δ vs nightly (same kind)
inkling-2-dflash2:mini strix 1k — → 18.7 — — → 406.1 — no baseline for this kind
inkling-2-dflash2:mini strix 2k — → 10.9 — — → 491.4 — no baseline for this kind
inkling-2-dflash2:mini strix 4k — → 18.8 — — → 499.3 — no baseline for this kind
inkling-2-dflash2:mini strix 8k — → 10.0 — — → 605.5 — no baseline for this kind
inkling-2:mini krackan 1k — → 13.6 — — → 558.9 — no baseline for this kind
inkling-2:mini krackan 2k — → 13.3 — — → 636.6 — no baseline for this kind
inkling-2:mini krackan 4k — → 13.1 — — → 681.5 — no baseline for this kind
inkling-2:mini krackan 8k — → 12.3 — — → 673.0 — no baseline for this kind

GSM8K accuracy (%)

Model Nightly baseline This run Δ (points) Notes
inkling-2-dflash2:mini — 96.0 —
inkling-2:mini — 100.0 —

Linux HRX

Perf (tok/s; dev-kit against the base package on the same runner)

Model Machine Context Decode base → dev-kit Δ Prefill base → dev-kit Δ Decode Δ vs nightly (same kind)
inkling-2-dflash2:mini strix 1k — → 13.4 — — → 370.3 — no baseline for this kind
inkling-2-dflash2:mini strix 2k — → 13.2 — — → 446.1 — no baseline for this kind
inkling-2-dflash2:mini strix 4k — → 13.0 — — → 548.4 — no baseline for this kind
inkling-2-dflash2:mini strix 8k — → 12.4 — — → 515.4 — no baseline for this kind
inkling-2:mini krackan 1k — → 10.4 — — → 282.9 — no baseline for this kind
inkling-2:mini krackan 2k — → 10.2 — — → 361.8 — no baseline for this kind
inkling-2:mini krackan 4k — → 9.8 — — → 364.2 — no baseline for this kind
inkling-2:mini krackan 8k — → 9.6 — — → 433.4 — no baseline for this kind

GSM8K accuracy (%)

Model Nightly baseline This run Δ (points) Notes
inkling-2-dflash2:mini — 98.0 —
inkling-2:mini — 98.0 —

Perf: flm bench, decode and prefill average tok/s per context. A/B is the one perf signal that judges a change; the runners differ by machine kind, so the nightly comparison is informational and only made for the same kind. Accuracy: GSM8K (first 50 questions) and DocVQA (when enabled), greedy; unanswered questions count as wrong. Per-question reports, server logs and CSVs: the devkit-bench-result-* artifacts.

The dev-kit engine libraries and kernels that run 46586996276 built from
e0e3612, staged into its product builds and tested on the NPU
(devkit_swap.py fetch): 6 engine file(s), 8 kernel(s).
CI checks these bytes against the run's staging manifests.

  src/lib/hrx/inkling2_npu.dll
  src/lib/hrx/inkling2_npu.lib
  src/lib/hrx/libinkling2_npu.so
  src/lib/xrt/inkling2_npu.dll
  src/lib/xrt/inkling2_npu.lib
  src/lib/xrt/libinkling2_npu.so
  src/xclbins/Inkling-2-Mini-NPU2/decode.xclbin
  src/xclbins/Inkling-2-Mini-NPU2/dflash2.xclbin
  src/xclbins/Inkling-2-Mini-NPU2/inkling2_verify.switches
  src/xclbins/Inkling-2-Mini-NPU2/mm_rtm2_glu.xclbin
  src/xclbins/Inkling-2-Mini-NPU2/prefill_attn.xclbin
  src/xclbins/Inkling-2-Mini-NPU2/verify.xclbin
  src/xclbins/Inkling-2-Mini-NPU2/vision_attn.xclbin
  src/xclbins/Inkling-2-Mini-NPU2/vision_mm.xclbin

Devkit-Swap-Run: 46586996276
Devkit-Swap-Tested: e0e3612
@tawei-amd
tawei-amd marked this pull request as ready for review December 1, 2026 09:23
@tawei-amd
tawei-amd merged commit 3e7e3dd into main Dec 1, 2026
76 checks passed
@tawei-amd
tawei-amd deleted the feat/inkling-2-dflash2 branch December 1, 2026 14:50
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