okami.mom/strata

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

waveringanadsv41: DS4_PROF splits the stream's waits (pieces, h, last piece in); CPU_MEASUREMENTS records the lane2 runs1373d34bd

main
9.7 KiB178 linesraw

CPU lane measurements on focalor

The baseline is e5331100. The machine is a Ryzen 7 5800X (Zen 3, AVX2, 8 cores / 16 threads). These runs used random expert blocks, not model outputs. Every run held /tmp/ds41-bench.lock; no GPU kernels ran.

Build ISA

The Nix GCC wrapper removed -march=native: preprocessing with that flag showed SSE2, but no AVX2/FMA/F16C. ggml therefore used scalar dots. Strata's AVX2 rows failed the bitwise check against those scalar float reductions, so both auto and own silently fell back to scalar ggml.

Configure with -DSTRATA_PORTABLE=ON to request AVX2/FMA/F16C explicitly. ds4_gg_bench now prints ggml's compiled ISA and warns when it is missing. --k256 checks the AVX2 implementation directly, without fallback.

With --expert --type T --dtype T --nt 1 --mb 1500 --reps 2, auto GB/s before / after the build correction were:

Type1 thread8 threads
IQ2_XXS (16)0.5 / 4.93.9 / 34.8
IQ2_XS (17)0.6 / 4.94.5 / 35.2
IQ1_M (29)0.4 / 2.73.0 / 18.9

The before figures are the parent experiment's streaming runs (IQ1_M 0.4 GB/s was independently reproduced here). After figures were measured in this worktree before the singleton change below. Raw logs are under build/avx2-type{16,17,29}-t{1,8}.log.

The build correction changes floating-point reduction order, not integer sums or precision. It is NOT bit-identical to scalar ggml. On roughly 1,300-1,800 random rows/type, 79% differed in bits; maximum absolute errors were 1.53e-5 (16,17) and 1.91e-6 (29), or 1.6-2.1e-7 of maximum output magnitude. See build/scalar-vs-avx2-floats.log. All Strata AVX2 results were bit-identical to the corrected ggml AVX2 build.

IQ1_M singleton chunks

At one token, consume each decoded 64-weight chunk immediately instead of storing four decoded chunks (1 KiB/block) and then rereading them. The integer lanes, float scale products, FMA order and reduction stay unchanged. Multi-token calls retain the decoded-chunk sharing path.

Paired 1.5 GB ABBA runs gave own throughput at one thread of 2.7 / 3.0 / 2.8 / 2.5 GB/s (baseline / candidate / candidate / baseline); the last baseline also suffered a large ggml slowdown, so these are noisy. At eight threads the corresponding figures were 13.7 / 16.4 / 15.9 / 13.5 GB/s. Within-process ggml throughput stayed 10.8-11.1 GB/s for those four eight-thread runs. This supports a roughly 17-20% eight-thread gain from the kernel change; it is not a second several-fold improvement. Logs: build/confirm-{base,direct,direct2,base2}-iq1m-t{1,8}.log.

Direct --k256 --mb 10 checks passed bitwise for 16/17/29 at 1,2,4,8 tokens, with no exactness fallback. Expert pipeline comparisons also passed. See build/direct-exact-validation.log.

A ternary activation LUT prototype was exact but slower (0.4 vs 2.7 GB/s single-thread own throughput), and was discarded. Its table occupied about 207 KiB per thread at gate width; scalar lookup/index work and preparation did not pay off. Log: build/lut-iq1m-t1.log.

Per-call scheduling

--expert --lane uses the production ds4::Pool, one expert per gate/up and down dispatch, and serial h quantization. It does not emulate disk reads, slot copies, NUMA splits, CUDA synchronization or other engine work. It changes no production scheduling.

At --nt 1 --threads 8 --mb 256 --reps 2, corrected AVX2 auto throughput was 31.2 / 28.1 GB/s for type 16, 30.7 / 29.8 for 17, and 19.6 / 18.3 for 29 (batched / one-expert calls). All pipeline results were bitwise identical to ggml. This synthetic per-call cost is modest; the engine's old two-fold gap cannot be attributed to dispatch alone from this test. Reprofile the corrected full engine before tuning production row chunks. Logs: build/scheduling-type{16,17,29}-lane{0,1}.log.

Store completion wait race

The store checked a slot's pending-read count before IoQueue::wait_any snapshotted its completion generation. A completion in between could make the waiter sleep until the two-millisecond timeout. The optional pending count is now checked in the wait predicate under the notification mutex. This changes neither expert arithmetic nor output accumulation order.

