Repository navigation
model : inkling2 graph with fewer ops in mix() and control() - #32948
Conversation
Assisted-by: Claude Opus 5.5
|
I did this last night with a long agentic optimization loop on an M5 Max, see ServeurpersoCom@ce7f315 Part of it is the same kind of graph cleanup as this PR (mix stack, no query repeat for one token, shared norms and sinks), so that part overlaps. With all the optimizations, Inkling-2-Mini Q4_K_XL goes from 39.4 to 75.5 t/s in tg64. In chat it goes from 37.9 to 73.3 t/s at 1.3k and from 33.9 to 61.2 t/s at 37k, ahead of Ollama MLX NVFP4 (70.6 and 40.1). Prefill at 37k goes from 457 to 1187 t/s. I started sorting it out into PR-sized pieces, beginning with a first commit in the spirit of this PR: ServeurpersoCom@7095422f5c (tg64 39.4 -> 58.4 t/s). Compared to this PR, on the graph side it also casts the F32 mask once for all the layers, skips the repeat of the per-expert scale for a single token, does not copy the inputs of a single token, and writes the clip as l2_norm + scale. Most of the gain comes from the Metal backend though, and it is not model-specific: one fusion pattern per reorder group, exact view ranges, streamed command buffers, an nvfp4 mat-vec with one sub-block per thread, the per-expert scale fused, and a vectorized full-vocab sampler. |
|
@ServeurpersoCom nice! Keep the improvements flowing in. |
|
I'm measuring your PR on my M5 Max right now. Since it's better scoped for splitting this into small PRs, I'll approve it once the numbers check out, and we follow up on top of it. |
Does this make a noticeable difference? With a single tensor, it will be copied across devices when using pipeline parallel and partial offloading. |
I measured it on an M5 Max (Inkling-2-Mini UD-Q4_K_XL, single device), this PR vs this PR with the per-layer FILL restored, two interleaved rounds each: tg128 44.4-44.5 -> 45.2-45.8 t/s, pp512 1031-1033 -> 1050 t/s So about 2%, and probably more from the barrier the FILL adds before each attention layer than from the FILL itself. For pipeline parallel and partial offload, one zero tensor per backend split, or a zero tensor allocated per layer at load, would keep that gain without the copies across devices. |
It's not clear which is better - single sinks or multiple? |
Sorry, I wasn't clear. The single shared sinks tensor (this PR) is faster:
So single is about 2% faster on Metal, single device. |
From ggml-org/llama.cpp PR ggml-org#32948 (open, head 64ac064), applied as is: normalized mix() stacks are built once per graph, no query repeat for one token, one rms_norm for cur and message in control(), one zero sinks tensor.
The looped visits of a layer padded the same relative-position bias table again; it is now cached per graph (the zero sinks already are, upstream ggml-org#32948). A SWA layer mixes one input for Q, K and V, which is taken as a reshape of the mix instead of a CONT of a view of it. Inkling 2 Mini, Arc Pro B70: tg128 60.4 -> 61.2 t/s. KLD over 6 chunks of wikitext-2: 0.0020 (-ub 64), 0.0018 (-ub 4), at the noise of the backend. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01P8newWYH2KNUBSwyU42kwd
The looped visits of a layer padded the same relative-position bias table again; it is now cached per graph (the zero sinks already are, upstream ggml-org#32948). A SWA layer mixes one input for Q, K and V, which is taken as a reshape of the mix instead of a CONT of a view of it. Inkling 2 Mini, Arc Pro B70: tg128 60.4 -> 61.2 t/s. KLD over 6 chunks of wikitext-2: 0.0020 (-ub 64), 0.0018 (-ub 4), at the noise of the backend. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01P8newWYH2KNUBSwyU42kwd
…owner 2026-11-25) Base b12723 (merge a940ab9), pin ggml-org#401 removed (80211b4), RoPE multi-section fusion from upstream ggml-org#32500 (owner's decision), MIX.md (3563400). Build gate: test-backend-ops ROCm 21878/21878, bench r17 (llama-mix-notes, mesures/2026.md): Inkling tg +4.5 % [bon], Qwen3.6 and Gemma 4 without regression. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QBjnvFCJ83vkmygsLNv5cu * mix/wip-b12723: (55 commits) mix: MIX.md — base b12723 (branche wip), retrait du pin ggml-org#401, conflit RoPE tranché (amont ggml-org#32500) revert: pin: CUDA: fuse the row L2 clip chain (unslothai#401, commit 6c0e84d) model : inkling2 graph with fewer ops in mix() and control() (ggml-org#32948) opencl: add clc coopmat moe kernel for q4_0/q4_1/q4_k/q5_0/q5_1/q5_k/q6_k/mxfp4 (ggml-org#32971) tests : fix MSVC static build of test-batch-alloc and test-server-component (ggml-org#32870) feat: Inkling 2 DSpark support (ggml-org#32218) cuda : fix int overflow of the MMVF matrix offsets (ggml-org#32965) docs : describe SpacemiT runtime environment variables (ggml-org#32452) ggml : fix SpacemiT flash attention null mask, ALiBi and softcap (ggml-org#32182) cmake : include the llguidance header from the source tree (ggml-org#32928) ci : move some jobs to gb10 runners (ggml-org#32968) ui: run Llama Chat apart from llama-server, named in config.json or npx --server (ggml-org#32945) ui: fix prebuilt UI download in shallow clones (ggml-org#32952) convert : fix qwen3-omni conversion (ggml-org#32941) ggml-cpu: repack kernels for targets without dotprod (ARMv8.0 64-bit) for Q4_0/Q8_0 (ggml-org#32142) ui: expect the Llama Chat name in the PWA manifest e2e test (ggml-org#32959) ggml-cpu: add SVE-optimized q5_0 and q5_1 dot-product kernels (ggml-org#30867) server : include MCP image and audio data in tool results (ggml-org#32064) context : prevent excessive CPU polling without OpenMP (ggml-org#32378) metal : reserve the top-k scratch only for short rows (ggml-org#32942) ...
The looped visits of a layer padded the same relative-position bias table again; it is now cached per graph (the zero sinks already are, upstream ggml-org#32948). A SWA layer mixes one input for Q, K and V, which is taken as a reshape of the mix instead of a CONT of a view of it. Inkling 2 Mini, Arc Pro B70: tg128 60.4 -> 61.2 t/s. KLD over 6 chunks of wikitext-2: 0.0020 (-ub 64), 0.0018 (-ub 4), at the noise of the backend. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01P8newWYH2KNUBSwyU42kwd
…g#32948) Assisted-by: Claude Opus 5.5
Overview
Four changes to the Inkling 2 graph that keep the results bit-identical and cut the ops per token:
mix()rebuilt the stack of all earlier block outputs on every call, with one CONCAT per block, and normalized the whole stack again. The rms_norm is per row, so each block can be normalized once:mix_stack()keeps the normalized stacks for the graph and grows them by one block at a time. In the loop graph all looped layers of a pass mix the same bank, so that stack is built once per pass.mix()does not repeat the queries for a single token.control()normalizescurandmessageas two rows of one rms_norm, instead of two rms_norm and a concat of the results.Additional information
Inkling 2 Mini IQ4_NL (ggml-org), master 26f5048 vs this PR,
llama-bench -ngl 99 -fa 1, interleaved rounds of-r 3:CUDA kernels per token by type: concat 548 -> 413, rms_norm 514 -> 400, repeat 120 -> 0, fill 51 -> 4.
Greedy decode of 96 tokens gives the same text on CUDA and Metal.
llama-perplexity --kl-divergenceagainst master gives the same numbers as master against itself on CUDA (40 chunks of 512), Metal (4 chunks) and CPU (2 chunks): mean KLD 0, same top p 100 %.This merges cleanly with #32855.
Requirements