Repository navigation
qdot: Q4_K's one-column kernel, tile and row lanes get AVX-512 VNNI bodies, picked at run time and bit-identical to the AVX2 ones - #86
Conversation
|
Thank you. Bit-identical bodies picked at run time, with an off switch in the same binary, are the shape we want for #81. It touches qdot, the lever registry and the release build, so we review it after tonight's train lands, and it joins the next one. We will run the qdot and kernel gates on our side and keep your commits. |
|
좋은 CPU가 있으시군요 부럽습니다!! |
There was a problem hiding this comment.
Verdict: CLEAN: I built no failure path through the three new AVX-512 bodies that the code or the tests do not block.
Non-blocking
⚠ A bad BLOOMERY_QDOT_AVX512 value panics at the first Q4_K dot, not at load: crates/qdot/src/lib.rs:266. q4k_avx512() is lazy and nothing outside qdot calls it at start. With BLOOMERY_QDOT_AVX512=yes the server loads, then panics in a pool worker on the first host Q4_K request. The row says Phase::Load (registry.rs:986). Fix direction: call qdot::q4k_avx512() once where the host tier is built.
⚠ Default is on for CPUs nobody measured: registry.rs:981. The release binary reaches every AVX-512 VNNI CPU: Zen 4 (256-bit datapath), Ice Lake and Sapphire Rapids (clock license). The PR measures Zen 5 only. Question: ship opt-in until a second CPU reports? The change is Unset::Is("0") and None => false.
⚠ The PR says AGENTS.md bans splitting these bodies. The rule allows an #[inline(always)] helper (AGENTS.md:331). The dy/my setup now exists in four bodies (lib.rs:4832, lib.rs:5386 and the two AVX2 twins). One helper keeps the bits and the speed. Check with the A/B.
Also 2 minor: hw_q4k_avx512_matches_avx2_synthetic re-runs assert_tile_matches and assert_lanes_match on the row sets of hw_lanes_match_dot_row_synthetic; the dot_row_avx2 doc sentence (lib.rs:556) is hard to read.
Checked
- Duplicates: 5 new items checked, dryer 0 pairs.
- Complexity: crapper did not run. By reading, growth is even (one arm each).
- Silent failure: 4 sites followed. The lever value panics by name; the odd
Ccase stays in range. - Tests: mutation check done. Planting
0x00FFfor thed8mask,.min(C)or thec % 2half turns an assertion red. - Gates:
unsafe-ratchet130/73 → 134/75 with a dated PIN; the count matches. - Escape catalog: no match.
Notes
tools/levers-direct.txtsays lever lines only shrink and this PR adds one. The author asks for a decision.AGENTS.md:3-4andAGENTS.md:269still say AVX2 only for the host kernels.
…t a failed run crapper prints "No source files to analyze" and exits 0 on a test file, writing no snapshot; the diagnostics read that as a failure and dropped the whole complexity section (PR #86, crates/qdot/tests/qdot.rs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
측정과 설명 감사합니다. 세 가지 결정입니다.
이 댓글은 @midagedev를 위해 bloomery AI 어시스턴트가 작성했습니다. |
065c95a to
99569eb
Compare
There was a problem hiding this comment.
Verdict: MUST_FIX: The Q4_K lane gate is duplicated, the AVX-512 gate misses disabled dispatch, and the new kernels violate R1's unsafe-scope rule.
Must fix
1. Give the Q4_K synthetic lane clause one owner (kind B)
crates/qdot/tests/qdot.rs:6039 repeats the clause at crates/qdot/tests/qdot.rs:5952. Both call assert_lanes_match with identical Q4_K 0xFF rows at k = 4096 and identical lane_columns, through the same dispatch. The extra AVX2 comparison does not remove the repeated lane clause. AGENTS.md requires one test per contract.
One owner avoids maintaining two gates when this contract changes. Keep Q4_K in the new gate, which also covers k = 512 and 768. Replace the existing gate's first doc line and type loop with:
/// Row-lane clause on synthetic rows: for Q5_K and Q6_K, groups of
// PIN(2026-10-13): Q4_K's clause moved to hw_q4k_avx512_matches_avx2_synthetic.
for ty in [GgmlType::Q5_K, GgmlType::Q6_K] {2. Assert that enabled dispatch selects AVX-512 (kind B)
crates/qdot/tests/qdot.rs:5985 only checks that an unsupported CPU cannot select AVX-512. Replacing crates/qdot/src/lib.rs:283's selector expression with false passes this assertion; subsequent comparisons exercise AVX2 and stay green. On a supported CPU with the lever enabled, the gate misses a selector regression that bypasses the new kernels.
Add the assertion now so the gate detects this mutant. Replace lines 5985–5988 with:
let wanted = std::env::var_os("BLOOMERY_QDOT_AVX512").is_none_or(|v| v == "1");
assert_eq!(qdot::q4k_avx512(), isa && wanted);3. Narrow the new kernels' unsafe scopes (kind B, R1)
crates/qdot/src/lib.rs:4919 and crates/qdot/src/lib.rs:5520 wrap entire kernel bodies in unsafe. R1 forbids this and requires one operation per block with its local SAFETY proof. check-unsafe.sh counts blocks; it does not enforce scope.
Localize the proofs before these bodies grow. Remove the outer blocks and wrap each unsafe operation inside the existing target-feature bodies. For example, replace the pointer offset at line 4972 with:
// SAFETY: i < nb; the column holds 2 * nb Q8_2_X4 groups.
let g0 = unsafe { col.add((2 * i) * Q82X4_STRIDE) };Apply this to the remaining pointer operations, loads, stores and unsafe helper calls in both bodies. Keep the kernel bodies intact and re-pin the resulting unsafe-block counts with a dated reason.
Non-blocking
⚠ Keep the paired scale conversion: crates/qdot/src/lib.rs:4926 converts d and dmin separately; the AVX2 kernel at crates/qdot/src/lib.rs:3809 uses one paired conversion. This adds k/256 source-level F16C conversions per Q4_K row dot [derived]. Reuse the existing helper:
let (d, dmin) = f16c_pair_to_f32([wb[0], wb[1], wb[2], wb[3]]);The integer-path reorder needs the owning qdot gate; the dispatch change needs an A/B on the contributor's machine. Provide evidence for the current base and head, including the required nvidia-smi line. The PR body reports earlier commit hashes.
Checked
Duplicates: the repeated lane clause is confirmed. ISA twins follow the kernel exemption. Diagnostics report 0 dryer pairs.
Complexity: diagnostics report dot_row at 18 → 19; the diff adds one ISA guard to its match.
Silent failure: invalid lever values panic by name; the lane kernel's replicated odd column is not returned.
Tests: bit assertions compare dot_row with AVX2/scalar and tile/lanes with dot_row. The selector-off mutant bypasses AVX-512 coverage. The PR reports FAIL-first arithmetic mutants.
Gates: unsafe ratchet 141/77 → 145/79 has a dated PIN. The release allowlist names the guarded AVX-512 bodies.
Escape catalog: no C1–C4 pattern in the changed script; release pipelines use pipefail.
Notes
The PR reports full qdot runs failing on missing fixtures in both arms. Validation was static; no hardware gates were run.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
| let d = f16c_to_f32(u16::from_le_bytes([wb[0], wb[1]])); | ||
| let dmin = f16c_to_f32(u16::from_le_bytes([wb[2], wb[3]])); |
There was a problem hiding this comment.
Use the existing paired conversion to perform one F16C conversion per weight block.
| let d = f16c_to_f32(u16::from_le_bytes([wb[0], wb[1]])); | |
| let dmin = f16c_to_f32(u16::from_le_bytes([wb[2], wb[3]])); | |
| let (d, dmin) = f16c_pair_to_f32([wb[0], wb[1], wb[2], wb[3]]); |
| assert!( | ||
| isa || !qdot::q4k_avx512(), | ||
| "q4k_avx512 picked the AVX-512 VNNI bodies on a CPU without their ISA" | ||
| ); |
There was a problem hiding this comment.
An always-disabled AVX-512 selector currently passes this gate; assert the expected arm too.
| assert!( | |
| isa || !qdot::q4k_avx512(), | |
| "q4k_avx512 picked the AVX-512 VNNI bodies on a CPU without their ISA" | |
| ); | |
| let wanted = std::env::var_os("BLOOMERY_QDOT_AVX512").is_none_or(|v| v == "1"); | |
| assert_eq!(qdot::q4k_avx512(), isa && wanted); |
There was a problem hiding this comment.
Verdict: MUST_FIX: The unsafe-scope fix still groups independent memory operations in single blocks.
Must fix
1. Finish the unsafe-scope fix (kind B, R1)
crates/qdot/src/lib.rs:4976 loads two separate groups in one unsafe block; crates/qdot/src/lib.rs:5576 writes two separate arrays. Other paired loads have the same defect. R1 requires one operation per block; its contiguous vector-load exception does not cover separate groups or arrays. The unsafe checker counts blocks and does not enforce their scope.
Local proofs cost less to fix now than after these bodies gain more access sites.
In both kernels, replace the (h1, h2) bindings with:
// SAFETY: g0's validated group has 8 readable header bytes.
let h1 = unsafe { _mm_loadl_epi64(g0 as *const __m128i) };
// SAFETY: g1's validated group has 8 readable header bytes.
let h2 = unsafe { _mm_loadl_epi64(g1 as *const __m128i) };Replace both (s1, s2) bindings with:
// SAFETY: offset 8 lies inside g0's validated 144-byte group.
let p0 = unsafe { g0.add(8) };
// SAFETY: offset 8 lies inside g1's validated 144-byte group.
let p1 = unsafe { g1.add(8) };
// SAFETY: p0 points at the group's readable bytes 8..16.
let s1 = unsafe { _mm_loadl_epi64(p0 as *const __m128i) };
// SAFETY: p1 points at the group's readable bytes 8..16.
let s2 = unsafe { _mm_loadl_epi64(p1 as *const __m128i) };In the tile, replace the mins8 binding and its comment with:
// SAFETY: offset 2 lies inside utmp's four u32 elements.
let min_ptr = unsafe { utmp.as_ptr().add(2) };
// SAFETY: min_ptr points at the final 8 readable bytes of utmp.
let mins8 = unsafe { _mm_loadl_epi64(min_ptr as *const __m128i) };Replace the tile's half and act closures with:
let half = |o: usize, p: usize| {
let lo = &q4[o..o + 32];
let hi = &q4[p..p + 32];
// SAFETY: lo is a checked 32-byte slice.
let lo = unsafe { _mm256_loadu_si256(lo.as_ptr() as *const __m256i) };
// SAFETY: hi is a checked 32-byte slice.
let hi = unsafe { _mm256_loadu_si256(hi.as_ptr() as *const __m256i) };
_mm512_inserti64x4::<1>(_mm512_castsi256_si512(lo), hi)
};let act = |o: usize| {
// SAFETY: o <= 96; offset 16 + o lies inside g0's group.
let p0 = unsafe { g0.add(16 + o) };
// SAFETY: o <= 96; offset 16 + o lies inside g1's group.
let p1 = unsafe { g1.add(16 + o) };
// SAFETY: 16 + o + 32 <= 144; p0 has 32 readable bytes.
let lo = unsafe { _mm256_loadu_si256(p0 as *const __m256i) };
// SAFETY: 16 + o + 32 <= 144; p1 has 32 readable bytes.
let hi = unsafe { _mm256_loadu_si256(p1 as *const __m256i) };
_mm512_inserti64x4::<1>(_mm512_castsi256_si512(lo), hi)
};In the lane kernel, replace the paired store block with:
// SAFETY: dy[c][ii] is a writable [f32; 8].
unsafe { _mm256_storeu_ps(dy[c][ii].as_mut_ptr(), dyv) };
// SAFETY: my[c][ii] is a writable [f32; 8].
unsafe { _mm256_storeu_ps(my[c][ii].as_mut_ptr(), myv) };Replace the (q0, q1) binding with:
// SAFETY: c0 < C and at + 16 <= 2 * nb * Q82X4_STRIDE.
let p0 = unsafe { acols[c0].add(at) };
// SAFETY: c1 < C and at + 16 <= 2 * nb * Q82X4_STRIDE.
let p1 = unsafe { acols[c1].add(at) };
// SAFETY: p0 points at 16 readable bytes of column c0.
let q0 = unsafe { _mm_loadu_si128(p0 as *const __m128i) };
// SAFETY: p1 points at 16 readable bytes of column c1.
let q1 = unsafe { _mm_loadu_si128(p1 as *const __m128i) };Keep these operations inside the existing target-feature bodies. Re-pin the unsafe count with a dated R1 reason after applying the replacements.
Non-blocking
⚠ Validation evidence remains open: crates/qdot/src/lib.rs:4925 now uses the paired conversion. The reported runs name earlier commits. Provide the owning qdot gate in both lever arms and current base/head A/B commands and output (R20), with CONTRIBUTING's evidence list, including the nvidia-smi line.
Checked
Duplicates: 0 new functions/types/constants in this increment; existing paired-conversion owner reused. The duplicate Q4_K lane clause is removed.
Complexity: no control-flow branch added to either kernel; dot_row is unchanged in this increment.
Silent failure: 0 new default/discard sites. Tile and lane callers validate lengths and return named shape errors.
Tests: statically, forcing the selector false fails the new equality assertion when ISA and lever are enabled. The Q4_K synthetic gate retains bit comparisons for rows, tiles and lanes; Q5_K/Q6_K retain their lane assertions.
Gates: clause move and unsafe-ratchet increase have dated PIN reasons; no numeric band moved.
Escape catalog: no C1–C4 match in this increment.
Adversarial: input validation rejects short buffers; chunk tails and odd columns use bounded indices. FMA order is unchanged.
Notes
The reported full qdot runs fail on missing fixtures in both arms. Review validation was static; no hardware gates were run.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
39c5f63 to
9cc1a20
Compare
|
Sorry, we made a mistake here. While tidying PRs we rebased your branch onto main and pushed two extra commits ( This comment was written by the bloomery AI assistant on behalf of the maintainer. |
|
No harm done, and thanks for flagging it. Please keep |
There was a problem hiding this comment.
Verdict: MUST_FIX: invalid override values bypass scalar-path validation, and the synthetic Q4_K fixture table has two owners.
Must fix
1. Validate the override before choosing a scalar path
Kind A. crates/qdot/src/lib.rs:477 and crates/qdot/src/lib.rs:294: BLOOMERY_QDOT_AVX512=2 with valid Q4_K inputs returns a scalar dot on aarch64 or x86_64 without AVX2, instead of the promised named panic. The x86_64 guard skips the parser when hw is false; the non-x86_64 entry never calls it. Startup does not close this path: crates/levers/src/lib.rs:684 skips Direct rows.
Closing this now keeps invalid configuration from becoming accepted behavior on more backends.
Replace both selector definitions with one implementation:
/// Whether Q4_K uses AVX-512 VNNI; false on other architectures.
/// Reads its override once and refuses values other than 0 or 1 by name.
#[must_use]
pub fn q4k_avx512() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| {
let wanted = match std::env::var_os("BLOOMERY_QDOT_AVX512") {
None => true,
Some(v) if v == "1" => true,
Some(v) if v == "0" => false,
Some(v) => panic!("BLOOMERY_QDOT_AVX512={v:?}: takes 0 or 1"),
};
#[cfg(target_arch = "x86_64")]
let isa = has_features(GgmlType::Q4_K)
&& std::arch::is_x86_feature_detected!("avx512f")
&& std::arch::is_x86_feature_detected!("avx512bw")
&& std::arch::is_x86_feature_detected!("avx512vnni");
#[cfg(not(target_arch = "x86_64"))]
let isa = false;
wanted && isa
})
}In x86 dot_row, insert this after check_row and change the Q4_K guard from if q4k_avx512() to if avx512:
let avx512 = w == GgmlType::Q4_K && q4k_avx512();Replace the non-x86 dot_row with:
#[cfg(not(target_arch = "x86_64"))]
pub fn dot_row(w: GgmlType, wrow: &[u8], acol: &[u8], k: usize) -> Result<f32, QdotError> {
if w == GgmlType::Q4_K {
let _ = q4k_avx512();
}
dot_row_scalar(w, wrow, acol, k)
}2. Give the Q4_K fixture table one owner
Kind B. crates/qdot/tests/qdot.rs:4381 and crates/qdot/tests/qdot.rs:6023 contain the identical six (k, rows, seed) tuples. Both clauses generate Q4_K rows from this table. R14 requires one owner.
Extracting the table now prevents later coverage changes from requiring two edits.
Add this beside the fixture helpers:
const Q4K_SYNTHETIC_ROWS: [(usize, usize, u64); 6] = [
(256, 16, 0x5a12_0001),
(512, 16, 0x5a12_0005),
(768, 16, 0x5a12_0006),
(2048, 16, 0x5a12_0002),
(2304, 16, 0x5a12_0003),
(4096, 24, 0x5a12_0004),
];Replace each six-tuple array literal with Q4K_SYNTHETIC_ROWS. Keep the tile loop and the lane test's existing .iter().map(...).collect().
Non-blocking
⚠ Refresh the validation evidence: crates/qdot/tests/qdot.rs:6066 moves tile coverage into the model-dependent gate; the old lane test also loses Q4_K. The PR body still describes their earlier arrangement. Rerun the changed clauses and FAIL-first mutants at this head on the AVX-512 host, and identify clauses completed before missing-model failures.
⚠ Complete the performance evidence: crates/qdot/src/lib.rs:4912 changes the decode and prompt integer path. The CPU, model, arm commands and rates are given, but the required nvidia-smi output is absent. Attach that output with the compared hashes and run output required by CONTRIBUTING.
Checked
Duplicates: 7 new function/constant definitions searched, counting cfg variants separately; both fixture tables confirmed. ISA kernel bodies have the R12 exemption.
Complexity: dot_row gains one guarded ISA arm.
Silent failure: traced the selector, scalar fallback and startup parser. Column-count guards bound the lane pairing and chunk minima.
Tests: read the bit comparisons and NaN canaries. Static mutant checks cover swapped scale fields (:4925), wrong column reduction (:5034), swapped FMAs (:5026–5027), wrong activation half (:5622) and a dropped output copy (:1268). No tests or mutants were run during validation. No scalar-path invalid-override assertion exists.
Gates: unsafe-count increases and coverage moves have dated PIN reasons; no numeric band changes.
Escape catalog: C1–C4 do not match the changed shell code; pipefail is enabled. No ledger lessons are in force.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
…odies, picked at run time (qdot::q4k_avx512, BLOOMERY_QDOT_AVX512) and bit-identical to the AVX2 ones, and the release check lists the two bodies as runtime-dispatched; hw_q4k_avx512_matches_avx2_synthetic and the f16 scale sweep hold them to dot_row_avx2 and the scalar mirror (FAIL-first: the tile's sub-block fmas swapped, a sub-block paired with the wrong activations, or a lane half reading the other half's activations turns it red)
… block per operation with its SAFETY line (R1), d and dmin through f16c_pair_to_f32, Q4_K's synthetic lane clause owned by hw_q4k_avx512_matches_avx2_synthetic, and that gate asserts the selector picks AVX-512 exactly where the ISA is present and the lever allows
…lock per pointer offset, load and store (R1), and the synthetic tile fixtures owned by hw_q4k_tile_matches_dot_row
Three AVX2 helpers take over setup that the Q4_K and Q5_K kernels repeated. q82x4_dy_my reads a column's dy (the eight blocks' bf16 scales as f32) and my (dy times the blocks' i16 sums) from the heads of super-block i's two Q8_2_X4 groups. q45k_scales_ps and q45k_mins_ps turn a block's unpacked scales and mins into eight f32 each. Each kernel still multiplies them by d and -dmin itself, where it did before. dot_q4k_q82x4_avx2, dot_q5k_q82x4_avx2, dot_q45k_q82x4_tile_avx2, pack_lanes_avx2 and dot_lanes_avx2 call them, and so do the two AVX-512 bodies, which also lose their extra block level. The helpers carry #[target_feature(enable = "avx2")] and #[inline], and keep one unsafe operation per block with its SAFETY line (R1). At x86-64-v3 and znver3, every out-of-line AVX2 kernel and tile::<C> keeps its instructions, and so do dot_lanes_avx2 and dot_q45k_q82x4_tile_avx2 when they are kept out of line. The two AVX-512 bodies, and dot_lanes_cols, which inlines the AVX2 lanes, compile differently. The qdot pin in tools/unsafe-ratchet.txt goes from 180 blocks and 79 fns to 172 and 80.
dot_row_cols now chooses Q4_K's AVX-512 VNNI tile before its column-count match and calls tile_q4k_avx512::<C>. tile::<C> loses its guard arm and is main's code again. With the arm inside, it changed the register allocation of the whole function and slowed the AVX2 tiles too. One local macro maps the column count to C for both tiles. dot_lanes_cols picks a LaneKind (Q45K, Q4KAvx512 or Q6K) once a call, and lanes::<C> matches on it instead of asking q4k_avx512 per chunk.
q4k_synthetic_rows builds Q4_K's seeded row sets and the all-0xFF rows at k = 4096. hw_q4k_tile_matches_dot_row and hw_q4k_avx512_matches_avx2_synthetic both read it, so the two clauses no longer carry their own copies of the same sets. The tile clause's PIN states where its rows now come from.
…t load q4k_avx512 is now one function on every architecture. It reads the lever first, panics by name on any value other than 0 or 1, and only then asks the CPU; off x86_64 the answer is false. Every Q4_K dot_row asks it, including the scalar arm off x86_64 and on an x86_64 CPU without AVX2. model::ops::host_stack_runs asks it first for a Q4_K stack, so a refused value stops the host tier's load before the server listens. dot_row_refuses_a_qdot_lever_value_by_name and host_layer_build_refuses_a_qdot_lever_value_by_name run a Q4_K dot_row and a Q4_K host layer build in a fresh process with the lever at 2, and hold the panic to name the lever. Taking the ask out of dot_row's AVX2 Q4_K arm or out of host_stack_runs turns its test red. tools/defaults-twins.tsv gets a none row for the refusal probe's value. The qdot test file's line in tools/levers-direct.txt names the lever, which the AVX-512 gate reads to know which body q4k_avx512 must pick.
The PIN above DISPATCHED names the check every caller passes before it reaches qdot's two Q4_K AVX-512 VNNI bodies: AVX-512 F, BW and VNNI beside the AVX2 kernels' AVX2, FMA and F16C.
README.md, docs/performance.md and tools/release/README.release.md said the host kernels are AVX2 only. The release README's requirements line now says AVX-512 is optional.
9cc1a20 to
0094a92
Compare
|
Thanks for the third pass. Earlier on this thread I said the branch would not be rewritten under the maintainer's two commits. That did not hold: 1. Validate the override before choosing a scalar path. Fixed in On x86_64 I used a different form than
A new test holds the The test sets 2. Give the Q4_K fixture table one owner. Done in t0 red on Non-blocking items.
The release allowlist (the inline note on #140). What else the new commits do. |
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix finding remains; the reference-backed Q4_K gate still needs a complete run.
Non-blocking
⚠ Complete the reference-backed Q4_K gate: crates/qdot/tests/qdot.rs:4376. The PR reports 41 fixture-read failures in each selector arm, including this test's reference dump read at line 4393. Run both arms at the head on a CPU with AVX-512 F, BW and VNNI and readable model and reference files, and attach the output before release.
BLOOMERY_BOX_LOCAL=1 BLOOMERY_QDOT_AVX512=1 just gate-qdot
BLOOMERY_BOX_LOCAL=1 BLOOMERY_QDOT_AVX512=0 just gate-qdotChecked
Duplicates: shared factor setup and Q4_K synthetic rows reuse common owners. The dryer pair shares wrapper shape but has different formats and output contracts.
Complexity: crapper reports dot_lanes_cols (13 → 16) and dot_row (18 → 20). Both add dispatch arms; growth alone proves no defect.
Silent failure: 5 added sites checked. Three discarded selector results retain named validation; two empty panic-message defaults fail assertions.
Tests: the PR reports FAIL-first for removed lever checks, swapped FMAs and wrong activation halves. Tile and lane assertions compare output bits; Q5_K/Q6_K lane clauses remain. Hardware tests were not run during validation.
Gates: release ISA exceptions, the unsafe ceiling and the moved Q4_K lane clause have dated reasons. No numerical band changed.
Escape catalog: C1–C4 do not match the changed shell code; the release scan retains pipefail and checks its result.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
Follow-up on the last review's non-blocking item: the reference-backed Q4_K gate in both selector arms. Tree: main Where the The reference files. The repository does not pin the ik commit behind Commands. LC_ALL=C BLOOMERY_BOX_LOCAL=1 BLOOMERY_DATA=$DATA BLOOMERY_BOX_ENV='BLOOMERY_QDOT_AVX512=1' \
./tools/box.sh 'bash tools/gate.sh --release -p bloomery-qdot --test qdot -- --include-ignored --nocapture'The second run is the same with Result. Both exit with 101, and the 23 failures are the same tests with the same messages in both arms. The Q4_K clauses that read the references, in both arms:
Gate 4 ( Still red, the same in both arms, by missing input:
|
|
A second run of the gate-qdot follow-up above, now with the real files: the V4.1 Q3_K_M shards (vcruz305/DeepSeek-V4.1-Flash-GGUF at Tree: main Inputs. The tests open fixed paths:
The command is the same recipe body as before, once per arm, with no Result. Both runs exit with 101 and fail the same 10 tests with the same messages. After normalizing run metadata and timings, the only difference between the two logs is the body name that The four checks the PR body named as the ones a maintainer's run checks on real weights now all pass in both arms. The two that waited on the V4.1 shards are the two The Q3_K paths, including Gate 4 ( 13 of the first run's 23 failures now pass: the ten that needed the V4.1 shards (five of them Q5_K) and the three UD-Q3_K_XL tile tests. No test went from pass to fail. Still red, the same in both arms:
This is consistent with ik_llama.cpp
I did not build No action on #86 is asked here. One consequence for the maintainers' own reference: once the reference ik moves past #2664 and the IQ4_XS dump is made again, |
What and why
Q4_K's two host kernels against Q8_2_X4 columns, the tile behind
dot_rowanddot_row_colsand the row lanes behinddot_lanes_cols, get AVX-512 VNNI bodies that write the AVX2 kernels' bits and are picked at run time on a CPU withAVX-512 F, BW and VNNI. On one Zen 5 desktop (Ryzen 9 9950X), prefill on Qwen3.6-35B-A3B Q4_K_M is 5.9 % (± 0.8)
faster at 474 prompt tokens and 6.2 % (± 0.7) at 3,681 than with
BLOOMERY_QDOT_AVX512=0in the same binary, anddecode shows no difference I could measure. This is step 2 of #81 for Q4_K only; step 1 and the other types stay open,
so there is no
Closesline.How it works
The two bodies:
dot_q4k_q82x4_tile_avx512::<C>is the tile behinddot_row_cols(C = 2..8). At C = 1 it is alsodot_row's Q4_Kkernel, which decode uses.
dot_lanes_avx512::<C>is the row-lane dot behinddot_lanes_cols, which a prompt batch's host experts use.pack_laneskeeps its AVX2 body in both arms.With the lever at
0, every out-of-line AVX2 kernel and everytile::<C>is main's machine code. The AVX2 lanesinline into
dot_lanes_cols, which differs from main's as a whole (under "Machine code").Bits
The integer sums move from
maddubsandmaddtovpdpbusd. Q4_K codes are at most 15 and the activationcodes lie in [-128, 127], so neither instruction saturates and both give the exact sum. The float side keeps the
AVX2 kernels' products and fused adds in each lane, in their order:
fma(my, mins), then the two sub-block halves,then
hsum_float_8. In the tile, a zmm holds sub-blocktbeside sub-block4 + t, and a 4x4 transpose per 128-bitlane puts the sums in the lanes of the AVX2 kernel's
sumi_0andsumi_1. In the row lanes, a zmm carries twocolumns (column
2pin the low half,2p + 1in the high half; an odd C pairs its last column with itself), and eachhalf does what one ymm does in
dot_lanes_avx2.Selection
qdot::q4k_avx512()decides once per process. It is true when the CPU has AVX-512 F, BW and VNNI on top of whathas_featuresasks for, andBLOOMERY_QDOT_AVX512is unset or1.0keeps the AVX2 bodies in the same binary,which is how the numbers below were taken. The maintainer chose to keep the default on, the in-place read and the
lever's name, and to revisit the default if another CPU reports a slowdown.
Any other value panics with the lever's name.
q4k_avx512()is one function on every architecture: it reads andchecks the lever first, and only then asks the CPU. Off x86_64 no AVX-512 body is compiled, so its answer there is
false, but a bad value still panics.
The panic comes while the host tier is built, before the server listens.
model::ops::host_stack_runscallsq4k_avx512()first for each Q4_K stack, before it asks whether qdot has a kernel for the type, so an x86_64 CPUwithout AVX2 also gets the lever's name. Every family's
HostLayer::buildruns that check on its routed stacks atload. The first call reads the lever; later calls get the cached answer. The new test
host_layer_build_refuses_a_qdot_lever_value_by_nameholds this (under "Lever value at load").Two cases stay outside the load check. A host tier with no Q4_K stack never reads the lever, and none of its kernels
depend on it. The CPU engine (
bloomery-decode) builds no host tier and reads the lever at its first Q4_K dot: everyQ4_K
dot_rowasksq4k_avx512(), also where it runs the scalar mirror (off x86_64, or on an x86_64 CPU withoutAVX2). The new test
dot_row_refuses_a_qdot_lever_value_by_nameholds this. I did not runbloomery-decodewith arefused value, so how it ends after that panic is not checked.
The release build stays
x86-64-v3: the new bodies carry their own#[target_feature], so the release binary hasthem and picks them at run time.
tools/release/build.shrefuses an instruction pastx86-64-v3outside thefunctions it lists as runtime-dispatched, and since
cff55213it reads each instruction's encoding, so AVX-512 at anyvector width counts. Its
DISPATCHEDpattern now also namesqdot::dot_q4k_q82x4_tile_avx512::<C>andqdot::dot_lanes_avx512::<C>, under a datedPIN(2026-10-12)comment that names the CPU check every caller passesfirst (AVX-512 F, BW and VNNI beside the AVX2 kernels' AVX2, FMA and F16C). The check and its FAIL-first are under
"Static checks".
The lever's registry row places the read in
crates/qdot/src/lib.rsunder the roundisa-owner(
tools/levers-direct.txt). The AVX-512 gate incrates/qdot/tests/qdot.rsalso reads the lever, to know which bodyq4k_avx512()must pick, so the list's line for that file names it too. When the step 1 owner lands,q4k_avx512canbecome a row of its per-type table, and the lever can stay as that owner's override or go. I did not try to build the
owner here.
Where each entry picks its body
Each entry asks
q4k_avx512()once per call, before it reaches any AVX2 code:dot_rowhas a guard arm ahead of its Q4_K arm, and a Q4_K arm of its own for a CPU without AVX2, which asksq4k_avx512()and runs the scalar mirror. Reading the selector once at the top ofdot_rowwould do the same, butat
x86-64-v3it made the compiler inline the AVX2 Q4_K kernel intodot_row; the extra arm leaves every kernelas it was (under "Machine code").
dot_row_colspicks before its column-count match and callstile_q4k_avx512::<C>. One local macro maps thecolumn count to
Cfor both tiles.tile::<C>, which inlines the AVX2 tiles of Q4_K, Q5_K and the other tiledtypes, is main's machine code.
dot_lanes_colscomputes aLaneKind(Q45K,Q4KAvx512orQ6K) once, andlanes::<C>matches on it.Commits
Nine commits on main
33fb317b. The six after the maintainer's answer the third review, one contract each:f566d8ba: the AVX-512 bodies, the lever and the release check.2e31d011and0f4d36e6, the maintainer's: the first two reviews folded in (one unsafe block per operation, theselector assertion, and the test layout under "Bit checks").
ef6e0c45(qdot): the three shared helpers in the Q4_K and Q5_K kernels and the two AVX-512 bodies, which also losetheir extra block level, and the re-pinned unsafe count. The output bits do not change.
2fb45954(qdot):dot_row_colspicks the AVX-512 tile beforetile::<C>, which is main's code again, anddot_lanes_colspicks aLaneKindonce a call.4052f514(qdot tests): one owner for Q4_K's synthetic rows,q4k_synthetic_rows().d9119c85(qdot, model): the behaviour change. A refused lever value stops every Q4_Kdot_rowon everyarchitecture and the host tier's load, with the two refusal tests, the row in
tools/defaults-twins.tsvand thelever's line in
tools/levers-direct.txt.e4412d01(release): the dated PIN above the AVX-512 entries ofDISPATCHED.0094a925(docs): the docs the change makes stale (under "Docs").The branch was rebased from main
f1a3e9e4onto33fb317b, becausecff55213rewrote the host-code check intools/release/build.sh. The first commit's two changes there, the newDISPATCHEDentry and the qdot clause in thecomment above the scan, now sit in the new check unchanged. Every other commit's diff is the same as before, and each
commit keeps its author. Before the rebase, the three commits already on this PR were
43e75820and the maintainer'sad7a4cb9and9cc1a203, and this branch's head wasf8e32756.crates/qdotis the same tree at each commitbefore and after.
qdot's line in
tools/unsafe-ratchet.txtgoes from 141 blocks and 77 fns on main to 172 and 80 (the count is under"Code shape").
The earlier builds that "What I ran" cites are not part of this PR:
38af59aa,5cc0a477,435b51ac,013f098e,5df92e10,b0ff0ac9,8e816da5,fbf33c06(this branch's head before the split above, with the same code apartfrom the review's fixes) and
f8e32756(the head before the rebase). Each is on the fork as a branch namedqdot-avx512-q4k-measured-<hash>, so the hashes resolve.Docs
These lines said the host kernels are AVX2 only. They now say Q4_K's switch to AVX-512 VNNI on a CPU that has it:
README.md:219("CPU experts at memory speed")docs/performance.md:70(the same item)tools/release/README.release.md:3-4, and its requirements line now adds that AVX-512 is optional.AGENTS.md:3-4("AVX2 kernels for the CPU expert tier") andAGENTS.md:128(crates/qdot/ fused quantized dot kernels, AVX2) say the same. I leftAGENTS.mdto the maintainer, since it is the project's working contract.What I ran into
The choice inside
tileAn earlier version of this branch (
435b51ac) put the guard arm insidetile::<C>. That changed the registerallocation of the whole function, so the AVX2 arms got slower too.
tile::<4>went from 249 stack stores and 346stack loads to 276 and 363, and at k = 512 its AVX2 arm ran 4.3 % (-7.7..-3.5) slower than main's in
tile4-l2and2.4 % (-2.6..-2.4) slower in
tile8-l2, in all 4 rounds. With the choice moved out oftile::<C>, that function ismain's again (under "Machine code"), and the comparison is under "Main and this branch, AVX2 arm".
64-byte loads
The first tile body loaded each block's 128 code bytes, and each column's two 128-byte groups, as 64-byte loads. At a
144-byte block pitch most of those loads split a cache line. In a single-core L2 loop that cost little, but at
k = 512 (Qwen3.6's down projection) with 16 threads streaming from DRAM that body read clearly less than AVX2, and
decode on the model below ran slower than with AVX2. Loading 32 bytes at a time, as the AVX2 kernels do, and joining
halves with
vinserti64x4brought that case to -0.2 % (-0.7..+0.2) against AVX2 (dot1-dram-T16under "Kernelrates"). A comment at the loads says why they are 32 bytes. If an Intel part prefers the 64-byte form, that would show
up in its numbers.
Code shape
float steps keep the AVX2 order, which is what keeps the bits.
AGENTS.md:185-186says not to split a#[target_feature]kernel body into helpers, and that a helper touching_mm*intrinsics is#[inline(always)]or carries the attribute itself. The setup the Q4_K and Q5_K bodies repeated is now threehelpers that carry
#[target_feature(enable = "avx2")]and#[inline]:q82x4_dy_my(
crates/qdot/src/lib.rs:3848) gives a column'sdyandmy, andq45k_scales_psandq45k_mins_ps(
:3876and:3888, safe fns) give a block's eight scales and eight mins as f32. Each kernel still multipliesthem by
dand-dminitself, at the point where main's kernel does. An earlier single helper that returnedboth products reordered the instructions of the AVX2 kernels, so I split it. All three inline into every caller
at
x86-64-v3andznver3(no symbol of theirs is left in the qdot library at either target); I did not checkplain
x86-64.crates/model/src/ops.rsgains thelever's load check in
host_stack_runs, andcrates/model/src/moe.rsgains its test.lanesnow takes aLaneKindin place of aq6flag, and nothing is left unused.0or1panics by name on every architecture: at load whenthe host tier holds a Q4_K stack, and at the first Q4_K
dot_rowotherwise, the scalar arm included (under"Selection"). A CPU without AVX-512 VNNI runs the AVX2 bodies, as before.
PIN(2026-10-14)incrates/qdot/tests/qdot.rsnowsays where its rows come from.
tools/unsafe-ratchet.txtre-pins qdot from 141 blocks and 77 fns to 172 and 80 with aPIN(2026-10-14):line. The new code holds one unsafe operation per block (R1), each with its own SAFETY line:the tile (7 blocks) and the row lanes (12) as two unsafe fns, the
dot_rowarm andtile_q4k_avx512that callthe tile (2),
q82x4_dy_my(one unsafe fn of 8 blocks, one per pointer offset and load), and one load block ineach of
q45k_scales_psandq45k_mins_ps. No block pairs two groups, two arrays, or a pointer offset with itsload. The AVX2 kernels whose setup now calls the helpers keep main's whole-body
unsafe {}(
crates/qdot/src/lib.rs:3904, 4599, 4813, 5204, 5409; main has the same shape, for exampledot_q4k_q82x4_avx2at main'slib.rs:3759). Splitting those is a refactor of every AVX2 kernel, which this PRdoes not take on.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up (41, the ratchet).Duplication found or removed (
path:line), or "none": removed, and one found. The per-columndyandmysetup ofdot_q4k_q82x4_avx2,dot_q5k_q82x4_avx2,dot_q45k_q82x4_tile_avx2,dot_lanes_avx2and the two new bodies isnow
q82x4_dy_my(crates/qdot/src/lib.rs:3918, 4614, 4831, 5008, 5422, 5538). The per-block scale and min loads ofdot_q4k_q82x4_avx2,dot_q5k_q82x4_avx2,dot_q45k_q82x4_tile_avx2, the AVX-512 tile andpack_lanes_avx2are nowq45k_scales_psandq45k_mins_ps(crates/qdot/src/lib.rs:3914, 3921, 4610, 4617, 4825, 4836, 4975, 4976, 5227, 5228). The scalar mirrors keep their scalar form of all three. Q4_K's synthetic rows, which the tile clause and theAVX-512 clause both read, have one owner,
q4k_synthetic_rows()(crates/qdot/tests/qdot.rs:5740), the all-0xFFrows at k = 4096 included. In
dot_row_cols, one local macro maps the column count for both tiles. Found, notchanged: Q6_K's three kernels keep the same
dydecode asq82x4_dy_my's first half (crates/qdot/src/lib.rs:4203, 4342, 5693). Ady-only helper for them is outside this PR: this PR does not change the Q6_K kernels, and moving their hot-pathdydecode needs its own bit check and timing.What I ran
Base
33fb317b, head0094a925. Most of the checks below ran atf8e32756, the head before the rebase onto33fb317b(under "Commits"), and each section says which head it ran at. At the new head I ran again what the rebasecan reach: the release check with its FAIL-first, the bit-printing program in both arms and on the new main, the
qdot default set in both arms, the server's qdot machine code against
f8e32756's,just contrib-check --tier t0,gate-levers, the unsafe ratchet and the x86_64 lint at every commit, andjust mac-static 33fb317b. Everythingx86_64 ran on the Zen 5 desktop under "Hardware", with the CPU governor at
performancefor every timed run.The timed runs used earlier builds. Their qdot kernels compile to the same machine code as the head's, and
dot_rowdiffers:
38af59aa(on main5c98cc70): the kernel table, the AVX2 arm against main, the first model window.5cc0a477(on maina7ed8b58): the second model window, beside that earlier version435b51ac(under "The choiceinside
tile").The step-by-step comparison is under "Machine code". The main commits from
5c98cc70tof1a3e9e4touch neitherqdot nor what it links. Main
33fb317bchangescrates/gguf, which qdot links, and the server's qdot functions staythe same machine code across the rebase (under "Machine code").
Bit checks
cargo test --release -p bloomery-qdot --test qdot -- --include-ignored(whatjust gate-qdotruns on the box),repository flags, once per arm, at
f8e32756:BLOOMERY_BOX_LOCAL=1 just gate-qdotgives the same lines, in both arms and atBLOOMERY_TIER=fixture. The 41failures are the same in both arms. Each stops on an input it cannot read: 15 on a model shard under
/models(theDeepSeek-V4, V4.1 and Qwen3.8 files; the open fails with "No such file or directory") and 26 on a reference dump under
$BLOOMERY_DATA/ref(the read fails withPermissionDenied), which the maintainers'just build-refandjust dump-refproduce. Neither input is readable on this machine. The Q4_K ones among them,hw_q4k_dot_row_matches_scalar_and_predicts,hw_q4k_tile_matches_dot_row,hw_lanes_match_dot_row_v41andhw_scalar_fallback_bit_identical_to_avx2, are the ones a maintainer's run checks onreal weights. The default model file,
/models/small/DeepSeek-V2-Lite-Chat.Q3_K_M.gguf, is there, so the 41 aremain's 42 failures from an earlier run on this machine minus
hw_q5f1_tile_matches_dot_row, which needs only thatfile. The default set (
cargo test --release -p bloomery-qdot) passes 27 in both arms, atf8e32756and again at0094a925.The three model-free tests that reach the new bodies pass in both arms at
f8e32756:hw_q4k_avx512_matches_avx2_synthetic(new) first asserts thatq4k_avx512()is true exactly when the CPU hasAVX-512 F, BW and VNNI and the lever is unset or
1. Then, for seeded Q4_K rows at k = 256, 512, 768, 2048, 2304and 4096, plus all-0xFF rows at k = 4096 (all from
q4k_synthetic_rows()), against 11 columns:dot_rowmust equaldot_row_avx2and the scalar mirror, and the row lanes must equaldot_row. It owns Q4_K'ssynthetic lane clause and prints which body ran:
hw_lanes_match_dot_row_synthetic(existing) keeps the lane clause for Q5_K and Q6_K.f16_scales_bit_identical_kernel_vs_mirror(existing, in the default set) now also holdsdot_rowto the AVX2kernel over every f16 scale that is not NaN (63,490 of the 65,536 patterns), so Q4_K's subnormal, infinite and zero
scales go through the AVX-512 body too. Where both results are NaN, the test only checks that both are NaN, not
their payload bits.
hw_q4k_tile_matches_dot_row(existing) now holds the tile todot_rowon the rows ofq4k_synthetic_rows()beforeit opens its model file. That part passes on this box. The test then opens the model file
(
crates/qdot/tests/qdot.rs:4384) and stops at:4394, where reading the reference dumpq4k-x4-ik-dot.txtfails with
PermissionDenied.A small program outside the tree also printed the bits of every output of
dot_row,dot_row_cols(C = 1..8) andpack_laneswithdot_lanes_cols, for seeded Q4_K and Q5_K rows at k = 256, 512 and 2048: 876 lines. The output isbyte for byte the same for main
5c98cc70, main33fb317b, andf8e32756and0094a925each with the lever at1and at
0(md51f2cf765ffc2d78e92a63e41b8bcb9f2).FAIL-first at
f8e32756: eight mutants ofcrates/qdot/src/lib.rs, one at a time, the crate rebuilt, each run oncewith the lever unset (the AVX-512 arm on this CPU). The unchanged code ran its clauses in both arms (above); the
mutants did not run at
0. Seven turn an assertion red, and the file's md5 was checked to come back after:hw_q4k_avx512_matches_avx2_synthetic,f16_scales_bit_identical_kernel_vs_mirrorhw_q4k_avx512_matches_avx2_synthetic,f16_scales_bit_identical_kernel_vs_mirrorhw_q4k_avx512_matches_avx2_syntheticq82x4_dy_mytaking the second group's sums from the first grouphw_q4k_avx512_matches_avx2_synthetic,f16_scales_bit_identical_kernel_vs_mirrorq45k_mins_psreading the scales' byteshw_q4k_avx512_matches_avx2_synthetic,f16_scales_bit_identical_kernel_vs_mirrorq4k_avx512false on every CPUhw_q4k_avx512_matches_avx2_synthetic(left: false,right: true)dot_row's AVX2 Q4_K arm not askingq4k_avx512()dot_row_refuses_a_qdot_lever_value_by_namedot_row's Q4_K arm for a CPU without AVX2 not askingq4k_avx512()The tile's synthetic part in
hw_q4k_tile_matches_dot_rowcompares the tile withdot_row, which runs the same bodyat C = 1, so a mutant of that body changes both sides alike and that part stays green; the comparison with the AVX2
kernel and the scalar mirror catches it. With the selector off, every comparison runs AVX2 against AVX2 and passes,
so the first assertion is what catches it. The last mutant needs a CPU without AVX2 to turn red here; its aarch64
counterpart is under "aarch64".
The maintainers' box is Zen 3, so
gate-qdotthere runs the AVX2 arm only. For the AVX-512 arm, the bit check isthese tests on a CPU that has it.
Lever value at load
host_layer_build_refuses_a_qdot_lever_value_by_name(crates/model/src/moe.rs:3282, a plain#[test]) runs itsown test binary again with
BLOOMERY_QDOT_AVX512=2, becauseq4k_avx512keeps its first answer in aOnceLock. Inthat process it builds a Q4_K host layer through
HostLayer::build, the load's own check, and asserts that the buildpanics and that the panic names the lever. Its shape follows
the_split_reads_no_environmentincrates/placement.It runs on every architecture. On x86_64 at
f8e32756(cargo test -p bloomery-model --lib -- --exact moe::tests::host_layer_build_refuses_a_qdot_lever_value_by_name --nocapture):The child checks that the panic contains
BLOOMERY_QDOT_AVX512="2", fromq4k_avx512's messageBLOOMERY_QDOT_AVX512="2": takes 0 or 1. FAIL-first: with theq4k_avx512()call taken out ofhost_stack_runs,the build succeeds and the test fails (
a refused lever value must stop the build: Ok(()),0 passed; 1 failed).With the call back, it passes. It also passes with
BLOOMERY_QDOT_AVX512=0set for the whole run, because the childsets its own value. The aarch64 runs are under "aarch64".
dot_row_refuses_a_qdot_lever_value_by_name(crates/qdot/tests/qdot.rs:6010, a plain#[test]on everyarchitecture) does the same for
dot_row: in a fresh process withBLOOMERY_QDOT_AVX512=2, a Q4_Kdot_rowmustpanic and the panic must name the lever. On x86_64 at
f8e32756it passes, also withBLOOMERY_QDOT_AVX512=0set for the wholerun, and turns red when
dot_row's AVX2 Q4_K arm stops askingq4k_avx512()(the table above). The aarch64 run isunder "aarch64".
The same refusal on a real load:
BLOOMERY_CARD_BUDGET=4G BLOOMERY_QDOT_AVX512=yes bloomery-serve --hf lmstudio-community/Qwen3.6-35B-A3B-GGUF:Q4_K_M --place a --ctx 8192 --parallel 1 --host 127.0.0.1 --port 8093.Before the load check (a server build of the first head of this PR):
The request got
{"error":{"code":500,"message":"engine: the engine thread ended mid-call","type":"server_error"}},and the server exited with code 70.
After (a server build of
38af59aa, built atx86-64-v3intotarget/portable):The server never listened and exited with code 1.
aarch64
On a DGX Spark (GB10), in a CUDA 13.3.1 dev container (
cargo test, debug profile), atf8e32756. The tree wasgit archive f8e32756, checked file by file against its md5 list (1,703 files, no difference). I did not run theseagain after the rebase: it does not change
crates/qdot, and main's changes tocrates/modelleaveHostLayer::buildandhost_stack_runs, which the load test runs, as they were.Both refusal tests also pass with
BLOOMERY_QDOT_AVX512=0set for the whole run.FAIL-first, each on a copy of that tree with one change:
dot_row'sq4k_avx512()ask taken out, thedot_rowrefusal test failswith
a refused lever value must stop dot_row: Ok(-572683.25). This is the aarch64 counterpart of the last mutantin the table above.
q4k_avx512()call taken out ofhost_stack_runs, the load test fails witha refused lever value must stop the build: Ok(()).Model text
After the timed requests of the first model window, each of the 16 servers (4 per arm, arms under "Model") answered
two greedy requests (192 tokens at most, thinking off): a 25-token question, whose decode goes through
dot_row, and a4,421-token excerpt of
crates/qdot/src/lib.rswith "Summarize what the code above does.", whose prompt goes throughthe row lanes. All 16 servers gave the same two answers, byte for byte.
Static checks
On an aarch64 Mac, at
0094a925:just mac-static 33fb317bends withmac-static: ok(no rustfmt diff, lint 41 =the ratchet, 27 shapes run with 0 red, every
check-*at rc 0). The x86_64 lint (just mac-lint) gives 41 warnings,the ratchet, at each of the nine commits, and
tools/check-unsafe.shpasses at each (qdot's count is at its pin each time). Atf8e32756,just mac-testgives 1140 passed, 1 failed and 177 ignored. The one failure,
bloomery-refset'sarch::draft::tests::a_plain_target_with_no_draft_beside_is_the_family_path, fails the same way on main on this Mac,and this branch does not touch
crates/refset.crates/qdotandcrates/modelare not among the cratesmac-testruns on the Mac (their tests need Linux), so on the Mac the qdot and model tests are checked with
cargo clippy --testsforx86_64-unknown-linux-gnuandaarch64-unknown-linux-gnubut not run.On the x86_64 machine, at
0094a925:just contrib-check --tier t0:DONE tier=t0 total=78 red=0.BLOOMERY_BOX_LOCAL=1 just gate-levers:40 passed; 0 failed. Atf8e32756:BLOOMERY_BOX_LOCAL=1 just gate-opspasses its 291 library tests, and its 8 model tests stop because they cannot read the reference manifest
(
$BLOOMERY_DATA/ref/MANIFEST.tsv,PermissionDenied).gate-unionpasses 4 of 7, and the other 3 stop on the missing DeepSeek-V4.1shards. The same counts come at
BLOOMERY_TIER=fixture.The release check, at
0094a925, on thex86-64-v3server build (objdumpfrom GNU Binutils 2.46):tools/release/build.sh --self-testgivesrelease: self-test ok (12 cases), andtools/release/build.sh --check target/portable/releasegivesrelease: checks passed on target/portable/release.FAIL-first, each with one change to
build.sh, against the same binary:lanestaken out of the newDISPATCHEDentry, the check fails and names the four instances ofqdot::dot_lanes_avx512, for example116 qdot::dot_lanes_avx512::<4>, first at 1a6d604: vmovaps -0x18d7b8e(%rip),%zmm1.qdot::dot_q4k_q82x4_tile_avx512::<1>to<8>.PIN(2026-10-12)comment taken out, the check passes. Nothing reads that comment, so it is there forreview, not for the check.
Machine code
I diffed the disassembly function by function (
objdump -d --no-show-raw-insn -C). The comparison keeps everyinstruction and operand and drops addresses and the numbering of anonymous symbols. A branch inside a function
compares as its offset from the function's start, a call or branch elsewhere as its target symbol, and a load of a
constant as the bytes it reads. A
lea, or a load whose width the operand does not show, compares as its targetsymbol. A
leato an anonymous symbol, or past the end of the named symbol it lands in, compares as "anonymous", so apanic location or exception table that moved does not count as a difference.
Against main, at
38af59aa. In the kernel bench under "Kernel rates" (-C target-cpu=x86-64-v3, where the AVX2tiles and lanes inline into their dispatchers), 31 of the 53 qdot functions are the same as main's and 22 differ:
dot_q4k_q82x4_avx2,dot_q5k_q82x4_avx2,tile::<2>totile::<8>,pack_groupin bothforms and
pack_lanes.tile_q4k_avx512::<4>to<8>andq4k_avx512.q4k_avx512()(dot_row,dot_row_cols,dot_lanes_cols), andquantize_col_check, whose one difference is the GOT slot of an indirect call.The server binary shows the same: 39 qdot functions the same, 21 different, and every AVX2 kernel and every
tile::<C>among the same.dot_lanes_colsinlinesdot_lanes_avx2::<C>, so it differs from main's as a whole. Tocompare the AVX2 lanes and tiles alone, I built the bench once more from both trees with
#[inline(never)]ondot_lanes_avx2anddot_q45k_q82x4_tile_avx2(a throwaway edit, not in this branch).dot_lanes_avx2::<1>to<4>and all 14 instances of
dot_q45k_q82x4_tile_avx2are then the same as main's.From
38af59aato the head, the same comparison on each step (bench and server built atx86-64-v3on the Zen 5box; 60 qdot functions in the server):
38af59aa5cc0a477host_stack_runsdiffer (the per-function listing of this step was not saved)5cc0a477013f098e#[target_feature], the lever's registry rowhost_stack_runsthe same013f098e5df92e10host_stack_runsthe same5df92e10b0ff0ac9f1a3e9e4; the samecrates/qdot/srccheck_row,dot_lanes_cols,dot_row_cols,quantize_col_checkandhost_stack_runsdiffer only in the GOT slot of one indirect callb0ff0ac98e816da5(=fbf33c06's code)q4k_avx512()on every architecturedot_row197 instructions, now 207dot_rowas in the bench;host_stack_runsthe samefbf33c06f8e32756dot_row_cols, everytile::<C>and everytile_q4k_avx512::<C>among them);host_stack_runs151 instructions, now 160 (it asksq4k_avx512()first)f8e327560094a925(head)33fb317b; the samecrates/qdothost_stack_runs, differ only in the address of a GOT slot, which the comparison here sets to one name (it does not compare the callee behind the slot), andnon_finite_activationalso in the bytes after the 4-byte constant it loads, which that load does not readBefore the rebase, for the step from
fbf33c06tof8e32756and for each of this branch's own commits, I also builtthe qdot library alone on the Mac (
cargo build --release -p bloomery-qdot --lib --target x86_64-unknown-linux-gnu,at
-C target-cpu=x86-64-v3and atznver3) and compared it the same way. The table names the commits by theirhashes after the rebase;
crates/qdotis the same tree at each. The results are the same at both targets:0f4d36e6toef6e0c45(helpers)tile::<C>is the same. With#[inline(never)]ondot_lanes_avx2anddot_q45k_q82x4_tile_avx2(the throwaway edit above), those two are the same too, and the same as main's. The two AVX-512 bodies change: the tile's instructions are reordered and renamed at the same counts, and the row lanes lose a few. Both are then the same as the head's, which ran the bit checks above.dot_lanes_colsinlines the AVX2 lanes. Atx86-64-v3that inlined copy compiles to a different instruction mix than at0f4d36e6; atznver3, and at both targets with the lanes kept out of line, only stack moves and padding differ. The head'sdot_lanes_colsis the timed builds' code (the table above).ef6e0c45to2fb45954(tile dispatch)tile::<2>to<8>become the same as main's.dot_row_colsanddot_lanes_colschange, andtile_q4k_avx512::<4>to<8>are new. Nothing else changes.2fb45954tod9119c85(lever refusal)dot_row(197 instructions, now 205) andq4k_avx512'sOnceLockinitializer, which now checks the lever before it asks the CPU. Nothing else changes.fbf33c06tof8e32756dot_row_colsgives the code of the two matches it replaced.The other three commits do not touch
crates/qdot/src. At the head, every AVX2 kernel, everytile::<C>, and with#[inline(never)]everydot_lanes_avx2anddot_q45k_q82x4_tile_avx2instance is the same as mainf1a3e9e4'sat both targets. The functions that differ from main are
dot_row,dot_row_colsanddot_lanes_cols, beside the newones; main's library also holds two
Zip::newinstances that0f4d36e6already lacks.host_stack_runsis incrates/model, so this check does not cover it; the server comparison in the table abovedoes.
Main and this branch, AVX2 arm
The kernel bench under "Kernel rates", built from main and from this branch (
38af59aa), ran itsl2cases asQB_K=<k> BLOOMERY_QDOT_AVX512=<0|1> qdot-isa-bench 5 1.0 l2at k = 2048 and 512: 4 rounds, the order of the fourruns rotated each round. Main has no lever, so its two runs are an A/A pair. M dots/s (rows/s for
pack-l2), medianof the 4 run medians; the ratios are the median of the 4 per-round ratios, with their range:
38af59aa, lever 038af59aa0 / maindot1-l2tile2-l2tile4-l2tile8-l2lanes8-l2pack-l2lanes8dot-l2dot1-l2tile2-l2tile4-l2tile8-l2lanes8-l2pack-l2lanes8dot-l2The tiles are within -0.2 % to +0.5 % of main, where the guard arm inside
tile::<C>had cost 4.3 % and 2.4 %.At k = 512,
dot1-l2reads -1.6 % (-2.9..+0.5) andlanes8dot-l2-1.4 % (-1.7..-1.0), against an A/A of-1.0 % (-1.0..+0.9) for the latter.
dot_row's AVX2 kernel is main's machine code, so I read the first as theentry's extra guard or the bench's spread;
lanes8dot-l2runsdot_lanes_cols, which inlines main'sdot_lanes_avx2beside the new arm, and I could not bring it closer to main than this. On the model, the lever-0 armagainst main reads -0.3 % (± 0.6) and -0.4 % (± 0.4) in prefill (under "Model"), under the 1 % that two binaries
can resolve.
Kernel rates
A small program outside the tree (source at the end) calls qdot's public entries (
dot_row,dot_row_cols,pack_lanes,dot_lanes_cols) on synthetic Q4_K rows and quantized columns. It is built withRUSTFLAGS="-C target-cpu=x86-64-v3" cargo build --releaselike the release, against this branch'scrates/qdotandcrates/gguf, and run asQB_K=<k> BLOOMERY_QDOT_AVX512=<0|1> qdot-isa-bench 5 1.0: 4 rounds, arm order flipped eachround, 5 reps per case and run, each rep at least 1 s (
l2cases) or 2 s (dramcases). The table gives the median ofthe 4 run medians, with the range of the per-round ratios:
dot1-l2:dot_row, 1 thread, M dots/stile2-l2:dot_row_cols, C = 2, M dots/stile4-l2: C = 4tile8-l2: C = 8lanes8-l2:pack_lanes+dot_lanes_cols, 8 columns, M dots/spack-l2:pack_lanesalone, M rows/slanes8dot-l2:dot_lanes_colson groups packed once, M dots/sdot1-dram-T1:dot_row, 1 thread, GB/sdot1-dram-T16: 16 threads, GB/slanes8-dram-T16: pack + 8 columns, GB/slanes64-dram-T16: pack + 64 columns, GB/sl2: 448 rows (504 KiB at k = 2048) dotted over and over on one thread.lanes8dot-l2keeps all 56 groups packed,1.1 MiB at k = 2048, a little more than the core's 1 MiB L2.
dram: 2.3 GB of rows at k = 2048 (0.58 GB at k = 512)split over T threads.
lanes64dots each packed group with 8 runs of 8 columns, as a prompt batch does. I can add theprogram under
crates/qdot/src/binif the maintainer wants it in the tree.The AVX-512 arm is slower in every round in three cases, all the one-column kernel:
dot1-l2at k = 512 (-2.1 %,-3.4..-1.0),
dot1-dram-T1at k = 512 (-0.5 %, -1.0..-0.0) anddot1-dram-T16at k = 2048 (-0.4 %, -0.6..-0.1). Atk = 512 a row is two super-blocks, so the setup of each call weighs more, and with 16 threads the leg is bound by
DRAM. Decode on the model, which runs this kernel, shows no difference.
dot_rowwithq4k_avx512()on every architecture: its new arm for a CPU without AVX2 moveddot_row's registerallocation, so the kernel bench of
8e816da5(fbf33c06's code) ran again beside that ofb0ff0ac9, built justbefore that change, with the same
l2cases in both arms, k = 2048 and 512, 4 rounds and the run order rotated eachround. For
dot1-l2,8e816da5againstb0ff0ac9(median of the per-round ratios, with their range): lever 1 reads+0.1 % (-2.8..+1.2) at k = 2048 and -0.6 % (-0.7..-0.5) at k = 512; lever 0 reads -0.1 % (-3.2..+0.4) and +0.7 %
(+0.5..+1.3). The other 24 cases run the same machine code in both benches and read from -1.1 % to +1.1 %, so the
change to
dot_rowstays inside what two binaries resolve here. At k = 512 the two arms each moved the same way inall 4 rounds (lever 1 slower, lever 0 faster). The
dramcases and the model did not run again for this change.Against the earlier version
435b51ac, in the second model window: its kernel bench and5cc0a477's, AVX-512 arm,4 rounds, order flipped each round. Two binaries, so read these as a guide. Most cases are within 1.5 %.
tile2-l2atk = 512 is 6.3 % faster.
dot1-l2is 3.2 % slower at k = 2048 and 2.4 % at k = 512, andlanes8-dram-T16at k = 5122.8 % slower.
pack-l2at k = 2048 is 4.1 % slower:pack_lanesruns AVX2 in both arms and is main's machine codehere (
pack-l2reads -0.4 % and +0.6 % against main above), so the earlier version's packing was faster than main's, andI gave that up to keep main's AVX2 code. On the model, prefill in the same window is 0.5 % (± 0.5) and 0.7 % (± 0.4)
faster at
5cc0a477than at435b51ac.Model
Qwen3.6-35B-A3B Q4_K_M (
lmstudio-community/Qwen3.6-35B-A3B-GGUF:Q4_K_M, 21,166,757,728 bytes),bloomery-servebuilt atx86-64-v3intotarget/portableastools/release/build.shdoes, run asBLOOMERY_CARD_BUDGET=4G BLOOMERY_QDOT_AVX512=<0|1> bloomery-serve --hf lmstudio-community/Qwen3.6-35B-A3B-GGUF:Q4_K_M --place a --ctx 8192 --parallel 1with the default worker pool (16 threads, the physical cores). The 4 GB card budget is there to
put the routed experts on the host: the plan line reads
host_experts=10108 card_experts=132. The host tier loadsq4_K k=2048(gate and up) andq4_Kandq6_Kat k = 512 (down), all fused. Decode reaches qdot throughdot_row,and a prompt through the row lanes.
Per arm and round, a fresh server got one warm-up and then 3 requests per prompt size on
/v1/chat/completions, 128tokens out, greedy, thinking off. The short prompt asks for a story; the two longer ones ask for a summary of 2,000 and
16,000 characters of Python source. A per-request nonce at the start keeps the prefix cache from reusing a prompt.
4 rounds, the arm order rotated each round. Every server of a window printed the same plan line and the same host tier
lines.
Two windows. The first ran four arms: main's server twice (an A/A pair; main does not know the lever, so it is unset),
and this branch's server (
38af59aa) with the lever at1and at0. The second ran this branch's server(
5cc0a477) and the earlier version435b51ac, each at1and at0.tok/s from the server's
timingsin the second window, median of the 12 requests (range in brackets):The ratios are the mean of the 4 per-round ratios with its 95 % interval (t, 3 degrees of freedom). Second window:
5cc0a4771 / 0435b51ac1 / 05cc0a477/435b51ac, at 15cc0a4771 / 0First window:
38af59aa1 / 038af59aa0 / main38af59aa1 / main38af59aa1 / 0The same code's prefill ratio, lever 1 against 0, read +4.6 % and +4.9 % in the first window and +5.9 % and +6.2 % in
the second, further apart than their intervals. The lever-1 arm moved between the windows (994 and 1013 tok/s in the
first, 1005 and 1027 in the second) while the lever-0 arm stayed near 949 and 967. In the second window
435b51acread +5.7 % and +6.2 %, as it did when it was measured first, and
5cc0a477read slightly above it, so I take the lowerfirst-window ratio to belong to that window, not to the code. Decode shows no difference in either window. The lever-0
arm against main, -0.3 % and -0.4 % in prefill, is under the 1 % that two binaries can resolve.
My reading, not measured here: decode's one-column leg is held by DRAM (
dot1-dram-T16above), and the host's dotproducts are only part of a prompt's wall.
Hardware
CPU: AMD Ryzen 9 9950X (Zen 5), 16 cores, 32 threads, AVX-512 F, BW, VL and VNNI, boost on, governor
performancefor the timed runs.
RAM: 2 x 32 GB DDR5 at 6000 MT/s, 2 channels.
GPU: the card holds the model's dense part; the change is on the CPU.
nvidia-smi:nvidia-smi --query-gpu=name,driver_version,clocks.max.sm --format=csv,noheader:NVIDIA GeForce RTX 5090, 595.99.02, 3090 MHz.Linux 7.0.0-38-generic, rustc 1.100.0-nightly (e457a7b0d 2026-08-27).
These numbers come from one Zen 5 desktop with two memory channels. Numbers from Zen 4 or an Intel AVX-512 server
would show where the gain starts and stops, and
BLOOMERY_QDOT_AVX512=0gives the AVX2 side from the same binary.The kernel bench program (
Cargo.tomlandsrc/main.rs)AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.