The ds4_pool_test regression passes for completed requests, a successful copy and cancellation. Restoring the old notification-only predicate makes the completed-request case fail (one-second timeout, 500-ms threshold). CTest passed 1/1 on focalor.

This is not a measured decode-throughput improvement. On the 64-token full-engine recipe, exact routing was 8.34 tok/s baseline and about 8.3 with the fix; Cache-Prior lambda=0.3/keep=3 remained about 12.1 tok/s. The fix's two 64-token runs matched each other and the baseline stdout for both routing configurations. The first 48-token exact baseline had different tokens from later runs, so its apparent 8.03-to-8.37 increase is not evidence for the change.

Artifacts: build/lane-{base64-exact,io64-exact-a,io64-exact-b,base64-cp, io64-cp-a,io64-cp-b}.{stdout,stderr,json}, build/io-old-predicate-test.log, build/io-fix-test-summary.txt. Baseline source: b0185826; immutable baseline and candidate executables are build/strata-dsv41-lane-base and build/strata-dsv41-io-wait. The CPU pool's source diff is preserved in build/io-wait-candidate.patch.

CPU store without relocation copies

DS4_STORE_INPLACE=1 leaves each CPU-only matrix at the address where its aligned read lands it. ExpertStore::mat returns that address. This avoids an extra full-matrix memmove on every cache miss. Prompt staging now reads the store's three matrix pointers rather than assuming a canonical blob. GPU-mapped slots retain the canonical layout; the option is disabled with DS4_STORE_ZC. The default remains unchanged.

On the same 64-token recipe, canonical versus two in-place runs:

RoutingCanonical tok/sIn-place tok/sGPU ms/token canonical / in-place
Exact8.278.83, 8.73119.79 / 112.10, 113.44
Cache-Prior 0.3, keep 312.0112.62, 12.6382.22 / 78.18, 78.16

For Cache-Prior, GPU waiting for the CPU lane fell from 61.10 to 57.09/57.07 ms/token, and store read waiting from 29.7 to 27.0/26.9 ms. At the final profile checkpoint the per-call IQ gate/up stage fell from 0.410 to 0.357/0.362 ms, down from 0.214 to 0.191/0.194 ms (prefill calls are included in these running averages). Miss counts, cache movement and bytes/token were identical in this confirmation batch.

Each routing recipe's three 64-token stdout files compare byte-for-byte: canonical versus in-place and repeated in-place. No integer arithmetic, precision or floating reduction order changed. The synthetic ds4_store_layout_test checks unaligned offsets, buffered and direct reads, slot reuse, read failures, and canonical GPU-mapped layout even when the in-place option was requested. CTest passed 2/2 with this and ds4_pool_test.

The 48-token screening run gave exact 7.77 -> 9.01 tok/s and Cache-Prior 12.17 -> 12.84, but use the 64-token confirmation above for the gain. Logs are build/lane-raw64-{canonical,exact-a,exact-b,canonical-cp,cp-a, cp-b}.{stdout,stderr,json} and build/lane-raw-{canonical,inplace, canonical-cp,inplace-cp}.*. Runs were batched under the approved gpu_run.py service lease inside /tmp/ds41-bench.lock.

Streamed CPU-lane batches (ana/lane2)

DS4_LANE_STREAM=1 (NH 1, i-quant experts, RAM store) computes a window's CPU-lane experts in one pool batch: the entries whose reads are done first, then the misses in the order their reads started; each entry's gate/up jobs, then its down jobs. DS4_STORE_PIECE_KB=n (in place only) reads each missed matrix in n KB pieces (gate and up interleaved, then down), and a job waits only for the pieces holding its rows; a piece whose read failed is read from the file's mapping. An entry's last gate/up job quantizes its h, which its down jobs wait for. Every row is the same call on the same rows into the same slot as cpu_experts_iq: no integer, precision or float-order change.

Paired 64-token runs (frozen profile, DS4_PROF=1 in every arm), with DS4_STORE_THREADS=16:

RecipeBefore tok/sStream + 1 MB pieces tok/sGPU ms/token
Exact9.01, 9.019.71-9.80110 -> 101
Exact + read-ahead (top-3)-9.80-9.90
lambda 0.3, keep 3, read-ahead13.89, 13.8914.71-14.9370.7 -> 66.4

Stdout hashes matched the baseline in every run (exact 36c021ba70, Cache-Prior b2838ebf36).

