Skip to content

poly: Inkling 2 Mini (inkling2 / inkling2_loop) - #200

Open
okada-shogo wants to merge 105 commits into
simplexai-labs:mainfrom
okada-shogo:inkling2
Open

okada-shogo wants to merge 105 commits into
simplexai-labs:mainfrom
okada-shogo:inkling2

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 21, 2026 •

Copy link
Copy Markdown

Title

poly: Inkling 2 Mini (inkling2 / inkling2_loop)

Refs #198. Depends on #199: the first commit here is #199's IQ1_S GPU kernel, unchanged. If #199 merges first, I'll rebase and it drops out of this PR.

What it is

A strata-poly engine for Thinking Machines' Inkling 2 Mini (26B, 128 experts, 8 a token), text and pictures. It reads ggml-org's inkling2_loop files (IQ4_NL, Q8_0) and Unsloth's inkling2 file (UD-Q2_K_XL). Its shared-engine hooks are used only by Inkling. One change reaches other families: the load order of a layer split.

How to use it

  • Install: ./setup.sh --family inkling (IQ4_NL by default)
  • Other file: --model UD-Q2_K_XL or --model Q8_0
  • Pictures: --vision cpu|gpu
  • Several requests at once: "parallel": N
  • Two or more cards: --gpus 0,1, or "layer_split"
  • Guesses from the conversation: --window 4
  • Guesses from Unsloth's DSpark drafter: --dspark yes in setup, or --draft-model FILE

Speed

Tokens/s, q8_0 caches, one request. "After 302" and "8,192" are prompt lengths in tokens.

Card Experts in VRAM IQ4_NL writes after 302 UD-Q2_K_XL writes after 302 IQ4_NL reads 8,192 UD-Q2_K_XL reads 8,192
A100 PCIe 40 GB (rented) all 101.5 102.3 2,147 1,889
RTX 3090 24 GB (rented, 6e61054 + the mix spread) † all 73.0-73.1 86.4-86.5 2,065-2,068 1,977-1,988
2x RTX 3070 8 GB, split at 18 (rented, 6e61054) 1,869 / 2,962 of 3,072 52.7-52.8 68.0-68.2
RTX 2070 Super 8 GB (local, the head fc96949) 923 / 1,977 38.9-39.0 50.6-51.5 1,019-1,021 949
RX 9070 XT 16 GB (WSL2, the head fc96949) * ~2,200 / all 43.5-50.1 79.1-80.2 584-611 890-904
  • The A100 row is medians of 3. The RTX 2070 Super row is two runs each (128 tokens written). The others are two runs each unless noted.
  • * Two runs each, with an RTX 4080's benchmark settings: 131,072 context, 256 tokens written, IQ4_NL with the 4080 run's expert profile. IQ4_NL prompts are about 4% slower than on a9ffc2b here (fewer CPU threads, below); the next push addresses it.
  • † That rented card ran its memory at half clock (power state P3, about 480 of 936 GB/s) for the whole session, so its writing numbers understate an RTX 3090.

How it was checked

  • Byte identity with the previous head: the same logit bytes in every capped, CPU-expert, serve and batch case (16 on CUDA, 8 on HIP).
  • A100: the same bytes in 18 of 18 cases, with and without CUDA graphs.
  • Kernel tests: 0 failures on sm_75, sm_60 and sm_80. On HIP only the 3 known conv_acc bit cases fail.
  • llama.cpp parity: prompt-logit cosine 0.9989-0.9998, always the same most likely token.
  • AMD vs NVIDIA: KL a row against an RTX 3090 is 9.7e-5 to 0.014 for the HIP default, and 7.9e-5 to 0.015 for an A100.

Platforms and limits

  • Linux, NVIDIA (CUDA): tested on every push.
  • Windows, CUDA (MSVC): ran on an earlier build. Not re-checked on every push.
  • AMD (HIP): builds and runs (RX 9070 XT under WSL2, RX 9060 XT on Linux). Setup does not offer it yet.
  • Not tested: HIP in CI, Metal (stubbed), the Q8_0 file, other families' models against main.
  • Context: no engine limit. The caches stay in VRAM (17 KiB a token with --kv q8_0, 32 KiB in fp16). No KV streaming.

Credits

  • Tako88: the HIP port (three commits, authorship kept). Thank you.
  • Svirful: the Windows / MSVC build and test run.

More

See docs/models/inkling.md and the sections below. I can split parts into their own PRs if you prefer.

Speed: RTX 2070 Super 8 GB

Local PC: RTX 2070 Super 8 GB (PCIe 3.0 x16), Ryzen 5 3600XT, 62 GB DDR4-3200, Ubuntu 22.04, CUDA 12.9. One request, q8_0 caches, guesses off, tokens/s.

Reading a prompt:

Prompt IQ4_NL UD-Q2_K_XL Code Conditions
2,048 tokens 775-781 927 aabcf2d 16K context, no expert profile, two runs
8,192 1,019-1,021 949 fc96949 (head) two runs
32,768 911-914 852-854 802b20d 128K context, expert profile, two runs
131,008 659 (199 s) 645 (203 s) 7f3f457 / 99e993f 128K context, expert profile, one run

Writing:

After IQ4_NL UD-Q2_K_XL Code Conditions
302 tokens 38.9-39.0 50.6-51.5 fc96949 (head) 128 tokens written, two runs
1,500 38.5-38.7 49.0-49.5 7f3f457 128K context, expert profile, 256 written, two runs
32,768 28.7 39.5 7f3f457 / 99e993f 128K context, expert profile, 64 written, one run
131,008 20.6 29.3 7f3f457 / 99e993f 128K context, expert profile, 64 written, one run
  • Experts in VRAM on the head rows: 923 of IQ4_NL's 3,072, and 1,977 of UD-Q2_K_XL's.
  • Experts in VRAM at a 128K context with the expert profile: 1,042 (IQ4_NL) and 2,022 (UD-Q2_K_XL).
  • RAM: 16.5 GiB with IQ4_NL, 9.1 GiB with UD-Q2_K_XL.
  • Longest prompt tested on this card: 131,008 tokens at a 128K context. The model file declares 1,048,576 tokens.
  • Batch slots, guesses, the drafter, pictures and MMQ tiles on this card: see "Opt-in features".
Speed: A100, RTX 3090, 2x RTX 3070, RTX 5080

A100 PCIe 40 GB (rented). Driver 580.126.09, 96 CPUs (11 CPU threads used). Code: c69df6a, which is the head's CUDA code. Every expert on the card (3,072 of 3,072). strata-poly --serve, q8_0, one fresh engine a prompt, 256 tokens written. 16K context; 40K for the 32K prompt, 132K for the 131K one. Medians of 3 runs [min-max], tokens/s.

Default STRATA_POLY_EXPERT_TILES=1
IQ4_NL reads 8,192 2,147 [2,140-2,183] 2,766 [1,902-2,842]
IQ4_NL reads 32,768 2,367 [2,278-2,502] 2,566 [2,505-2,682]
IQ4_NL reads 131,008 2,030 [2,029-2,033]
UD-Q2_K_XL reads 8,192 1,889 [1,846-2,067] 1,848 [1,542-2,187]
UD-Q2_K_XL reads 32,768 2,119 [2,023-2,178] 2,281 [2,224-2,395]
UD-Q2_K_XL reads 131,008 1,832 [1,815-1,864]
IQ4_NL writes after 302 101.5 [81.0-101.9]
IQ4_NL writes after 8,192 96.5 [96.3-96.7]
IQ4_NL writes after 131,008 69.1 [68.4-73.0]
UD-Q2_K_XL writes after 302 102.3 [102.1-102.5]
UD-Q2_K_XL writes after 8,192 96.8 [96.5-96.9]
UD-Q2_K_XL writes after 131,008 73.3 [61.6-73.3]
  • Prompts of 302 and 2,048 tokens were too noisy on this box to report.
  • Writing after 131,008 tokens sometimes drops in a single run (see the minimums).

A100, prompts of 262K to 1M tokens (UD-Q2_K_XL, every expert in VRAM, q8_0, one run each):

Prompt Reads it (c808b53) Writes after it Writes with STRATA_KV_INT8=1 VRAM in use
262,144 tokens 1,342 tokens/s (195 s) 51.4 tokens/s 55.5 14.7 GB
524,288 927 (566 s) 36.6 42.5 19.0 GB
1,048,576 589 (29.7 min) 17.8 (c808b53) 27.7 GB
  • The 262,144 and 524,288 writing numbers are with the 8-lane decode attention kernel. The 1,048,576 row is on c808b53, without that kernel, and was not rerun.

A100, prompt attention kernel (attn_fa2_kernel) size gate. Kernel bench, one run, ms, attn_mma_kernel / attn_fa2_kernel, a full layer's 1,024-token call:

Position q8_0 fp16 Kernel taken
0 0.206 / 0.299 0.249 / 0.292 attn_mma_kernel
1,024 0.515 / 0.531 0.516 / 0.514 attn_mma_kernel
2,048 0.812 / 0.760 0.763 / 0.731 FA2
7,168 2.279 / 1.889 1.993 / 1.812 FA2
31,744 9.245 / 7.344 8.106 / 6.970 FA2
  • A full layer's 4,096 tokens at 28,672 (q8_0): 32.3 ms with attn_mma_kernel, 28.4 ms with FA2.
  • A window layer's 4,096 tokens at 28,672 (q8_0): 0.98 ms with attn_mma_kernel, 1.32 ms with FA2. So window layers stay on attn_mma_kernel.

RTX 3090 24 GB (rented). EPYC 7B12, 15 CPU threads, PCIe 4.0. Every expert in VRAM, q8_0, tokens/s. The 6e61054 rows: 16K context, 256 tokens written, two runs.

IQ4_NL UD-Q2_K_XL Code
Reads 8,192 2,065-2,068 1,977-1,988 6e61054 + the mix spread
Reads 32,768 1,995-2,002 1,917-1,922 4d7ca06
Reads 131,008 1,604-1,609 1,548-1,550 4d7ca06
Writes after 302 73.0-73.1 86.4-86.5 6e61054 + the mix spread
Writes after 8,192 70.2 82.5-82.7 6e61054 + the mix spread
Writes after 32,768 57.5-58.1 65.0 4d7ca06
Writes after 131,008 45.3-45.4 49.8-49.9 4d7ca06
  • This card ran its memory at half clock (see † above), so its writing numbers understate an RTX 3090.
  • With the CUDA graph a token is 4 host launch calls. Without it: 1,059 (IQ4_NL) and 1,167 (UD-Q2_K_XL).
  • GPU kernels a token: 779 (IQ4_NL) and 890 (UD-Q2_K_XL).

2x RTX 3070 8 GB, split at layer 18 (rented, 6e61054).

