Repository navigation
poly: Inkling 2 Mini (inkling2 / inkling2_loop) - #200
okada-shogo wants to merge 105 commits into
Conversation
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.
4e3e151 to
9702b2b
Compare
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>
9702b2b to
d784ec4
Compare
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>
2c703b2 to
c808b53
Compare
|
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. One build fix was needed for MSVC: #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); }
#endifWith that, everything else compiled and ran. Speed (IQ4_NL, one request):
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! |
|
Thanks for the build fix for MSVC! I'll add that in |
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>
…ls (same bits) **Same bits as main.** In a prompt read of several calls (layer-major read or `read_groups()`), Inkling 2 hands each call's row tables to the card by a kernel, so they no longer wait behind the experts copied over the bus. On an RTX 2070 Super 8 GB a 2,048-token prompt reads 6.5% faster with IQ4_NL and 2.7% faster with UD-Q2_K_XL. Outputs, experts in VRAM and peak VRAM are unchanged. From our reference PR #200 (commit 802b20d). The PR's diff is the row-tables change only. The first commit's prestage code is removed by the second, and the third only adds the `stage_ahead > 0` gate and the docs' final numbers, so please squash on merge. ## Problem and result On an 8 GB card most experts stay outside VRAM. A prompt read copies about 22 GB of them, and the card waits for those copies about 1.3 s of a 2,048-token IQ4_NL prompt (nsys). Part of that wait was avoidable. Each call's row tables (about 100 KB) went to the card by `cudaMemcpyAsync`, and copies to the card run one after another. So the tables waited behind the layer's expert copy (about 440 MB), and the layer's products waited with them. In a read of several calls (layer-major read or `read_groups()`, marked by `shared_ahead_`) that copies ahead (`stage_ahead > 0`), `moe_rows()` now hands the tables to the card by `copy2()`. That kernel reads them from pinned memory, and no copy waits for it. A single-call read (such as 302 tokens) keeps main's copies. `STRATA_INK_KERNEL_TABLES=0` keeps the copies everywhere. **Prompt tok/s, higher is better.** RTX 2070 Super 8 GB (PCIe 3.0 x16), Ryzen 5 3600XT, fp16 KV, `--serve`, one request a run, default flags, no expert profile. Mean of 3 interleaved runs. The 302 and 2K rows are from this PR's binary. The 8K and 32K rows are from the first version of this PR, see "Each run" below: | Card | Model | Measure | main (tok/s) | this PR alone (tok/s) | Change | Experts in VRAM after the prompt (main → PR) | |---|---|---|---:|---:|---:|---:| | RTX 2070 Super 8 GB | IQ4_NL | prompt 302 | 202.7 | 206.1 | +1.7% | 994 → 994 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 302 | 234.8 | 235.8 | +0.4% | 2099 → 2099 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 2K | 448.2 | 477.2 | +6.5% | 795 → 795 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 2K | 581.1 | 596.7 | +2.7% | 1822 → 1822 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 8K | 578.5 | 589.3 | +1.9% | 1042 → 1042 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 8K | 598.0 | 601.4 | +0.6% | 1989 → 1989 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 32K | 589.3 | 589.1 | 0% | 149 → 149 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 32K | 568.8 | 569.4 | +0.1% | 766 → 766 | **Decode tok/s, higher is better** (256 tokens written after the prompt, same runs). Decode does not run the changed code: a 1-token call never reaches `moe_rows()`. | Card | Model | Measure | main (tok/s) | this PR alone (tok/s) | Change | Experts in VRAM after the prompt (main → PR) | |---|---|---|---:|---:|---:|---:| | RTX 2070 Super 8 GB | IQ4_NL | decode after 302 | 39.9 | 39.5 | −0.9% | 994 → 994 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | decode after 302 | 42.3 | 42.2 | −0.2% | 2099 → 2099 | | RTX 2070 Super 8 GB | IQ4_NL | decode after 8K | 31.6 | 31.7 | +0.3% | 1042 → 1042 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | decode after 8K | 36.6 | 36.5 | −0.3% | 1989 → 1989 | "Experts in VRAM after the prompt" is the cache after the request. The 2K and 32K reads shrink it for their carried rows (main's `read_groups()`). <details><summary>Each run (tok/s)</summary> **This PR (7bdb17166, md5 370535ec; the head adds only the `stage_ahead > 0` gate, which the default 1,024 leaves on) vs main 18a176e (md5 07a8b84b)**, both CUDA 12.9, sm_75;86. Order A B in rounds 1 and 3, B A in round 2. Experts at load follow the desktop's free VRAM: 916 or 922 (IQ4_NL) and 1,966 or 1,977 (UD-Q2_K_XL). The two builds had the same count in every round except UD-Q2_K_XL 302 round 2 (main 1,977, this PR 1,966). Log `~/inkling-work/e2e/kt-e2e/progress.log`. Prompt tok/s: | Card | Model | Measure | Build | Run 1 | Run 2 | Run 3 | |---|---|---|---|---:|---:|---:| | RTX 2070 Super 8 GB | IQ4_NL | prompt 302 | main | 202.7 | 204.5 | 200.8 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 302 | this PR alone | 207.0 | 205.4 | 205.9 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 302 | main | 236.7 | 230.9 | 236.9 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 302 | this PR alone | 239.6 | 235.9 | 232.0 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 2K | main | 448.3 | 448.8 | 447.6 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 2K | this PR alone | 477.2 | 477.7 | 476.6 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 2K | main | 580.4 | 580.3 | 582.7 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 2K | this PR alone | 595.5 | 596.8 | 597.8 | Decode tok/s: | Card | Model | Measure | Build | Run 1 | Run 2 | Run 3 | |---|---|---|---|---:|---:|---:| | RTX 2070 Super 8 GB | IQ4_NL | decode after 302 | main | 39.8 | 39.7 | 40.1 | | RTX 2070 Super 8 GB | IQ4_NL | decode after 302 | this PR alone | 39.5 | 39.4 | 39.6 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | decode after 302 | main | 42.0 | 42.6 | 42.3 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | decode after 302 | this PR alone | 42.0 | 42.1 | 42.6 | **The 8K and 32K rows: the first version of this PR** (md5 f1fa5bac), with experts at load of 928 (IQ4_NL) and 1,986 (UD-Q2_K_XL) in every run of both builds. That version took the kernel in single-call reads too, and also had a prestage copy that never ran on this card. Reads of several calls therefore ran the same code as this PR. Log `~/inkling-work/e2e/ps-e2e/progress.log`. Prompt tok/s: | Card | Model | Measure | Build | Run 1 | Run 2 | Run 3 | |---|---|---|---|---:|---:|---:| | RTX 2070 Super 8 GB | IQ4_NL | prompt 8K | main | 578.5 | 577.9 | 579.1 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 8K | this PR alone | 589.7 | 589.0 | 589.3 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 8K | main | 598.5 | 597.7 | 597.8 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 8K | this PR alone | 602.6 | 600.3 | 601.2 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 32K | main | 589.1 | 589.4 | 589.5 | | RTX 2070 Super 8 GB | IQ4_NL | prompt 32K | this PR alone | 589.2 | 589.1 | 588.9 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 32K | main | 569.8 | 568.9 | 567.8 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | prompt 32K | this PR alone | 568.9 | 569.6 | 569.7 | Decode tok/s: | Card | Model | Measure | Build | Run 1 | Run 2 | Run 3 | |---|---|---|---|---:|---:|---:| | RTX 2070 Super 8 GB | IQ4_NL | decode after 8K | main | 31.9 | 31.6 | 31.3 | | RTX 2070 Super 8 GB | IQ4_NL | decode after 8K | this PR alone | 31.8 | 31.5 | 31.8 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | decode after 8K | main | 36.5 | 36.7 | 36.5 | | RTX 2070 Super 8 GB | UD-Q2_K_XL | decode after 8K | this PR alone | 36.4 | 36.7 | 36.3 | </details> ## Related discussion Split out of #200 as asked (one optimization per PR). From #200's 802b20d ("Inkling 2 Mini's prompt reads do not wait for the copies to the card"). That commit's other half copies the next layer run's experts during the current run. It does not engage on an 8 GB card and is left out of this PR. See Limits. ## Approach - `copy2(h_tab_, tab_, n_tab, h_ex_, d_ex_, n_ex, st_)` in place of the two `cudaMemcpyAsync` calls, when `kernel_tables_ && opt_.stage_ahead > 0 && shared_ahead_`: the kernel is for reads that copy experts ahead on `up_`, and `--stage-ahead 0` keeps the copies. The same int32 words reach the same buffers, in order on the same stream. `h_tab_` and `h_ex_` are pinned, as `copy2()`'s other callers' sources are. - Classification: same bits. No VRAM is added. - `kernel_tables_` is set by Inkling 2 on CUDA only. Other families, HIP and Metal keep the copies. ## Validation **Passed:** - Identity, main vs this PR vs this PR with `STRATA_INK_KERNEL_TABLES=0`, on an RTX 2070 8 GB (sm_75). `strata-poly --tokens @idsn --max-new 64 --top-probs 20 --kv fp16 --expert-swaps 0`, `STRATA_FREEZE_EXPERTS=1`, with and without `--no-graphs`. The 8K runs used `--max-context 9216 --vram-reserve-mib 1536` on every build: a frozen run otherwise has no VRAM left for 8K's attention cache, on main too. Token ids and all 64 top-20 lines were byte for byte the same in all 24 comparisons. Experts at load and peak VRAM were the same in every run. Logs: `~/inkling-work/h2h/psid-kt-id-75/`, `psid-kt-id8k-75/`. - End-to-end A/B above: 25 of 25 runs rc=0 (this PR) and 49 of 49 (first version). - Builds: CUDA 12.9 `-DCMAKE_CUDA_ARCHITECTURES="75;86"` (strata-poly). HIP (ROCm 7.2.4 container, gfx1201;gfx1100) strata-poly compiles. - `python tools/settings_register.py --check` and `python -m unittest tools.test_settings_register`: OK. - nsys, IQ4_NL 2K, one run each (first version, same code for this read): GPU idle while experts are copied fell from 1,304 ms (main) to 1,030 ms. 22.0 GB H2D in both. **Identity (token ids and every `--top-probs 20` line, byte for byte; SAME = identical):** | Card | Model | Prompt (tokens + written) | Mode | ids + top-20: main vs this PR alone | ids + top-20: main vs `STRATA_INK_KERNEL_TABLES=0` | |---|---|---|---|---|---| | RTX 2070 8 GB | IQ4_NL | 302 + 64 | graphs | SAME | SAME | | RTX 2070 8 GB | IQ4_NL | 302 + 64 | `--no-graphs` | SAME | SAME | | RTX 2070 8 GB | IQ4_NL | 2,048 + 64 | graphs | SAME | SAME | | RTX 2070 8 GB | IQ4_NL | 2,048 + 64 | `--no-graphs` | SAME | SAME | | RTX 2070 8 GB | IQ4_NL | 8,192 + 64 | graphs | SAME | SAME | | RTX 2070 8 GB | IQ4_NL | 8,192 + 64 | `--no-graphs` | SAME | SAME | | RTX 2070 8 GB | UD-Q2_K_XL | 302 + 64 | graphs | SAME | SAME | | RTX 2070 8 GB | UD-Q2_K_XL | 302 + 64 | `--no-graphs` | SAME | SAME | | RTX 2070 8 GB | UD-Q2_K_XL | 2,048 + 64 | graphs | SAME | SAME | | RTX 2070 8 GB | UD-Q2_K_XL | 2,048 + 64 | `--no-graphs` | SAME | SAME | | RTX 2070 8 GB | UD-Q2_K_XL | 8,192 + 64 | graphs | SAME | SAME | | RTX 2070 8 GB | UD-Q2_K_XL | 8,192 + 64 | `--no-graphs` | SAME | SAME | **Failed:** - none observed. **Not run:** - HIP and Metal runs: the change is off there. Metal was not built (engine.cpp is in the Metal build; the new lines are a call to the existing `copy2()`). - Windows, and cards other than Turing 8 GB. ## Limits - About 1.0 s of copy wait is left at a 2K IQ4_NL prompt (nsys, against 3.0 s of kernels and 1.7 s of copies). #200's other half (prestage, the next layer run's experts copied during this run) would address it. Here it never engages, for two reasons: - On Linux the experts outside VRAM come from the pinned mirror, which prestage does not take. - A 2K read keeps 89 to 128 of each layer's 128 IQ4_NL experts outside VRAM (436 to 627 MB), and the staging buffer holds one layer, so two runs never fit side by side. - A two-layer staging buffer during a read (about 627 MB more taken from the expert cache for the read only, regrown after it) plus the mirror path is a planned opt-in follow-up, with its own measurements. - The 302-token rows differ from main by +1.7% and +0.4%. That read runs main's code, so this is run-to-run spread. From #265 by okada-shogo, head bf48b9d, squashed as asked.
…tiles, loaded two steps ahead Inkling 2 Mini's prompt batches send its controllers' down products (4,608 inputs to 64 outputs) and its routers (2,304 to 128) through gemm_f32(). gemm_f32_tiles() takes one group of 33 to 256 outputs in gemm_ahead_kernel: a template on the block's and a thread's tokens and outputs that reads a step's inputs and weights into registers two steps before it works on them and stores them so that a warp's writes fill the 32 banks, in the largest of four tiles that still gives half the SMs a block. Other shapes go to gemm_f32(). Each output is still one fmaf after the other in the inputs' order, so the bits are gemm_f32()'s: poly_gemm_small_test checks both against the host on Inkling 2 Mini's shapes too, and its --bench times both and prints a hash of each product. Only Inkling 2 takes it (Engine::f32_tiles_); the other families' products are unchanged. CUDA and HIP; Metal keeps its own gemm_f32. Ported from our Inkling engine (simplexai-labs#200, a34789a), adapted to main's gemm_f32(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kernels_inkling.dp.cpp, inkling.cpp, inkling.hpp. Depends on PR simplexai-labs#200's engine. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FA86cq7ktJuaewMKKonxr7
…s a warp a row With MmvqSlots::lanes / MmvqIds::lanes set (Inkling 2 only, already set by Inkling2::load_geometry()), launch_slots() now takes native_mmvq_slots_lanes_kernel for native_mmvq.cu's formats IQ4_NL, Q8_0, Q2_0, MXFP4, Q4_0, Q2_K, Q4_K and IQ4_XS. Q5_0, Q3_K, Q5_K and Q6_K were slower with it (RTX 2070, 8 experts: Q3_K 2304 -> 2304 131 -> 181 us, Q5_K 94 -> 112, Q6_K 119 -> 152, Q5_0 1152 -> 2304 53 -> 59) and keep the block kernel (kSlotsLanesFaster). That is both native_mmvq_slots() (the host's list of cached experts) and native_mmvq_ids() (the card's picks, the path taken when a layer's routed experts are all in VRAM). Before, only IQ3_S and IQ3_XXS had a lanes kernel; these formats ran native_mmvq_slots_kernel, a block of 4 warps a row. A warp takes a row. Lane l does the work of the block's threads l, 32 + l, 64 + l and 96 + l, each into its own sum, and adds them in the order the block adds its warps' partials, then the same warp_sum: the same terms in the same order, so the same bits. No shared memory, no barrier, and no thread idle where the block's threads do not divide a row (an expert's 2304 and 1152 IQ4_NL values are 72 and 36 blocks for the block's 64 thread pairs). CUDA only; HIP launches are unchanged. Ported from our earlier engine in PR simplexai-labs#200 (commit a4fa510, "kernels: the cached experts' slots launches a warp a row, opt-in"), adapted to main's launch_slots(). poly_slots_lanes_test checks the lanes launch (host list and card picks) against the launch without lanes, to the bit, for 12 formats, 1 to 32 experts, n_in from one block to 4096 and row counts that leave a block's last warps empty; canaries after each slot's outputs catch rows left unwritten and writes past a slot. 0 of 660 checks fail on an RTX 2070 (sm_75) and an RTX 3060 (sm_86), with and without STRATA_SLOTS_WARP=1; compute-sanitizer memcheck clean. 8 experts per launch, RTX 2070: IQ4_NL 2304 -> 2304 118.2 -> 106.1 us, 1152 -> 2304 54.0 -> 51.2; Q8_0 1152 -> 2304 85.3 -> 62.7; Q2_0 1152 -> 2304 47.1 -> 38.5. RTX 2070 Super, decode after a 302-token prompt (--prompt-int8 setting), mean of 3 runs: IQ4_NL 43.0 -> 44.0 tok/s, UD-Q2_K_XL 46.2 -> 46.5. Greedy tokens and top-20 SAME as main with frozen experts (IQ4_NL, UD-Q2_K_XL; graphs and no graphs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s a warp a row With MmvqSlots::lanes / MmvqIds::lanes set (Inkling 2 only, already set by Inkling2::load_geometry()), launch_slots() now takes native_mmvq_slots_lanes_kernel for native_mmvq.cu's formats IQ4_NL, Q8_0, Q2_0, MXFP4, Q4_0, Q2_K, Q4_K and IQ4_XS. Q5_0, Q3_K, Q5_K and Q6_K were slower with it (RTX 2070, 8 experts: Q3_K 2304 -> 2304 131 -> 181 us, Q5_K 94 -> 112, Q6_K 119 -> 152, Q5_0 1152 -> 2304 53 -> 59) and keep the block kernel (kSlotsLanesFaster). That is both native_mmvq_slots() (the host's list of cached experts) and native_mmvq_ids() (the card's picks, the path taken when a layer's routed experts are all in VRAM). Before, only IQ3_S and IQ3_XXS had a lanes kernel; these formats ran native_mmvq_slots_kernel, a block of 4 warps a row. A warp takes a row. Lane l does the work of the block's threads l, 32 + l, 64 + l and 96 + l, each into its own sum, and adds them in the order the block adds its warps' partials, then the same warp_sum: the same terms in the same order, so the same bits. No shared memory, no barrier, and no thread idle where the block's threads do not divide a row (an expert's 2304 and 1152 IQ4_NL values are 72 and 36 blocks for the block's 64 thread pairs). CUDA only; HIP launches are unchanged. Ported from our earlier engine in PR simplexai-labs#200 (commit a4fa510, "kernels: the cached experts' slots launches a warp a row, opt-in"), adapted to main's launch_slots(). poly_slots_lanes_test checks the lanes launch (host list and card picks) against the launch without lanes, to the bit, for 12 formats, 1 to 32 experts, n_in from one block to 4096 and row counts that leave a block's last warps empty; canaries after each slot's outputs catch rows left unwritten and writes past a slot. 0 of 660 checks fail on an RTX 2070 (sm_75) and an RTX 3060 (sm_86), with and without STRATA_SLOTS_WARP=1; compute-sanitizer memcheck clean. 8 experts per launch, RTX 2070: IQ4_NL 2304 -> 2304 118.2 -> 106.1 us, 1152 -> 2304 54.0 -> 51.2; Q8_0 1152 -> 2304 85.3 -> 62.7; Q2_0 1152 -> 2304 47.1 -> 38.5. RTX 2070 Super, decode after a 302-token prompt (--prompt-int8 setting), mean of 3 runs: IQ4_NL 43.0 -> 44.0 tok/s, UD-Q2_K_XL 46.2 -> 46.5. Greedy tokens and top-20 SAME as main with frozen experts (IQ4_NL, UD-Q2_K_XL; graphs and no graphs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… test Rewrite the notes in sycl/tools/poly-port/README.md for people who want to try the branch: - Measured: two batches of runs on one binary (Intel Arc Pro B70, WSL2, Inkling 2 Mini Q3_K_XL, token IDs 1..8, 64 new tokens): 14 completed runs of batch 1 at 34.5-41.3 tok/s and 30 of 30 runs of batch 2 at 31.3-38.6 tok/s; all 44 printed the same 64 tokens. One startup failure (oneMKL warm-up, unexplained) and no DEVICE_LOST since h2d_copy. - Status: upstream PR simplexai-labs#200 was closed unmerged on 2026-11-23; upstream main has its own newer Inkling code, and its SYCL kernels now have NVFP4 too. This branch is not moved onto either. - Commit table (nine commits), the fixes found on the way (card-routing buffers, h2d_copy), the known gaps, and a "Test it yourself" section with the build and run commands, the expected 64 tokens, and what to report. Not validated: no comparison of logits or tokens with llama.cpp or the CUDA build; one prompt, one model, one machine; the build flags are from our build cache and a fresh clone configured with them has not been tried. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FA86cq7ktJuaewMKKonxr7
…run, opt-in (STRATA_INK_PRESTAGE=1, same bits) In a prompt read of several calls (read_groups()), each layer run's experts that are not cached go through the staging buffer, and main copies them only when the run starts, so the card waits for that copy. With STRATA_INK_PRESTAGE=1 the read's staging buffer gets a second part as large as the first (widen_stage(); the expert cache lends that VRAM for the read and takes it back in narrow_stage(), as it does for the first part), and once a run's first call has queued its own copy, the next run's uncached experts are copied from the pinned mirror into the other part on the upload stream (prestage()). The copy waits for the last call that read that part (the run before's, ev_free_); the next run's calls wait for its event and read their experts there. If the next run's experts are not the ones copied, it copies its own as before. Only with the pinned mirror (build_mirror(), the Linux default): its copies are queued at once, where the pinned buffers' CPU copy would hold the call's launches up. The experts, their layout within a part and the launches are the same, so the results are too: identity of main, this change with STRATA_INK_PRESTAGE=1, and without it, on an RTX 2070 8 GB (302 / 2,048 / 8,192 tokens, IQ4_NL and UD-Q2_K_XL, graphs and --no-graphs, experts frozen), 40 of 40 comparisons byte-identical, prestage engaged in 12 of the 20 opt-in runs. RTX 2070 Super 8 GB, mean of 3 runs: IQ4_NL 2,048-token prompt +12.6% (480.3 -> 540.7 tok/s), UD-Q2_K_XL 2,048 -1.3%, IQ4_NL 32,768 -1.9%; decode unchanged. Off by default. Inkling 2 on CUDA only; HIP compiles the code, never takes it. From our reference PR simplexai-labs#200 (commit 802b20d, "Inkling 2 Mini's prompt reads do not wait for the copies to the card"), whose row-table half is simplexai-labs#265; adapted to main's read_groups() and the pinned mirror. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same bits. HIP ran ink_clips() as up to 8 launches and ink_qkv() as 8 (the simplexai-labs#217 workaround: ink_clips_kernel and ink_qkv_kernel never finished on gfx1100/gfx1201 under ROCm 7.2.4). A HIP-only ink_clips_hip_kernel does the clips, the head norms and the fp16 / Q8_0 stores in one launch: each block a token's head through the same clip_head() / rms_head() and the same stores, its job picked by comparisons and its fields copied out (the hanging kernel indexed them in a counted loop). ink_qkv() on HIP is ink_conv_few() of K and V in one launch, then that. poly_inkling2_test's clips and qkv cases compare it with the separate launches, and its clips case now also compares the fp16 caches with store_f16() / ink_store_ring() and store_f16_at() of the same rows. CUDA unchanged. Checked on ROCm 7.2.4 (gfx1201, gfx1101). The idea of fewer clip launches on AMD is from our reference engine's clip_many (PR simplexai-labs#200). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same bits. In a prompt's read of several calls a call's row tables go to the card by a kernel (copy2()), not as a copy queued behind the layer's expert copies (kernel_tables_), on HIP as on CUDA. STRATA_INK_KERNEL_TABLES=0 keeps the copies. From our reference PR simplexai-labs#200 (802b20d). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_POLY_HIP_INT8=1) The int8 prompt kernel (i8_mma.cuh) gets a HIP body: the same block (64 weight rows x 16 NJ activation rows, 256 values a stage, the weights decoded to int8 in LDS by the same decoders, the next stage read into registers while this one is multiplied), with the products on v_wmma_i32_16x16x16_iu8 (gfx11: duplicated 16-value operands; gfx12: 8 values a lane) and LDS-only barriers. The next stage's reads are made without branches (put() zeros what is not there), so the compiler counts them and does not wait for all of them in the middle. Each 32-value block's integer sum (16 for a type with a scale per 16) is scaled and added in the same order as the CUDA m16n8k32 / m16n8k16 path, so a product has the same bits as CUDA's int8 kernel: poly_mmq_paths_test's new STRATA_MMQ_TEST_DUMP dumps are byte-identical between an RTX 2070 (--turing-int8) and an RX 9070 XT (gfx1201), an RX 7900 XTX (gfx1100) and an RX 7800 XT (gfx1101 running the gfx1100 code), for all 20 types the kernel takes. A launch whose blocks pass the grid's y side (65,535) goes as runs of matrices instead of failing (a row's product does not depend on its launch). poly_mmq_paths_test also covers matrices of 500 rows (not whole tiles), launches of 10 and 20 rows (the 16- and 32-row tiles), small experts, Q2_0, and 70,000 one-row matrices by offset; STRATA_MMQ_TEST_REF=DIR fails the test where a product's bytes differ from another card's dump. strata-poly takes it on HIP only with STRATA_POLY_HIP_INT8=1 (mmq_own.cu): int8 activations are a rounding change against HIP's FP16 tiles and BLAS loop, the same class as CUDA's default on Ampere and newer. NVFP4 goes with it unless STRATA_PREFILL_NVFP4 names a mode. Unset, nothing changes. gfx906 keeps the stubs. The idea of int8 activations a 32-value block with per-block scaled integer sums is llama.cpp/ggml's MMQ, which our inkling2-amd-preview branch (PR simplexai-labs#200's AMD work) ran on HIP through llama.cpp; NVFP4 on the int8 tiles follows Tako88's approach. The code here is our own, on main's kernel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Quick question about I ran it on an RX 9060 XT (gfx1200, native Linux, ROCm 10.1) and it is about 4x faster on prompts than main on the same The merged PRs (226, 227, 262, 264, 266, 278, 280) look like the NVIDIA half of the work, and I could not find the Numbers and setup are in #309. |
|
@Tako88 Yes I'm currently focusing to porting AMD performance optimizations to main now. Currently it's still quite a bit slower than the old AMD preview branch, but with the currently open PRs + some inflight work I think it should end up being faster. |
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_loopfiles (IQ4_NL, Q8_0) and Unsloth'sinkling2file (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
./setup.sh --family inkling(IQ4_NL by default)--model UD-Q2_K_XLor--model Q8_0--vision cpu|gpu"parallel": N--gpus 0,1, or"layer_split"--window 4--dspark yesin setup, or--draft-model FILESpeed
Tokens/s, q8_0 caches, one request. "After 302" and "8,192" are prompt lengths in tokens.
fc96949)fc96949) *a9ffc2bhere (fewer CPU threads, below); the next push addresses it.How it was checked
conv_accbit cases fail.Platforms and limits
--kv q8_0, 32 KiB in fp16). No KV streaming.Credits
More
See
docs/models/inkling.mdand 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:
Writing:
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.STRATA_POLY_EXPERT_TILES=1A100, prompts of 262K to 1M tokens (UD-Q2_K_XL, every expert in VRAM, q8_0, one run each):
STRATA_KV_INT8=1A100, 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:attn_mma_kernelattn_mma_kernelattn_mma_kernel, 28.4 ms with FA2.attn_mma_kernel, 1.32 ms with FA2. So window layers stay onattn_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.
2x RTX 3070 8 GB, split at layer 18 (rented, 6e61054).
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.
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:
a9ffc2bfc96949a9ffc2bfc96949The 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:
STRATA_INKLING_WMMA=1inkling2_loop) pp512 1,096-1,172, pp2048 224-555, tg128 37-44.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):
"parallel"RTX 3090 (4d7ca06, 32K context):
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:
--window 1--window 4--window 8on a prose prompt: 127.8 tokens/s (UD-Q2_K_XL).--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:--window 4pays 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):
MMQ expert tiles (
STRATA_POLY_EXPERT_TILES=1, CUDA only).Prompt reading, default -> tiles, tokens/s:
Kernel bench (
poly_mmq_tiles_test bench, 8 calls, rows from the IQ4_NL expert profile), TOPS:STRATA_KV_INT8=1(past 32K, needs a q8_0 cache).STRATA_KV_INT8=1.Pictures (
--vision cpu|gpu, RTX 2070 Super, 6 encoder threads).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_dumpand 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.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.
Opt-in features against the default.
STRATA_KV_INT8=1STRATA_KV_INT8=1--prompt-batch 64) moves the logits by the same amount.--no-gpu-experts: the same answers in 6 of 6 cases. Graphs on and off: the same in 2 of 2.Pictures (llama.cpp 29b52d398b, IQ4_NL, the Q8_0 mmproj).
llama-mtmd-clidescribed the photo in nearly the same words.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.
tokenizerson 1,006 strings (about 587,000 tokens).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).--no-graphsSTRATA_KV_INT8=1at 16,500--no-graphsSTRATA_GPU_EXPERTSat the same N (773 to 1,884), equal set hashes--no-graphsSTRATA_KV_INT8off and on--serve, four prompts in one engine--check-batch 2STRATA_GPU_EXPERTS(UD-Q2_K_XL N=2,971, IQ4_NL N=1,932), equal set hashes--no-graphs--no-gpu-experts--vram-poolattn_fa2_kernelvsattn_mma_kernel, kernel test--window 4and 8, and the drafter at windows 4 and 8, vs--window 1and vs--no-graphs--no-graphs, for--window 4and for the drafter--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 tokensSTRATA_FREEZE_EXPERTS=1--serveafter checkpointed and resumed reads--window 4vs--window 1, every expert on the CPU"auto"; 3, 20 and 3+18 on an earlier treeTests:
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.conv_accbit 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.What changed, by file area
Engine (
src/poly/inkling.*,kernels_inkling.cu,include/strata/poly/inkling_kernels.hpp)attn_mma_kernel, FP16 MMA, Turing or newer) for prompt calls of more than 16 tokens. The bias stays in float.attn_fa2_kernel, A100 and A800): full layers past position 2,048. Same steps in the same order asattn_mma_kernel, so the same bits. Measured on an A100-PCIE-40GB only, not on the A30 or A800. Other cards keepattn_mma_kernel.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.native_mmvq.cu's fast-math operations as PTX so their bits match; on HIP they are plain IEEE operations.STRATA_INKLING_MIX_SPREAD=0turns it off. On HIP it stays one block.--window N, the drafter) is one graph too.--no-graphsturns it off; the bits are the same either way.--batch, pictures,--dump-layers, and the drafter's own launches.--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)
dspark-Inkling-2-Mini-Q8_0.gguf(0.4 GB, pinned by SHA-256), run as llama.cpp's PR 32218 runs it.--batch,--layer-splitor several cards.poly_dspark_paritycompares its guesses with a record of llama.cpp's run;--reloadchecks 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).Expert cap (test only,
STRATA_GPU_EXPERTS=N)cache set N experts fnv <hash>. Two builds can then be compared byte for byte with experts on the card.Shared engine (
engine.*,cpu_experts.*,mmq.*). Each change is gated, so other families keep their path.Layer::alias,home_of).load_moetakes expert scales of any type when asked (only Inkling asks).Engine::lowbit_experts_(only Inkling).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.strata_poly_cpustatic library, linked by every engine and test target.native_mmvq_supported(additive), and theSTRATA_GPU_EXPERTStest knob.HIP (AMD)
Engine::openno longer refuses the model on HIP.Engine::nvfp4_int8_). Other families' HIP runs keep their path unlessSTRATA_PREFILL_NVFP4=w4a8.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).Metal: Inkling is not ported. Opening the model says so (
metal/src/poly/unported.cpp). SYCL compiles nosrc/polycode.Server (
serve/frontend.py,serve/server.py,tools/strata_tokenizer.py)InklingParser, forcedtool_choice, andignore_mergesforinkling2.strata_prefixmatches withreasoning_effortand thinking off.<|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 sharedstrata-visionis unchanged. Picture rows skiptoken_embd_norm, as in llama.cpp.build_vision_ownin 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_seqskernels.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 inklingwith three pinned files, and--dspark yes|no. Several cards and"parallel"as for the other families. Setup still marks the familycuda_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".
HSA_ENABLE_DXG_DETECTION=1.hipMemSetAccesson 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.--vram-poolat 774 experts.STRATA_GPU_EXPERTSfor byte comparisons.rocprofv3does not work under WSL2 (rocprof v1 does).--n-cpu-moecrashed in librocdxg after the first one. Not resolved.Known issues and follow-ups
Known issues
Follow-ups, not in this PR
Engine::card_moe()andEngine::load_state()copy from pageable memory with a plaincudaMemcpyon the legacy stream, which the engine's non-blocking streams do not wait for. This needs a separate fix.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
inkling2_loopcopies the core layers into slots 24-47 before it attaches the*_exps.scaletensors. So passes 2 and 3 run without the scales on Unsloth's files.inkling2file as it is. The UD-Q2_K_XL reference was made from a copy converted toinkling2_loop. Loading was fixed upstream (#32704).Commits named in this text
fc96949a9ffc2bplus faster F32 prompt products, the shared expert launched plainly, one CPU thread a core for Inkling, docs.a9ffc2b3cb428dd4eba79c69df6ad4eba79changes HIP only; equal preprocessed CUDA source).aabcf2dd4eba79minus 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.6e61054e6c285e1d91dab16f3585attn_kernel, and the opt-in RDNA4 WMMA attention. It does not build on CUDA until07e6249. Its test-only TQ 2 alignment fault lasts untildbd4227.07e6249__trap()instead of__builtin_trap()).63ec88f,a92763c032794de61c27c,e85c7aahip_compatnames.cee948edbd4227attn_kernel(a test-only shape; CUDA too).1dcd568e0b37b9,f5a29160720b38,3b2189e,a6511c21b6dca2,576681ccde2d1b,ec63e7fSTRATA_GPU_EXPERTS).f5e5a7e802b20dc5f26c67df039924243777f3f4574d7ca06,c808b53,99e993f,249b2de,791be9e,68d4c86🤖 Generated with Claude Code
https://claude.ai/code/session_01Erqa3PhC87SPTfVSKZ3Ri5