Measured and discarded: stream without pieces (+2.7% only); 256 KB pieces with 8 reader threads (8.47); 2 MB pieces, 512 KB pieces, 8/12/24/32 reader threads (all within 9.5-9.8); the store arena on transparent huge pages (72 s of compaction at preload, 7.56 tok/s); DS4_CPU_SMT pool on both hardware threads of each core (exact 9.62 -> 9.26, Cache-Prior 14.93 -> 14.49); a dynamic order taking a missed expert's job as soon as its pieces land and RAM hits otherwise (unchanged, 9.80 / 14.93); capping concurrent guess reads at 4 or 8 (unchanged).

Where the exact lane's time goes now (ds4 prof CPU lane (IQ stream)): 32 calls a token, 2.97 ms each, the last missed piece in at 2.19 ms on average and ~0.8 ms of compute after it. fio on /strata-fast: 1 MB direct reads at queue depth 16 give 7.9 GB/s with 2.1 ms mean latency; depth 8: 6.3 GB/s; depth 4: 4.9 GB/s. A layer's ~12 MB of misses arrive together, so the exact recipe is bound by the miss bytes per layer, not by compute order.

IQ1_M rows: maddubs by ones instead of |g| (sign(q8, g) is already 0 where g is: the same int16 pair sums). ds4_gg_bench --expert --type 29 --dtype 29 --nt 1, two rounds: 1 thread 3.0/3.1 -> 3.2/3.1 GB/s, 8 threads 19.8/20.3 -> 20.7/20.7. --k256 bit-identical at 1, 2, 4 and 8 tokens. Gathered grid loads (18.5/17.9) and movq/movhps pairs (19.0/18.8) were slower and were dropped.

