The previous commit skipped the fused up-mix (STRATA_HC_UPMIX) whenever STRATA_HIP_PROMPT_F16=1, which is correct but gives up
its speed. gr_upmix_kernel now has an FP16 path, taken when the activation image is FP16 (g_act_f16, set by Prefill::init with
Gemm::set_f16_io): the lo16 fragments are read as FP16 and multiplied on __builtin_amdgcn_wmma_f32_16x16x16_f16_w32, the BF16
W_up rows are converted to FP16 while they are staged in LDS (bf_to_hf_conv, the conversion the FP16 GEMM route applies; a BF16
value is exact in FP16 above 6e-5), FP32 accumulate in the same K order as the BF16 kernel. The guard of the previous commit
is removed again. With FP16 io off the kernel takes the BF16 path it took before (one uniform branch).
New test hip_gr_upmix_parity (src/prefill/gr_upmix_parity.cu on HIP; exit 77 off gfx11): the BF16 cases against the default
pair (the 20 sizes from T = 1 to 8192 pass on a Radeon 780M) and six FP16-io cases (T = 33 to 8192) against an FP64 reference and
against the FP16 pair: the fused kernel's error against FP64 is 1.6e-7 to 3.6e-7 of the largest value, the pair's (its GEMM
output rounded to FP16) 6.2e-5 to 1.2e-4.
Radeon 780M, Q2_0 pack, forced-token KL against the FP16 path (24 prompts of 2,048 tokens, 64 forced tokens each, draft-cost
table fixed, repeat arms equal their first run byte for byte), STRATA_HIP_PROMPT_F16=1: fused experts beside it 0.00598 (ratio
to the MMQ arm 1.101, 95% CI 0.954 to 1.248, top-1 97.53% against 97.27%); alone 0.00593 (ratio 1.091, CI 0.968 to 1.231, top-1
97.46%). Before this change with the up-mix skipped: 1.075 and 0.914; before either: 166 and 171 times. Prompt tok/s medians of 3
rounds, ratio to nothing set: fused + FP16 io 300 tokens x1.111, 1,000 x1.152, 2,048 x1.628, 8,192 x1.450; FP16 io alone
x1.114 / x1.152 / x1.193 / x1.251 (with the up-mix skipped: x1.087 / x1.113 / x1.569 / x1.389 and x1.088 / x1.113 / x1.161 / x1.207).
Without STRATA_HIP_PROMPT_F16=1 nothing changes: the nothing-set arm is byte-identical to the old default.
prefill_expert_paths_bench (CUDA) and hip_prefill_expert_paths_bench (HIP) time one layer of routed experts on synthetic weights, no model file:
MMQ where the build has it, the dequantize + FP16 GEMM path (the library calls of prefill.cpp's FP16 branch, in its order), the same with the few-row
experts on the quantized grouped kernels, one grouped call for the whole layer (the Qwen3.6 engine's fallback), and the fused kernels where the card has
them. Median of N repeats after a warm-up, speed ratios against MMQ, error against a CPU FP32 reference on a sample of pairs, an output hash per path,
VRAM used, one machine-readable RESULT line per cell. Runs on cards without fused kernels and in builds without MMQ.
--dense times strata::prefill::Gemm at the dense prompt shapes of the compiled geometry (the call sites in prefill.cpp) with set_f16_io off and on
(STRATA_HIP_PROMPT_F16), with the error against the CPU reference.
Test and CMake wiring only (a ctest smoke entry for each backend); no product source is touched.
f-p4-q36 6d10d61e7 brings a96d13e1a (the Q5_K / Q6_K down projections of the Qwen3.6 fused kernels join the weight-staging rings)
and the lane's merge of f-p4-sm 98e21c171, so f-p4-sm 98e21c171 comes in through it: a failed weight-staging check
(check_staged_blobs / staged_blobs_ok) no longer ends the process, the launch takes the unstaged kernel (launch_ww, used by
experts_native_ext and by the Qwen3.6 copy).
One conflict, src/prefill/moe_fused_iq.cu, two adjacent hunks after pick_ww: this branch (f-own-4h) closes the decode-only guard
and the anonymous namespace there ("#endif / } // namespace / #if !defined(STRATA_FUSED_DECODE_ONLY)"), the lane inserts launch_ww,
the namespace close and staged_blob_fallbacks. Resolution: launch_ww stays in the anonymous namespace before the "#endif", the
namespace close and the guard reopening are kept as in this branch, staged_blob_fallbacks follows the reopened guard (it reads
g_staged_mu and g_staged_fallbacks, which sit inside the guard). Nothing else is changed by hand.
The merge is textually clean. On top of it, in the merge commit:
- experts_native_ext (moe_fused_iq_q36.cu) takes its ww from launch_ww(b, g, n, n_expert, staged, wide) instead of pick_ww plus the old check_staged_blobs
call (which the merge renamed to staged_blobs_ok). staged and wide are what the K-quant down commit passed: staged = sw_on(gu_type, true) ||
sw_on(d_type, false) (the Q5_K / Q6_K downs are staging instances, K = 512), wide = the gate/up is Q6_K or Q8_0 (false for the Q4_K / Q5_K gate/up of
this path). A staged K-quant launch whose expert blobs are not device memory at 2-byte aligned addresses now takes the unstaged 64-row kernel, sticky for the
process, one log line, no exit, like every other launch of the copy.
- prefill_fused_q36_test takes --host-blobs=N [--expect-fallback | --expect-no-fallback] (the first N experts' blobs in pinned, mapped host memory; timing
part; MMQ is not run for those pairs), as prefill_fused_iq_test does; moe_fused_q36.hpp declares the copy's staged_blob_fallbacks(); ctest entry
prefill_fused_q36_test_hostblobs (Q4_K / Q5_K, 2,048 tokens).
Checked on RTX A6000 (sm_86, CUDA 13.1): the five pairs' output bits hashes at tile default / 64 / 128 and 2048 / 4096 / 8192 / 20000 tokens are the
ones of the K-quant down commit (20 of 20, three tiles); the three K-quant pairs with --host-blobs=1 take the unstaged kernel (one log line, 346 to
1,198 launches counted over the pairs, no exit), at the default tile and with STRATA_PF_FUSED_TILE=128 forced, and their hashes are the all-device
run's (6 of 6, both).
check_staged_blobs ended the process with std::exit(1) when an expert blob was not device / managed memory, or a row size or offset was odd.
No default configuration reaches it (the prompt path passes expert-cache slots and stage-ring slots), but the engine must not exit there.
The check is now staged_blobs_ok (bool) and launch_ww combines it with pick_ww: a launch that fails it gets ww = 4 (fused_tile::kUnstagedWw),
the 64-row instances, which no weight-staging instance shares, also when STRATA_PF_FUSED_TILE=128 forces the 128-row tile. The output bits
are the same (the identity tables of RESULTS-P4-SM.md: tile 64, 128 and the default hash equal). The first failing launch of a process logs one
line to stderr. The check still runs on the first 256 launches only (a pointer query is a driver call); the decision is sticky: once one launch
failed it, every later launch of the process takes the unstaged kernel without asking, because after the first launches nothing is checked any
more and a call site that gave one bad blob will give more.
The decision is a set of pure functions and a small state struct in fused_tile_rule.hpp (staged_geometry_ok, staged_blob_ok, StagedGuard),
tested on the host in fused_tile_rule_test (blob memory kinds x addresses, the 16 odd / even geometries, the 256-launch budget, the sticky
fallback, one log line). moe_fused_iq.hpp declares staged_blob_fallbacks(), the number of launches that took the fallback (0 in a HIP build).
prefill_fused_iq_test takes --host-blobs=N (the first N experts' blobs in pinned host memory, timing part) with --expect-fallback /
--expect-no-fallback; ctest entry prefill_fused_iq_test_hostblobs.
moe_fused_iq.cu is also compiled a second time for the Qwen3.6 shape (moe_fused_iq_q36.cu includes it under a renamed namespace): the new
names are inside the included source and carry no `fused` token outside namespaces, the state is per copy. A dispatch of that copy that
launches staging instances itself (experts_native_ext) takes its ww from launch_ww(b, g, n, n_expert, staged, wide) instead of pick_ww.
prefill_fused_group_test (f-p4-small) and prefill_fused_q36_test (f-p4-q36) named strata_mmq in
target_link_libraries; a build with -DSTRATA_MMQ=OFF has no such target, so both now link
${_strata_pf_tests_lib} (strata_mmq with MMQ, strata_pf_own without). With MMQ nothing changes.
prefill_fused_group_test returns 1 where mmq::built() is false (no no-MMQ rule yet), so it is
registered only with STRATA_MMQ; prefill_fused_q36_test has its no-MMQ rule and is built both ways.
tests/cuda/prefill_fused_q36_test.cpp is the counterpart of prefill_fused_iq_test.cpp for the second copy of the kernels (strata::prefill::fused_q36,
moe_fused_q36.hpp): the existing test is built for the compiled geometry (Flash-Next's 2560 / 640) and cannot reach it. Pairs: UD-Q6_K_XL's Q6_K / Q8_0
(40 layers) and Q8_0 / Q8_0 (1), the Q8_0 file's Q8_0 / Q8_0. Part 1, per pair: 256 tokens over 64 experts with skewed routing (experts with no row, with
one, with several 64-row tiles), an all-zero token, expert blobs at unrelated 2-byte aligned addresses, three launches over different expert ranges, then
33 / 1 / 130 / 517 tokens; the fused path against a double-precision reference (ggml's to_float), against the same with the kernels' int8 rounding of the
activations and H per 32 values ("the int8 model"), and against the MMQ path in prefill.cpp's sequence. Part 2: one layer at 2048 and 8192 tokens over
256 experts at top 8, MMQ and fused alternating (medians), the grouping checked, a 96-pair sample against the reference, and a hash of the fused
output's bits (so two builds or two tile choices can be compared bit for bit). Rules as the existing test's: the fused path against the int8 model at
2e-3 rel RMS / 3e-2 worst row, FP32 distance at most 1.5x / 2x MMQ's; for a pair without MMQ the rule of e22f397d0 (the model's own distance under a
ceiling, the fused path at most 1.15x / 1.5x of it plus 1e-3). Exit 77 without an sm_80 device. ctest entry prefill_fused_q36_test.
RTX A4000 (sm_86, CUDA 12.9, z440-20261111-2016-c3b9; the file as it was then: the bits hash line, the comment above the ceilings and the run without MMQ
in main were added after that run and are compiled and run in the next z440 job), both pairs, all shapes: pass. Fused against the int8 model rel RMS 2.3e-7 to 2.6e-4 (worst row
3.2e-7 to 3.9e-3); fused against FP32 equal to MMQ's to four digits (rel RMS 1.53e-2 to 1.63e-2); fused against MMQ rel RMS up to 2.9e-4 (worst row up to
5.0e-3). The int8 model's own distance to FP32 (largest 1.634e-2 / 3.013e-2) is in the comment above the ceilings. One layer, MMQ / fused ms: Q6_K + Q8_0
2048 tokens 9.479 / 8.459, 8192 tokens 19.868 / 31.224; Q8_0 / Q8_0 9.895 / 7.095 and 19.086 / 29.253.
Qwen3.6 runs its prompt experts on llama.cpp's MMQ wherever MMQ exists, and on its own older grouped kernels (0.35-0.41 of MMQ's prompt speed on a
Tesla P100) elsewhere. Strata's fused int8 kernels (moe_fused_iq.cu) are compiled for one geometry, kCompiledGeometry (2560 / 640 for Flash-Next), so
they could not be used for a 2048 / 512 model in the same binary.
src/prefill/moe_fused_iq_q36.cu includes moe_fused_iq.cu a second time with the geometry set to 2048 / 512 and the namespace renamed to
strata::prefill::fused_q36 (a #define of `fused`), after processing the system and Strata headers the original includes once. moe_fused_iq.cu is not
changed: every function of the existing copy keeps its code, and every name of the second copy is its own. The one function of moe_fused.cu the kernels'
rules call (requested()) is forwarded to the original. include/strata/prefill/moe_fused_q36.hpp is the hand-written API (Batch, NativeGeom,
native_supported, quantize_act_native, experts_native) with static_asserts that the copy's types agree with it. CUDA only; the file is empty under hipcc.
The only shared edit is the guarded shape hook in moe_fused.hpp: kMoeEmbd / kMoeFF take STRATA_FUSED_GEO_N_EMBD / _N_FF when both are defined, and the
compiled geometry otherwise (nothing else defines them).
Nothing calls the new entry points yet (the engine wiring is the next commit); no default and no setting changes.
Device code (the gate of the hook), measured on the tree of this commit together with the two that follow it (the test and the engine wiring, which add no
device code): RTX PRO 5000, sm_120, CUDA 13.2 (l620-20261111-2127-04e5), strata-q36 of f-own-int 9bef5255d against that tree: 2,767 functions in the base,
base against base rebuilt 0 differing, base against the tree 0 differing, 0 only in the base, 76 only in the tree (the second copy's instances);
libstrata_kq.so 256 functions, 0 differing. sm_86 was not run for this commit (the one-layer test of the next commit and
the engine runs ran on an RTX A4000, sm_86, with this code). HIP: not compiled (the hook is under a macro nothing defines in a HIP build and the new file
is empty there).
Nine conflicts, one hunk each, all of the kind "ds-out removes DeepSeek next to a line that
main's fixes bundle (c1ff07f1a) or f-agent-turn changed". Resolved by keeping the other side's
addition and ds-out's removal (resolutions a-i accepted by the coordinator):
- apps/host/src/lib/native-fit.ts FitInput, apps/host/src/lib/native.ts NativeSize: ds-out's line
(no DeepSeek fields or note) plus main's context_fit field.
- apps/host/src/components/GuidedSetup.tsx, NativeModels.tsx imports: contextCacheGb kept,
deepseekContexts / OLD_DEEPSEEK_CONTEXT out.
- apps/host/tests/ui-r3.test.mjs: ds-out's first assert, main's second (context_fit).
- serve/server.py READY line: f-agent-turn's can_hold kept, the DeepSeek self.multi read out.
- strata_cli/launch/cmd.py: ds-out's suppressed --speed / --full-quality, main's new --gpu help.
- strata_cli/launch/screens.py: ds-out's STEP_LABELS, main's middle_shorten kept,
speed_choice_available out.
- data/settings-register.json: the 39 STRATA_DS4_* entries out.
The register's stale "line" values are not regenerated here.
UD-Q6_K_XL's 47 layers (and UD-Q5_K_XL's one Q6_K layer) have a Q6_K gate/up with a Q8_0 down. On gfx1200 / gfx1201 they
ran on MMQ (the K-quant library, STRATA_MMQ_KQ=1). STRATA_PF_FUSED_Q6K, CUDA's switch for the same layers, now means the
same there: a Q6_K gate/up with a Q8_0 down takes native_w11_kernel's new Q6_K gate/up instance.
Kernel: none edited. load_unit / convert<T_Q6_K> are the shared decode (CUDA's bits), 256-value superblocks with an int8
scale per 16 values, native_w11's existing per-16 path; the unit / sub lambdas need no change. Host (HIP only):
q6k_hip_requested(), gu_covered and d_covered_on take the pair on gfx12 when it is set, native_supported pairs a Q6_K
gate/up with a Q8_0 down only, experts_native launches native_w11_kernel<T_Q6_K, true> (the plain launch). Off by
default; gfx11 unchanged (the instance is compiled for gfx1151 but no host rule reaches it there).
Test: hip_prefill_fused_iq_q6k (--only="Q6_K + Q8_0" --edge --no-timing, STRATA_PF_FUSED_Q6K=1, STRATA_MMQ_KQ=1); the
trellis skip rule of the test also skips the Q6_K pair on a card that is not gfx12. Settings register: STRATA_PF_FUSED_Q6K
lists the HIP read (note marked [DRAFT], status research).
R9700 (p620, gfx1201), base f3608ce31 vs this tree, same folders and flags:
- build commands identical, warnings 4,454 / 4,454
- device code: one new function (native_w11_kernel<Q6_K, true>) in the engine (3,936 -> 3,937), moe_fused_iq.cu.o
(91 -> 92) and hip_prefill_fused_iq (1,349 -> 1,350); hip_prefill_decode_golden identical; 38 existing functions differ
in 62 lines, all 62 are the PC-relative address constants of a table, none other
- new instance: 227 VGPRs, 0 scratch instructions on gfx1201 (no spill); gfx1151: 256 VGPRs, 7 scratch instructions
(not reached by any host rule)
- decode digests 136 / 136
- Q6K entry PASS: fused vs the int8 model <= 7.1e-5 rel RMS, fused vs MMQ <= 3.2e-4 (limit 1e-3), fused and MMQ the same
distance from FP32 (1.4-1.6e-2); not covered without the switch or under Q8GU alone (rc 1); the Q8GU and Q8D entries
still PASS
- default run: all 12 output hashes equal the base's; hashes repeat over two runs
- one layer, fused / MMQ path: 3.32x / 2.74x / 2.30x at 2,048 / 3,584 / 8,192 tokens
- CUDA side (l620, RTX PRO 5000 sm_120, CUDA 13.2, same folder and flags): compile command identical; moe_fused_iq.cu.o
SASS identical (70 functions), decode test SASS identical (20), prefill_fused_iq_test SASS identical (1,209); decode
digests 136 / 136; the CUDA Q8GU and Q6K entries pass; warnings 6 / 6
The Q8_0 set's 48 layers (and UD-Q6_K_XL's one Q8_0 layer) have a Q8_0 gate/up and a Q8_0 down. On gfx1200 / gfx1201
they ran on MMQ. STRATA_PF_FUSED_Q8GU, CUDA's switch for the same layers, now means the same there: a Q8_0 gate/up
with a Q8_0 down takes native_w11_kernel's new Q8_0 gate/up instance.
Kernel: a Q8_0 gate/up has 32-value blocks, two a stage, like the Q8_0 down, so the unit / sub lambdas of
native_w11_kernel no longer treat it as a 256-value superblock (a constexpr GU256 = GU && WT != T_Q2_0 && WT != T_Q8_0;
every other instance's code is unchanged). Host (HIP only): q8gu_hip_requested(), gu_covered and d_covered_on take the
pair on gfx12 when it is set, native_supported pairs a Q8_0 gate/up with a Q8_0 down only (and an i-quant / K-quant
gate/up keeps its own rule: STRATA_PF_FUSED_Q8D or the K-quant route), experts_native launches
native_w11_kernel<T_Q8_0, true> (the plain launch). Off by default; gfx11 unchanged.
Test: hip_prefill_fused_iq_q8gu (--only="Q8_0 / Q8_0" --edge --no-timing --no-kq, STRATA_PF_FUSED_Q8GU=1). The test's
--no-kq probe uses the Q8_0 / Q8_0 pair when that switch is set. Settings register: STRATA_PF_FUSED_Q8GU lists the HIP
read (note marked [DRAFT], status research).
R9700 (p620, gfx1201), base 041591f1d vs this tree, same folders and flags:
- build commands identical, warnings 4,454 / 4,454
- device code: one new function (native_w11_kernel<Q8_0, true>) in the engine (3,935 -> 3,936), moe_fused_iq.cu.o
(90 -> 91) and hip_prefill_fused_iq (1,348 -> 1,349); hip_prefill_decode_golden identical; 38 existing functions differ
in 62 lines, all 62 are the PC-relative address constants of a table (s_add_u32 / s_add_co_u32 sN, sN, 0x...), none
other
- new instance: at most 184 VGPRs (gfx1201) / 222 (gfx1151), no scratch instructions (IQ3_S gate/up 181 / 219)
- decode digests 136 / 136
- Q8GU entry PASS: fused vs the int8 model <= 9.0e-5 rel RMS, fused vs MMQ <= 1.4e-4, fused and MMQ the same distance
from FP32 (1.56-1.60e-2); not covered without the switch or with only the K-quant switch (rc 1); an i-quant / Q8_0
pair under Q8GU alone is not covered (rc 1); the Q8D entry still PASS
- default run: all 12 output hashes equal the base's; hashes repeat over two runs
- one layer, fused / MMQ path: 4.22x / 3.72x / 3.08x at 2,048 / 3,584 / 8,192 tokens (5.83 / 24.6 ms at 2,048)
- CUDA side (l620, RTX PRO 5000 sm_120, CUDA 13.2): compile command identical; moe_fused_iq.cu.o SASS identical (70
functions), decode test SASS identical (20), prefill_fused_iq_test SASS identical (1,209); decode digests 136 / 136;
the CUDA Q8GU entry passes
Gyro-S (TQK6 gate/up, TQK7 down) and Gyro-M (TQ2_T both) read their prompt on MMQ on every AMD card. With
STRATA_PF_FUSED_TQ=1 (CUDA's switch, same meaning) they take native_w11_kernel on gfx1200 / gfx1201:
- the trellis decode (load_unit / convert / grid_src: 15-bit states, MMQ's int8 codebook tq_lut_i8, one scale a 128-value
block) and the block-Hadamard kernels (fwht128_warp, hadamard128_kernel, rot_quant_h_kernel, hadamard128_rows) are no
longer CUDA-only; a local constant in the TQK load_unit renamed NW -> NWD (it shadowed the template parameter: clang
refuses that, nvcc warned);
- native_w11_kernel: 128-value block addressing for the trellis types (a block per two stages, sub-blocks 0-3), and for a
folded down the gate/up writes H as FP32 into the row's own down-output row, which rot_quant_h_kernel rotates and
quantizes before the down product (CUDA's dm-row invariant);
- host, HIP only: tq_hip_requested(), gu_covered / d_covered_on for the trellis types on gfx12, the pairing and geometry
rule in native_supported (TQK6 + TQK7, TQ2_T + TQ2_T only), the launches in experts_native.
gfx11 keeps MMQ (not measured). Off by default.
Tests: ctests hip_prefill_fused_iq_tq / _tqh (STRATA_PF_FUSED_TQ=1; another AMD card skips with 77); the decode-digest
test decodes all 17 formats on HIP. Settings register: STRATA_PF_FUSED_TQ lists the HIP read (status research).
R9700 (p620, gfx1201), base c5c26171e vs this tree, same folders and flags:
- build commands and warnings (4,454) identical
- device code: only in new native_w11_kernel<144, true / false>, <145, true>, <146, false>, hadamard128_kernel,
rot_quant_h_kernel (engine 3,929 -> 3,935 functions); existing functions differ only in the PC-relative address
constants of the device tables (the new 4 KB codebook moves them), no other instruction
- decode digests 136 / 136 equal the CUDA-written file (the trellis decode gives CUDA's bits on gfx1201)
- _tq: fused vs the int8 model <= 8.7e-5 rel RMS, vs MMQ <= 3.1e-4; _tqh (folded): <= 2.1e-4 / <= 3.2e-4; fused and MMQ
the same distance from FP32; without the switch the pairs are not covered
- default run: 12 / 12 output hashes equal the base's; trellis hashes repeat run to run
- one layer, fused / MMQ path at 2,048 / 3,584 / 8,192 tokens: TQK6 + TQK7 3.28x / 1.67x / 1.51x (folded 3.20 / 1.63 /
1.47), TQ2_T + TQ2_T 3.26x / 1.65x / 1.49x (folded 3.19 / 1.61 / 1.44)
CUDA (l620, RTX PRO 5000 sm_120, same folder and flags): moe_fused_iq.cu.o SASS identical (70 functions), the decode
test SASS identical, decode digests 136 / 136.
End to end: not run (no Gyro set on p620).
A new option, STRATA_MMQ (default ON: every build stays as it is). Off, strata_mmq,
strata_mmq_w4a4 and strata_kq are not built; Strata's own prompt kernels
(strata_pf_own: the fused experts and moe_helpers.cu) are, with
src/prefill/mmq_absent.cpp for the MMQ half of moe_mmq.hpp (every query answers
"no MMQ"; the calls that would launch an MMQ product cannot be reached and stop
with a plain message instead of leaving garbage). CUDA: MMQ iff STRATA_MMQ. HIP:
MMQ iff STRATA_PREFILL_MMQ and STRATA_MMQ; a HIP build without
STRATA_PREFILL_MMQ now builds Strata's own kernels (it built neither before).
A new name rather than STRATA_PREFILL_MMQ: every CUDA build folder configured
before has STRATA_PREFILL_MMQ=OFF in its cache.
- CMakeLists.txt: the option; strata_cuda_mmq / strata_cuda_pf_own and
strata_hip_mmq / strata_hip_pf_own, then the prompt tests
(strata_cuda_prompt_tests / strata_hip_prompt_tests, cut from the end of the
MMQ macros: the same tests in the same order with MMQ).
- prefill.cpp: the all-stub block only where neither library is linked
(no native experts, Metal), as before.
- prefill_fused_iq_test / prefill_fused_moe_test: without MMQ they check the
fused path against the references alone (the iq test's existing no-MMQ bound,
rel RMS 0.03 / worst row 0.25; the moe test takes the same bound).
- tools/check_no_mmq.py (+ test): llama.cpp's MMQ names in a binary's bytes, its
symbols (nm) and its device functions (cuobjdump); ctest no_mmq_symbols runs it
on strata and strata_pf_own in every build without MMQ.
A request that resumes from a checkpoint parks the live branch first. When that checkpoint is the live branch's own turn checkpoint (the history before its last assistant turn), the live branch holds nothing else past it, and the prompt opens the same assistant turn there again, the client has re-sent the history with that reply dropped (an OpenAI-style client sends every earlier reply back without its reasoning), edited, or regenerated. That branch is no longer parked: no request of the client sends the reply back as it was, and the park copied the whole conversation to host memory on the request's path (131-209 ms per turn at 2K-20K on an R9700, lane PERF-AUDIT's chat run) for a copy the next park dropped as superseded.
The rule is live_tail_is_replaced_reply() (include/strata/program/reply_branch.hpp, test src/program/reply_branch_test.cpp): live[resume] and ids[resume] open a turn with the same role token, live has no other turn after it, and both agree before resume. generate.cpp asks it only when nothing else comes in (no parked conversation restored, no borrow, no batch slot, no lent slot, same cvec, no pin sibling) and the live branch has no picture at or past resume. Reuse is unchanged: the request reads from the same checkpoint as before. A real switch to another conversation parks as before. New engine log line [DRAFT]: "conversation cache: the reply this request replaces is not parked (N tokens past the turn checkpoint at M)".
Lane AGENT-TURN, P3.
fused::group_bounds(bounds, n, scratch, stream) writes the fused kernels' tables
(counts, offsets, the 64-row tile list) for one gathered group: its experts get the
local indices 0..n-1, expert e the rows [bounds[e], bounds[e+1]) of the group, the
form the layer-major and staged walks already keep for MMQ. experts_native then
runs the group's gate/up, SwiGLU and down in one launch pair, reading each expert
where it is, with the rows' tokens from the walk's own row-token table. Nothing
calls it yet (the walks follow in the next commits); a stub for builds without the
fused kernels.
tests/cuda/prefill_fused_group_test (ctest prefill_fused_group_test): builds the
walk's tables on the host as lm_run does (rows sorted by expert, entries cut at the
group cap, groups of at most 16 entries) and checks, per native format pair the
device takes, that the group entry gives the SAME bits as the layer's fused path
(fused::group + experts_native, the streamed walk's call) for every routed row,
with unwritten rows caught as NaN, and prints both paths' distance to MMQ in the
walk. Cases: 55 / 300 / 1,000 tokens over 512 experts; 2,048 tokens over 128
experts, skewed routing, cap 700 (experts split over groups).
RTX A4000 (sm_86, CUDA 13.0): PASS, 8 pairs x 4 cases, 0 differing rows.
The pinned UD-IQ4_XS's five Q8_0-down layers (IQ3_S / Q8_0 4, IQ4_XS / Q8_0 1) left the fused path for MMQ on gfx12
unless STRATA_PF_FUSED_KQ=1, whose meaning is the K-quant experts. STRATA_PF_FUSED_Q8D, CUDA's switch for the same
layers, now means the same on gfx1200 / gfx1201: d_covered_on takes a Q8_0 down there, and native_supported keeps the
Q2_0 gate/up + Q8_0 down pair on MMQ unless STRATA_PF_FUSED_KQ=1 (as on CUDA; the K-quant route's wider rule is
unchanged). Host code only: the gfx12 int8 Q8_0 down instances of native_w11_kernel already exist. Off by default;
gfx11's rules (STRATA_PF_F16, q8d_f16_default) unchanged.
Test: hip_prefill_fused_iq_q8d (the i-quant / Q8_0 pairs, --edge, STRATA_PF_FUSED_Q8D=1) with the new --no-kq flag
(the test leaves STRATA_PF_FUSED_KQ unset; without the switch, or off gfx12, it skips with 77).
Settings register: STRATA_PF_FUSED_Q8D lists the HIP read (status research, not on the users' page).
R9700 (p620, gfx1201), base 6b32d91c5 vs this tree, same folders and flags:
- device code: engine 3,929 / 3,929 functions, moe_fused_iq.cu.o 84 / 84, hip_prefill_fused_iq 1,342 / 1,342,
hip_prefill_decode_golden 15 / 15: 0 differing, 0 new, code objects identical; build commands and warnings
(4,454) identical; host bytes of moe_fused_iq.cu.o and strata differ, prefill.cpp.o identical
- the Q8D entry: both pairs, all 6 shapes, fused vs the int8 model <= 8.2e-5 rel RMS, fused vs MMQ <= 9.1e-4
(limit 1e-3), fused and MMQ the same distance from FP32; without the switch: skipped (77)
- the same kernels as STRATA_PF_FUSED_KQ=1 takes: one-layer output hashes equal for both pairs at 2,048 / 3,584 /
8,192 tokens (6 of 6)
- default run: all 12 output hashes equal the base's; decode digests 112 / 112
- one layer, fused / MMQ path: IQ3_S / Q8_0 3.74x / 3.03x / 2.54x, IQ4_XS / Q8_0 4.00x / 3.24x / 2.78x at
2,048 / 3,584 / 8,192 tokens (the layer leaves MMQ entirely)
The decode-digest test of the previous commit, built with strata_mmq's own include directories, compile definitions and
compile options (generator expressions on strata_mmq's properties), so the decode compiles as the library compiles it;
on HIP the source is HIP with the compat include directory, as moe_fused_iq.cu. ctest entries check
tests/cuda/prefill_decode_golden.txt (exit 77 without a card). CUDA: inside STRATA_BUILD_TESTS; HIP: beside
hip_prefill_fused_iq.
- src/dsv41, include/strata/dsv41, tests/dsv41, tools/dsv41_lab and data/dsv41 are deleted (no other target
compiled or included them: checked with git grep for includes and CMake references).
- CMake: the STRATA_BUILD_DSV41 block of cmake/strata_gpu_engine.cmake (strata_dsv41_kernels, strata-dsv41, the
ds4_* benches and tests, the hip_extra.h force-include), the CPU-only bench macro (cpu.cmake, CMakeLists.txt),
the DeepSeek default architectures of cuda.cmake and the BMI2-off branch of strata_ggml.cmake. All were behind
STRATA_BUILD_DSV41 (default OFF; the release scripts pass their architectures), so every other target is
configured as before.
- Mac, the two pieces that cannot wait: metal/CMakeLists.txt no longer builds strata_ds4 (it compiled src/dsv41),
and metal/src/engine/exl3_legacy_stub.cpp goes (a member of the strata_metal_kernels glob that included
include/strata/dsv41/exl3.hpp). The other DeepSeek Metal files stay for the separate Metal commit.
- CI: the Metal job builds strata only.
- data/settings-register.json: the 42 names only the DeepSeek engine read go; STRATA_FORCE_AVX2,
STRATA_METAL_KEEP_FREE_GB and STRATA_METAL_LEAVE_SHARE keep their other readers. Every other entry is unchanged
(tools/settings_register.py --check: no difference).
- tests/quant/check_no_ggml.sh: no ds4_gg_cpu pattern.
The gathers of expert blobs (gather_native, gather_native_group, gather_strata_q2),
the SwiGLU passes (swiglu, swiglu_scaled, down_row_scales), iota, matrix_bytes and
q8_bytes leave moe_mmq.cu, text unchanged, for src/prefill/moe_helpers.cu in
strata_pf_own, so that a build without llama.cpp's MMQ keeps them.
Lines moved, of moe_mmq.cu at 9bef5255d (each with the blank line after it):
68-154 (copy16 / copy16_group / copy1 / strata_q2 / swiglu kernels),
204-230 (swiglu_scaled / down_row_scales / iota kernels), 382-388 (matrix_bytes,
q8_bytes), 701-770 (gather_native .. swiglu), 794-798 (iota). moe_helpers.cu has
its own copies of the small helpers both files use (is_tq, type_blck, type_bytes,
ck, pad512, blocks). q8_bytes counts 144-byte block_q8_1_mmq rows from two
constants; moe_mmq.cu checks them against the real struct (static_assert).
No header and no caller changes.
moe_fused.cu and moe_fused_iq.cu (and on HIP moe_f16_kq.cu) leave strata_mmq, the
library of llama.cpp's MMQ kernels, for strata_pf_own. With MMQ (every build today)
strata_pf_own is compiled with strata_mmq's include directories, definitions and
options (strata_pf_own_mirror) and strata_mmq links it PUBLIC, so every target
that linked strata_mmq gets the same objects as before. No source file changes.
This is step 1 of P4-SPLIT: a build without MMQ that keeps the fused kernels.
The gfx906 build adds moe_f16_kq.cu to strata_pf_own (beside moe_fused_iq.cu,
which calls it); tools/test_gfx906_build_files.py follows. The CUDA spill guard
also checks strata_pf_own.
Checks native_gu_rows / native_down_rows against ggml-cpu's one-row dot and
the same SwiGLU, bit for bit, at 1, 2, 3, 4, 8 and 16 tokens per expert, for
six gate/up and down pairs (arm64, where every row takes the one-row loop;
ctest pool_rows_bench_bits). Its speed part times the rows on one thread
with the experts streamed from memory, so a build with the quant layer and
one with ggml-cpu can be compared at the pool's level, which a dot bench
alone does not cover (the arm64 gap of the layer build sat in that loop).
Conflict: tools/test_setup_llama_archive.py, deleted on f-own-int (e43ff9885, no llama.cpp archive
download in the own stack) and changed on main (fd40eb0fd, its urlopen mock moved to netpolicy):
kept deleted.
Phase 4, the trellis commit 2 of 3. The Gyro packs store their experts block-Hadamard rotated (include/strata/kernels/cpu/hadamard.hpp:
W' = W diag(s) H^T per 128 input values), so the down product's input H must be rotated, y = H_128 (s * h) / sqrt(128), before it is
quantized. The fused gate/up writes H as int8 in its epilogue, which cannot be rotated afterwards without a second rounding; MMQ rotates
H in FP32 (prefill.cpp, hadamard_rows after the SwiGLU). So with a folded down (fused::set_down_rotation(true, signs)):
- the trellis gate/up instances write H as FP32 into the first n_ff floats of each row's own down-output row in dm (no other buffer:
the down product rewrites that row only after the next step has read it);
- rot_quant_h_kernel (new) rotates each row's 128-feature blocks (one warp a block, the fast Walsh-Hadamard transform by shuffles) and
quantizes them per 32 values into H's int8 layout (quant_act_nat_kernel's), for the rows of the call's experts only;
- the down product runs as before.
hadamard128_rows (new, host API) applies the same rotation in place to FP32 rows: the test rotates MMQ's H with it. Off by default (no
caller in this commit); with it off every launch is the decode commit's.
Device code: two new kernels (hadamard128_kernel, rot_quant_h_kernel); the four trellis gate/up instances of the decode commit change
(their epilogue's FP32-H branch, taken only when dm is passed); no other function changes. Line numbers of this commit's
src/prefill/moe_fused_iq.cu: 176-240 (fwht128_warp, hadamard128_kernel, rot_quant_h_kernel; CUDA only), 1112-1123 (the trellis
gate/up epilogue's FP32-H branch, if constexpr is_tq), 2533-2550 (set_down_rotation, hadamard128_rows; HIP: a stub that refuses),
2698, 2702 (the trellis gate/up launches pass dm when the rotation is on), 2716-2719 (rot_quant_h_kernel before the trellis down).
include/strata/prefill/moe_fused_iq.hpp:49-56: the two declarations.
tests/cuda/prefill_fused_iq_test.cpp: --folded: the trellis pairs as folded experts with random signs (their own generator): the gate/up
input rotated on the host for every path, the reference's H rotated on the host (from the definition: signs, then the Sylvester
transform, / sqrt(128)), the fused path's H through set_down_rotation, MMQ's through hadamard128_rows. cmake/backends/cuda.cmake: ctest
prefill_fused_iq_test_tqh (STRATA_PF_FUSED_TQ=1, --only="+ T" --folded --edge --no-timing).
Phase 4. Gyro-S (TQK6 gate/up, TQK7 down) and Gyro-M (TQ2_T both) had no fused prompt kernel on any platform: their experts ran on
the trellis MMQ instances the overlay adds (cmake/strata_ggml_tq_overlay.cmake). With STRATA_PF_FUSED_TQ=1 (CUDA, default off) these two
pairs take native_kernel on any sm_80+ card. This commit is the decode only: the Gyro packs' layers are Hadamard-folded, and the
prompt path still declines folded layers on the fused kernels (prefill.cpp's fused_nat), so in the engine nothing changes yet; the
H rotation and the prompt path follow in their own commits.
The decode is MMQ's (third_party/strata-ggml/ggml/src/ggml-cuda-tq/tq.cuh tq_states4 / tq_lane_to_q8): a 128-weight block {fp16 d;
qs} of 32 trellis steps; step t's 15-bit state (TQ2_T: qs[(t + 31) % 32] << 8 | qs[t]; TQK: the 16 bits from bit (31 - t) K of the
circular stream), x = state * 0x9e3779b1, codebook points x >> 21 and (x >> 10) & 2047 of the int8 codebook tq_lut_i8 (two int8 a
point), one scale d * TQ_LUT_I8_SCALE a block. So the int8 weights are MMQ's exactly; products, SwiGLU and H are the int8 mma.sync path
every native format takes. The codebook (4 KB) goes to shared memory through the existing grid_bytes / grid_src mechanism.
Device code: four new instance pairs, native_kernel<TQK6, true, 2|4>, <TQ2_T, true, 2|4>, <TQK7, false, 2|4>, <TQ2_T, false, 2|4>; no
existing instance changes (the edited constants in native_kernel and the shared helpers have their old values for every other format;
the trellis branches of load_unit / convert / grid_src are CUDA-only, so no HIP template sees them). The int8 codebook table
(src/kernels/cuda/tq_lut_i8.cuh) is included in this translation unit on CUDA. Line numbers of this commit's src/prefill/moe_fused_iq.cu:
- 43-47: the codebook include (CUDA only). 103-109: T_TQ2_T / T_TQK6 / T_TQK7 (144-146; the pinned ggml.h has no enumerators for
them), is_tq, tq_k. 121 block_bytes, 126 raw_words (TQ2_T 4, TQK 5), 131 grid_bytes (4 KB).
- 399-416: load_unit<TQ2_T> (the 8 state bytes of a 32-value sub-block and the byte before them) and <TQK6 / TQK7> (six u16 words of the
circular stream from bit (24 - 8 ib) K, d, the start bit). 526-557: convert<TQ*> (8 states, 16 codebook reads, q[8], one scale).
652-654: grid_src<TQ*> = tq_lut_i8. All inside #if !defined(__HIPCC__).
- native_kernel, body inside __CUDA_ARCH__ >= 750: 756 (static_assert: no NT = 256 trellis form), 807-814 (B128: a 128-value block per
two stages, sub-blocks 2 (s & 1) + uj, gate/up and down; GU256 false for the trellis types), 819 (SBB for the L2 prefetch: 2 blocks).
- DevInfo tq / occ_tq_gu / occ_tq_d: 1928-1929. tq_cuda_requested(): 1972-1977. dev_info(): 2151-2159 (the four pairs set up or none;
their own occupancy). gu_covered(): 2215. d_covered_on(): 2278. native_supported(): 2391-2397 (TQK6 / TQK7 and TQ2_T / TQ2_T only;
not on Turing, not with the NT = 256 / warp-specialized opt-ins). experts_native(Batch): 2601-2608 (gate/up cases), 2620-2623 (down);
experts_native(WideBatch): 2638-2639 (refuses the trellis types). All inside #if !defined(__HIPCC__).
tests/cuda/prefill_fused_iq_test.cpp: the pairs "TQK6 + TQK7" and "TQ2_T + TQ2_T" (run only under --only); the pinned ggml's type table
has no entry for these ids, so their sizes and their dequantization come from the format definition (ggml-common-tq.h's header comment,
the fp16 codebook tq_lut_f16) for the double-precision reference, and from the int8 codebook for the int8 model; MMQ = the overlay's
trellis instances. Every other pair's sizes, data and checks are unchanged. cmake/backends/cuda.cmake: ctest prefill_fused_iq_test_tq
(STRATA_PF_FUSED_TQ=1, --only="+ T" --edge --no-timing). data/settings-register.json: the STRATA_PF_FUSED_TQ entry (status research)
and the Q8D / Q8GU / Q6K read lines.
Phase 4 (own prompt kernels). UD-Q6_K_XL keeps its gate/up in Q6_K in 47 of 48 layers (UD-Q5_K_XL in one), with Q8_0 downs; no
platform had a fused kernel for Q6_K, so those layers ran on MMQ (CUDA: the K-quant library, STRATA_MMQ_KQ=1 by default on cc >= 8.0).
With STRATA_PF_FUSED_Q6K=1 (CUDA, default off) a Q6_K gate/up with a Q8_0 down takes native_kernel on any sm_80+ card, whatever the
80-SM rule says.
The decode: a 32-value sub-block of the 256-value super-block (half n = ib / 4, quarter r = ib % 4, as ggml's dequantize_row_q6_K
walks it): low nibbles from ql[64 n + 32 (r & 1) ..] (bits 4 (r >> 1)..), two high bits from qh[32 n ..] (bits 2 r..), codes q - 32
as int8, and w = d * scales[8 n + 2 r (+ 1)] per 16 values, no minimum. So it takes the per-16-value scale path the IQ2_XS / IQ2_S
gate/up already use (per16); the int8 products, the SwiGLU + H epilogue and the Q8_0 down (A2's instances) are unchanged.
Device code: two new instances, native_kernel<T_Q6_K, true, 2> and <T_Q6_K, true, 4>; no existing instance changes. The shared
helpers get a Q6_K branch each (if constexpr: load_unit, convert) and a Q6_K entry each in block_bytes / raw_words / per16 (values
unchanged for every other format); the HIP kernels instantiate none of them for Q6_K. Line numbers of this commit's
src/prefill/moe_fused_iq.cu:
- T_Q6_K: 95-98; the block layout static_assert: 102-103; block_bytes 109-110, raw_words 115 (18 words: 8 of ql, 8 of qh, d with
the two scales, the quarter r), per16 117.
- load_unit<T_Q6_K>: 376-387 (2-byte aligned loads, ld32 / ld16: the 210-byte blocks). convert<T_Q6_K>: 487-496.
- native_kernel: 665 (static_assert: no NT = 256 Q6_K form).
- DevInfo q6k / occ_q6k: 1833-1834, inside #if !defined(__HIPCC__). q6k_cuda_requested(): 1871-1876 (reads STRATA_PF_FUSED_Q6K).
- dev_info(): 2043-2049, the CUDA (#else) branch: setup_one<T_Q6_K, true> and <T_Q8_0, false>, both or neither; its own occupancy.
- gu_covered(): 2104, inside #if !defined(__HIPCC__). d_covered_on(): 2167, the CUDA (#else) branch.
- native_supported(): 2274-2278, inside #if !defined(__HIPCC__): a Q6_K gate/up only with a Q8_0 down, not on Turing, not with the
NT = 256 / warp-specialized opt-ins.
- experts_native(Batch): 2478-2481, the switch's T_Q6_K case inside #if !defined(__HIPCC__).
With the switch unset nothing is set up and these layers keep MMQ, as before.
tests/cuda/prefill_fused_iq_test.cpp: the pair "Q6_K + Q8_0" (named with "+" so the _kq entry's --only="K / Q" does not take it),
appended, run only when --only names it; fill_matrix writes Q6_K's fp16 d at its end (byte 208) and keeps the 16 int8 scales random
(every other format's blocks and random draws are unchanged). cmake/backends/cuda.cmake: ctest prefill_fused_iq_test_q6k
(STRATA_PF_FUSED_Q6K=1 STRATA_MMQ_KQ=1, --edge --no-timing): against the double-precision reference, the int8 model and MMQ's K-quant
library at every shape. data/settings-register.json: the STRATA_PF_FUSED_Q6K entry (status research), the Q8D / Q8GU read lines.
Phase 4 (own prompt kernels). The Q8_0 set (every expert Q8_0) and UD-Q6_K_XL's one Q8_0 layer had no fused kernel on any platform:
their prompt experts run on MMQ. With STRATA_PF_FUSED_Q8GU=1 (CUDA, default off) a Q8_0 gate/up with a Q8_0 down takes
native_kernel on any sm_80+ card, whatever the 80-SM rule says.
The gate/up decode is the Q8_0 down's (load_unit / convert<T_Q8_0>: int8 codes, one scale per 32 values, no minimum); like the down
rows it reads two 32-value blocks a 64-value stage, one per decode thread of the row; the products and the SwiGLU + H epilogue are the
i-quant gate/up's. The down is A2's native_kernel<T_Q8_0, false, 2 | 4>.
Device code: two new instances, native_kernel<T_Q8_0, true, 2> and <T_Q8_0, true, 4>; no existing instance changes (the two edited
lines in native_kernel are constants per instance whose value is unchanged for every existing one). Line numbers of this commit's
src/prefill/moe_fused_iq.cu:
- native_kernel, body inside __CUDA_ARCH__ >= 750: 687-689 (GU256 is false for a Q8_0 gate/up: its blocks are addressed as the
32-value down formats' are, line 692), 699 (SBB, bytes per 256 values of a row for the L2 prefetch: 8 blocks for Q8_0).
- DevInfo q8gu / occ_q8gu: 1804-1805, inside #if !defined(__HIPCC__).
- q8gu_cuda_requested(): 1836-1841, in the #if !defined(__HIPCC__) block (reads STRATA_PF_FUSED_Q8GU).
- dev_info(): 2001-2007, the CUDA (#else) branch: setup_one<T_Q8_0, true> and <T_Q8_0, false>, both or neither; the gate/up's own
occupancy (occ_q8gu), the down's in occ_kq8; a failed setup leaves those layers on MMQ.
- gu_covered(): 2061, inside #if !defined(__HIPCC__). d_covered_on(): 2124, the CUDA (#else) branch.
- native_supported(): 2226-2230, inside #if !defined(__HIPCC__), first of the phase-4 rules: a Q8_0 gate/up only with a Q8_0 down,
not on Turing, not with the NT = 256 / warp-specialized opt-ins.
- experts_native(Batch): 2425-2430, the switch's T_Q8_0 case inside #if !defined(__HIPCC__) (a HIP build has no such instance).
With the switch unset nothing is set up, gu_covered(T_Q8_0) is false and these layers keep MMQ, as before.
tests/cuda/prefill_fused_iq_test.cpp: the pair Q8_0 / Q8_0, appended (it runs only when --only names it). cmake/backends/cuda.cmake:
ctest prefill_fused_iq_test_q8gu (STRATA_PF_FUSED_Q8GU=1, --only="Q8_0 / Q8_0" --edge --no-timing). data/settings-register.json:
the STRATA_PF_FUSED_Q8GU entry (status research), and STRATA_PF_FUSED_Q8D's read line (1830 -> 1833).
Phase 4 (own prompt kernels). The pinned UD-IQ4_XS has five Q8_0-down layers (IQ3_S / Q8_0 in 4, IQ4_XS / Q8_0 in 1). On a card
where the fused kernels take that set's other 43 layers (sm_120 with 80+ SMs by default, any sm_80+ card with STRATA_PF_FUSED=1)
these five still fall back to MMQ, because a Q8_0 down was only taken behind a K-quant gate/up (A2, 1bf13cd02). With
STRATA_PF_FUSED_Q8D=1 (CUDA, default off) they take native_kernel too, on any sm_80+ card, whatever the 80-SM rule says.
The kernels are A2's: native_kernel<T_Q8_0, false, 2 | 4> (load_unit / convert<T_Q8_0>: int8 codes, one scale per 32 values, no
minimum). A Q8_0 down reads no activation code sums (has_min(T_Q8_0) is false), so the i-quant gate/up epilogue's H feeds it
unchanged. No device function is added or changed: the instances were already in the binary; every edit is host code on a
CUDA-only path (line numbers of this commit's src/prefill/moe_fused_iq.cu):
- DevInfo q8d: 1802, inside #if !defined(__HIPCC__).
- q8d_cuda_requested(): 1827-1832, in the #if !defined(__HIPCC__) block (reads STRATA_PF_FUSED_Q8D).
- dev_info(): 1988-1991, the CUDA (#else) branch: setup_one<T_Q8_0, false> when the switch is 1, A2's occupancy field (occ_kq8:
the same instances); a failed setup leaves those layers on MMQ.
- d_covered_on(): 2107, the CUDA (#else) branch, T_Q8_0 is covered by kq8 or q8d.
- native_supported(): 2205-2212, inside #if !defined(__HIPCC__), before the K-quant rule: a Q8_0 down behind an i-quant gate/up (not Q2_0, not
Q4_K / Q5_K) only with q8d, not on Turing, not with the NT = 256 / warp-specialized opt-ins (no Q8_0 form): MMQ.
- experts_native(Batch): 2410-2412, inside #if !defined(__HIPCC__), after the i-quant gate/up launch, the Q8_0 down with occ_kq8.
With the switch unset nothing is set up and native_supported returns false for these pairs, as before.
tests/cuda/prefill_fused_iq_test.cpp: two pairs, IQ3_S / Q8_0 and IQ4_XS / Q8_0, appended to the list (the default timing set
takes pairs 0, 1, 4, 3 by index: unchanged). They run only when --only names them, so every existing ctest entry, the HIP build's
hip_prefill_fused_iq included, runs what it ran. cmake/backends/cuda.cmake: ctest prefill_fused_iq_test_q8d
(STRATA_PF_FUSED_Q8D=1, --only="S / Q8_0" --edge --no-timing): against the double-precision reference, the int8 model and MMQ (the
i-quant rule) at the 6 reference shapes and the real-shape sample.
data/settings-register.json: the STRATA_PF_FUSED_Q8D entry (status research, CUDA, opt-in).
serve STOP on a closed pipe, the launch worker after quit, the stall report
asks the prompt's GPU work, ISA-floor parity legs, the sleep stand-in, a
Windows child in the kill-on-close job before it runs, and the approved
wording of their lines.
Conflict: CMakeLists.txt, where f-gh1110 and this branch both add test
targets after batch_telemetry_test (conversation_heap_test and
stream_watch_test). Both blocks are kept.
With STRATA_ISA_FLOOR=avx or none, ggml-cpu is built without AVX2 and FMA,
so its dot rounds differently from the AVX2 path our rows copy step for
step: iq_avx2_parity's "exact singleton vs ggml" (4049-4424 of 5120 outputs
differ) and nvfp4_cpu_parity's AVX2 "not bit-equal" count (up to 5.41e-07
relative, all inside 1e-5) failed both tests there. In those builds the two
tests now print why bit-equality is not required and count only the
tolerance legs; every other leg runs as before, and the release build
(STRATA_ISA_FLOOR empty) still requires bit-equality.
Test-only: the define STRATA_TEST_GGML_WITHOUT_AVX2 on the two test targets.
The golden file: 891 lines, 54 KB. Family gcc: every group of the
three x86 flavours (avx2 291, avx 291, generic 283 groups) as GCC 13.3
builds ggml-cpu. Family msvc: 14 lines, the avx2 Q5_K and IQ1_S dot
groups at n = 512..2048, where MSVC 19.44's reference (and the layer
under MSVC) differs from GCC's because MSVC does not contract the
intrinsics' add-of-mul into FMA (1-512 ulp, max relative 3.3e-5 for
Q5_K; 1-16 ulp, 1.6e-6 for IQ1_S). Every other group, and every input
digest, is the same under both toolchains. ggml pin 3cf03257f.
The comments next to the IQ4_NL tail pin (x86_dots.inc) and the tier
flags (quant.cmake) now say what is pinned, against which reference,
and what was measured under GCC 13.3, 14.3, 15.2 and MSVC 19.44.
golden_merge.py writes the MSVC version as 19.44.35228.
ggml-cpu's own results move with the compiler that builds the oracle:
GCC 14.3 fuses the IQ4_NL odd-block tail into an FMA, GCC 15.2 that and
the generic Q2_0 dot, where GCC 13.3 does not (55 and 238 rows of the
oracle, 1-4 ulp). The layer's results are the same bytes under all
three. A live compare alone therefore fails on a newer GCC for a change
in ggml, not in the layer.
Leg 1, the gate: every group (flavour, section, type, n) of the layer's
results against tests/quant/golden_x86.txt, the digests of the
reference that GCC 13.3's ggml-cpu computes for the same inputs (input
digest checked too). A toolchain family can carry its own line for a
group (msvc: MSVC does not contract the intrinsics' add-of-mul).
Leg 2, information: the row-by-row compare with the ggml-cpu linked
here; its summary names the compiler and the groups where that ggml
differs from the golden reference. QUANT_PARITY_LIVE_STRICT=1 makes it
fail too. Without golden lines for a flavour (arm64, or --rows other
than 24) leg 2 stays the gate.
The digest is FNV-1a 64, written in the test, with its published test
vectors checked at start. --dump-group KEY prints every row of a group
(ours per kernel and ggml's) for a diff against a GCC 13 run;
--write-golden FILE writes a flavour's lines; --regen-check (ctest
quant_golden_regen, only when the golden file exists) regenerates the
stored lines byte for byte under GCC 13.x (family gcc) or MSVC 19.4x
(family msvc) and skips elsewhere. tests/quant/make_golden.sh and
golden_merge.py make the file.
device_free_bytes() ignored cudaMemGetInfo's result, so a failed query left
free_b at 0 and the start said "expert cache auto: 0.00 GiB free" as if it
had measured a full card. It now checks the result: still 0 free (the
callers size from it), the error taken off the thread's last-error state,
and one line on stderr with the error's text and number, once per kind of
error. (cudaGetErrorName is not used: the HIP shim and the Mac's
metal_compat do not map it.)
The line's wording is a PLACEHOLDER marked [DRAFT #5708], pending review;
the large-page / pinning behaviour of the report is not touched.
Test: tests/core/device_free_error_test.cpp (CUDA build, no GPU needed: the
query fails with every device hidden). z440: before "stderr: (nothing)",
FAIL; after the line with the no-device error, ok.
Phase 4 step 1. UD-IQ4_XS v31 has Q5_0 down projections in 33 of its 48 layers. This build has no MMQ tile for
them and the CUDA fused kernels had no Q5_0 form, so on every NVIDIA card they ran the dequantize + FP16 GEMM path.
With STRATA_PF_FUSED_Q50=1 they now run on native_kernel. The decode is the one the HIP kernels already use
(load_unit / convert<T_Q5_0>: int8 codes q - 16, one scale per 32 values). The products are the IQ4_NL down's:
int8 mma.sync m16n8k32, int32 sums, FP32 scales and accumulation. Off by default on CUDA: no default changes.
Every edit is on a CUDA-only path; HIP device code and HIP's choices are unchanged:
- native_kernel (body inside __CUDA_ARCH__ >= 750): the raw-word buffer is sized from raw_words(WT) (5 for every
existing format, 6 for Q5_0); Q5_0 blocks are addressed like IQ4_NL's (two 32-value blocks a stage); the two-pass
load lambdas compile only in the NT = 256 instances (if constexpr), with a static_assert that no Q5_0 instance
takes them.
- DevInfo: the q50 / occ_q50 fields inside #if !defined(__HIPCC__).
- q50_cuda_requested(): new, in the #if !defined(__HIPCC__) block beside host_astages.
- dev_info(): the Q5_0 setup in the CUDA (#else) branch, with its own occupancy (occ_q50), so the other formats'
launches do not change; a failed setup leaves those layers on the FP16 path.
- d_covered_on(): a new #else (CUDA) branch, Q5_0 covered when d.q50.
- native_supported(): inside the existing #if !defined(__HIPCC__) block. A Q5_0-down pair is taken on any sm_80+ card
with d.q50, whatever the 80-SM rule says. STRATA_PF_FUSED=0 still turns it off. Not taken with the NT = 256 /
warp-specialized opt-ins.
- experts_native(Batch): the Q5_0 launch inside #if !defined(__HIPCC__), so a HIP build gains no Q5_0 instance of
native_kernel. experts_native(WideBatch): refuses a Q5_0 down, CUDA-only through a constexpr false under HIP.
Tests: tests/cuda/prefill_fused_iq_test.cpp already had the IQ3_XXS / Q5_0 and IQ4_XS / Q5_0 pairs and their tails;
two comments change. cmake/backends/cuda.cmake adds prefill_fused_iq_test_q50 (STRATA_PF_FUSED_Q50=1, --only=Q5_0).
RTX A6000 (sm_86, CUDA 13.1): all six prefill_fused_iq_test entries pass (ws skips as before). The Q5_0 pairs against the
int8-rounded model: rel RMS 2.3e-7 to 1.6e-4, worst row 3e-7 to 4.0e-3, at 1 / 33 / 130 / 256 / 517 tokens.
Phase 4, NVIDIA item 4, step A2, on top of A1b (18027b91c). UD-Q4_K_XL's remaining five layers have a Q8_0 down (4 Q4_K / Q8_0,
1 Q5_K / Q8_0); with STRATA_PF_FUSED_KQ=1 they now take native_kernel too, so the whole set reads its prompt experts without MMQ.
The decode is the HIP kernels' (load_unit / convert<T_Q8_0>: int8 codes, one scale per 32 values, no minimum); the products are
the IQ4_NL / Q5_0 down's (int8 mma.sync m16n8k32, FP32 scales and sums). A Q8_0 down is taken only behind a K-quant gate/up
(the i-quant sets' Q8_0-down layers keep their path); opt-in unchanged, default off.
Every edit is on a CUDA-only path (line numbers of this commit's src/prefill/moe_fused_iq.cu):
- native_kernel, body inside __CUDA_ARCH__ >= 750: 637 (static_assert, no NT = 256 Q8_0 form), 690 (Q8_0 blocks addressed like
IQ4_NL / Q5_0 / Q5_1: a constant per instance, the existing instances' value unchanged).
- DevInfo kq8 / occ_kq8: 1799-1800, inside #if !defined(__HIPCC__).
- dev_info(): 1976-1978, the CUDA (#else) branch, inside the STRATA_PF_FUSED_KQ=1 setup; its own occupancy; a failed setup
leaves those layers on MMQ.
- d_covered_on(): 2095, the CUDA (#else) branch.
- native_supported(): 2194-2197, inside #if !defined(__HIPCC__) (the K-quant rule: a Q8_0 down only behind Q4_K / Q5_K).
- experts_native(Batch): 2363, 2369-2372, inside #if !defined(__HIPCC__). experts_native(WideBatch): 2405, CUDA-only.
The shared decode helpers are not edited.
cmake/backends/cuda.cmake: prefill_fused_iq_test_kq takes every K-quant pair (--only="K / Q").
RTX A6000 (sm_86, CUDA 13.1), prefill_fused_iq_test: Q4_K / Q8_0 and Q5_K / Q8_0 against the int8-rounded model rel RMS 2.8e-7
to 1.9e-4 at the 6 reference shapes (lane OWN-4A's gfx12 kernel: 1.1e-4), 2.9e-7 to 2.7e-5 on the real-shape samples; against
FP32 0.99x to 1.015x MMQ's own distance; fused against MMQ 3.0e-3 to 4.3e-3 (MMQ's activation-sum arithmetic, information under
the K-quant rule of 8b0988d72). One layer, MMQ path / fused (uniform random routing; not the end-to-end measure): Q4_K / Q8_0
2K 12.91 / 9.91 ms (1.30x), 3.5K 14.98 / 13.35 (1.12x), 8K 23.78 / 29.06 (0.82x), 16K 38.24 / 50.77 (0.75x), 32K 66.25 / 99.60
(0.67x). The Q8_0 down instances use 124-126 registers, no stack. The default, q2n, q50 and kq entries pass.
Phase 4, NVIDIA item 4, step A1. UD-Q4_K_XL's experts (Q4_K gate/up in 47 layers, Q5_K in one; Q5_1 down in 43) have no CUDA
fused kernel and run on MMQ (libstrata_kq, STRATA_MMQ_KQ=1 by default on cc >= 8.0). With STRATA_PF_FUSED_KQ=1 (the switch HIP
already has, same name, same meaning; on CUDA default off) the Q4_K / Q5_K gate/up + Q5_1 down layers run on native_kernel on any
sm_80+ card. The decode is the HIP kernels' (load_unit / convert: int8 codes, a scale and a minimum per 32 values); the products
are the i-quants' (int8 mma.sync m16n8k32, int32 sums, FP32 scales and accumulation), plus the minimum term s1 * d_x * (sum of the
activation codes) per 32 values, from the sums quant_act_nat_kernel already stores in the activation blocks' spare bytes 72-79,
as HIP's native_w11_kernel does. The K-quant gate/up epilogue writes the same sums for H (the Q5_1 down reads them). The Q8_0-down
layers (5 of 48) keep MMQ in this commit. No default changes.
Every edit is on a CUDA-only path (line numbers of this commit's src/prefill/moe_fused_iq.cu):
- native_kernel, body inside __CUDA_ARCH__ >= 750: 594 (static_assert, no NT = 256 K-quant form), 646 (Q5_1 blocks addressed
like IQ4_NL / Q5_0: a constant per instance, the existing instances' value unchanged), 737-744 (the activation code sums,
if constexpr has_min), 825-827 (the minimum term, if constexpr has_min), 871-890 (the gate/up epilogue writes the H code sums,
if constexpr has_min; the existing instances take the unchanged else branch).
- DevInfo kq / occ_kq: 1743-1744, inside #if !defined(__HIPCC__).
- kq_on() forward declaration: 1769, in the #if !defined(__HIPCC__) block.
- dev_info(): 1912-1920, the CUDA (#else) branch; the K-quant kernels' own occupancy (occ_kq), so the other formats' grids do
not change; a failed setup leaves those layers on MMQ.
- gu_covered(): 1973, inside #if !defined(__HIPCC__). d_covered_on(): 2035, the CUDA (#else) branch.
- native_supported(): 2130-2137, inside #if !defined(__HIPCC__), before the Q5_0 rule: a K-quant gate/up only with a Q5_1 down,
a Q5_1 down only behind a K-quant gate/up; not with the NT = 256 / warp-specialized opt-ins.
- experts_native(Batch): 2298-2312, inside #if !defined(__HIPCC__) (a HIP build gains no K-quant instance of native_kernel).
experts_native(WideBatch): 2340-2341, CUDA-only (refuses K-quant / Q5_1 like Q5_0).
The shared decode helpers (load_unit / convert / has_min / raw_words) are not edited.
cmake/backends/cuda.cmake: ctest prefill_fused_iq_test_kq (STRATA_PF_FUSED_KQ=1 STRATA_MMQ_KQ=1, --only="K / Q5_1" --edge).
data/settings-register.json: STRATA_PF_FUSED_KQ's note names the CUDA meaning.
RTX A6000 (sm_86, CUDA 13.1), prefill_fused_iq_test: Q4_K / Q5_1 and Q5_K / Q5_1 against the int8-rounded model rel RMS
1.5e-7 to 4.2e-5 at the 6 reference shapes, 1.2e-7 to 3.4e-6 on the real-shape samples; against FP32 at MMQ's distance (rel RMS
0.99x to 1.10x MMQ's). The default, q2n, q50 and kq entries pass. Registers: the K-quant instances sit at the 128-register cap
of the 512-thread kernel with 40-72 bytes of stack (Q4_K 64, Q5_K 72, Q5_1 40); speed is not yet MMQ's (opt-in only).
Phase 4 step 1. UD-IQ4_XS v31 has Q5_0 down projections in 33 of its 48 layers. This build has no MMQ tile for
them and the CUDA fused kernels had no Q5_0 form, so on every NVIDIA card they ran the dequantize + FP16 GEMM path.
With STRATA_PF_FUSED_Q50=1 they now run on native_kernel. The decode is the one the HIP kernels already use
(load_unit / convert<T_Q5_0>: int8 codes q - 16, one scale per 32 values). The products are the IQ4_NL down's:
int8 mma.sync m16n8k32, int32 sums, FP32 scales and accumulation. Off by default on CUDA: no default changes.
Every edit is on a CUDA-only path; HIP device code and HIP's choices are unchanged:
- native_kernel (body inside __CUDA_ARCH__ >= 750): the raw-word buffer is sized from raw_words(WT) (5 for every
existing format, 6 for Q5_0); Q5_0 blocks are addressed like IQ4_NL's (two 32-value blocks a stage); the two-pass
load lambdas compile only in the NT = 256 instances (if constexpr), with a static_assert that no Q5_0 instance
takes them.
- DevInfo: the q50 / occ_q50 fields inside #if !defined(__HIPCC__).
- q50_cuda_requested(): new, in the #if !defined(__HIPCC__) block beside host_astages.
- dev_info(): the Q5_0 setup in the CUDA (#else) branch, with its own occupancy (occ_q50), so the other formats'
launches do not change; a failed setup leaves those layers on the FP16 path.
- d_covered_on(): a new #else (CUDA) branch, Q5_0 covered when d.q50.
- native_supported(): inside the existing #if !defined(__HIPCC__) block. A Q5_0-down pair is taken on any sm_80+ card
with d.q50, whatever the 80-SM rule says. STRATA_PF_FUSED=0 still turns it off. Not taken with the NT = 256 /
warp-specialized opt-ins.
- experts_native(Batch): the Q5_0 launch inside #if !defined(__HIPCC__), so a HIP build gains no Q5_0 instance of
native_kernel. experts_native(WideBatch): refuses a Q5_0 down, CUDA-only through a constexpr false under HIP.
Tests: tests/cuda/prefill_fused_iq_test.cpp already had the IQ3_XXS / Q5_0 and IQ4_XS / Q5_0 pairs and their tails;
two comments change. cmake/backends/cuda.cmake adds prefill_fused_iq_test_q50 (STRATA_PF_FUSED_Q50=1, --only=Q5_0).
RTX A6000 (sm_86, CUDA 13.1): all six prefill_fused_iq_test entries pass (ws skips as before). The Q5_0 pairs against the
int8-rounded model: rel RMS 2.3e-7 to 1.6e-4, worst row 3e-7 to 4.0e-3, at 1 / 33 / 130 / 256 / 517 tokens.
Conflicts (f-own-2n branched from f-own-2a 6213c0839; f-own-2a's later
commits and f-own-2n both added a tool called quant_bench):
- cmake/backends/quant.cmake: f-own-2n's ${_sq}-rooted paths (for the
Metal project) applied to f-own-2a's AVX-512 tier lines (MSVC and GCC
options), the Arm tier block from f-own-2n kept as is.
- tests/quant/quant_bench.cpp (add/add): f-own-2a's no-ggml one-thread
bench keeps the name quant_bench (built always, ${_sq}/ path now);
f-own-2n's ggml A/B bench is renamed to tests/quant/quant_bench_ggml.cpp,
target quant_bench_ggml (test builds only, links ggml-cpu); its usage and
banner lines say the new name.
src/quant/isa.cpp merged by itself (2a: Avx512 needs VNNI; 2n: Neon needs
dotprod).
dot_avx512.cpp compiles the same ported ggml dots as dot_avx2.cpp with -mavx512vl -mavx512vnni so the helper's VPDPBUSD branch (ggml's own, for
__AVX512VNNI__ && __AVX512VL__) replaces maddubs + madd. Integer sums are exact either way and the float order is the AVX2 one, so the bits are the
AVX2 tier's: quant_parity runs these kernels against ggml's AVX2 dots (19097 comparisons, 0 differences, p2006). Isa::Avx512 now means AVX-512
F/DQ/BW/VL + VNNI (isa_ok / best_isa). One thread, Zen 4 (p2006), GB/s of weights, DRAM set / L2 set, avx2 -> avx512 build:
q4_0 15.98/16.27 -> 16.73/17.03, q4_1 16.20/16.55 -> 17.02/17.44, q5_0 15.36/15.69 -> 16.87/17.26, q5_1 15.49/15.84 -> 16.63/17.03,
q8_0 37.42/39.55 -> 38.07/40.41, iq4_nl 14.93/15.30 -> 15.19/15.58, mxfp4 11.39/11.88 -> 11.65/12.11 (+2% to +10%).
Tried and dropped (not in the tree): a two-block 512-bit decode (nibbles of two blocks, the 5th bit from a mask register, one VPDPBUSD) with the float chain in ggml's
order: 14.94 vs 15.35 (Q5_0), 12.6 vs 15.9 (Q4_0), no gain; and 4-rows-at-a-time kernels (bit-exact, R chains in flight): L2-resident +15-20%, DRAM-streamed
-30% (four streams per core), so a loss where the pool lives.
tests/quant/quant_bench.cpp: one-thread GB/s of every kernel (no ggml), interleaved rounds, medians.
tests/quant/check_no_ggml.sh: nm -u over the pool's objects (strata_kernels_cpu, strata_quant, mtp.cpp, ds4_gg_cpu.cpp): none may reference ggml
(own build: 29 objects, clean; ggml build: ggml_cpu_init, ggml_get_type_traits_cpu, ggml_row_size, ggml_cpu_has_* found, as it must).