ferrox-quant 0.18.0

Quantized weight formats and fused dequant kernels for Ferrox
Documentation
//! The one f32 fixture every K-quant golden in this crate is built
//! from, and the developer tool that hands it to the C harness.
//!
//! ONE fixture, three formats. The alternative -- a `sample_input` next
//! to each encoder -- is two structures that must agree with nothing
//! enforcing it: the day one copy's seed is nudged, its golden is
//! regenerated against different input and the comment claiming all
//! three encoders see the same data becomes false without a test going
//! red. It also means one C harness run produces all three goldens from
//! one dump, so they cannot be generated from different bytes.
//!
//! The input lives here and ONLY here. A C harness that re-derived the
//! same values from a copy of the generator would be the same bug shape
//! one level up, and it would silently compare two different inputs the
//! day one copy drifted.

use half::f16;

use super::fit::{QK_SUBS, QK_SUB_ELEMS};
use crate::Q4_K_BLOCK_ELEMS;

/// Twelve 256-element super-blocks: four of deterministic,
/// **f16-shaped** input built so that every branch of the references a plausible
/// rewrite would get wrong is exercised at least once.
///
/// f16-shaped is not decoration. Step 1 of this work learned it the
/// expensive way: its Q8_0 golden was documented as catching
/// `v * (1/d)` versus `v / d` and did not, because over uniform f32
/// noise the two spellings agree for 8192 consecutive values. f16's
/// 11-bit mantissa lands on rounding boundaries constantly, and real
/// weights are f16, so the fixture is f16.
///
/// The 32-element sub-block roster, by index (32 sub-blocks of 32
/// values). The indices are Q4_K/Q5_K's; Q6_K reads the same buffer in
/// 16-element groups, so each entry below covers two of its groups:
///
/// * 8 -- all zero: `max == min`, the `make_qkx2_quants` early return
///   that fills the codes with 0 and reports a scale of 0; and, for
///   Q6_K, `amax < GROUP_MAX_EPS` in `make_qx_quants`.
/// * 9 -- constant non-zero: `max == min` again, but with a min that is
///   clamped to 0 because it is positive.
/// * 10 -- all positive: exercises `if (min > 0) min = 0`.
/// * 11 -- all negative: `max` is negative and `min` is not clamped --
///   and for Q6_K, `max` negative makes `iscale` positive, which is the
///   sign case a symmetric fit gets wrong quietly.
/// * 17 -- four orders of magnitude smaller than its super-block's
///   neighbours, so its 6-bit scale rounds to **zero** and stage 3
///   skips it. The codes written for it are the ones stage 1 left in
///   `l`; an encoder that clears `l` per sub-block writes 32 different
///   bytes here and nowhere else.
/// * everything else -- weight-like noise at one of four gains, so
///   sub-blocks within a super-block disagree about scale and the
///   6-bit scale quantization actually has to do something.
///
/// **The seed is not decorative either.** Two of the references'
/// decisions -- `nearest_int`'s round-half-to-even and the
/// `this_min > 0` clamp inside the least-squares step -- only show up
/// on some data, and the first seed tried exercised neither: the whole
/// Q4_K golden stayed green with `f32::round` substituted for
/// `nearest_int`. This one was picked by encoding 3999 candidate
/// fixtures twice, once with each spelling of every decision in the
/// reference, and keeping a seed where all of them differ. 255 of the
/// 3999 qualify, so this is a fixture chosen to be able to fail, not a
/// seed fitted to one assertion.
///
/// # Blocks 4..11 are real weights, and they are what pins the fused
/// # multiply-adds
///
/// Synthetic noise turned out NOT to be able to fail for the property
/// that matters most. llama.cpp's C is compiled with floating-point
/// CONTRACTION, so `sumlx += w*x[i]*l` is ONE fused multiply-add and
/// not a multiply followed by an add; `fit.rs` reproduces that with
/// `mul_add`. Removing those `mul_add`s changes ~1.2% of the
/// super-blocks of a real checkpoint and NONE of the four synthetic
/// ones. The sabotage pass caught exactly that: with every `mul_add`
/// removed, all three goldens stayed green.
///
/// So [`REAL_WEIGHT_BLOCKS`] adds one real block per fusion site,
/// each found by reverting that one site and scanning 16384 real
/// super-blocks for the first whose encoding moved. Nine of the
/// thirteen sites are pinned this way.
///
/// FOUR are not, and saying so is better than implying otherwise: the
/// two error accumulators (`best_error`, `cur_error`) and the two
/// `diff` reconstructions in `make_qkx2_quants` have no differing block
/// in those 16384. They only change which candidate scale WINS, and the
/// comparison is not close often enough to show up in that many blocks.
/// They are covered only by the whole-model measurement in the PR body,
/// which is not a CI test.
pub(crate) fn k_quant_fixture() -> Vec<f32> {
    const GAINS: [f32; 4] = [0.02, 0.05, 0.1, 0.25];
    let mut state: u32 = 0xb54c_da26;
    let mut next = move || {
        state ^= state << 13;
        state ^= state >> 17;
        state ^= state << 5;
        // [-1, 1)
        ((state >> 8) as f32 / 8_388_608.0) - 1.0
    };
    let mut out = Vec::with_capacity(4 * Q4_K_BLOCK_ELEMS);
    for sub in 0..4 * QK_SUBS {
        for _ in 0..QK_SUB_ELEMS {
            let v = next();
            let shaped = match sub {
                8 => 0.0,
                9 => 0.125,
                10 => v.abs() * 0.05 + 0.01,
                11 => -(v.abs() * 0.05 + 0.01),
                17 => v * 1e-4,
                _ => v * GAINS[sub % GAINS.len()],
            };
            out.push(f16::from_f32(shaped).to_f32());
        }
    }
    for bits in REAL_WEIGHT_BLOCKS {
        out.push(f16::from_bits(*bits).to_f32());
    }
    out
}