1# CPU lane measurements on focalor
2
3The baseline is e5331100. The machine is a Ryzen 7 5800X (Zen 3, AVX2,
48 cores / 16 threads). These runs used random expert blocks, not model
5outputs. Every run held `/tmp/ds41-bench.lock`; no GPU kernels ran.
6
7## Build ISA
8
9The Nix GCC wrapper removed `-march=native`: preprocessing with that flag
10showed SSE2, but no AVX2/FMA/F16C. ggml therefore used scalar dots. Strata's
11AVX2 rows failed the bitwise check against those scalar float reductions,
12so both `auto` and `own` silently fell back to scalar ggml.
13
14Configure with `-DSTRATA_PORTABLE=ON` to request AVX2/FMA/F16C explicitly.
15`ds4_gg_bench` now prints ggml's compiled ISA and warns when it is missing.
16`--k256` checks the AVX2 implementation directly, without fallback.
17
18With `--expert --type T --dtype T --nt 1 --mb 1500 --reps 2`, auto GB/s
19before / after the build correction were:
20
21| Type | 1 thread | 8 threads |
22| --- | --- | --- |
23| IQ2_XXS (16) | 0.5 / 4.9 | 3.9 / 34.8 |
24| IQ2_XS (17) | 0.6 / 4.9 | 4.5 / 35.2 |
25| IQ1_M (29) | 0.4 / 2.7 | 3.0 / 18.9 |
26
27The before figures are the parent experiment's streaming runs (IQ1_M
280.4 GB/s was independently reproduced here). After figures were measured
29in this worktree before the singleton change below. Raw logs are under
30`build/avx2-type{16,17,29}-t{1,8}.log`.
31
32The build correction changes floating-point reduction order, not integer
33sums or precision. It is NOT bit-identical to scalar ggml. On roughly
341,300-1,800 random rows/type, 79% differed in bits; maximum absolute errors
35were 1.53e-5 (16,17) and 1.91e-6 (29), or 1.6-2.1e-7 of maximum output
36magnitude. See `build/scalar-vs-avx2-floats.log`. All Strata AVX2 results
37were bit-identical to the corrected ggml AVX2 build.
38
39## IQ1_M singleton chunks
40
41At one token, consume each decoded 64-weight chunk immediately instead
42of storing four decoded chunks (1 KiB/block) and then rereading them.
43The integer lanes, float scale products, FMA order and reduction stay
44unchanged. Multi-token calls retain the decoded-chunk sharing path.
45
46Paired 1.5 GB ABBA runs gave own throughput at one thread of 2.7 / 3.0 /
472.8 / 2.5 GB/s (baseline / candidate / candidate / baseline); the last
48baseline also suffered a large ggml slowdown, so these are noisy.
49At eight threads the corresponding figures were 13.7 / 16.4 / 15.9 /
5013.5 GB/s. Within-process ggml throughput stayed 10.8-11.1 GB/s for those
51four eight-thread runs. This supports a roughly 17-20% eight-thread gain
52from the kernel change; it is not a second several-fold improvement.
53Logs: `build/confirm-{base,direct,direct2,base2}-iq1m-t{1,8}.log`.
54
55Direct `--k256 --mb 10` checks passed bitwise for 16/17/29 at 1,2,4,8
56tokens, with no exactness fallback. Expert pipeline comparisons also
57passed. See `build/direct-exact-validation.log`.
58
59A ternary activation LUT prototype was exact but slower (0.4 vs 2.7 GB/s
60single-thread own throughput), and was discarded. Its table occupied
61about 207 KiB per thread at gate width; scalar lookup/index work and
62preparation did not pay off. Log: `build/lut-iq1m-t1.log`.
63
64## Per-call scheduling
65
66`--expert --lane` uses the production `ds4::Pool`, one expert per gate/up
67and down dispatch, and serial h quantization. It does not emulate disk
68reads, slot copies, NUMA splits, CUDA synchronization or other engine
69work. It changes no production scheduling.
70
71At `--nt 1 --threads 8 --mb 256 --reps 2`, corrected AVX2 auto throughput
72was 31.2 / 28.1 GB/s for type 16, 30.7 / 29.8 for 17, and 19.6 / 18.3
73for 29 (batched / one-expert calls). All pipeline results were bitwise
74identical to ggml. This synthetic per-call cost is modest; the engine's
75old two-fold gap cannot be attributed to dispatch alone from this test.
76Reprofile the corrected full engine before tuning production row chunks.
77Logs: `build/scheduling-type{16,17,29}-lane{0,1}.log`.
78
79## Store completion wait race
80
81The store checked a slot's pending-read count before `IoQueue::wait_any`
82snapshotted its completion generation. A completion in between could make
83the waiter sleep until the two-millisecond timeout. The optional pending
84count is now checked in the wait predicate under the notification mutex.
85This changes neither expert arithmetic nor output accumulation order.
86
87The `ds4_pool_test` regression passes for completed requests, a successful
88copy and cancellation. Restoring the old notification-only predicate makes
89the completed-request case fail (one-second timeout, 500-ms threshold).
90CTest passed 1/1 on focalor.
91
92This is not a measured decode-throughput improvement. On the 64-token
93full-engine recipe, exact routing was 8.34 tok/s baseline and about 8.3
94with the fix; Cache-Prior lambda=0.3/keep=3 remained about 12.1 tok/s.
95The fix's two 64-token runs matched each other and the baseline stdout
96for both routing configurations. The first 48-token exact baseline had
97different tokens from later runs, so its apparent 8.03-to-8.37 increase
98is not evidence for the change.
99
100Artifacts: `build/lane-{base64-exact,io64-exact-a,io64-exact-b,base64-cp,
101io64-cp-a,io64-cp-b}.{stdout,stderr,json}`, `build/io-old-predicate-test.log`,
102`build/io-fix-test-summary.txt`. Baseline source: b0185826; immutable baseline
103and candidate executables are `build/strata-dsv41-lane-base` and
104`build/strata-dsv41-io-wait`. The CPU pool's source diff is preserved in
105`build/io-wait-candidate.patch`.
106
107## CPU store without relocation copies
108
109`DS4_STORE_INPLACE=1` leaves each CPU-only matrix at the address where its
110aligned read lands it. `ExpertStore::mat` returns that address. This avoids
111an extra full-matrix memmove on every cache miss. Prompt staging now reads
112the store's three matrix pointers rather than assuming a canonical blob.
113GPU-mapped slots retain the canonical layout; the option is disabled with
114`DS4_STORE_ZC`. The default remains unchanged.
115
116On the same 64-token recipe, canonical versus two in-place runs:
117
118| Routing | Canonical tok/s | In-place tok/s | GPU ms/token canonical / in-place |
119| --- | --- | --- | --- |
120| Exact | 8.27 | 8.83, 8.73 | 119.79 / 112.10, 113.44 |
121| Cache-Prior 0.3, keep 3 | 12.01 | 12.62, 12.63 | 82.22 / 78.18, 78.16 |
122
123For Cache-Prior, GPU waiting for the CPU lane fell from 61.10 to
12457.09/57.07 ms/token, and store read waiting from 29.7 to 27.0/26.9 ms.
125At the final profile checkpoint the per-call IQ gate/up stage fell from
1260.410 to 0.357/0.362 ms, down from 0.214 to 0.191/0.194 ms (prefill calls
127are included in these running averages). Miss counts, cache movement
128and bytes/token were identical in this confirmation batch.
129
130Each routing recipe's three 64-token stdout files compare byte-for-byte:
131canonical versus in-place and repeated in-place.
132No integer arithmetic, precision or floating reduction order changed.
133The synthetic `ds4_store_layout_test` checks unaligned offsets, buffered
134and direct reads, slot reuse, read failures, and canonical GPU-mapped
135layout even when the in-place option was requested. CTest passed 2/2
136with this and `ds4_pool_test`.
137
138The 48-token screening run gave exact 7.77 -> 9.01 tok/s and Cache-Prior
13912.17 -> 12.84, but use the 64-token confirmation above for the gain.
140Logs are `build/lane-raw64-{canonical,exact-a,exact-b,canonical-cp,cp-a,
141cp-b}.{stdout,stderr,json}` and `build/lane-raw-{canonical,inplace,
142canonical-cp,inplace-cp}.*`. Runs were batched under the approved
143`gpu_run.py` service lease inside `/tmp/ds41-bench.lock`.
144
145## Streamed CPU-lane batches (ana/lane2)
146
147`DS4_LANE_STREAM=1` (NH 1, i-quant experts, RAM store) computes a window's CPU-lane experts in one pool batch: the
148entries whose reads are done first, then the misses in the order their reads started; each entry's gate/up jobs, then
149its down jobs. `DS4_STORE_PIECE_KB=n` (in place only) reads each missed matrix in n KB pieces (gate and up interleaved,
150then down), and a job waits only for the pieces holding its rows; a piece whose read failed is read from the file's
151mapping. An entry's last gate/up job quantizes its h, which its down jobs wait for. Every row is the same call on the
152same rows into the same slot as `cpu_experts_iq`: no integer, precision or float-order change.
153
154Paired 64-token runs (frozen profile, `DS4_PROF=1` in every arm), with `DS4_STORE_THREADS=16`:
155
156| Recipe | Before tok/s | Stream + 1 MB pieces tok/s | GPU ms/token |
157| --- | --- | --- | --- |
158| Exact | 9.01, 9.01 | 9.71-9.80 | 110 -> 101 |
159| Exact + read-ahead (top-3) | - | 9.80-9.90 | |
160| lambda 0.3, keep 3, read-ahead | 13.89, 13.89 | 14.71-14.93 | 70.7 -> 66.4 |
161
162Stdout hashes matched the baseline in every run (exact 36c021ba70, Cache-Prior b2838ebf36).
163
164Measured and discarded: stream without pieces (+2.7% only); 256 KB pieces with 8 reader threads (8.47); 2 MB
165pieces, 512 KB pieces, 8/12/24/32 reader threads (all within 9.5-9.8); the store arena on transparent huge pages
166(72 s of compaction at preload, 7.56 tok/s); `DS4_CPU_SMT` pool on both hardware threads of each core (exact 9.62 ->
1679.26, Cache-Prior 14.93 -> 14.49); a dynamic order taking a missed expert's job as soon as its pieces land and RAM
168hits otherwise (unchanged, 9.80 / 14.93); capping concurrent guess reads at 4 or 8 (unchanged).
169
170Where the exact lane's time goes now (`ds4 prof CPU lane (IQ stream)`): 32 calls a token, 2.97 ms each, the last
171missed piece in at 2.19 ms on average and ~0.8 ms of compute after it. fio on /strata-fast: 1 MB direct reads at
172queue depth 16 give 7.9 GB/s with 2.1 ms mean latency; depth 8: 6.3 GB/s; depth 4: 4.9 GB/s. A layer's ~12 MB of
173misses arrive together, so the exact recipe is bound by the miss bytes per layer, not by compute order.
174
175IQ1_M rows: maddubs by ones instead of |g| (sign(q8, g) is already 0 where g is: the same int16 pair sums).
176`ds4_gg_bench --expert --type 29 --dtype 29 --nt 1`, two rounds: 1 thread 3.0/3.1 -> 3.2/3.1 GB/s, 8 threads
17719.8/20.3 -> 20.7/20.7. `--k256` bit-identical at 1, 2, 4 and 8 tokens. Gathered grid loads (18.5/17.9) and
178movq/movhps pairs (19.0/18.8) were slower and were dropped.