IQ4_NL UD-Q2_K_XL
Experts in VRAM, of 3,072 1,869 2,962
Writes after 302 52.7-52.8 68.0-68.2
  • Two RTX 3070s split at 18 wrote 12-21% faster than one.

RTX 5080 16 GB (c808b53, an early tree, one run each). UD-Q2_K_XL fits whole. IQ4_NL holds 2,469 of 3,072 experts.

IQ4_NL UD-Q2_K_XL
Reads 2K 3,040 3,472
Reads 32K 3,231 3,658
Reads 128K 2,610 2,920
Writes after 302 101.9 130.5

RTX 4060 Laptop 8 GB, Windows 11 (Svirful, an earlier build). MSVC from VS 2022 Build Tools, CUDA 13.0. IQ4_NL wrote 26 tokens/s and read 484.

Speed: RX 9070 XT (AMD)

Box: RX 9070 XT 16 GB (gfx1201), Ryzen 7 7800X3D, 31 GB RAM for WSL2, Windows with WSL2 Ubuntu 24.04, ROCm 7.2.4, librocdxg 1.2.2. The desktop holds 2-3.5 GB of the card's VRAM. One request, tokens/s.

q8_0 caches, 131,072 context, 256 tokens written, two runs each:

IQ4_NL, a9ffc2b IQ4_NL, head fc96949 UD-Q2_K_XL, a9ffc2b UD-Q2_K_XL, head fc96949
Writes after 302 45.7-46.0 43.5-50.1 80.1 79.1-80.2
Reads 2,048 1,097 991-1,116 973-998 990-994
Reads 8,192 609-635 584-611 892-915 890-904

The head uses 8 CPU threads on this 8-core CPU (one a core), against 11 before; that costs IQ4_NL prompts a few percent, since part of their experts run on the CPU.

fp16 caches, 16K context:

IQ4_NL (about 2,050 experts, two runs) IQ4_NL with STRATA_INKLING_WMMA=1 UD-Q2_K_XL (3,072 of 3,072 experts)
Reads 2,048 1,141-1,146 1,404 988-998
Reads 8,192 628-633 766-777 818-848
Reads 32,768 416-428 630-639
Writes after 286 44.0-48.4 80.0 (head, medians of 3)
Writes after 2,048 77.0 (d4eba79, medians of 3)
  • The UD-Q2_K_XL reading rows are on the AMD commits before they were merged into this branch.
  • IQ4_NL writing is CPU-bound: the GPU idles 60% of a token.
  • Prompt reading is attention-bound: 53% of kernel time at 2,048 tokens.
  • NVFP4's int8 prompt tiles are Inkling's default on HIP. Without them the 2,048-token UD-Q2_K_XL prompt read at 373 tokens/s.
  • The one-token mix stays one block on HIP. Spread over many blocks it was 7.5% slower on this card.
  • llama.cpp 29b52d398b HIP on the same box, for scale: UD-Q2_K_XL (converted to inkling2_loop) pp512 1,096-1,172, pp2048 224-555, tg128 37-44.
  • Not run on native Linux ROCm.
Opt-in features: speed

Batch slots (--batch / "parallel"). All chats together, tokens/s.

RTX 2070 Super (791be9e, a fresh server per row, 300-token chats, greedy, two runs):

Chats "parallel" IQ4_NL UD-Q2_K_XL
1 1 37.1-37.7 46.2-47.8
1 4 34.5-35.0 44.3-44.9
2 2 44.6-45.5 57.7-59.7
4 4 51.2-51.9 64.1-66.5

RTX 3090 (4d7ca06, 32K context):

Chats IQ4_NL UD-Q2_K_XL
1 56.4-56.6 66.6-67.2
2 81.3-81.6 98.3-99.3
4 109 141-144
8 118-119 145-147
  • Each slot's caches take VRAM from the expert cache. So one chat on a 4-slot server is 3-9% slower than on a 1-slot one.

Guesses from the conversation (--window 4) and the DSpark drafter.

RTX 3090 (every expert in VRAM, 16K context, q8_0, 256 tokens written, two runs each; 6e61054 + the window graphs), tokens/s:

Prompt --window 1 --window 4 Drafter
IQ4_NL, code, 302 70.8-70.9 72.8 72.3-72.9
IQ4_NL, code, 1,500 69.8-69.9 73.3 78.1-78.4
UD-Q2_K_XL, code, 302 84.1 89.4-89.5 103.5-103.9
UD-Q2_K_XL, code, 1,500 82.8 93.8-93.9 100.6-100.8
  • Drafter on code on this card: +2-12% (IQ4_NL), +21-24% (UD-Q2_K_XL).
  • --window 8 on a prose prompt: 127.8 tokens/s (UD-Q2_K_XL).
  • Host launch calls a window at --window 4 (nsys): 5.6 (IQ4_NL) and 24 (UD-Q2_K_XL) with the graph, 787 and 921 without.

RTX 2070 Super, --window 1 -> --window 4 (68d4c86; the code prompt asks for a file back with a change), tokens/s:

IQ4_NL UD-Q2_K_XL
Code 35.1-35.4 -> 38.8-40.0 47.1-47.4 -> 47.9-48.1
Text 36.7-37.8 -> 36.7-37.2 48.2-48.4 -> 48.8
  • --window 4 pays where the answer copies the prompt.

Drafter on an 8 GB card (a rented RTX 2070, 6e61054 + the drafter, greedy, frozen experts, 256 tokens, two runs each, against the same build without the drafter):

  • From -11% to +22% on 12 of 14 prompts.
  • The two 8,192-token prose prompts gained 44% and 59%. There the drafter's 192 guesses were all right.
  • With the drafter the cache holds fewer experts: IQ4_NL 875 instead of 961, UD-Q2_K_XL 1,881 instead of 2,056.

MMQ expert tiles (STRATA_POLY_EXPERT_TILES=1, CUDA only).

Prompt reading, default -> tiles, tokens/s:

Card File 2,048 8,192 32,768
RTX 2070 Super IQ4_NL 741 -> 810 (+9%) 920 -> 1,075 (+17%)
RTX 2070 Super UD-Q2_K_XL 917 -> 1,032 (+13%) 883 -> 983 (+11%)
RTX 3090 IQ4_NL 2,115 -> 2,308 2,103 -> 2,288 2,007 -> 2,177
RTX 3090 UD-Q2_K_XL 2,029 -> 2,176 2,027 -> 2,156 1,921 -> 2,048
  • RTX 2070 Super: 6e61054 + the tiles, warm, with the expert profile; 1,038 / 1,989 experts cached.
  • RTX 3090: every expert in VRAM, one run each, warm. The gain is +6-9%.
  • A100: see the A100 table. IQ4_NL at 8,192 is +29% over the default. UD-Q2_K_XL at 8,192 is within the spread.

Kernel bench (poly_mmq_tiles_test bench, 8 calls, rows from the IQ4_NL expert profile), TOPS:

Card Matrix The engine's launches All experts in three launches Tiles
RTX 2070 Super IQ4_NL gate|up 12.8 16.1 22.4
RTX 2070 Super IQ4_NL down 9.8 13.0 19.1
RTX 3090 IQ4_NL gate|up 20.0 43.8 58.5
RTX 3090 IQ4_NL down 13.7 35.7 46.6
A100 IQ4_NL gate|up 17.4 29.3 45.9
A100 IQ4_NL down 11.6 26.7 39.2

STRATA_KV_INT8=1 (past 32K, needs a q8_0 cache).

  • A100 writing after 262,144 and 524,288 tokens: see the A100 long-prompt table.
  • Decode attention alone (RTX 2070 Super, one full layer, q8_0, 1M positions = 2.3 GB read): 8.98 ms by default, 8.32 ms with STRATA_KV_INT8=1.

Pictures (--vision cpu|gpu, RTX 2070 Super, 6 encoder threads).

Encoder Time VRAM
GPU 63 ms for 256 rows, 314 ms for 990 576 MiB (908 experts cached instead of 1,038)
CPU 1.7-2.5 s for 208-300 rows, 12.3 s for 990

More tables are in docs/models/inkling.md (Guesses from the conversation; Guesses from its DSpark drafter).

Accuracy

Against llama.cpp's logits. poly_logits_dump and llama.cpp at the commit that added the model. IQ4_NL and UD-Q2_K_XL, a short prompt and prompts of 302 and 1,500 tokens, twice each, RTX 2070 Super.

Result
Prompt logits, cosine 0.9989-0.9998
Prompt logits, top 20 the same 16-20 of 20; always the same most likely token
Decode, llama.cpp's own 32-token answer fed in the same most likely token at 29-32 of 32 steps
With the tensor-core prompt attention (7f3f457) cosine 0.99919-0.99984, decode 30-31 of 32
  • Where decode differed, llama.cpp's top two were within 0.14 in logit, except at one step (1.0 apart).
  • The engine is not bit-deterministic from run to run when experts move in and out of VRAM (cosine 0.9992 between two runs).

AMD (HIP) against NVIDIA. Reference: an RTX 3090's CUDA default dumps. Noise floor: an A100's CUDA default against the same RTX 3090. 12 cases: both files, fp16 and q8_0, prompts of 286, 2,048 and 8,192 tokens, prompt + 32 decode rows. HIP code: the AMD commits before they were merged into this branch.

Full-row KL a row, mean Top token
A100 vs RTX 3090 (the floor) 7.9e-5 to 0.015 30-33 of 33
HIP, NVFP4 decode kernels 9.3e-5 to 0.011 32-33 of 33
HIP, NVFP4 int8 tiles (the default) 9.7e-5 to 0.014 32-33 of 33
HIP, int8 tiles + WMMA attention (opt-in) 1.2e-4 to 0.014 31-33 of 33
  • Greedy answers part from the RTX 3090's in the same cases as the A100's do (for example at token 2 after the 2,048-token prompts).
  • IQ4_NL held about 2,050 of 3,072 experts on the RX 9070 XT, and all of them on the NVIDIA cards.

Opt-in features against the default.

Feature Setup Result
MMQ tiles RTX 3090 and A100, every expert on the card KL 0 at 33 of 33 rows after 8,192 tokens; the same 256 greedy tokens, both files
MMQ tiles RTX 2070 Super, experts split, UD-Q2_K_XL KL 1.5e-4 a row on average; top token 33 of 33
STRATA_KV_INT8=1 RTX 2070 Super, frozen experts, after 19,500 tokens KL a row 0.0026 (IQ4_NL), 0.0091 (UD-Q2_K_XL)
STRATA_KV_INT8=1 the same, after 30,000 tokens KL a row 0.0002-0.0004; greedy 256 of 256 tokens the same
DSpark drafter every expert on the card, or every expert on the CPU the same greedy answer as without it
DSpark drafter experts split (rented RTX 2070 8 GB) answers parted in 12 of 14 prompts
  • MMQ tiles on the RTX 2070 Super: greedy answers part only at near-ties (top two within 0.33 nats). The default path's own reordering (--prompt-batch 64) moves the logits by the same amount.
  • MMQ tiles: prompts of fewer than 32 rows do not use the tiles, and give the same bits.
  • Drafter with split experts: each parting was at a step where the two likeliest tokens were within 0.016-0.18 nats. The cause is the smaller expert cache, which moves a few scores.
  • Drafter with --no-gpu-experts: the same answers in 6 of 6 cases. Graphs on and off: the same in 2 of 2.
  • Drafter's guesses against llama.cpp's drafter on llama.cpp's inputs: 84 of 84, 178 of 179 and 137 of 138 the same (code, prose, 1,523 tokens; RTX 3090).