/// Eight super-blocks of real Llama-3.2-1B weights, as f16 BIT
/// PATTERNS, taken from `blk.0.attn_q.weight` of an F16 conversion.
///
/// f16 bit patterns rather than decimal literals because a decimal
/// literal that round-trips through an editor is one edit away from
/// being a different float, and the whole point of these blocks is that
/// they sit on a knife edge. f16 rather than f32 because the source
/// tensor is F16, so these ARE the checkpoint's exact values -- and
/// because it halves the table.
///
/// Each block is here because it pins one of `fit.rs`'s fused
/// multiply-adds: remove that one `mul_add` and this block's bytes
/// change. The comments name which. They were found by reverting one
/// fusion at a time and scanning 16384 real super-blocks for the first
/// one whose encoding moved.
#[rustfmt::skip]
const REAL_WEIGHT_BLOCKS: &[u16] = &[
    // block 5 -- the Q4_K golden had no real block at all before this
    0x2043, 0x9c97, 0x9dae, 0x1d76, 0x8afe, 0x993e, 0x1de6, 0xa6d4, 0x113e, 0x2435, 0x213e, 0xa6f0,
    0x1e56, 0x9f6e, 0x0000, 0x9e56, 0x23a6, 0x23de, 0x9a1e, 0x1afe, 0xa097, 0x2176, 0x953e, 0xa419,
    0xa443, 0x1e1e, 0xa05f, 0x1de6, 0x0000, 0xa62c, 0x19ae, 0xa584, 0x9d1e, 0x1af6, 0x2474, 0x99bb,
    0xa63e, 0x9ef6, 0x9418, 0x1881, 0x9f93, 0xa081, 0x128d, 0x1e59, 0x1e24, 0x22f6, 0x20b5, 0x9418,
    0xa0b5, 0x24b5, 0xa1a1, 0x20b5, 0xa104, 0x1b5f, 0x1cea, 0x1d87, 0x21f0, 0x9e8d, 0x10ea, 0xa680,
    0xa5d6, 0x9d1e, 0x2379, 0x22a7, 0x9964, 0x9964, 0x0fd8, 0x2640, 0x99e2, 0x1f1c, 0x22be, 0x91e2,
    0xa0e7, 0xa5b3, 0xa44a, 0x21a3, 0x2126, 0x21c3, 0x986a, 0x25c3, 0xa4e7, 0x277a, 0x1964, 0x9b5a,
    0x98e7, 0x237a, 0x23f7, 0x0000, 0x24e7, 0xa126, 0x1e60, 0x20e7, 0x245a, 0x9f5a, 0xa7c8, 0x98e7,
    0x23be, 0x98b7, 0xa20f, 0x2522, 0x9163, 0xa291, 0xa33d, 0x9c0a, 0xa33d, 0x9d63, 0x940a, 0x9f12,
    0x1fbe, 0x21e4, 0xa2e7, 0x9c0a, 0x1d63, 0xa33d, 0xa00a, 0x980a, 0x1c60, 0x980a, 0x223a, 0x1f12,
    0x22bc, 0x1db9, 0x2563, 0xa291, 0x2060, 0xa00a, 0xa00a, 0x2958, 0xa5f8, 0x24b2, 0xa33c, 0xa430,
    0x9edb, 0xa29a, 0x0000, 0x1010, 0x9d96, 0x1f9e, 0x8c10, 0x9618, 0x2808, 0x2628, 0xa461, 0x1b1c,
    0xa534, 0x9a18, 0x2030, 0x274d, 0x9996, 0xa472, 0x25a6, 0x2514, 0xa6db, 0xa35d, 0xa114, 0x0000,
    0x1996, 0xa4e3, 0xa3df, 0x2596, 0x1911, 0x9911, 0xa0d6, 0xa1fd, 0x2750, 0x25a5, 0x9587, 0xa3d5,
    0x9d11, 0x1cd6, 0x24b9, 0xa5e0, 0x23f2, 0x21c2, 0x0000, 0xa238, 0x24f4, 0x1b5f, 0xa408, 0x8f5f,
    0x19fd, 0x9dfd, 0x9f5f, 0x9f24, 0x237c, 0x9587, 0xa733, 0x9911, 0x2060, 0x9911, 0x25a5, 0x24e5,
    0x1fc8, 0x9f2f, 0x8cca, 0x1963, 0x8cca, 0x1b2f, 0x9963, 0x27db, 0xa2e2, 0xa47d, 0x90ca, 0x1dfc,
    0x207d, 0x1b2f, 0xa517, 0x2742, 0x2576, 0x15fc, 0x1dfc, 0x26a9, 0x226f, 0x932f, 0x932f, 0x1831,
    0xa13d, 0x10ca, 0x28c0, 0xa3a2, 0xa444, 0x15fc, 0x23a2, 0xa5c3, 0x152a, 0xa52a, 0xa637, 0x212a,
    0x21f9, 0xa920, 0x9f6c, 0x2343, 0x21cf, 0x9c85, 0x2009, 0x2674, 0xa12a, 0x9f1a, 0x2758, 0x21a6,
    0xa4ec, 0x1f6c, 0xa0d7, 0x0d2a, 0xa0ae, 0x1a74, 0x2222, 0x112a, 0xa470, 0x17bf, 0x1674, 0x24ae,
    0xa101, 0x9bbf, 0x1d2a, 0x13bf,
    // block 35 -- make_qx_quants sumlx
    0x2189, 0x27b8, 0xa85e, 0xaa8e, 0x14a9, 0x2748, 0xa519, 0x26d8, 0xa4ce, 0xa884, 0xa8a9, 0xa7b8,
    0xa05e, 0xa0f4, 0x28a9, 0xa84c, 0xaaeb, 0xac01, 0x1e68, 0xa5f9, 0xa976, 0xa7dd, 0xa61e, 0xaca0,
    0x2c30, 0x9dd3, 0xa906, 0x2668, 0xa643, 0x268e, 0x2919, 0x9afe, 0x29d3, 0x2919, 0xab10, 0xa793,
    0x21d3, 0x99d3, 0x2839, 0x21d3, 0xa0f4, 0x21d3, 0x213e, 0xac55, 0xa4f4, 0x2439, 0x2748, 0xa99b,
    0x284c, 0x9efe, 0x2989, 0x2268, 0xa563, 0x1f93, 0xa21e, 0x2268, 0x9f93, 0xa484, 0x1afe, 0x94a9,
    0xa827, 0xa439, 0xac14, 0x2ca0, 0x2546, 0x9dcd, 0x9edb, 0x2102, 0xaa87, 0xa784, 0xac30, 0x1cbf,
    0x21cd, 0xa102, 0xa210, 0xa07c, 0xa146, 0x258a, 0x207c, 0xa568, 0x9b62, 0xa18a, 0x2838, 0x9e54,
    0x2524, 0xa102, 0x9fe9, 0x2038, 0xaaca, 0x23a6, 0x249d, 0x9dcd, 0x29cd, 0x27c7, 0xa6db, 0xa8e1,
    0x26e2, 0x9dd7, 0x2497, 0x291c, 0xa2ad, 0xa097, 0xac2c, 0x25d7, 0x23ed, 0x92ad, 0x1d02, 0x9aad,
    0xa383, 0x2c8a, 0xa462, 0x2097, 0x2a5d, 0xaea0, 0x1dd7, 0x1ead, 0xa811, 0xa02c, 0xa462, 0xa502,
    0x21d7, 0xaa92, 0x9d02, 0x2383, 0x2847, 0x2a42, 0xa242, 0x274d, 0x1987, 0xa86f, 0x1ee9, 0x2b50,
    0x189b, 0xa111, 0xa6cc, 0xa09b, 0xa88d, 0x252f, 0xa77c, 0x261b, 0x0000, 0x2425, 0xa39a, 0xa025,
    0xa060, 0x254c, 0xab15, 0x2ada, 0xa5e0, 0xa834, 0xa5fd, 0xa808, 0xa8b9, 0x1f5f, 0x254c, 0x25c2,
    0xa09b, 0x2a38, 0x2843, 0xa691, 0x26db, 0x1f1c, 0x2410, 0xa2db, 0xa79e, 0xaa18, 0x9d96, 0x1d96,
    0xa659, 0x267a, 0xa67a, 0x2638, 0xa4b2, 0x9e9a, 0x277e, 0xabbe, 0x2afc, 0x2010, 0x29c7, 0xa820,
    0x9c92, 0xac08, 0xa092, 0x1010, 0x0000, 0x235d, 0x2196, 0x9618, 0x2514, 0x2218, 0x2596, 0xa051,
    0x2b61, 0xa022, 0xacb0, 0x1d50, 0x267e, 0xa550, 0x9716, 0xa822, 0x1b16, 0x2150, 0x98b9, 0x206d,
    0x2822, 0xa60d, 0x2505, 0xa976, 0x219c, 0xa1e7, 0xa6ca, 0xa67e, 0xa9af, 0xa150, 0xa60d, 0x1f16,
    0xaa7e, 0x29c1, 0xa761, 0x2659, 0xa80f, 0x2950, 0xa422, 0x1fad, 0x2448, 0xa6ae, 0x2c1c, 0xa41c,
    0x285e, 0xa90d, 0x20cc, 0x26ae, 0x2789, 0xa5ff, 0x28a0, 0xa282, 0x2389, 0xa848, 0x0000, 0xa832,
    0x281c, 0xa5a7, 0xa22a, 0xaa82, 0xaada, 0xa789, 0xa5a7, 0xa22a, 0xa4f7, 0x2d70, 0x1ccc, 0xa923,
    0xa62a, 0x2b9f, 0x294f, 0x25ff,
    // block 76 -- make_qkx2_quants sum_xl, and this_min
    0x10b1, 0x99dd, 0xa01b, 0xa41b, 0xaa03, 0x264e, 0xa0fc, 0xa228, 0xa992, 0x2a28, 0xa5b8, 0xa628,
    0xa1dd, 0x2192, 0x23eb, 0x1fa0, 0x2355, 0xa64e, 0xa192, 0xa5dd, 0x2abe, 0x970a, 0x2879, 0xa466,
    0x19dd, 0x27a0, 0xa1dd, 0x90b1, 0xa4d7, 0x2b8d, 0xa72f, 0x2ca8, 0x9936, 0xa106, 0x2106, 0xa371,
    0x9ab2, 0x2136, 0x2312, 0xa8b3, 0xa912, 0x29e8, 0x1f12, 0x23a1, 0xa741, 0x26b2, 0x8df4, 0xa7b8,
    0xa1f4, 0x9c18, 0xa3a1, 0xa371, 0xa283, 0x2936, 0xa60c, 0x2283, 0xa1f4, 0x22e2, 0x9f12, 0xa6b2,
    0x1c77, 0x9e53, 0x9d36, 0x99f4, 0xa0b0, 0x1cb0, 0x9804, 0x9ab2, 0xaa5c, 0x205a, 0xa85a, 0xa05a,
    0xa35d, 0x2206, 0x2d50, 0x289a, 0x255b, 0xa7de, 0x995b, 0x235d, 0xa05a, 0x2970, 0x2631, 0x225c,
    0x2004, 0x1d5b, 0xa0b0, 0xa5b1, 0xac65, 0x1eb2, 0xa35d, 0x9804, 0x2631, 0x25dc, 0xa81a, 0x115b,
    0x28e3, 0xa690, 0xa804, 0xa449, 0x2607, 0x1d5b, 0xa6f7, 0xac40, 0xa004, 0xa73b, 0x22f7, 0xa1a0,
    0x9049, 0x2a3a, 0x248e, 0x2117, 0x29f6, 0xa33b, 0x264b, 0x2449, 0xa6d4, 0x9049, 0x166e, 0x273b,
    0xa96c, 0x2404, 0x22b2, 0xa427, 0x9d5b, 0x1a6e, 0x288e, 0x21e4, 0xa4b0, 0x0000, 0x21a0, 0x1ef7,
    0x264b, 0x9b80, 0x166e, 0xa9d3, 0x1cd2, 0x26b2, 0xa838, 0xa690, 0x9049, 0x1e6e, 0x1de4, 0xac40,
    0x9cd2, 0x208e, 0xa838, 0x295b, 0x2629, 0xa95b, 0x246b, 0xa404, 0xa2f7, 0x298f, 0x9c49, 0x2629,
    0x208e, 0xa1a0, 0x2049, 0xa2f7, 0xa5f8, 0x9471, 0x22aa, 0x2071, 0x2523, 0x1aaa, 0xab02, 0x20b8,
    0x242a, 0xa895, 0x1471, 0x9471, 0x9471, 0x285f, 0x2071, 0xa58d, 0x20ff, 0x2c68, 0x1f38, 0x998d,
    0x16aa, 0x25b1, 0x261b, 0xa8ff, 0x221b, 0xa546, 0x263f, 0xa338, 0xa0b8, 0x2406, 0x26f1, 0xa44d,
    0xa87b, 0xa511, 0x9b46, 0xaad2, 0xa725, 0x28df, 0x1828, 0x9ec1, 0x1a3c, 0xa407, 0x2817, 0x2304,
    0x24f0, 0x2449, 0xa596, 0x2028, 0xa9d8, 0xa06a, 0xa5b7, 0x2839, 0xa4ce, 0x2596, 0xa5fa, 0x26a0,
    0x26a0, 0xa4ad, 0x2c20, 0xa7ec, 0x2932, 0x9db7, 0x25b7, 0xa0f0, 0x16e6, 0x9d2c, 0x1499, 0x2806,
    0x9499, 0xa609, 0xac90, 0x9ae6, 0x9e52, 0x212c, 0x9c99, 0x25e4, 0x2874, 0x1f79, 0x2176, 0x1e52,
    0x9f79, 0x279d, 0x1ae6, 0x2988, 0x2887, 0x1c06, 0xa379, 0x2209, 0xa8ab, 0x9d2c, 0xa779, 0xaa2e,
    0xa209, 0x9c06, 0xa82b, 0x2806,
    // block 162 -- make_qx_quants suml2
    0xa52c, 0x2379, 0xa5e4, 0xa0e3, 0xaa09, 0x9c99, 0x1f79, 0xa8d0, 0x28d0, 0xa8d0, 0x2006, 0x204f,
    0x2006, 0x2406, 0x1c99, 0xa7c2, 0xa576, 0x28f5, 0xa8f5, 0xa209, 0x2c90, 0x9d2c, 0x1dbf, 0xa576,
    0x2099, 0xa84f, 0x9f79, 0x1ae6, 0x2bd5, 0x2887, 0xa507, 0xa474, 0xa743, 0xa8c3, 0x1fbf, 0x271a,
    0xa71a, 0x2553, 0xa2c7, 0xa5f9, 0x192a, 0x2adc, 0xa4ae, 0xa93f, 0x2d20, 0xa6f0, 0xa81d, 0xa7e8,
    0xa7e8, 0x26f0, 0x1bbf, 0x217d, 0xa553, 0xa0d7, 0x21cf, 0x2553, 0xa2c7, 0x231a, 0xa501, 0x28ae,
    0x2ac7, 0x97bf, 0x28c3, 0x9d2a, 0x99c9, 0xa8d9, 0x2432, 0xa057, 0x18a1, 0x9c0d, 0xa5a4, 0x281f,
    0x2786, 0x0000, 0x2b17, 0x26cc, 0x2832, 0x2432, 0xa386, 0xa65d, 0xa7d0, 0xa33c, 0x29ee, 0xaa26,
    0x18a1, 0x225d, 0xa33c, 0x99c9, 0xa9b7, 0x2c98, 0x296d, 0x288e, 0x2b17, 0xa0a1, 0xa6cc, 0x2135,
    0x21ec, 0xa245, 0x9593, 0x9faa, 0x982e, 0x202e, 0xaab5, 0x213a, 0xa818, 0xad88, 0x9c2e, 0x2351,
    0x982e, 0x2672, 0x25c0, 0x2a72, 0xa3aa, 0x1193, 0x2724, 0x253a, 0x22f8, 0x2751, 0x2487, 0x1d93,
    0xa02e, 0x1193, 0x2351, 0xa4e1, 0x1593, 0xa5c0, 0x2645, 0x9993, 0x2120, 0xa8c3, 0xa95f, 0x2520,
    0xa8f2, 0xa55f, 0x2b34, 0x2894, 0x1ce2, 0x1ddc, 0xa734, 0xa4c3, 0x296f, 0xa9ad, 0xa6f5, 0x2298,
    0xabc0, 0x28b3, 0x1ce2, 0x9d5f, 0xa484, 0x25dc, 0xa6f5, 0x2901, 0x298e, 0xa55f, 0xa884, 0xa9ec,
    0xa826, 0xa8e2, 0x97d0, 0x2678, 0x9d23, 0xa87f, 0x1db5, 0x2823, 0x1bfe, 0xa86c, 0x25da, 0xa4ff,
    0x2790, 0x2c11, 0x16da, 0x9091, 0x9c91, 0x2c88, 0x2448, 0x276c, 0x2811, 0xa5fe, 0x2a35, 0x23b5,
    0x28ec, 0xa4ff, 0x276c, 0x9ffe, 0x23b5, 0x2448, 0x2a11, 0x2b47, 0xa6fe, 0x27b5, 0x236c, 0xaaec,
    0x27ad, 0xa1e2, 0x2c10, 0x9624, 0x9018, 0xa5c2, 0x2018, 0x236c, 0x21e2, 0x25a1, 0x0000, 0x9ea7,
    0xa2e8, 0x287a, 0x2160, 0xa5c2, 0x292e, 0x9c9b, 0x2418, 0xaae8, 0x9d1e, 0xa1e2, 0xa266, 0xa439,
    0xa85a, 0xa624, 0xa0dc, 0x21a1, 0x274b, 0xa6c8, 0xa3ee, 0x2439, 0xabc1, 0x1ec2, 0xa673, 0x25fd,
    0x1d87, 0x20ea, 0x26e9, 0x2974, 0x2a24, 0x20ea, 0x24c3, 0x9b5f, 0x9cea, 0x2560, 0x9f5f, 0x2ce0,
    0x9f5f, 0x23ae, 0xa624, 0x2139, 0x9ec2, 0xa7d5, 0x1e24, 0x18ea, 0x28ea, 0x1b5f, 0xa960, 0x204d,
    0xa1d6, 0x269a, 0x975f, 0x27d5,
    // block 190 -- make_qkx2_quants sum_x
    0x9b2a, 0x28a8, 0x232a, 0xa72a, 0xa0a8, 0xa272, 0xa385, 0xa217, 0x9fe1, 0xa785, 0xa531, 0x272a,
    0xa948, 0xa4d6, 0x91bb, 0x25e9, 0x26fc, 0x99bb, 0x2617, 0xa976, 0x241e, 0x204c, 0x984c, 0xa104,
    0x9d04, 0x2db0, 0xa531, 0x9e72, 0x2c7a, 0x24d6, 0x1d04, 0xab58, 0xa870, 0xabd8, 0x2b36, 0x1a56,
    0x267f, 0x2447, 0xa256, 0x267f, 0x239b, 0x9f9b, 0x1f9b, 0xa39b, 0x2512, 0xa447, 0x1a56, 0x179b,
    0xa4e9, 0x9112, 0xaae4, 0x2563, 0x2721, 0x253b, 0xa79b, 0xa112, 0xa93b, 0x9f9b, 0xa9a0, 0x1b9b,
    0xa772, 0x239b, 0x2205, 0xad08, 0x26b2, 0xad50, 0x2505, 0x9d5b, 0x2c1a, 0x1804, 0xa586, 0x2687,
    0x2946, 0x2a47, 0xa85a, 0x2885, 0x0000, 0x195b, 0x9f5d, 0xac85, 0x2004, 0x255b, 0xa15b, 0xa606,
    0xa7de, 0x22b2, 0x1804, 0xa89a, 0x2c3a, 0x2c04, 0x0000, 0xa530, 0xa65c, 0x2930, 0x23b3, 0x225c,
    0x9d3e, 0xa8a9, 0x9afe, 0xa76d, 0x1d3e, 0x2589, 0x28e1, 0x2189, 0xa268, 0xa484, 0xa68e, 0x0000,
    0xa896, 0x2a43, 0x2afe, 0xa21e, 0xaa68, 0x98a9, 0x10a9, 0xa014, 0x2268, 0xab80, 0x26fe, 0xa7b8,
    0xa414, 0xaca0, 0x10a9, 0x2c39, 0x90a9, 0xa563, 0x9c14, 0x2519, 0x298a, 0x1ae4, 0xaad4, 0x97e0,
    0x23e0, 0x8fe0, 0x93e0, 0xa762, 0x9be0, 0x21a9, 0x26a5, 0x15e8, 0xaa66, 0x1c6e, 0x2266, 0xab62,
    0x202f, 0xa9e8, 0x297a, 0x22a5, 0x28fc, 0x2bd0, 0x1d6a, 0xa782, 0xa1a9, 0x2323, 0x1cec, 0xa97a,
    0xa266, 0x24cc, 0x18ec, 0xa6e4, 0x285c, 0xa027, 0x2af5, 0x2a8a, 0xa77a, 0xa37a, 0x2931, 0x259b,
    0x18fc, 0x223b, 0xa4c7, 0x2966, 0x98fc, 0x2606, 0x259b, 0xa3e4, 0x1cfc, 0xa427, 0x16a5, 0xab2a,
    0x2744, 0x18fc, 0x2491, 0x2966, 0x2e98, 0x27e4, 0x29b6, 0x2166, 0xa091, 0x96a5, 0x22a5, 0xa6a5,
    0xa5d3, 0x219f, 0x9c04, 0x1e6d, 0x2539, 0xa66d, 0x28d2, 0xae60, 0xa8eb, 0x26a0, 0x926d, 0x9e6d,
    0x2707, 0x2505, 0x9d9f, 0xa89e, 0x2986, 0x291f, 0xa851, 0x26a0, 0x2004, 0x2a6d, 0x18d2, 0x256c,
    0xa26d, 0xa91f, 0x98d2, 0xa7d5, 0x28eb, 0xa939, 0x20d2, 0xa06b, 0x25b7, 0xaa2e, 0xa3fa, 0xa3b6,
    0x2485, 0xa852, 0x1951, 0xaa73, 0x9441, 0x27fa, 0x29a6, 0x9951, 0xa4a7, 0x1ffa, 0x2262, 0x2995,
    0x1e62, 0x23b6, 0xa7d8, 0xa6a6, 0xa7fa, 0x9041, 0xaa1d, 0x1841, 0x1dd9, 0x272e, 0x2794, 0x2c38,
    0x9cc9, 0xa9ea, 0x2830, 0xa441,
    // block 561 -- the Q5_K golden had no real block at all before this
    0x1481, 0x9481, 0x272e, 0x2c78, 0xa803, 0xa4c9, 0x2039, 0x1ac2, 0x245d, 0x16c2, 0xac54, 0xa79a,
    0xa511, 0xa30a, 0xa72e, 0x16c2, 0xa439, 0x28ff, 0xa839, 0x99a1, 0x24c9, 0x2415, 0x19a1, 0xa4c9,
    0xaa1f, 0xa839, 0x1c81, 0xac0c, 0xa96b, 0xa415, 0x1ec2, 0x21a1, 0x289d, 0xa924, 0xa416, 0x288c,
    0x23e9, 0xa58a, 0x25cd, 0x2502, 0xa038, 0xa935, 0x2b84, 0x9038, 0xa3a6, 0x2a21, 0xaa32, 0x9f62,
    0x27e9, 0x26fd, 0xa524, 0x9a54, 0x2546, 0xa210, 0x25ef, 0x29de, 0xa9ab, 0xa4bf, 0x2c30, 0xa805,
    0x1038, 0x1038, 0xa98a, 0xa210, 0xa85c, 0xa720, 0xa885, 0x21be, 0x222b, 0x2041, 0x2928, 0xa151,
    0x2477, 0x2720, 0x27a8, 0x1841, 0xa22b, 0xa86a, 0xa33b, 0x256c, 0x1cae, 0x2833, 0x2ac0, 0x9ece,
    0xa426, 0xaa54, 0xa441, 0xa492, 0x1fa8, 0xa95f, 0xa00a, 0x0ece, 0xa826, 0x260f, 0x222b, 0xa6e9,
    0x2cb0, 0xa7d2, 0xa550, 0x29fa, 0xa361, 0xa848, 0x18b9, 0x246d, 0xa27e, 0x2bc0, 0x29c1, 0x28b9,
    0x23ad, 0xa59c, 0xa9d4, 0x2105, 0xa8f2, 0xa576, 0xa19c, 0xa917, 0xaa0d, 0x2b87, 0x2505, 0x259c,
    0x9de7, 0xa761, 0x26ca, 0x28f2, 0x1c22, 0x25e7, 0x2917, 0x20b9, 0x25ae, 0x20f4, 0x9d3e, 0xa8a9,
    0x9e68, 0x9c14, 0xa92b, 0x2ca0, 0xac1d, 0xa13e, 0x2827, 0x2563, 0xa0f4, 0xa906, 0x24a9, 0xa2fe,
    0xa5f9, 0x1c14, 0x14a9, 0x1c14, 0xa68e, 0x2ab3, 0x90a9, 0xa8ce, 0x1c14, 0xa5d3, 0xa8e1, 0xa21e,
    0xa668, 0x1f93, 0xa8e1, 0x268e, 0xaa8f, 0x2906, 0x26be, 0x9fd8, 0xa77a, 0xa799, 0xa67f, 0xa564,
    0xa0e7, 0xa67f, 0x242b, 0x1d64, 0x98e7, 0xa221, 0xa35a, 0x28f7, 0x1d64, 0x20a8, 0xa879, 0xa40b,
    0xaafc, 0x1ce7, 0x19e2, 0x2221, 0xabc8, 0x273b, 0x20a8, 0x25e2, 0x28f7, 0xa8b8, 0x28b8, 0xa3d8,
    0x213c, 0xa4d8, 0xa776, 0xa53c, 0x2648, 0x1430, 0x29d3, 0x2b97, 0xa9a0, 0xa13c, 0x1648, 0x9e48,
    0xa430, 0x28d8, 0x28c7, 0x9dc2, 0x9a48, 0xa990, 0x1dc2, 0x9cb6, 0x1648, 0xac28, 0xa57f, 0x294d,
    0xa9e4, 0xaa05, 0xa626, 0x29d3, 0x240e, 0x20b6, 0xabfc, 0x228b, 0xa69e, 0x25ca, 0x229e, 0xa960,
    0x2b19, 0x2422, 0xa634, 0xac34, 0x1c69, 0xa0b0, 0x20f6, 0x9cf6, 0xa707, 0x2583, 0xaa57, 0xa29e,
    0x2972, 0x9f2b, 0x229e, 0x2c4f, 0x9d83, 0xa4b0, 0x9069, 0x9983, 0xa89e, 0x213d, 0x269e, 0x292b,
    0x24d3, 0xa53d, 0xa422, 0x2c60,
    // block 732 -- make_qkx2_quants sum_l
    0xa941, 0x9b02, 0xa1f5, 0xad90, 0x2b5b, 0x2c4b, 0x224e, 0x1e4e, 0x2b18, 0xa81e, 0xa7e2, 0x28e8,
    0x2034, 0x2302, 0xa99b, 0x2a0b, 0x999b, 0xa6a8, 0xa914, 0x1b02, 0x9d9b, 0x2861, 0x2958, 0xa92b,
    0x2514, 0xaa22, 0x2abe, 0xa461, 0x281e, 0xab18, 0x248e, 0x2958, 0x24fe, 0x2c14, 0x2728, 0x2d48,
    0x0000, 0x257e, 0x2628, 0x24fe, 0x97fc, 0xa993, 0x1bfc, 0x9ffc, 0xa0fe, 0xa6a8, 0x9953, 0xad33,
    0x2429, 0x9aa8, 0xa429, 0x23a7, 0xa9bd, 0x2253, 0xa5fd, 0x0000, 0xa2a8, 0x2968, 0x22a8, 0x1553,
    0x1ea8, 0xa0a9, 0x9ca9, 0x1dfd, 0xa38e, 0xa42d, 0x9d91, 0x1bf4, 0x2a5d, 0x27c1, 0x965d, 0xa8ac,
    0x2945, 0xabc1, 0xabc1, 0xac07, 0x98c6, 0xa978, 0x1bf4, 0x278e, 0xa9f7, 0xa92c, 0x2b5c, 0x9ff4,
    0xaca0, 0x1cc6, 0x9f29, 0xa8c6, 0xae50, 0x2e37, 0x2a90, 0x9cc6, 0xa55e, 0x2329, 0x225d, 0x1d91,
    0xac01, 0x2c3a, 0x2401, 0x26ac, 0xa401, 0x1c73, 0x2f10, 0xa757, 0x28ac, 0x9c73, 0x281d, 0xa873,
    0xa8c8, 0x2c65, 0xa1c8, 0xa0e5, 0x281d, 0xa43a, 0xa556, 0xaa3a, 0x2c9d, 0xa601, 0x2a90, 0x2c8f,
    0x2956, 0xa23a, 0x251e, 0xa2ac, 0x2790, 0x271e, 0x231e, 0x971e, 0x2a42, 0xa8f8, 0xa853, 0x2b45,
    0xa986, 0xa9fc, 0x9b5d, 0x2910, 0x2824, 0xa75d, 0x240d, 0x15e4, 0x9de4, 0x9f5d, 0x186b, 0x272e,
    0xa78c, 0xa7ea, 0xa78c, 0x9f5d, 0x29b5, 0x2dd8, 0xa75d, 0xa853, 0xa06b, 0xa128, 0xa8f8, 0xaa2b,
    0x2853, 0x2c3c, 0x243c, 0x1c6b, 0x9ff0, 0x1ace, 0x2c53, 0x29d0, 0x211a, 0x9ece, 0xa3f0, 0x2685,
    0x2ace, 0xa563, 0x9c89, 0xa963, 0xa4d2, 0x2685, 0x3080, 0xa23c, 0x1ff0, 0xa089, 0xa4d2, 0x2489,
    0x2563, 0xaace, 0x25f4, 0x23f0, 0x2c40, 0x2d3e, 0xa685, 0xa51a, 0x29d0, 0xa35f, 0xa7a7, 0x1ece,
    0xaa66, 0x1804, 0x9f07, 0x9e06, 0x9a06, 0x2286, 0x1e06, 0xa186, 0xa105, 0xacd5, 0x2388, 0xa8e5,
    0xa8c5, 0xaa26, 0x28e5, 0x2388, 0x0000, 0xa788, 0x2ca5, 0x2307, 0x2a86, 0x1c04, 0x2c95, 0x2444,
    0xa9e6, 0xa9c6, 0xa286, 0xa404, 0x2206, 0x1a06, 0x2c04, 0x2ff8, 0x9f00, 0xa180, 0x9e00, 0x2440,
    0x2200, 0xa400, 0xa080, 0x25c0, 0x1800, 0x9c00, 0xa6c0, 0xa200, 0x2080, 0x1d00, 0x1a00, 0xa7c0,
    0x2700, 0x1400, 0xaff0, 0x1a00, 0xab00, 0x2640, 0xad50, 0x2b60, 0x2480, 0x2580, 0xa800, 0x25c0,
    0x1e00, 0x9f00, 0xa900, 0x2a00,
    // block 8674 -- make_qkx2_quants this_scale
    0x126d, 0x2ad4, 0xaa20, 0x27d5, 0x26d4, 0x9f3b, 0xab6e, 0xa5d3, 0x2e60, 0xad05, 0x2c1e, 0x256c,
    0x2004, 0xa6d4, 0xab3b, 0x286b, 0x2d45, 0xa46b, 0x28eb, 0x2139, 0x291f, 0xac04, 0x9d9f, 0xa0d2,
    0xa89e, 0xa86b, 0xa8eb, 0xa986, 0x2004, 0x2c85, 0x9e6d, 0x2c9e, 0x265a, 0xade0, 0xa472, 0x2690,
    0xadc5, 0xac3c, 0xa623, 0xa65a, 0x27d5, 0x9ac6, 0x2806, 0xa472, 0x2b84, 0xa981, 0xaa75, 0xacec,
    0xaeb8, 0xa2c6, 0xa181, 0xadb7, 0x1f9f, 0x29b7, 0x1ec6, 0x28f9, 0x2981, 0x2a75, 0xa623, 0x28f9,
    0x2bba, 0x2b9f, 0x1c3c, 0xa65a, 0x2399, 0xa45e, 0x2152, 0x2552, 0x208f, 0xa8f0, 0xa8d8, 0xa738,
    0xa7ca, 0x2815, 0xa5b3, 0x9d52, 0x2bfa, 0xabfa, 0xaa14, 0xa1b3, 0x2c52, 0xa45e, 0xa768, 0x2877,
    0x1ed6, 0x1c8f, 0x9f99, 0x29cb, 0x29fc, 0x2db3, 0xa614, 0xa88f, 0x2e08, 0x28d8, 0xa96a, 0x24c0,
    0x28b6, 0xaa56, 0x981c, 0xa5a7, 0x2a98, 0xa806, 0x294f, 0x2789, 0x2832, 0xaa40, 0x25ff, 0x2965,
    0x28f7, 0x197b, 0xac32, 0x2ac4, 0xa88a, 0xa4cc, 0x117b, 0x22da, 0xa54f, 0x9d7b, 0x997b, 0xa4f7,
    0x2c3d, 0x997b, 0x27e1, 0x288a, 0x20cc, 0xabb5, 0xa706, 0xad70, 0x9614, 0xa521, 0x242e, 0x9c8f,
    0x2214, 0x27fa, 0x1c8f, 0xa99a, 0x2b50, 0xac09, 0xa0f0, 0x2738, 0x2152, 0xa521, 0x2e08, 0x2552,
    0xacfc, 0xa0f0, 0xa9b3, 0x1f99, 0xa5e3, 0xa738, 0x2614, 0x285e, 0x2c15, 0x24c0, 0x23fa, 0x29fc,
    0xadfc, 0xa5e3, 0xa2d6, 0x2909, 0xa967, 0xa8c8, 0xa4f6, 0x9f16, 0x0000, 0x2040, 0xa8b2, 0x2743,
    0x1dab, 0x0000, 0x25ab, 0xa2bb, 0x9840, 0xa5ab, 0x268e, 0x2370, 0xa57e, 0x9fcb, 0x28df, 0x2923,
    0xabb4, 0xa523, 0x2950, 0xa1ab, 0x2cea, 0xa79e, 0xada0, 0x2633, 0x19ab, 0x2d5c, 0xacdf, 0xabb4,
    0x9eee, 0xaa24, 0x28e2, 0xa90a, 0x190a, 0x29e8, 0xa7b7, 0x27b7, 0x978f, 0x910a, 0xac0e, 0x2b3e,
    0x24b9, 0x29bf, 0x291e, 0x2624, 0x2b3e, 0x950a, 0xa804, 0xa6ee, 0x2946, 0x25fc, 0x190a, 0x2d00,
    0xa418, 0xac40, 0x2716, 0x2b53, 0x110a, 0x21ab, 0x2018, 0x1d0a, 0x2783, 0xa594, 0x2602, 0xa89d,
    0xadb0, 0xa926, 0x2a02, 0x2194, 0x2d42, 0x1d26, 0x2cc6, 0xaa39, 0xa4b9, 0x284b, 0x2202, 0xac22,
    0xaeb5, 0x255d, 0xa783, 0x1ade, 0x204b, 0x29b0, 0x28d4, 0x2ed0, 0x92de, 0xa34c, 0x1e02, 0x9e02,
    0x2ade, 0x27f1, 0x2670, 0xa7ba,
];

/// Regenerates every K-quant golden in this crate. Ignored, because it
/// needs a llama.cpp install: it writes [`k_quant_fixture`] as raw
/// little-endian f32 to `$FERROX_K_QUANT_FIXTURE_OUT`.
///
/// The goldens are then produced by the INSTALLED `llama-quantize`, not
/// by a locally built libggml. That distinction is not pedantry: a
/// libggml built here from the same b7650 source disagrees with the
/// installed binary on exactly the knife-edge blocks this fixture is
/// made of, because the two builds differ in whether the compiler fuses
/// the multiply-adds. The procedure is in the PR body -- implant the
/// fixture into a GGUF as one `[256, 12]` F16 tensor, run
/// `llama-quantize --pure` once per format, read the tensor back.
#[test]
#[ignore = "developer tool: dumps the fixture the golden procedure reads"]
fn dump_the_fixture_the_golden_procedure_reads() {
    let path = std::env::var("FERROX_K_QUANT_FIXTURE_OUT")
        .expect("set FERROX_K_QUANT_FIXTURE_OUT to the path to write");
    let mut bytes = Vec::new();
    for v in k_quant_fixture() {
        bytes.extend_from_slice(&v.to_le_bytes());
    }
    std::fs::write(path, bytes).unwrap();
}