okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

albedocmake: strata_kernels links strata_kernels_cpu (iq_kernels.cu reads the latent colscale table from expert_layout.cpp; strata-q36ref failed to link)a4af4df61

main
16 files

files

README.md12.8 KiB
bench.py2.6 KiB
dequant-wide-parity.txt2.4 KiB
engine-runs.txt10.3 KiB
equal_check.py2.3 KiB
fused-gr-bench.txt3.7 KiB
gemm-f32-parity.txt2.8 KiB
gemm-sweep.txt99.6 KiB
gemm_sweep.cu5.2 KiB
mmvq-il-bench-p40-run1.txt11.7 KiB
mmvq-il-bench-p40-run2.txt11.7 KiB
mmvq-il-bench-p40-run3.txt11.7 KiB
native-expert-bench.txt9.5 KiB
nvprof-base.txt49.1 KiB
profile-base.txt11.5 KiB
profile-new.txt11.4 KiB

Tesla P40 (sm_61): wide dequantization, the dense GEMMs as cublasSgemm (opt-in), expert mode 8 and a matvec table (2026-10-12)

One Tesla P40 with IQ3_S. The card is the bottleneck of the prompt and of the decode, so the profile was read first and four things were changed where it pointed. Each gives exactly the bits of what it replaces.

WhatWas on sm_61Now on sm_61Switch
Dequantization of the dense weights for the prompt GEMMs (Q4_K / Q5_K / Q6_K / IQ4_XS)a thread per 32 values, byte loads, 2-byte stores 64 bytes aparta thread per 8 values, 16-bit loads, one 16-byte storeon by default, STRATA_DEQUANT_WIDE=0
The large dense prompt GEMMs (qkv, query, gate and output projections)cublasGemmEx on FP16 operandscublasSgemm on FP32 copiesopt-in, STRATA_DENSE_F32=1
Routed experts in VRAM (native_expert_grouped)the CUDA layout (mode 0)mode 8on by default, STRATA_SM61_TABLE=0
Dense 1-4 column GEMVs and the head (native_mmvq_il)native_mmvqthe interleaved kernel with a table read off the P40 (kIlRows_61, kIl1Rows_61)on by default, STRATA_SM61_TABLE=0

Through the server, medians of 3 requests, two runs per build alternated, every run started with the card at 65 C:

a0116b2this change (defaults)this change + STRATA_DENSE_F32=1
565-token prompt, tok/s203 / 205 and 205 / 210256 / 255254 / 252
7,047-token prompt, tok/s360-365 or 430-432, by the token count (below)369-374 or 437-443, by the token count464-474 at every count
decode after the short prompt, tok/s35.0 / 34.2 and 35.4 / 34.438.2 / 37.237.7 / 37.9
decode after the long prompt, tok/s33.1 / 33.3 and 32.1 / 33.433.5 / 35.635.9 / 34.0

The decode gain is small (+6-10% after the short prompt) and inside the spread of single requests; it is the same size in the GPU stage profile (49.1 -> 45.6 ms per window), which is the steadier measurement.

Rig

Where the time goes on a P40 (base build)

STRATA_PREFILL_TIMING=1 STRATA_DECODE_TIMING=1 STRATA_VERIFY_PROFILE=1 (profile-base.txt), and one run under nvprof for the kernels' names.

What that leaves alone: cublasSgemm already runs at 8.5-10 TFLOPS on this card (11.8 at its boost clock), ggml's MMQ has its own Pascal dp4a configuration, and the decode GEMVs sit at 60-90% of the memory bandwidth the wide dequant kernel reaches (227 GB/s). No larger kernel lever was found.

Kernels (no engine)

Dequantization, dequant_wide_parity --bench (dequant-wide-parity.txt): 360 cases bitwise (FP16, BF16, FP32 out, a padded row stride, row slices; sane blocks and raw random bytes), FP16 out:

Shapeper-groupwide
Q6_K 10240 x 25607.25 ms (10 GB/s)0.33 ms (227 GB/s)22.3x
Q6_K 2560 x 61444.45 ms0.20 ms22.5x
Q4_K 10240 x 25601.67 ms0.32 ms5.2x
Q5_K 10240 x 25601.24 ms0.33 ms3.8x
IQ4_XS 10240 x 25601.21 ms0.34 ms3.6x

The FP16-operand GEMM, a sweep of the chunk size T (gemm-sweep.txt, gemm_sweep.cu, cuBLAS only). cuBLAS 12.4 has two kernels for FP16 operands with FP32 sums on this card, maxwell_sgemm_fp16_64x64_tn and _32x128_tn, and for most T it picks the slower one:

ShapecublasGemmEx FP16 operandscublasSgemm FP32 copies
qkv 10240 x 25607.6 TFLOPS at 27 of the 76 sizes sampled from T 256 (T 7,030-7,040 among them), 4.3-4.6 at the others (49 -> 85 ms from T 7,040 to 7,041)6.8-10.0 from T 256, 8.4-9.6 from 512 (39-42 ms at 7K)
query 12288 x 25607.5 at 24 of the 76 sizes, 3.8-4.7 at the others (103 ms at 7,041)6.7-9.8 from 256, 8.4-9.8 from 512 (47-50 ms at 7K)
gate 6144 x 25607.3-7.8 at 26 of the 65 sizes from T 512 (up to ~1,100, and 7,030-7,040), 4.5-6.1 at the others8.2-9.7 from 512
out 2560 x 61447-8 at 23 of the 47 sizes from T 4,096, 4.4-6.2 at the others8.3-9.2 from 4,096