Pictures (llama.cpp 29b52d398b, IQ4_NL, the Q8_0 mmproj).

  • The encoder's rows are bit-identical to llama.cpp's with flash attention off.
  • The engine's most likely token is the same at 33 of 33 positions for six drawings and a photo.
  • The server and llama-mtmd-cli described the photo in nearly the same words.
  • UD-Q2_K_XL with pictures: cosine 0.99984-0.99993, 32-33 of 33.

Answers (50 GSM8K + 50 MMLU-Pro, greedy, an early build): IQ4_NL 93, UD-Q2_K_XL 89. The same answer to 92 of 100.

Tokenizer and chat format.

  • Token ids matched Hugging Face's tokenizers on 1,006 strings (about 587,000 tokens).
  • The prompts for 14 requests and the parsed results of 11 replies matched llama.cpp's chat code (serve/test_inkling.py).

Kernel accuracy. Tensor-core prompt attention: the largest error against a double reference was 3.8e-3 (kernel test, sm_75).

Byte-identity checks and tests

"The same bytes" means the md5 of the dumped logits is equal (poly_logits_dump, experts frozen).

What Compared Cases Result
RTX 2070 Super and RX 9070 XT fc96949 (head) vs a9ffc2b every capped, CPU-expert, serve and batch case: 18 on CUDA, 6 on HIP the same bytes; kernel tests as before; the F32 GEMM bit test passes
RTX 2070 Super and RX 9070 XT a9ffc2b vs 3cb428d / d4eba79 16 on CUDA, 8 on HIP the same bytes
A100, every expert on the card c69df6a vs 6e61054 + the expert cap; and vs --no-graphs 18: both files; prompts of 302, 1,500, 8,150 and 16,500 tokens; fp16 and q8_0; STRATA_KV_INT8=1 at 16,500 the same bytes (prompt + 64 decode logits)
RTX 2070 Super, every expert on the CPU aabcf2d vs 6e61054; and vs --no-graphs 4: both files, 302 and 1,500 tokens, fp16 and q8_0 the same bytes
RTX 2070 Super, STRATA_GPU_EXPERTS at the same N (773 to 1,884), equal set hashes aabcf2d vs 6e61054; and vs --no-graphs 10: 302 to 16,500 tokens, fp16 and q8_0, STRATA_KV_INT8 off and on the same bytes, 10 of 10
RTX 2070 Super, --serve, four prompts in one engine aabcf2d vs 6e61054 both files the same tokens
RTX 2070 Super, --check-batch 2 aabcf2d every sequence wrote the tokens it writes alone
RX 9070 XT, STRATA_GPU_EXPERTS (UD-Q2_K_XL N=2,971, IQ4_NL N=1,932), equal set hashes aabcf2d: repeat runs and --no-graphs 6: 286, 2,048, 8,192 tokens the same bytes, 6 of 6
RX 9070 XT, IQ4_NL, --no-gpu-experts Tako88's tree, the guard-only tree, ours 10 pairs the same bytes, 10 of 10
RX 9070 XT, 120K-token prompts a9ffc2b, with and without --vram-pool load with no fd or VRAM errors
A100 prompt attention (FA2) attn_fa2_kernel vs attn_mma_kernel, kernel test 64 comparisons the same bits, 64 of 64
Windows as graphs, RTX 3090 --window 4 and 8, and the drafter at windows 4 and 8, vs --window 1 and vs --no-graphs both files, three prompts, 256 greedy tokens with the top 5 at every step the same
Windows as graphs, A100 graphs vs --no-graphs, for --window 4 and for the drafter both files, a code and a prose prompt, 128 greedy tokens and top 5 the same
Decode attention f5e5a7e vs the kernel before it 3,240 kernel calls; with --no-gpu-experts, both files, fp16 and q8_0, prompts of 302 to 7,500 tokens (RTX 2070 Super, RTX 2070, RTX 2080 Ti); IQ4_NL after 30,000 tokens the same bytes
Second fusion pass, graphs and split 6e61054 vs 2424377 RTX 3090, every expert in VRAM: 10 cases, with and without graphs. RTX 2070, every expert on the CPU the same bytes
Prompt copy 802b20d vs 249b2de, STRATA_FREEZE_EXPERTS=1 4 steps, both files; --serve after checkpointed and resumed reads the same top-20 tokens and probabilities; the same tokens
Restore fix c5f26c6 vs the commit before it 8 reloads in each of 3 cases the same bytes (the race was never seen)
Batch slots each sequence in a batch vs alone 20 runs, and with staggered joins exactly the same tokens
Guesses --window 4 vs --window 1, every expert on the CPU every step the same tokens and top 5
Layer split, every expert on the CPU split vs one card splits at 18, 6 and "auto"; 3, 20 and 3+18 on an earlier tree one card's logits to the byte
Layer split, every expert in VRAM two stages on one RTX 3090, split at 18, vs one card with and without graphs one card's bytes
Other families (the split's load order) LFM2.5-24B-A2B UD-Q3_K_XL, with and without the change two RTX 3070s, two RTX 3060s the same bytes

Tests:

  • Kernel test (poly_inkling_kernels_test): 0 failures on sm_75, sm_60 and sm_80. It compares every fused launch with the separate launches, to the bit.
  • Kernel test on HIP: only the 3 known conv_acc bit cases fail (fused vs separate launches). They also fail on Tako88's own tree.
  • python -m unittest discover -s serve: 1,049 passed (18 skipped), on a build without batch slots.
  • serve/test_inkling.py: 44 (3 skipped). tools/test_setup_*.py: 799 (1 skipped).
  • poly_mmq_tiles_test: the tiles match llama.cpp's MMQ run without splits bit for bit, for the seven expert types.
  • Metal: checked by compiling its sources on Linux. Not built on macOS.
  • Other families: I read the diff with each switch off. Nothing ran against main. A run on Flint or GLM with and without this PR, by someone who has them, would confirm it.
What changed, by file area

Engine (src/poly/inkling.*, kernels_inkling.cu, include/strata/poly/inkling_kernels.hpp)

  • The model: layers 6-17 run three times (48 visits), with cross-pass messages and rank-64 controllers. Also short convs, the output gate, the softcap, SiTU and the sigmoid router.
  • Attention: residuals, SWA 1024, and a relative-position bias with per-query sinks. The kernels apply the bias and sinks themselves and read the fp16 or q8_0 cache directly. They build no score matrix.
  • Prompt attention on the tensor cores (attn_mma_kernel, FP16 MMA, Turing or newer) for prompt calls of more than 16 tokens. The bias stays in float.
  • Prompt attention on sm_80 (attn_fa2_kernel, A100 and A800): full layers past position 2,048. Same steps in the same order as attn_mma_kernel, so the same bits. Measured on an A100-PCIE-40GB only, not on the A30 or A800. Other cards keep attn_mma_kernel.
  • Decode attention at long contexts: 8 lanes a key and fewer shuffles, in the same sum order, so the same bits.
  • STRATA_KV_INT8=1 (opt-in, as Kolibri's): a written token's full-layer attention over 32K or more, with __dp4a. Needs a q8_0 cache. The bits differ.
  • Fewer decode launches a token, with the same bits (two fusion passes). Some launches write native_mmvq.cu's fast-math operations as PTX so their bits match; on HIP they are plain IEEE operations.
  • One-token mixes over many blocks of 32 threads (CUDA). Same operations in the same order, so the same bits. It falls back to one block a mix if not all its blocks fit on the card (MPS, green contexts). STRATA_INKLING_MIX_SPREAD=0 turns it off. On HIP it stays one block.
  • One CUDA graph a token when every expert is on the card. A window of 2-8 tokens (--window N, the drafter) is one graph too. --no-graphs turns it off; the bits are the same either way.
  • Not recorded as graphs: experts on the CPU, --batch, pictures, --dump-layers, and the drafter's own launches.
  • Prompt reads on a card that can't hold every expert: the next layer's uncached experts are copied while a layer runs.
  • Layer split (--layer-split, "auto"): layers 6-17 stay on one card, so a card starts at layer 1-6 or 18-22. A card hands the next one 64.5 KB a token through pinned memory.

DSpark drafter (opt-in)

  • Unsloth's dspark-Inkling-2-Mini-Q8_0.gguf (0.4 GB, pinned by SHA-256), run as llama.cpp's PR 32218 runs it.
  • It taps the model's streams entering visits 5, 23 and 41 and its normed output. One block of 8 rows, three dense layers and a recurrent head. The engine takes its three guesses a round as one window.
  • Its caches go with a conversation's saved state.
  • Setup asks only where the card holds every expert beside the drafter, with "no" as the default. It counts the drafter's 0.4 GiB and its 4 KiB a context token.
  • Not with --batch, --layer-split or several cards.
  • poly_dspark_parity compares its guesses with a record of llama.cpp's run; --reload checks save and restore.

MMQ expert tiles (opt-in, STRATA_POLY_EXPERT_TILES=1)

  • Mmq::mul_tiles() runs llama.cpp's MMQ tiles from a table. One launch takes all of a layer's cached experts, each in tiles of its own width (16 to 128).
  • The default path goes to MMQ in about 25 runs of slots, ~73 launches with stream-k's fixups, each as wide as its largest expert.
  • No tile is split over K, so the sums can round differently from the default. Hence opt-in. Off, nothing changes.

Expert cap (test only, STRATA_GPU_EXPERTS=N)

  • The cache holds exactly the first N experts of its fill order, frozen. An N that does not fit stops the load. One card only.
  • The load logs cache set N experts fnv <hash>. Two builds can then be compared byte for byte with experts on the card.
  • The hash matters: UD-Q2_K_XL's experts come in seven sizes, so the same count can be a different set (1,640 experts can be three sets within 2.5 MiB of cache).

Shared engine (engine.*, cpu_experts.*, mmq.*). Each change is gated, so other families keep their path.

  • The three loop passes share one cached copy of each expert (Layer::alias, home_of).
  • load_moe takes expert scales of any type when asked (only Inkling asks).
  • Fast Q2_0 and IQ1_S CPU dot products and Q2_0 in MMQ, through Engine::lowbit_experts_ (only Inkling).
  • Inkling loads its CUDA modules eagerly and reserves MMQ's fixup buffer.
  • New kernels and hooks that only Inkling uses: native_mmvq_jobs(), native_mmvq_jobs_mixed(), the slots launch a warp a row, the norm rows with a Q8_1 copy, layer_graphs(), card_sum_in_tail(), act_rows_q8_1(), windows_on_card(), the drafter hooks, Mmq::mul_tiles(), Mmq::Allow.
  • New strata_poly_cpu static library, linked by every engine and test target.
  • Reaches other families: a split's load order. Every part's layers load before any part's experts. One card without a split loads as it did.
  • Reaches other families: IQ1_S in native_mmvq_supported (additive), and the STRATA_GPU_EXPERTS test knob.
  • Reaches other families on HIP: VRAM pieces of one size a reservation, and a higher open-file soft limit (a ROCm workaround, shown on ROCm 7.2.4 / WSL2 only).

HIP (AMD)

  • Engine::open no longer refuses the model on HIP.
  • Inkling takes NVFP4's int8 prompt tiles by default on HIP (Engine::nvfp4_int8_). Other families' HIP runs keep their path unless STRATA_PREFILL_NVFP4=w4a8.
  • A faster attn_kernel (built for CUDA too, with the same arithmetic in the same order), and an opt-in RDNA4 WMMA attention (STRATA_INKLING_WMMA=1, gfx12 only).
  • CUDA builds compile what they did for the HIP-only parts.

Metal: Inkling is not ported. Opening the model says so (metal/src/poly/unported.cpp). SYCL compiles no src/poly code.

Server (serve/frontend.py, serve/server.py, tools/strata_tokenizer.py)

  • InklingParser, forced tool_choice, and ignore_merges for inkling2.
  • strata_prefix matches with reasoning_effort and thinking off.
  • A tool call whose JSON closed without <|end_message|> is parsed.
  • test_responses.NoLeakedSampler (test only, its own commit) checks only its own server's sampler thread.

Pictures (opt-in): llama.cpp 29b52d398b's mtmd encoder, built into engine-poly/vision-inkling/. The shared strata-vision is unchanged. Picture rows skip token_embd_norm, as in llama.cpp. build_vision_own in setup.py copies the shared encoder build's steps rather than sharing a helper, to keep the other families' path as it is.

Batch slots (--batch / "parallel"): the generic slot machinery, with five _seqs kernels.

Guesses from the conversation (--window 4): after a repeat of the last 3+ tokens, up to three guesses. A partly kept window rolls back.

Setup and docs

  • --family inkling with three pinned files, and --dspark yes|no. Several cards and "parallel" as for the other families. Setup still marks the family cuda_only.
  • docs/models/inkling.md (English only), and rows in GLM.md (STRATA_GPU_EXPERTS), NVFP4.md (HIP), MULTI_GPU.md, README, AI_SETUP, BACKENDS and Q8_KV.md.

Tools and tests: poly_logits_dump, poly_dspark_parity, poly_inkling_kernels_test, poly_cpu_lowbit_test, poly_lowbit_gpu_test, poly_mmq_tiles_test, tools/window_agree.py.

AMD (HIP): WSL2 caveats

Seen on the RX 9070 XT box (WSL2 Ubuntu 24.04, ROCm 7.2.4, librocdxg 1.2.2). The commits are in "Commits named in this text".

Problem What the PR does
ROCm finds no device Nothing. Set HSA_ENABLE_DXG_DETECTION=1.
ROCm 7.2.4 with librocdxg refuses hipMemSetAccess on a VMM piece mapped after a larger one in the same reservation. Without the fix the cache lost its last piece (3,058 of 3,072 experts) and a full-length KV cache failed to grow. Maps pieces of one size on HIP.
Each VMM handle holds a file descriptor. The usual soft limit of 1,024 capped --vram-pool at 774 experts. Raises the soft limit to the hard one on HIP.
The desktop's VRAM use changes, so IQ4_NL's cached expert count varied from run to run (1,867-2,157). Nothing. Use STRATA_GPU_EXPERTS for byte comparisons.
  • rocprofv3 does not work under WSL2 (rocprof v1 does).
  • llama.cpp's IQ4_NL runs with --n-cpu-moe crashed in librocdxg after the first one. Not resolved.
  • My runs are all under WSL2. Tako88's are on Linux (RX 9060 XT).
Known issues and follow-ups

Known issues

  • The DSpark drafter is not lossless when the experts are split between card and CPU (see "Accuracy").
  • The engine is not bit-deterministic from run to run when experts move in and out of VRAM.
  • KV streaming for contexts beyond VRAM is not in this PR and not planned for it.
  • Setup does not offer Inkling on AMD, and prompt speed on AMD is not tuned.
  • HIP is not built in CI. Metal is stubbed. The Q8_0 file is not tested.
  • The MMQ tiles are CUDA-only.

Follow-ups, not in this PR

  • AMD step 2: WMMA attention with hi+lo halves as HIP's default, and MMQ and decode tuning for RDNA4.
  • MMQ tiles on by default, after more cards are measured.
  • mmvq occupancy: loading ahead doubled the registers and was 2-6% slower on an RTX 3090, so it is not here.
  • Every family: Engine::card_moe() and Engine::load_state() copy from pageable memory with a plain cudaMemcpy on the legacy stream, which the engine's non-blocking streams do not wait for. This needs a separate fix.
  • Separate PR: FP4 prompt products on RTX 50 (STRATA_PREFILL_NVFP4=w4a4x2), poly: NVFP4 prompt products with two-term FP4 activations on RTX 50 (STRATA_PREFILL_NVFP4=w4a4x2), Inkling 2 Mini #202.

llama.cpp problems found while checking

  • In 29b52d398b, inkling2_loop copies the core layers into slots 24-47 before it attaches the *_exps.scale tensors. So passes 2 and 3 run without the scales on Unsloth's files.
  • That release cannot load Unsloth's inkling2 file as it is. The UD-Q2_K_XL reference was made from a copy converted to inkling2_loop. Loading was fixed upstream (#32704).
  • llama.cpp turns flash attention off for this model (its kernel cannot take the KQ bias). So a quantized KV cache costs more VRAM there than fp16.
Commits named in this text
Commit What it is
fc96949 The head: a9ffc2b plus faster F32 prompt products, the shared expert launched plainly, one CPU thread a core for Inkling, docs.
a9ffc2b The head before those four commits.
3cb428d The head before the 23 review-fix commits.
d4eba79 One block a mix on HIP. It changes HIP only.
c69df6a The build measured on the A100. The head's CUDA code is the same (d4eba79 changes HIP only; equal preprocessed CUDA source).
aabcf2d d4eba79 minus five commits: the A100 kernel and its gate, the test-only alignment fix, and two HIP-only changes. None of them runs on the RTX 2070 Super's default path.
6e61054 The base that the identity checks compare with. Some rented-card rows are on it.
e6c285e Tako88: run Inkling on HIP.
1d91dab Tako88: NVFP4 int8 tiles on HIP.
16f3585 Tako88: a faster attn_kernel, and the opt-in RDNA4 WMMA attention. It does not build on CUDA until 07e6249. Its test-only TQ 2 alignment fault lasts until dbd4227.
07e6249 The WMMA kernel builds on CUDA (__trap() instead of __builtin_trap()).
63ec88f, a92763c HIP: VRAM pieces of one size, and a raised open-file limit.
032794d The WMMA branch applies the gate and the Q8_1 copy too.
e61c27c, e85c7aa Missing hip_compat names.
cee948e NVFP4's int8 prompt tiles by default for Inkling on HIP.
dbd4227 An alignment fix in the unsplit attn_kernel (a test-only shape; CUDA too).
1dcd568 One-token mixes over many blocks.
e0b37b9, f5a2916 Windows as one CUDA graph; a window of 5-8 tokens routed on the card.
0720b38, 3b2189e, a6511c2 The DSpark drafter.
1b6dca2, 576681c The MMQ expert tiles.
cde2d1b, ec63e7f The expert cap (STRATA_GPU_EXPERTS).
f5e5a7e The 8-lane decode attention.
802b20d The prompt-copy change.
c5f26c6 The restore fix.
7df0399 The MSVC fix.
2424377 A build without CUDA graphs and the second fusion pass.
7f3f457 A build with the tensor-core prompt attention.
4d7ca06, c808b53, 99e993f, 249b2de, 791be9e, 68d4c86 Older builds that some measurements above are on.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Erqa3PhC87SPTfVSKZ3Ri5

Maya-XS GLM-5.3-Flash keeps its gate/up experts (and three layers' downs) in IQ1_S, which
native_mmvq_supported refused, so every expert ran on the CPU. Adds llama.cpp's
vec_dot_iq1_s_q8_1 and dequantize_iq1_s (transcribed), a decode-once Split<19> sharing
IQ1_M's staged iq1s_grid_gpu table, and type 19 in the gate/up, down and mmvq lists.

iq_parity: dequant bitwise equal to gguf-py, mmvq rel 7.6e-3. iq_multi_parity: new kernels
bitwise equal to the per-column ones; its float guard is 2e-2 for IQ1_S, whose delta term
uses the q8_1 float sum.
okada-shogo and others added 3 commits November 21, 2026 20:33
Inkling 2 Mini (Thinking Machines) is a 26B mixture of 128 experts,
8 a token, with a sigmoid router and SiTU activation.  Its 24 layers
run 6-17 three times (48 visits) with cross-pass messages and rank-64
controllers; attention residuals; a sliding window of 1024 on five
layers of six; a relative-position bias and per-query sinks; short
convolutions; an output gate; a logit softcap.  The engine reads both
GGUF forms: ggml-org's inkling2_loop (the loop unrolled) and
Unsloth's inkling2 (24 blocks).

 - kernels_inkling.cu: the bias and the sinks are applied inside the
   attention kernel, which reads the fp16 or q8_0 cache directly and
   builds no score matrix, so a 128K context fits beside an 8 GB card.
 - The three passes share one cached copy of each expert
   (Layer::alias, home_of); the expert prefetch follows the run order
   across the loop.
 - Unsloth's *_exps.scale tensors apply on every pass (load_moe takes
   scales of any expert type when asked).
 - Q2_0 and IQ1_S experts (Unsloth's UD-Q2_K_XL) on the CPU
   (cpu_lowbit, AVX2) and Q2_0 in MMQ, opt-in per engine: only this
   engine turns them on, so other families' files take the same paths
   as before.  IQ1_S on the GPU comes from the commit before this one
   (PR 199).
 - The engine loads its CUDA modules eagerly and reserves MMQ's fixup
   buffer: lazy loading took VRAM after the expert cache had filled
   it.
 - Not on Metal or HIP yet: opening the model there says so.
 - poly_logits_dump writes a prompt's logits, and those of tokens fed
   one at a time after it, for comparison with llama.cpp's.

Checked against llama.cpp's logits on IQ4_NL and UD-Q2_K_XL, short,
302- and 1,500-token prompts, each run twice: cosine 0.9989-0.9998,
16-20 of the top 20 the same, and with llama.cpp's answer fed in the
same most likely token at 29-32 of 32 steps.  RTX 2070 Super 8 GB,
Ryzen 5 3600XT, DDR4, 128K context, q8_0 caches: IQ4_NL writes 37
tokens/s and reads 270-434; UD-Q2_K_XL 45-47 and 366-544.  Built and
tested with CUDA 12.9 only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InklingParser reads Inkling's replies, a list of blocks (thinking,
text, tool calls), into the server's events.  A forced tool_choice is
written after the thinking, or at the start of the reply with
thinking off; the reply ends with that call.  The tokenizer treats
inkling2 as an ignore_merges pre-tokenizer, as Hugging Face's does
(llama.cpp splits some words, such as "kwargs", differently).

Checked against Hugging Face's tokenizers (1,006 strings) and
llama.cpp's chat code (14 prompts, 11 replies); serve/test_inkling.py
keeps a fixture of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setup --family inkling installs ggml-org's IQ4_NL (the default) or
Q8_0, or Unsloth's UD-Q2_K_XL, each pinned and checked by SHA-256,
with q8_0 caches allowed.  The family is CUDA only, so the Mac setup
leaves it out.  docs/models/inkling.md has what was measured, what was
checked and what was not run (Q8_0, Windows, AMD); the README,
AI_SETUP, BACKENDS and the MCP server's catalog list it.

On 100 questions (50 GSM8K, 50 MMLU-Pro, greedy) IQ4_NL got 93 right
and UD-Q2_K_XL 89.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo and others added 4 commits November 21, 2026 20:52
Inkling's engine now says it sees, so GENI's pictures reach it.  At
the first visit a picture's rows go in as the encoder made them:
llama.cpp 29b52d398b norms the token embeddings only (inkling2.cpp,
"if (ubatch.token)"), and a call here can hold text and picture rows,
so the raw rows are copied back over the normed ones row by row.  With
no picture in the sequence nothing changes.

poly_logits_dump takes --images FILE --image-pad ID: strata-vision's
SVE1 records at the prompt's runs of the pad token, as GENI places
them, so the engine can be checked against llama.cpp's mtmd with the
same rows.  Its prompt calls go through whole().

Checked on an RTX 2070 Super 8 GB (IQ4_NL, fp16 cache) against
llama.cpp's mtmd on the CPU, given llama.cpp's rows, for 6 prompts
(pictures of 1 to 990 rows, one with two pictures): the prompt's
logits had a cosine similarity of 0.99986 or more and greedy decoding
chose the same token at all 33 positions in each.  With the rows
normed, as before, it was 0.98485 or more and 29 to 32 of 33.  A
picture split across calls (--prompt-batch 64) and --kv q8_0 kept the
agreement (32 or 33 of 33, the one miss at a near tie).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling's template writes <|content_image|><|unused_200054|> in a
block of its own for a picture.  The server now puts one
<|unused_200054|> a row of the picture after <|content_image|>, which
is the sequence llama.cpp 29b52d398b's mtmd feeds (its img_beg is
<|content_image|>, it writes no end).  The other formats' marks are
unchanged.

serve/test_inkling.py checks the ids around two pictures and the
image_pad the engine is told, two pictures back to back, a picture in
a tool's message (its header has the tool's name), that the same marks
inside a message stay text, and that a picture in an assistant message
is refused by the template.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The other families' encoder is built from llama.cpp 69f201a, which
has neither the inkling2v projector nor the inkling2 tokenizer.
Moving that pin would change every family's encoder, so Inkling gets
a third pin (INKLING_VISION_LLAMA_CPP_COMMIT, 29b52d398b) through the
family's "vision_llama": build_vision_own() compiles tools/vision from
it into engine-poly/vision-inkling/ with a BUILD.json of its own, and
before a start update_vision_own() rebuilds it from that stamp, after
the engine's update and with a warning of its own when it fails.  Its
stamp records the toolkit's library folders, which go into the run
config's lib_dirs; a CPU-only one is not rebuilt for another toolkit,
as the shared check.  The shared engine-poly/strata-vision and its
stamp are not touched: for such a family the shared engine is built
with vision "none".  get_llama_cpp() takes commit= for that checkout;
its vision True and False do what they did.