So the base build reads a 7K-token prompt in 16.3 s when its chunk has 7,040 tokens or fewer and in 19.5 s when it has 7,041 or more. The two results are bitwise equal wherever both run a Maxwell kernel; below T ~144 (6,144+ rows) or ~408 (2,560 rows) cuBLAS takes another kernel family for one of them and the bits differ, so the route starts at T 256 / 512 / 4,096 for the three groups of shapes. gemm_f32_parity --bench (gemm-f32-parity.txt) runs Gemm::f16 both ways: 5,201 chunk sizes bitwise (every 7th T to 8,192, every T of 7,000-7,100, around the powers of two and the activation slices' split), and with the conversions included qkv at T 7,041 85.4 -> 44.7 ms, at 560 6.5 -> 4.4 ms; the gate projection at 560 and the 4,096-column output projection at 4,096 are 5-7% slower that way (2.9 -> 3.05 ms, 12.3 -> 13.3 ms).

That equality is a property of this cuBLAS build, not of the code: which kernel cuBLAS picks, and that both add in the same order, was measured with 12.4.5.8 only. Hence opt-in. gemm_f32_parity is the check for another library (CUDA 12.9's, the ready-made CUDA 12 engine's).

Experts, native_expert_bench <shard1> 0,5,11,17,23,29,35,41,47 18 2 0 8 (18 groups, 2 tokens, the model's real rows, bitwise on all nine layers; native-expert-bench.txt):

Layer gate/up / downmode 0mode 8
IQ3_S / IQ4_NL390 us255 us
IQ3_XXS / IQ4_NL345 us252 us
IQ2_S / IQ4_NL290 us238 us
IQ4_XS / IQ4_NL328 us261 us

Modes 2, 5 and 6 are slower than mode 0 here, mode 7 is 3-6% behind mode 8.

Dense GEMVs, mmvq_il_parity --bench --emit-table, three runs (mmvq-il-bench-p40-run1.txt, run2, run3). The three emitted tables are identical but for two Q3_K cells (4 columns below 2,048 rows: 1, 1, 2 -> 1; one column at 2,048-4,095 rows: 2, 2, 0 -> 0). A few cells of run 1:

Shapecolumnsnative_mmvqinterleaved
IQ4_XS 2560 x 10,2402111.8 us65.0 us (rows 4)
Q6_K 2560 x 12,2884189.3 us127.4 us (rows 2)
Q6_K 2560 x 10,240192.6 us109.7 us (rows 2): the table keeps native_mmvq for one Q6_K column
Q5_K head 2560 x 248,32032,545 us1,766 us (rows 2)
Q5_K head 2560 x 248,32011,754 us1,507 us (rows 2)

Not taken: the latency-hidden hyper-connection read (fused-gr-bench.txt, bitwise): 82.0 -> 88.2 us at one token, 92.4 -> 102.6 at two, faster only from five (192 -> 181 us). sm_61 keeps the plain one.

Engine

engine-runs.txt has every request. Each run is one server start; before it the card cooled to 65 C (it ends a run at 82-84 C). Two builds of the change were run: without the GEMM route (what this change does by default) and with it (STRATA_DENSE_F32=1).

Prompt read time by the prompt's token count, engine ms (a chunk has 7 tokens fewer):

prompt tokensbasedefaults+ STRATA_DENSE_F32=1
7,04316,374 / 16,37015,90514,845
7,04616,352 / 16,33415,96315,065
7,04716,325 / 16,31816,13615,191 / 14,863
7,04819,540 / 19,384 / 19,600 / 19,489 / 19,33419,081 / 18,902 / 18,856(no request of this size)
7,04919,533(no request of this size)14,861 / 14,914

GPU stages per verify window (STRATA_VERIFY_PROFILE=1; three requests after the short prompt 49.2 / 48.3 / 49.1 -> 46.8 / 45.6 / 45.0 ms, after the long one 48.2 / 49.5 / 49.0 -> 45.2 / 45.2 / 44.9 ms). VRAM hits 9.6 + 3.1 -> 7.5 + 2.5 ms, the GDN qkv / gate GEMVs 4.2 + 2.5 -> 3.9 + 2.2 ms, the QSA query GEMV 1.83 -> 1.60 ms, the head 2.87 -> 2.45 ms; the other stages unchanged (profile-base.txt, profile-new.txt).

With STRATA_DEQUANT_WIDE=0 STRATA_SM61_TABLE=0 STRATA_DENSE_F32=0 the changed build measures as the base one: 210 tok/s short, 360 / 431 / 365 tok/s long (7,048 / 7,047 / 7,048 tokens), decode 33.3 tok/s.

Answers

Seven fixed prompts (equal_check.py: code, prose, arithmetic, JSON, Italian, a 2.6K-token summary, a needle in 3K tokens), greedy, first requests after a start. With --prompt-cache 0 --adapt-swaps 0 --pcie-frac 0 STRATA_PREFILL_CPU_SHARE=0 STRATA_ROUTE_TAIL_SKIP=0 STRATA_IQ_MT_MIN=1, two runs of the base build and two of the changed one (GEMM route on) give byte-identical answers, 4 of 4 runs on 7 of 7 prompts (2,900 characters each).

Without STRATA_IQ_MT_MIN=1 that comparison cannot be made on this CPU: the same build gave two different answers to the Italian prompt in two runs (drafts accepted 34 of 65 against 33 of 69). 60% of that prompt's experts run on the CPU, where a lone token's rows round differently from a group's (native_gu_mt_min), and how many drafts a window holds depends on timing.

Two traps on such a card

Not tested

Files

engine-runs.txt (every request), profile-base.txt, profile-new.txt (the timing lines), the kernel outputs named above, nvprof-base.txt (the base build's kernels over three short and three long prompts), bench.py, equal_check.py, gemm_sweep.cu.