The family entry: vision on offer (the question's default stays no,
so --yes installs text only), ggml-org's Q8_0 mmproj at the pinned
revision with its SHA-256, and ggml-org's mmproj for Unsloth's size
too.  "vision_vram_gb" 0.6: the encoder's process held 576 MiB after
its warm-up on an RTX 2070 Super.

Q8_0 rather than BF16, and the encoder's flash attention left on (its
default), from measurements there and on a Ryzen 5 3600XT: Q8_0 is half
the download, 576 against 904 MiB of VRAM, 2.1 against 3.3 s for 256
rows on 6 CPU threads; flash attention off was slower (22.7 against
12.3 s for 990 rows on the CPU) and took 1,584 MiB on the GPU.  The
engine's logits with rows from any of these were as close to
llama.cpp's (cosine 0.99989 or more, the same greedy tokens, 2
pictures).  The token limits stay setup's (1,024 GPU, 300 CPU).

strata-vision built at the new pin needs no change to tools/vision;
on the CPU with flash attention off its rows were bit-identical to
llama.cpp's mtmd for 6 cases (7 drawn pictures).  End to end the server answered as
llama-mtmd-cli did about a test picture, and a real install
(./setup.sh --family inkling --model IQ4_NL --cuda 12 --vision gpu on
the RTX 2070 Super) built engine-poly/vision-inkling/ with its own
stamp, left the shared engine's stamp at vision "none", and its
server described a photo (llama.cpp's tools/mtmd/test-1.jpeg) as
llama-mtmd-cli did: the New York Times of July 20, 1969, "MEN WALK ON
MOON".  An install with --vision cpu built the encoder without CUDA
(stamp vision "cpu"; config gpu false, 6 threads, 300 tokens) and its
server answered about the photo word for word as llama-mtmd-cli; a
GPU encoder asked for the CPU is kept, a CPU one asked for the GPU is
compiled again.  UD-Q2_K_XL reads pictures with the same encoder
(its server answered about the photo as llama-mtmd-cli on the same
weights).  docs/models/inkling.md has the numbers.  The setup tests
pass; tools/test_setup_inkling.py covers the opt-in, the own folder
and stamp, the shared encoder left alone, the update path (a failed
encoder build leaves the engine's update), the toolkit libraries and
the checkout each pin takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NoLeakedSampler counted every "(_loop)" thread in the process, so a
sampler still finishing from an earlier test made it fail now and
then.  It now records the threads alive before serve() and checks only
the one its own server started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Svirful

Svirful commented Nov 21, 2026

Copy link
Copy Markdown

Thanks for this PR! I built and ran it on Windows, and it works.

Setup: Windows 11, RTX 4060 Laptop 8 GB (driver 621.01), Ryzen 7 8845HS, 32 GB DDR5, CUDA 13.0, MSVC from VS 2022 Build Tools. START-HERE.bat --build --family inkling --model IQ4_NL, 64K context, images off.

One build fix was needed for MSVC: src/poly/cpu_lowbit.cpp uses _cvtsh_ss, which MSVC does not have (error C3861: '_cvtsh_ss': identifier not found). This worked:

#if defined(_MSC_VER) && !defined(__clang__)
// MSVC has no _cvtsh_ss; the same F16C conversion through the vector intrinsic.
inline float h2f(uint16_t h) { return _mm_cvtss_f32(_mm_cvtph_ps(_mm_cvtsi32_si128(h))); }
#else
LOWBIT_FN inline float h2f(uint16_t h) { return _cvtsh_ss(h); }
#endif

With that, everything else compiled and ran.

Speed (IQ4_NL, one request):

  • Writing: 26 tokens/s in a short chat, 20 after a 41K-token prompt.
  • Reading: 484 tokens/s (a 7.8K-token prompt).
  • 765 of 3,072 experts in VRAM. Only about 14 GB of RAM was free, so part of the experts came from the file cache.
  • For comparison, Unsloth's llama.cpp prebuilt b12588-mix-c0c3de8 with UD-Q4_K_XL (the best offload I found on this card) wrote 14-15 tokens/s and read about 106.

Answers: on a small set of 30 (14 tool-call cases, then 4 each of GSM8K, MATH-500, MMLU-Pro and HumanEval with a 16K-token cap), it got 25/30, with the same accuracy items right as the llama.cpp prebuilt. Tool calls came through the server correctly, including parallel calls and nested arguments. Three agent tasks in the Pi coding agent (write and run a script, fix a bug against its tests) all passed.

Not tested: images, Q8_0, UD-Q2_K_XL.

Thanks again!

@okada-shogo

Copy link
Copy Markdown
Author

Thanks for the build fix for MSVC! I'll add that in

okada-shogo and others added 14 commits November 22, 2026 00:46
MSVC has no _cvtsh_ss, so src/poly/cpu_lowbit.cpp did not compile
there (error C3861).  Under MSVC the same F16C conversion now goes
through _mm_cvtph_ps.  The AVX2 path itself stays off on MSVC
(cpu_ok() is false there), so nothing changes at run time.

Reported, with the fix, by Svirful on PR 200 (Windows 11, MSVC from
VS 2022 Build Tools, CUDA 13.0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sequences

Engine::step()'s rows are each the next token of a sequence of its
own.  Five calls take such rows in one launch, each row with its own
caches, convolution state and position passed by value:
inkling_kv_store_seqs, inkling_clip_many_seqs (tau at each row's
position), inkling_attend_seqs (the split path, each row split as it
is alone) and inkling_conv_seqs / inkling_conv_acc_seqs, up to
kInklingSeqRows (16) rows.  Flint calls its single-sequence kernels a
row at a time; Inkling would make five such calls a row in each of its
48 visits, 240 launches a sequence for every step, and a step is not
replayed from a recorded graph (the positions differ every step).

The single-sequence calls run the same arithmetic as before: their
kernels take where a row's caches, state and position come from as a
template parameter (the attention, the K/V store, the clip and the
convolution's walk alike).

poly_inkling_kernels_test checks each new call against a call for
each row alone, to the bit: 1 to 16 rows, fp16 and q8_0, full caches
and rings, positions across the window's edge, the ring's wrap and the
room steps, rows of one split beside rows of several, a full-attention
row at 131,000 of a 128K context, and that every call refuses 17 rows.
0 failures on an RTX 2070 Super (CUDA 12.9).  Not built for HIP: there
is no ROCm toolchain here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling no longer refuses --batch (up to kInklingSeqRows - 1, the
_seqs kernels' rows).  Its step() rows go through one head
(batch_heads()): the projections, the depth mixes, the loop's messages
and controllers, the norms and the router run once for all rows.  Each
row's caches, convolution states and position come from its own
sequence (seq_buf(), seq_state()), through the _seqs kernels.  The
routed experts are shared, as for the other families.  The head keeps
step()'s rows for the tail's FFN convolution.  A slot's rows, rings and
state are the ones bind() already gives every sequence.

--check-stagger (with --check-batch K): sequence j's prompt is the
first n >> 3 (K - 1 - j) of the --tokens' n (16 at least), read when
the others have taken j * max_new / (2K) steps, and it writes max_new -
j * max_new / K tokens: prompts of different lengths, sequences that
join between steps and steps of fewer rows as they leave.

--check-batch gave each sequence the tokens it gets alone, every token,
in all 20 runs (RTX 2070 Super; IQ4_NL and UD-Q2_K_XL; fp16 and q8_0;
2, 3 and 4 sequences after a 302-token prompt, 4 after a 3,000-token
one, and 4 with --check-stagger after prompts of 16, 46, 375 and 3,000
tokens, 64 to 16 tokens each).

One request is unchanged.  With every expert on the CPU
(poly_logits_dump --no-gpu-experts, a 302-token prompt and 32 tokens
fed after it) the base (c808b53) and this build wrote byte-identical
logits, fp16 and q8_0.  With the expert cache frozen and of one size in
both (STRATA_FREEZE_EXPERTS, --expert-swaps 0, --cpu-share 0,
--vram-reserve-mib 1024) both wrote the same 48 tokens and top-5
probabilities, fp16 and q8_0.  Its speed, the server's flags, two runs
each, base and then this build: decode after a 302-token prompt IQ4_NL
37.6-38.2 and 37.3-38.1 tok/s, UD-Q2_K_XL 49.4-51.3 and 50.7-53.0; a
1,500-token prompt read at 453-455 and 452-455 tok/s (IQ4_NL), 587-591
and 586-611 (UD-Q2_K_XL).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its engine takes batch slots now.  Setup writes "parallel" for it
when asked and suggests it by poly_parallel_note()'s rule, as for the
other families of strata-poly.  The rule suggests 2 to 4 where the
card holds every expert of the size.  On a smaller card it says that
requests at once gain less.  "one_request" goes, and so does the
branch that read it.

tools/test_setup_inkling.py: --parallel 3 is written and carried over
to a later run without --parallel, and so is an earlier "parallel": 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
models/inkling.md: a section on several requests at once, and
BATCHING.md: Inkling in the list of strata-poly models, its numbers
and its --check-batch runs.  AI_SETUP.md: Inkling's line no longer
says one request at a time or text only.

Measured on an RTX 2070 Super 8 GB (Ryzen 5 3600XT, 62 GB DDR4)
through the server: 128K context, q8_0 caches, the expert profile,
chats of 300 tokens, two runs a row, a fresh server for each row,
"parallel" equal to the chats except one row.  All chats together:

  chats  "parallel"  IQ4_NL     UD-Q2_K_XL
  1      1           37.1-37.7  46.2-47.8
  1      4           34.5-35.0  44.3-44.9
  2      2           44.6-45.5  57.7-59.7
  3      3           48.9-49.0  63.2-64.5
  4      4           51.2-51.9  64.1-66.5

"parallel": 2 took about 0.5 GiB of the expert cache at load (two
sequences beside the first), each slot after it about 0.27 GiB.

The one-request table is measured again, all on one day with the same
flags (the server's, with each model's expert profile): UD-Q2_K_XL
wrote 50.7-53.0 tok/s after a 302-token prompt, where the page had
46.9 from an earlier day; IQ4_NL 37.3-38.1 (it had 37.4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
inkling_attend() walked a prompt batch's keys in float on the CUDA
cores (attn_kernel), which made the attention most of a long prompt's
time.  A call of more than 16 tokens (every call that the split path
does not take) now runs attn_mma_kernel on cards of Turing or newer.
It works the way kernels.cu's attn_flash128_kernel does: 21 tokens of
a group a block, four warps of 16 rows (a token's three heads side by
side), keys 32 at a time in shared memory as halves, S = Q K^T and
O += P V as m16n8k16 steps (two of k = 8 on Turing) that sum floats,
and an online softmax in floats.  A Q8_0 cache's codes times their
scales go to shared memory as halves.  The relative-position bias is
a product too: each warp's R times the table rows of the distances a
tile spans, put in shared memory as floats and read back at each
score's distance, only in the tiles that hold a distance below the
extent.  The per-token sinks come at the end.  The tiles count from
position 0, so a token's result does not depend on the tokens beside
it in the call (tested to the bit).  The split path (decode), the
batch slots' per-sequence calls and the old unsplit kernel (calls of
up to 16 tokens without work, older cards, HIP) are unchanged.  No
other family's code is touched.

The switch at 17 tokens is measured (poly_inkling_kernels_test bench,
RTX 2070 Super; the unsplit kernel's times from the day before): 17
tokens at position 8192 took 0.88 ms against 5.2 ms (full layer) and
0.15 against 0.74 ms (window layer).  4,096 tokens from 0 took 4.8 ms
against 128.7 (full) and 2.7 against 63.6 (window).

poly_inkling_kernels_test checks the new path against the doubles for
fp16 and q8_0 caches, full and window layers, the ring's wrap, the
extent's edge, 16 to 2,048 rows and rows about the switch. Its bound
is fattn_test.cu's for the other families' tensor-core attention,
7.5e-3 of the largest result: Q, R, the table's rows, P and V are
halves in the products, as in llama.cpp's flash attention (Q, P and
V); the bias stays a float. The most error seen was 3.8e-3 of 1
(sm_75). Probes whose weights are exact (q = 0 and R = 0, so the
result is the mean of the visible values; and a table that is nonzero
only at distance extent - 1) hold the mask, the window, the ring's
wrap and the extent's edge to 1e-5 (2.2e-6 seen on the tensor cores).
The old paths keep 2e-5. Parity against llama.cpp (run_parity.sh,
IQ4_NL and UD-Q2_K_XL): prompt cosine 0.99919 to 0.99984, top-20 18 to
20 of 20, decode 30 to 31 of 32, inside the range in inkling.md
(0.9989 to 0.9998, 16 to 20 of 20).

Speed against 791be9e, the same card on the same day (strata-poly
--serve, a 128K context, q8_0 caches, a fresh copy of the expert
profile each run): IQ4_NL prompts of 302 and 1,500 tokens 282-290 and
521-523 tokens/s against 271-272 and 458-461; UD-Q2_K_XL 557-561 and
881-888 against 504-508 and 609-611 (two runs each); IQ4_NL 2K 658
against 504, 32K 820 against 263, 131,008 tokens 659 against 92 (199 s
against 1,421). Writing (256 tokens after the 302- and 1,500-token
prompts) does not run the new kernel and differed by up to 4.5% in
single runs, both ways (at most 1.5% on the means of two runs).

Built for sm_75 and compiled for sm_61, 80, 86, 89 and 120 (no
spills; 30,336 bytes of shared memory a block).  HIP compiles the
kernel empty and never launches it; HIP was not built here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Engine::window() keeps the recurrent state as it is after some of a
window's tokens, so that keep() can go back to it after a wrong
guess.  For Inkling that state is its short convolutions' (the last
three inputs of a channel).  inkling_conv_snaps() writes, for each
token whose bit is set, the state inkling_conv() leaves after that
token.  It reads the call's input and the state before the call
changes it, so the convolution kernels stay as they are.

poly_inkling_kernels_test checks each snapshot against the state that
inkling_conv() leaves after that many tokens, to the bit (4, 8 and 2
rows, several sets of bits), and that bits at or past the call's rows,
and past the kernel's 32 tokens (a call of 40 rows), write nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling no longer refuses --window above 1.  A window's convolutions
leave their state after the window's snapshot tokens
(inkling_conv_snaps(), through Inkling::conv_snaps(), before each
convolution advances it: the K and V convolutions in kv_store, the
attention's and the FFN's post-convolutions), so keep() can go back
after a wrong guess.  The other per-position state (the window visits'
rings and the full visits' rows) is rewritten when a position gets its
real token, as for the other families.

With experts on the CPU a window can go through the layers in two
halves (Engine::shift_rows()).  Inkling's shift_rows() moves its
gathered stream (res_) with the engine's buffers, and a layer's head
and tail each take the stream at their own rows (work_stream()), not
one the head leaves in a member: in halves the other half's head runs
between them.

The file has no block that guesses ahead, so the guesses come from the
conversation's repeats (--lookup) alone, and a guessed window is
opt-in: without --window it stays 1, identical to --window 1, where
the engine's default would be 4.  The draft model is still refused.

tools/window_agree.py checks that a window changes no answer: it runs
--window 4 and --window 1 with every expert on the CPU and compares
their tokens and likeliest tokens at every step, and fails when the
window took no guesses.  tools/test_window_agree.py tests its verdicts
against a stand-in engine, without a GPU.

Built and tested with CUDA only.  kernels_inkling.cu and inkling.cpp
are also in the HIP build, which was not built: there is no ROCm on
the machine this was written on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
models/inkling.md: a section on --window for Inkling, which is
opt-in and whose guesses come from the conversation's repeats alone,
with its speed against --window 1 and how its answers were checked.
GLM.md's options table: --window's default for Inkling is 1.

Greedy answers of 300 tokens, 128K context, q8_0 caches, two runs
each, tokens/s with --window 1 -> 4:

  RTX 2070 Super 8 GB (Ryzen 5 3600XT), a fresh copy of the expert
  profile each run, this build
    IQ4_NL code      35.1-35.4 -> 38.8-40.0
    IQ4_NL text      36.7-37.8 -> 36.7-37.2
    UD-Q2_K_XL code  47.1-47.4 -> 47.9-48.1
    UD-Q2_K_XL text  48.2-48.4 -> 48.8-48.8
  RTX 3090 24 GB (rented, every expert in VRAM), an earlier build:
  the same window code on inkling2-batch 79d48fe
    IQ4_NL code      59.4-59.8 -> 64.3-64.4
    IQ4_NL text      58.0-59.8 -> 59.9-60.1
    UD-Q2_K_XL code  68.1-68.2 -> 74.6-75.2
    UD-Q2_K_XL text  68.2-68.5 -> 70.1-70.2

On the 2070 Super, 200 greedy tokens: with every expert on the CPU,
--window 4 gave the tokens and top-5 probabilities of --window 1
(both sizes, three prompts; on this build tools/window_agree.py: both
sizes on the code prompt and UD-Q2_K_XL on its own prompt); with the same experts cached and frozen,
the same for UD-Q2_K_XL (code and text); IQ4_NL's runs held one expert
apart and parted at near ties (ln p1/p2 0.01 and 0.07).
Without --window, 200 greedy tokens against inkling2 791be9e's (tokens
and top-20 probabilities; both sizes, fp16 and q8_0, code and text,
every expert on the CPU and with the same experts cached): 15 of 16
identical.  In the 16th (UD-Q2_K_XL, fp16, code, cached) the two runs
never held the same experts (1,864 and 1,869 at load), and they first
differ at a near tie (ln p1/p2 0.15).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
native_mmvq_jobs() takes up to 8 matrices of one format and input
width, each with its own rows, Q8_1 columns and output, in one launch:
an attention's projections of the same normed input.  Each row block is
native_mmvq_multi_kernel's exact layout for its matrix, so the outputs
are those of native_mmvq() for each matrix, bit for bit.  Q8_0, Q4_K,
Q5_K and Q6_K; it declines (launching nothing) other formats, repacked
matrices (STRATA_Q8_PACKED, STRATA_Q6_PACKED), the gfx906 wave layout
and the switches whose several-column bits are another layout's, and
the caller then launches the matrices one by one.  Metal's stub
declines.  A new call only: nothing calls it yet.

On an RTX 2070 Super, Inkling 2 Mini's six Q8_0 projections of a
2304-value input (3072, 3072, 384, 24, 1024 and 1024 rows) took 62.3 us
in one launch against 79.0 us one by one for a token, 67.8 against 92.8
for 2 and 92.3 against 101.3 for 4 (a microbenchmark, the weights not
in L2).

poly_inkling_kernels_test checks it against native_mmvq() for each
matrix, to the bit: the four formats, 8 matrices of 2304 values (a row a
block) for 1, 2, 4 and 8 columns, and 3 and 8 of 512 (2 rows a block,
matrices of odd rows) for 1 and 3.  It now links strata_kernels.  0 failures on the RTX 2070 Super (CUDA 12.9).
Not built for HIP: there is no ROCm toolchain here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Engine::lin_jobs() takes several matrices, each as lin() gives it, and
puts those of one quantized format and input width whose inputs are in
Q8_1 through native_mmvq_jobs(); the rest, and everything for more than
8 tokens (a prompt batch, MMQ), go through lin() one by one.  Each
output is lin()'s, bit for bit.  Inkling::attn() takes its 6 projections
(8 in a full-attention layer, with the convolution's taps) through it:
in IQ4_NL's and UD-Q2_K_XL's files they are all Q8_0 of 2304 values, 3
inputs, in one launch where they were 6 or 8.  The other families do
not call it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MmvqSlots::lanes and MmvqIds::lanes (default false) take the same bits
through other kernels.  native_mmvq.cu's formats: a warp a row instead
of a block of 4 warps, lane l doing the work of the block's threads l,
32 + l, 64 + l and 96 + l, each into its own sum, added in the order the
block adds its warps' partials; the same terms in the same order, with
no shared memory, no barrier and no thread idle where the block's
threads do not divide a row evenly (an IQ4_NL expert's 2304 and 1152
values are 72 and 36 blocks for the block's 64 pairs of threads).
iq_kernels.cu's formats whose grid is staged in shared memory (IQ1_S,
IQ1_M, IQ2_XXS, IQ2_XS, IQ2_S): the grid staged once for 8 rows a warp,
each row row_dot_multi's for one column, row_dot's arithmetic in its
order (not with STRATA_OLD_IQ_MMVQ or STRATA_IQ_STAGE_GRID=0).  The
other IQ formats' launches are as without it.  Unset, every launch is
as before.  Metal takes no notice.  It takes precedence over
native_mmvq_slots_wide(), which HIP has on by default; measured on CUDA
only.

On an RTX 2070 Super, 8 cached experts' launch, these kernels against
the slots kernels (a microbenchmark, the weights not in L2):
IQ4_NL 2304 -> 2304 80.9 -> 73.8 us, 1152 -> 2304 46.9 -> 43.3; Q2_0
1152 -> 2304 45.6 -> 33.8; IQ1_S 2304 -> 2304 101.2 -> 78.4, IQ2_XXS
94.6 -> 81.5, IQ2_XS 119.0 -> 87.6, IQ2_S 119.3 -> 91.4.

poly_inkling_kernels_test checks both launches (by slot and through the
card's picks) against native_mmvq() for each expert, and the slots
launch against itself without lanes, to the bit: IQ4_NL, Q8_0 and Q2_0
(Inkling 2's experts), IQ1_S, IQ1_M, IQ2_XXS, IQ2_XS and IQ2_S, 1 and 8
experts; Q4_0, Q5_0, MXFP4, Q2_K, Q3_K, Q4_K, Q5_K, Q6_K and IQ4_XS; and
row counts that leave a partial block (2301, 37).  0 failures on the
RTX 2070 Super (CUDA 12.9).  Not built for HIP: there is no ROCm
toolchain here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Engine::lane_slots_ (Inkling sets it, as lowbit_experts_) sets
MmvqSlots::lanes and MmvqIds::lanes on the cached experts' launches, and
with it one cached expert also goes through the slots launch rather
than native_mmvq(): the same bits, faster where the format has a lanes
kernel (Inkling 2's do).  Off, the other families' launches are as they
were.  Not set on HIP, where it is unmeasured (and the engine does not
run Inkling 2 yet).

Measured on an RTX 2070 Super 8 GB (Ryzen 5 3600XT), strata-poly alone:
302-token prompt, 128 tokens written, 128K context, q8_0 caches, two
interleaved runs each, this commit and the three before it against
their base: IQ4_NL wrote 38.9 and 38.3 tok/s before, 39.8 and 40.1
after (38.2 and 38.7 -> 39.5 and 39.0 with a copy of its expert
profile); UD-Q2_K_XL 51.2 and 51.9 -> 55.2 and 54.6.  Nsys over the
decode (before the rebase onto the batch slots): a visit's dense work
124 -> 108 us, its cached experts 109 -> 96 us, 31 -> 26 launches.

The logits against llama.cpp's stay as close: IQ4_NL prompt cos
0.99969, 0.99902 and 0.99964, the same argmax at 31 and 32 of 32 steps;
UD-Q2_K_XL 0.99969, 0.99948 and 0.99955, 32 and 31 of 32 (its medium
prompt's top two, 0.068 apart in llama.cpp's logits, swap places).
--check-batch with the expert cache held still: every sequence got the
tokens it gets alone, both files, 2 and 4 sequences, q8_0 caches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed again

models/inkling.md: the 302-token row's writing speeds with the
projections in one launch and the cached experts a warp a row, and
what they were before in the same runs (the gain, +2% and +6%); the
page says the row's prompt speeds are from the earlier runs, and the
other rows and the batch table that they are from before.

Measured on an RTX 2070 Super 8 GB (Ryzen 5 3600XT, 62 GB DDR4),
strata-poly alone with the server's flags (128K context, q8_0 caches),
128 tokens written, two interleaved runs each: IQ4_NL with a copy of
its expert profile 38.2-38.7 -> 39.0-39.5 tok/s, UD-Q2_K_XL (no
profile) 51.2-51.9 -> 54.6-55.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…cts split in halves

On HIP ink_attend_batch() took nothing (ink_flash_kernel is NVIDIA's mma.sync), so a prompt batch went to
attend_batch(), which writes every score out and rounds the queries and the weights to one half each.  On gfx12
(the card asked: gfx_arch_is_gfx12_wmma()) it now takes ink_wmma_kernel, for fp16 caches and Inkling 2 Mini's heads
(128 values, 3 on a key head, 16 relative values); elsewhere, and with STRATA_INK_FLASH=0, the path is as it was.

- S^T = K Q^T and O^T = V^T P^T as v_wmma_f32_16x16x16_f16 steps: a lane's C fragment of S^T is its row's scores at
  8 keys, which is the same lane's B fragment of P^T, so the weights never leave the registers and a row's online
  softmax lives in two lanes (one shuffle).  The queries (in log2 units) and R stay in registers.
- The queries, R, the bias table's rows and the weights go into the products as a half and the half of what it
  leaves (two or three steps a product), so the sums are float-exact to about 2^-22 of a term; fp16 caches are exact
  halves.  The weights go in times 2^12 (the output comes out divided by it), so a small weight's lo half is a
  normal half.
- The bias is R times the table's rows of the distances a warp's rows reach in a tile (three steps), through the
  warp's shared memory; only tiles with a distance below the extent compute it.  The sink's term and the gate as
  ink_flash_kernel has them.
- 4 warps of 16 rows (21 tokens of a 3-head group), 32-key tiles counted from position 0, so a token's result does
  not depend on the call it is in; about 37 KB of shared memory a block.

poly_inkling2_wmma_test (HIP, gfx12; 77 elsewhere) holds it to an FP64 reference at 2e-5, next to ink_attend()'s
float kernels, and checks a token's result to the bit in two calls that start at other tokens.  RDNA3 (gfx11) keeps
attend_batch(): a gfx11 variant of this kernel missed both checks on an RX 7900 XT.  CUDA builds compile the same
code (all of it is under __HIPCC__).

The kernel is Tako88's idea and start (his WMMA prompt attention for RDNA4 on PR simplexai-labs#200); this one is the rewrite of
it that our first Inkling engine shipped.  There, on an RX 9070 XT (gfx1201, ROCm 7.2.4), --max-context 16384, fp16
caches, prompt tok/s, medians of 3, its scalar kernel -> this one: UD-Q2_K_XL 2,048 tokens 923.7 -> 1269.6, 8,192
801.0 -> 1331.6; IQ4_NL 1062.3 -> 1503.9, 628.8 -> 871.4; against an RTX 3090's logits its KL was within the
card-to-card range.  Tako88 measured it at +64-96% over his own kernel on a gfx1200.  Here the path it replaces is
attend_batch() on rocBLAS, so the gain is to be measured again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
Where run() and step() replay a token's layer launches, they recorded each layer's shared expert apart
(Layer::shared) and replayed it, a graph launch a layer visit.  Inkling 2's shared expert is one memset of fo_
(moe_shared()), and on HIP, where the doorbell is off, a token with experts outside VRAM goes layer by layer: 48
visits, each with that extra graph launch.  A family can now say its shared expert is launched as it is
(Engine::shared_recorded()), and Inkling 2 does on HIP.  The same kernels in the same order, so the same bits.  CUDA
and the other families replay it as before.

In our first Inkling engine (PR simplexai-labs#200), the same change (the shared expert launched as it is where the heads are)
wrote IQ4_NL +17% faster on an RX 9070 XT (gfx1201, ROCm 7.2.4) with the same logits; there the heads were
launched one by one too, here they stay recorded, so the gain is to be measured on this engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…P card

table16_lookup() (IQ4_NL, IQ4_XS, MXFP4, the formats of 16 values) took llama.cpp's v_perm_b32 sequence on gfx906
only, and the __byte_perm one elsewhere.  Both give the same bytes; on RDNA4 the v_perm_b32 one is faster.  In our
first Inkling engine (PR simplexai-labs#200) on an RX 9070 XT (gfx1201, ROCm 7.2.4), 8 cached IQ4_NL experts' products read at
337 -> 411 GB/s (2,304 values) and 244 -> 349 (1,152), and Inkling 2 Mini IQ4_NL wrote 256 tokens after 302 at
43.2 -> 45.6 tok/s, medians of 3.  So every HIP build takes it.  CUDA builds compile the same code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…Q build)

Mmq::fits() in mmq.cu leaves MXFP4 out on a Blackwell card other than 12.0, whose CUDA build has no image of the
instance, by comparing the card's cc with GGML_CUDA_CC_BLACKWELL.  An AMD card's cc carries GGML_CUDA_CC_OFFSET_AMD
and is above every NVIDIA one, so on HIP MXFP4 never fitted, although its instance is built for the HIP
architectures and RDNA has its configurations.  UD-Q2_K_XL's layer 20 has MXFP4 down experts, and the engine takes
MMQ for a layer's prompt experts only when gate|up and down both fit, so that layer's prompt MoE took the decode
kernels a token at a time.  The check is now CUDA's only.  Only the -DSTRATA_POLY_MMQ=ON build has mmq.cu; the
default build's mmq_own.cu has no such check.

Measured in our first Inkling engine (PR simplexai-labs#200), on an RX 9070 XT (gfx1201, ROCm 7.2.4), UD-Q2_K_XL, q8_0 caches,
prompt tok/s, medians of 2: 2,048 tokens 1454 -> 1613, 8,192 1678 -> 1873, 32,768 1467 -> 1620.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…inux)

Between prompts the expert cache takes the VRAM of the buffers only a
prompt batch uses (lend_prompt()), and a prompt maps them again.  ROCm
on Linux gives VRAM back only with its addresses (vmm_unmap() frees and
reserves them again), which the staging buffer's widening already stays
away from (Engine::alloc(), `lend`).  With the buffers lent strata-poly
crashed in 15 of 16 runs of Inkling 2 Mini IQ4_NL on an RX 9070 XT with
2,443 of its 3,072 experts in VRAM (ROCm 7.2.4 container): SIGSEGV
inside hipLaunchKernel, the dequantize launch of a prompt's dense
product (Mmq::mul's BLAS path) into the lent work memory.  With every
expert in VRAM nothing is lent, and it ran.  With this change 8 of 8 runs on that
card finished (2,424 of 3,072 experts in VRAM, 16 tokens written, the same first
tokens as on an RX 7900 XT).

Where STRATA_VMM_RELEASE_WITH_ADDRESSES is defined (HIP on Linux) the
buffers are now allocated as they are without VMM (our engine in simplexai-labs#200, which
ran this case, never lent them).  CUDA and Windows HIP are unchanged (the
preprocessed CUDA engine.cpp is identical).

Class: placement only (the buffers' VRAM stays theirs; the expert cache
does not grow into it between prompts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…cts split in halves

On HIP ink_attend_batch() took nothing (ink_flash_kernel is NVIDIA's mma.sync), so a prompt batch went to
attend_batch(), which writes every score out and rounds the queries and the weights to one half each.  On gfx12
(the card asked: gfx_arch_is_gfx12_wmma()) it now takes ink_wmma_kernel, for fp16 caches and Inkling 2 Mini's heads
(128 values, 3 on a key head, 16 relative values); elsewhere, and with STRATA_INK_FLASH=0, the path is as it was.

- S^T = K Q^T and O^T = V^T P^T as v_wmma_f32_16x16x16_f16 steps: a lane's C fragment of S^T is its row's scores at
  8 keys, which is the same lane's B fragment of P^T, so the weights never leave the registers and a row's online
  softmax lives in two lanes (one shuffle).  The queries (in log2 units) and R stay in registers.
- The queries, R, the bias table's rows and the weights go into the products as a half and the half of what it
  leaves (two or three steps a product), so the sums are float-exact to about 2^-22 of a term; fp16 caches are exact
  halves.  The weights go in times 2^12 (the output comes out divided by it), so a small weight's lo half is a
  normal half.
- The bias is R times the table's rows of the distances a warp's rows reach in a tile (three steps), through the
  warp's shared memory; only tiles with a distance below the extent compute it.  The sink's term and the gate as
  ink_flash_kernel has them.
- 4 warps of 16 rows (21 tokens of a 3-head group), 32-key tiles counted from position 0, so a token's result does
  not depend on the call it is in; about 37 KB of shared memory a block.

poly_inkling2_wmma_test (HIP, gfx12; 77 elsewhere) holds it to an FP64 reference at 2e-5, next to ink_attend()'s
float kernels, and checks a token's result to the bit in two calls that start at other tokens.  RDNA3 (gfx11) keeps
attend_batch(): a gfx11 variant of this kernel missed both checks on an RX 7900 XT.  CUDA builds compile the same
code (all of it is under __HIPCC__).

The kernel is Tako88's idea and start (his WMMA prompt attention for RDNA4 on PR simplexai-labs#200); this one is the rewrite of
it that our first Inkling engine shipped.  There, on an RX 9070 XT (gfx1201, ROCm 7.2.4), --max-context 16384, fp16
caches, prompt tok/s, medians of 3, its scalar kernel -> this one: UD-Q2_K_XL 2,048 tokens 923.7 -> 1269.6, 8,192
801.0 -> 1331.6; IQ4_NL 1062.3 -> 1503.9, 628.8 -> 871.4; against an RTX 3090's logits its KL was within the
card-to-card range.  Tako88 measured it at +64-96% over his own kernel on a gfx1200.  Here the path it replaces is
attend_batch() on rocBLAS, so the gain is to be measured again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
Where run() and step() replay a token's layer launches, they recorded each layer's shared expert apart
(Layer::shared) and replayed it, a graph launch a layer visit.  Inkling 2's shared expert is one memset of fo_
(moe_shared()), and on HIP, where the doorbell is off, a token with experts outside VRAM goes layer by layer: 48
visits, each with that extra graph launch.  A family can now say its shared expert is launched as it is
(Engine::shared_recorded()), and Inkling 2 does on HIP.  The same kernels in the same order, so the same bits.  CUDA
and the other families replay it as before.

In our first Inkling engine (PR simplexai-labs#200), the same change (the shared expert launched as it is where the heads are)
wrote IQ4_NL +17% faster on an RX 9070 XT (gfx1201, ROCm 7.2.4) with the same logits; there the heads were
launched one by one too, here they stay recorded, so the gain is to be measured on this engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…P card

table16_lookup() (IQ4_NL, IQ4_XS, MXFP4, the formats of 16 values) took llama.cpp's v_perm_b32 sequence on gfx906
only, and the __byte_perm one elsewhere.  Both give the same bytes; on RDNA4 the v_perm_b32 one is faster.  In our
first Inkling engine (PR simplexai-labs#200) on an RX 9070 XT (gfx1201, ROCm 7.2.4), 8 cached IQ4_NL experts' products read at
337 -> 411 GB/s (2,304 values) and 244 -> 349 (1,152), and Inkling 2 Mini IQ4_NL wrote 256 tokens after 302 at
43.2 -> 45.6 tok/s, medians of 3.  So every HIP build takes it.  CUDA builds compile the same code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 22, 2026
…Q build)

Mmq::fits() in mmq.cu leaves MXFP4 out on a Blackwell card other than 12.0, whose CUDA build has no image of the
instance, by comparing the card's cc with GGML_CUDA_CC_BLACKWELL.  An AMD card's cc carries GGML_CUDA_CC_OFFSET_AMD
and is above every NVIDIA one, so on HIP MXFP4 never fitted, although its instance is built for the HIP
architectures and RDNA has its configurations.  UD-Q2_K_XL's layer 20 has MXFP4 down experts, and the engine takes
MMQ for a layer's prompt experts only when gate|up and down both fit, so that layer's prompt MoE took the decode
kernels a token at a time.  The check is now CUDA's only.  Only the -DSTRATA_POLY_MMQ=ON build has mmq.cu; the
default build's mmq_own.cu has no such check.

Measured in our first Inkling engine (PR simplexai-labs#200), on an RX 9070 XT (gfx1201, ROCm 7.2.4), UD-Q2_K_XL, q8_0 caches,
prompt tok/s, medians of 2: 2,048 tokens 1454 -> 1613, 8,192 1678 -> 1873, 32,768 1467 -> 1620.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robwiss

robwiss commented Nov 23, 2026

Copy link
Copy Markdown

Thanks for all the work on this! I just built and benchmarked the latest inkling2 branch on Windows (START-HERE.bat --build --family inkling --model IQ4_NL).

Two Windows Build Fixes Needed

1. MSVC std::aligned_storage static assertion in src/poly/mmq.cu
When building with MMQ enabled (-DSTRATA_POLY_MMQ=ON), std::stable_sort on strata::poly::Mmq::Tile (16-byte aligned) fails on MSVC (type_traits(1128): error: static assertion failed...). Because nvcc implicitly pre-includes cuda_runtime.h before line 1 of mmq.cu, defining _ENABLE_EXTENDED_ALIGNED_STORAGE inside the .cu file is too late—passing it in CMakeLists.txt fixed it:

if(WIN32)
    add_compile_definitions(_ENABLE_EXTENDED_ALIGNED_STORAGE)
endif()

2. Windows MAX_PATH error extracting llama.cpp in setup.py (line 2732)
In commit 29b52d398b (used for vision-inkling), llama.cpp's web UI moved from /tools/ui/ to top-level /ui/, so deeply nested Svelte filenames hit Windows' 260-character path limit during zipfile.extractall(). Excluding "/ui/" in get_llama_cpp() resolved it:

f.extractall(tmp, [m for m in f.namelist() if "/tools/ui/" not in m and "/ui/" not in m])

With those two changes, everything built and ran cleanly.


Benchmark Results

Setup: Windows, NVIDIA RTX 3080 Ti (12 GB VRAM), 64 GB system RAM, MSVC Build Tools, CUDA.
Model & Command: python polystrata.py benchmark --model inkling --prompt-tokens 24000 (inkling2_loop, IQ4_NL, context 65536).

Prompt Tokens In Tokens Out TTFT (s) Prefill (tok/s) Decode (tok/s) Cache Hits Peak System VRAM Peak System RAM
short 25 231 0.749 38.4 62.9 0.886 11.41 GiB 37.92 GiB
long-24000 32,461 256 25.026 1,325.0 46.6 0.843 11.71 GiB 36.85 GiB

(Note: VRAM and RAM figures reflect peak total machine usage during the run.)

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.

9 participants