Modern Apps git

← Modern-Apps.git

ml: int4 prefill GEMM on int8 dot product, gemma4 prefill GEMM 2212 -> 2020 ms

Commit
d5e989dea6b1627eafb91164c430bc063cad5307
Author
vayun-mathur <[email protected]>
When
2026-10-26 18:27 UTC (1 month ago)
Parents
ca07f52

Diff

library/ml/src/main/rust/examples/probe_int_dot.rs
diff --git a/library/ml/src/main/rust/examples/probe_int_dot.rs b/library/ml/src/main/rust/examples/probe_int_dot.rsnew file mode 100644index 0000000000..1a14ff5aa1--- /dev/null+++ b/library/ml/src/main/rust/examples/probe_int_dot.rs@@ -0,0 +1,70 @@+//! Reports what the GPU offers for int8 matrix work: `VK_KHR_shader_integer_dot_product`'s+//! acceleration flags and every `VK_KHR_cooperative_matrix` shape.+//!+//! ```text+//! cargo run --offline -p modelrunner --example probe_int_dot+//! ```+use std::ffi::CStr;++use ash::vk;+use modelrunner::vulkan::context;++fn main() {+    let context = match context::shared() {+        Ok(context) => context,+        Err(why) => {+            println!("no usable Vulkan device: {why}");+            return;+        }+    };+    let (instance, physical) = (&context.instance, context.physical_device);+    // SAFETY: plain queries on the physical device the context holds alive.+    let names: Vec<String> = unsafe { instance.enumerate_device_extension_properties(physical) }+        .unwrap_or_default()+        .iter()+        .map(|e| {+            // SAFETY: the driver NUL-terminates extension names inside the fixed array.+            unsafe { CStr::from_ptr(e.extension_name.as_ptr()) }.to_string_lossy().into_owned()+        })+        .collect();+    for wanted in [+        "VK_KHR_shader_integer_dot_product",+        "VK_KHR_cooperative_matrix",+        "VK_KHR_8bit_storage",+        "VK_KHR_shader_float16_int8",+    ] {+        println!("{wanted:40} {}", names.iter().any(|n| n == wanted));+    }+    println!("runtime enabled int8 dot: {}", context.int_dot);++    let mut dot = vk::PhysicalDeviceShaderIntegerDotProductProperties::default();+    let mut properties = vk::PhysicalDeviceProperties2::default().push_next(&mut dot);+    // SAFETY: as above; an unknown chained struct is left zeroed by a driver without it.+    unsafe { instance.get_physical_device_properties2(physical, &mut properties) };+    println!("4x8 packed accelerated: signed {} unsigned {} mixed {}",+        dot.integer_dot_product4x8_bit_packed_signed_accelerated,+        dot.integer_dot_product4x8_bit_packed_unsigned_accelerated,+        dot.integer_dot_product4x8_bit_packed_mixed_signedness_accelerated);+    println!("acc-sat 4x8 packed accelerated: signed {} mixed {}",+        dot.integer_dot_product_accumulating_saturating4x8_bit_packed_signed_accelerated,+        dot.integer_dot_product_accumulating_saturating4x8_bit_packed_mixed_signedness_accelerated);++    if !names.iter().any(|n| n == "VK_KHR_cooperative_matrix") {+        return;+    }+    let coop = ash::khr::cooperative_matrix::Instance::new(&context.entry, instance);+    // SAFETY: the extension is present, so the instance-level entry point resolves.+    match unsafe { coop.get_physical_device_cooperative_matrix_properties(physical) } {+        Ok(shapes) => {+            println!("cooperative matrix shapes ({}):", shapes.len());+            for s in shapes {+                println!("  M {} N {} K {}  A {} B {} C {} R {}  sat {} scope {}",+                    s.m_size, s.n_size, s.k_size, s.a_type.as_raw(), s.b_type.as_raw(),+                    s.c_type.as_raw(), s.result_type.as_raw(), s.saturating_accumulation,+                    s.scope.as_raw());+            }+            println!("  (component types: 0 f16, 1 f32, 3 s8, 5 s32, 7 u8, 9 u32; scope 3 subgroup)");+        }+        Err(e) => println!("cooperative matrix query failed: {}", e.as_raw()),+    }+}
library/ml/src/main/rust/shaders/conv_point_int4_dot.comp
diff --git a/library/ml/src/main/rust/shaders/conv_point_int4_dot.comp b/library/ml/src/main/rust/shaders/conv_point_int4_dot.compnew file mode 100644index 0000000000..2395ba4b60--- /dev/null+++ b/library/ml/src/main/rust/shaders/conv_point_int4_dot.comp@@ -0,0 +1,108 @@+#version 450+//! The int4 GEMM on the hardware int8 dot product (`VK_KHR_shader_integer_dot_product`).+//!+//! Reads the activations `quantize_blocks.comp` staged at element `p.kw`: int8 per position per+//! 32-channel block with an f32 scale. A weight word's 8 nibbles become two packed byte quads+//! (`w ^ 0x88888888` turns each two's-complement nibble `s` into `s + 8`, 0..15, a valid signed+//! byte), each multiplied against its activation quad by one signed `OpSDotKHR` (the Mali-G715+//! accelerates signed but not mixed-signedness); the staged `8 * sum(q)` removes the `+ 8`.+//! A block accumulates exactly in int32, then `acc += wscale * ascale * isum`.+//!+//! 4 channels x 4 positions per lane over 32 x 32 tiles, one 16-byte weight load per row per+//! block and one 16-byte activation load per position per half block. On a Pixel 8 that took+//! ConvPointInt4 of a 200-token Gemma prefill 2212 -> 2020 ms; the same tiling with 4-byte weight+//! and 8-byte activation loads took 4144 ms, and 4 x 8 per lane (32 x 64 tiles) 2282 ms.+//!+//! The tiling is also the `in1` 0 path of `conv_point_int4.comp`, so the emit's dispatch serves+//! that path when the device lacks the extension: `Shaders::for_kind` then hands out the fp32+//! pipeline with this push unchanged.+//! Requires `in_c % 32 == 0`, `positions % 4 == 0`, `p.weight % 4 == 0`, `p.kw % 8 == 0`.+#extension GL_EXT_spirv_intrinsics : require+#include "common.glsl"++spirv_instruction(extensions = ["SPV_KHR_integer_dot_product"], capabilities = [6019, 6018], id = 4450)+int sdot(uint a, uint b, spirv_literal int format);++layout(std430, binding = 0) readonly buffer ArenaOct {+    uvec4 arena_oct[];+};++#define TILE 32u+#define BLOCK 4u+#define NIBBLES 0x0F0F0F0Fu++void main() {+    uint tile = gl_WorkGroupID.y * gl_NumWorkGroups.x + gl_WorkGroupID.x;+    if (tile >= p.count) {+        return;+    }+    uint positions = p.out_h * p.out_w;+    uint tiles_across = (positions + TILE - 1u) / TILE;+    uint lid = gl_LocalInvocationID.x;+    uint channel_base = (tile / tiles_across) * TILE + (lid >> 3u) * BLOCK;+    uint position_base = (tile % tiles_across) * TILE + (lid & 7u) * BLOCK;+    if (position_base >= positions) {+        return;+    }+    uint blocks = p.in_c >> 5u;+    uint rows[BLOCK];+    for (uint i = 0u; i < BLOCK; i++) {+        rows[i] = min(channel_base + i, p.out_c - 1u);+    }+    vec4 acc[BLOCK];+    for (uint i = 0u; i < BLOCK; i++) {+        acc[i] = vec4(0.0);+    }+    uint data = p.kw >> 3u;+    uint meta = (p.kw + positions * p.in_c / 2u) >> 3u;+    for (uint block = 0u; block < blocks; block++) {+        uvec4 w[BLOCK];+        for (uint i = 0u; i < BLOCK; i++) {+            w[i] = weights128[(p.weight >> 2u) + rows[i] * blocks + block] ^ uvec4(0x88888888u);+        }+        ivec4 isum[BLOCK];+        for (uint i = 0u; i < BLOCK; i++) {+            isum[i] = ivec4(0);+        }+        uint cell = block * positions + position_base;+        for (uint h = 0u; h < 2u; h++) {+            uint lo0[BLOCK];+            uint hi0[BLOCK];+            uint lo1[BLOCK];+            uint hi1[BLOCK];+            for (uint i = 0u; i < BLOCK; i++) {+                lo0[i] = w[i][2u * h] & NIBBLES;+                hi0[i] = (w[i][2u * h] >> 4u) & NIBBLES;+                lo1[i] = w[i][2u * h + 1u] & NIBBLES;+                hi1[i] = (w[i][2u * h + 1u] >> 4u) & NIBBLES;+            }+            for (uint j = 0u; j < BLOCK; j++) {+                uvec4 x = arena_oct[data + (cell + j) * 2u + h];+                for (uint i = 0u; i < BLOCK; i++) {+                    isum[i][j] += sdot(x.x, lo0[i], 0) + sdot(x.y, hi0[i], 0)+                        + sdot(x.z, lo1[i], 0) + sdot(x.w, hi1[i], 0);+                }+            }+        }+        uvec4 m0 = arena_oct[meta + (cell >> 1u)];+        uvec4 m1 = arena_oct[meta + (cell >> 1u) + 1u];+        vec4 ascale = vec4(uintBitsToFloat(m0.x), uintBitsToFloat(m0.z),+            uintBitsToFloat(m1.x), uintBitsToFloat(m1.z));+        ivec4 correction = ivec4(m0.y, m0.w, m1.y, m1.w);+        for (uint i = 0u; i < BLOCK; i++) {+            acc[i] += vec4(isum[i] - correction) * (ascale * int4_scale(rows[i], block, blocks));+        }+    }+    for (uint i = 0u; i < BLOCK; i++) {+        uint channel = channel_base + i;+        if (channel >= p.out_c) {+            continue;+        }+        float offset = float(weights[p.bias + channel]);+        for (uint j = 0u; j < BLOCK; j++) {+            uint index = channel * positions + position_base + j;+            arena[p.out_at + index] =+                float16_t(quant_store(fused_store(acc[i][j] + offset, p.act, channel, index)));+        }+    }+}
library/ml/src/main/rust/shaders/quantize_blocks.comp
diff --git a/library/ml/src/main/rust/shaders/quantize_blocks.comp b/library/ml/src/main/rust/shaders/quantize_blocks.compnew file mode 100644index 0000000000..7fde575f02--- /dev/null+++ b/library/ml/src/main/rust/shaders/quantize_blocks.comp@@ -0,0 +1,57 @@+#version 450+//! Block-quantises a channel-major fp16 activation `(in_c, positions)` to int8 for+//! `conv_point_int4_dot.comp`: one scale per position per 32-channel block, matching the int4+//! weights' `I4_BLOCK`.+//!+//! # Layout written at `p.out_at` (element offset, a multiple of 8)+//!+//! Data, `[block][position]`, 8 words each: word `2q` packs channels `8q + 0, 2, 4, 6` and word+//! `2q + 1` channels `8q + 1, 3, 5, 7`, one signed byte each, low byte first. That is the order a+//! weight word's nibbles fall into after `& 0x0F0F0F0F` and `>> 4 & 0x0F0F0F0F`. Then, from+//! element `p.out_at + positions * in_c / 2`, a `[block][position]` table of `uvec2`: the scale as+//! f32 bits and `8 * sum(q)`, the correction for weights read as unsigned nibbles `w + 8`.+//!+//! # Push fields+//!+//! `p.in0` the input, `p.out_at` the output, `p.in_c` channels, `p.out_h * p.out_w` positions,+//! `p.count` `positions * in_c / 32` invocations.+#include "common.glsl"++layout(std430, binding = 0) buffer ArenaWord {+    uint arena_word[];+};++uint pack4(vec4 v, float inv, inout int sum) {+    ivec4 q = clamp(ivec4(roundEven(v * inv)), ivec4(-127), ivec4(127));+    sum += q.x + q.y + q.z + q.w;+    return uint(q.x & 255) | (uint(q.y & 255) << 8u) | (uint(q.z & 255) << 16u) | (uint(q.w) << 24u);+}++void main() {+    uint index = global_index();+    if (index >= p.count) {+        return;+    }+    uint positions = p.out_h * p.out_w;+    uint position = index % positions;+    uint block = index / positions;+    float v[32];+    float amax = 0.0;+    uint at = p.in0 + block * I4_BLOCK * positions + position;+    for (uint t = 0u; t < 32u; t++) {+        v[t] = float(arena[at + t * positions]);+        amax = max(amax, abs(v[t]));+    }+    float inv = amax > 0.0 ? 127.0 / amax : 0.0;+    int sum = 0;+    uint base = (p.out_at >> 1u) + index * 8u;+    for (uint q = 0u; q < 4u; q++) {+        uint k = q * 8u;+        arena_word[base + 2u * q] = pack4(vec4(v[k], v[k + 2u], v[k + 4u], v[k + 6u]), inv, sum);+        arena_word[base + 2u * q + 1u] =+            pack4(vec4(v[k + 1u], v[k + 3u], v[k + 5u], v[k + 7u]), inv, sum);+    }+    uint meta = ((p.out_at + positions * p.in_c / 2u) >> 1u) + index * 2u;+    arena_word[meta] = floatBitsToUint(amax / 127.0);+    arena_word[meta + 1u] = uint(8 * sum);+}
library/ml/src/main/rust/src/nets/mod.rs
diff --git a/library/ml/src/main/rust/src/nets/mod.rs b/library/ml/src/main/rust/src/nets/mod.rsindex 2cf6911e9f..e3e1477120 100644--- a/library/ml/src/main/rust/src/nets/mod.rs+++ b/library/ml/src/main/rust/src/nets/mod.rs@@ -346,6 +346,13 @@ pub enum Kind {     /// S10's live attention quantizes the mixture to int8 before the O projection     /// consumes it; the scale rides the push block like [`Kind::Softcap`]'s cap.     Quantize,+    /// Block-quantise an activation to int8 for [`Kind::ConvPointInt4Dot`]. See+    /// `shaders/quantize_blocks.comp`.+    QuantizeBlocks,+    /// [`Kind::ConvPointInt4`] on the int8 dot product, reading the staged activation at+    /// [`Push::kw`]. Falls back to the fp32 pipeline on a device without the extension. See+    /// `shaders/conv_point_int4_dot.comp`.+    ConvPointInt4Dot,     /// `O[h][d][i] = sum_j S[h][i][j] * V[h][d][j]`, attention's weighted sum.     ///     /// `O[h][d][i] = sum_j S[h][i][j] * V[h][d][j]`, attention's weighted sum.
library/ml/src/main/rust/src/nets/mod_part1.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part1.rs b/library/ml/src/main/rust/src/nets/mod_part1.rsindex 8b068b3283..5b32fda0e1 100644--- a/library/ml/src/main/rust/src/nets/mod_part1.rs+++ b/library/ml/src/main/rust/src/nets/mod_part1.rs@@ -288,7 +288,7 @@ impl Kind {             // word view, and its scale table is fp16 like an int8 one - only wider. Q2_K             // reads identically too: superblocks through the word view, the `(d, dmin)`             // table through the fp16 view, bias as usual.-            Kind::ConvVecInt4 | Kind::ConvPointInt4 | Kind::ConvQ2K | Kind::ConvVecQ2K | Kind::ConvPointQ2K => {+            Kind::ConvVecInt4 | Kind::ConvPointInt4 | Kind::ConvPointInt4Dot | Kind::ConvQ2K | Kind::ConvVecQ2K | Kind::ConvPointQ2K => {                 reads.push(WeightRead { at: words(push.weight), field: "weight" });                 reads.push(WeightRead { at: elems(push.bias), field: "bias" });                 reads.push(WeightRead { at: elems(push.act_weight), field: "act_weight" });@@ -331,6 +331,7 @@ impl Kind {             | Kind::CacheWrite             | Kind::Softcap             | Kind::Quantize+            | Kind::QuantizeBlocks             | Kind::Argmax             | Kind::ArgmaxFold             | Kind::TopK@@ -445,11 +446,16 @@ impl Kind {             | Kind::ConvPointInt8             | Kind::ConvVecInt8             | Kind::ConvPointInt4+            | Kind::ConvPointInt4Dot             | Kind::ConvVecInt4             | Kind::ConvQ2K             | Kind::ConvPointQ2K             | Kind::ConvVecQ2K => {                 let mut ranges = vec![(push.in0, dense)];+                // The dot GEMM also reads the int8 blocks staged at `kw`.+                if self == Kind::ConvPointInt4Dot {+                    ranges.push((push.kw, push.in_c / 8 * 5 * push.out_h * push.out_w));+                }                 if push.res != NO_FUSE {                     ranges.push((push.res, written));                 }@@ -472,6 +478,7 @@ impl Kind {             | Kind::Affine             | Kind::Softcap             | Kind::Quantize+            | Kind::QuantizeBlocks             | Kind::Activate             | Kind::GatedActivate             | Kind::MulScalar
library/ml/src/main/rust/src/nets/mod_part10.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part10.rs b/library/ml/src/main/rust/src/nets/mod_part10.rsindex cefe29b792..a26c21595d 100644--- a/library/ml/src/main/rust/src/nets/mod_part10.rs+++ b/library/ml/src/main/rust/src/nets/mod_part10.rs@@ -32,6 +32,7 @@ impl Node {             | Node::ArgmaxFold { out, .. } => *out,             | Node::TopK { out, .. } => *out,             | Node::Quantize { out, .. } => *out,+            | Node::QuantizeBlocks { out, .. } => *out,             | Node::Activate { out, .. }             | Node::GatedActivate { out, .. } => *out,             | Node::MulScalar { out, .. } => *out,@@ -50,10 +51,11 @@ impl Node {                 reads.extend(shift.iter().copied());                 reads             }-            Node::ConvInt8 { input, res, shift, .. } => {+            Node::ConvInt8 { input, res, shift, staged, .. } => {                 let mut reads = vec![*input];                 reads.extend(res.iter().copied());                 reads.extend(shift.iter().copied());+                reads.extend(staged.iter().copied());                 reads             }             Node::MaxPool { input, .. }@@ -66,6 +68,7 @@ impl Node {             | Node::Softcap { input, .. }             | Node::Argmax { input, .. }             | Node::Quantize { input, .. }+            | Node::QuantizeBlocks { input, .. }             | Node::GatedActivate { input, .. }             | Node::Activate { input, .. }             | Node::MulScalar { input, .. }
library/ml/src/main/rust/src/nets/mod_part11.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part11.rs b/library/ml/src/main/rust/src/nets/mod_part11.rsindex 7c1d1f887d..ba78765254 100644--- a/library/ml/src/main/rust/src/nets/mod_part11.rs+++ b/library/ml/src/main/rust/src/nets/mod_part11.rs@@ -178,7 +178,9 @@ pub(crate) mod tests {             // serves a `1 x 1` is a lowering decision the op-inventory tests should not see.             // The int4 and Q2_K triples fold the same way.             super::Kind::ConvPointInt8 | super::Kind::ConvVecInt8 => "ConvInt8".to_string(),-            super::Kind::ConvPointInt4 | super::Kind::ConvVecInt4 => "ConvInt4".to_string(),+            super::Kind::ConvPointInt4 | super::Kind::ConvVecInt4 | super::Kind::ConvPointInt4Dot => {+                "ConvInt4".to_string()+            }             super::Kind::ConvQ2K | super::Kind::ConvPointQ2K | super::Kind::ConvVecQ2K => {                 "ConvQ2K".to_string()             }
library/ml/src/main/rust/src/nets/mod_part2.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part2.rs b/library/ml/src/main/rust/src/nets/mod_part2.rsindex 3658fdbb40..adb97b3edf 100644--- a/library/ml/src/main/rust/src/nets/mod_part2.rs+++ b/library/ml/src/main/rust/src/nets/mod_part2.rs@@ -360,6 +360,11 @@ pub(crate) enum Node {         out: Id,         scale: f32,     },+    /// int8 blocks of an int4 GEMM's input. See [`Kind::QuantizeBlocks`].+    QuantizeBlocks {+        input: Id,+        out: Id,+    },     /// An activation on its own. See [`Kind::Activate`].     Activate {         input: Id,@@ -437,6 +442,9 @@ pub(crate) enum Node {         /// convolution produced folds into the store, which keeps         /// `quantize(activate(acc + bias))` and never dispatches it.         quant_scale: Option<f32>,+        /// The input block-quantised to int8 by a [`Node::QuantizeBlocks`], for an int4 GEMM+        /// on the int8 dot product. See [`Kind::ConvPointInt4Dot`].+        staged: Option<Id>,     },     AttnApply {         probs: Id,
library/ml/src/main/rust/src/nets/mod_part2b.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part2b.rs b/library/ml/src/main/rust/src/nets/mod_part2b.rsindex d2372cf45d..e286ce61dc 100644--- a/library/ml/src/main/rust/src/nets/mod_part2b.rs+++ b/library/ml/src/main/rust/src/nets/mod_part2b.rs@@ -18,6 +18,8 @@ pub struct Builder<'a> {     spatial_tiled: bool,     /// See [`Builder::widen_int8`].     widen_int8: bool,+    /// See [`Builder::fp32_int4`].+    fp32_int4: bool, }  /// Arena allocations are aligned to this many fp16 elements, i.e. 16 bytes — the same
library/ml/src/main/rust/src/nets/mod_part4.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part4.rs b/library/ml/src/main/rust/src/nets/mod_part4.rsindex f8417bfe8e..292ec71a59 100644--- a/library/ml/src/main/rust/src/nets/mod_part4.rs+++ b/library/ml/src/main/rust/src/nets/mod_part4.rs@@ -12,8 +12,14 @@ impl<'a> Builder<'a> {             pad_edge: false,             spatial_tiled: false,             widen_int8: false,+            fp32_int4: false,         }     }+    /// Keep this net's int4 GEMMs on fp32 activations, off the int8 dot-product path that+    /// `stage_int8` otherwise picks.+    pub fn fp32_int4(&mut self) {+        self.fp32_int4 = true;+    }      /// Run this net's int8 GEMMs over fp16 copies of their weights, widened at upload.     ///@@ -398,6 +404,7 @@ impl<'a> Builder<'a> {         let out_h = conv_out(in_shape.h, kh, stride.0, dilation.0, pad_t + pad_b);         let out_w = conv_out(in_shape.w, kw, stride.1, dilation.1, pad_l + pad_r);         let out = self.tensor(Shape::new(m, out_h, out_w));+        let staged = self.stage_int8(input, weight, quant, kernel, stride, (pad_t, pad_l, pad_b, pad_r), group);         self.nodes.push(Node::ConvInt8 {             input,             out,@@ -414,7 +421,67 @@ impl<'a> Builder<'a> {             res: None,             shift: None,             quant_scale: None,+            staged,         });         out     }-}\ No newline at end of file++    /// The int8 blocks an int4 GEMM over `input` reads on the dot-product path, or `None` when+    /// it stays fp32: decode (one position), shapes the dot shader cannot tile, or+    /// `MODELRUNNER_INT8_DOT=0`. Convolutions sharing an input share one staging.+    #[allow(clippy::too_many_arguments)]+    fn stage_int8(+        &mut self,+        input: Id,+        weight: u32,+        quant: Quant,+        kernel: (u32, u32),+        stride: (u32, u32),+        pads: (u32, u32, u32, u32),+        group: u32,+    ) -> Option<Id> {+        let s = self.shape_of(input);+        let positions = s.h * s.w;+        let eligible = quant == Quant::I4+            && !self.fp32_int4+            && kernel == (1, 1)+            && stride == (1, 1)+            && pads == (0, 0, 0, 0)+            && group == 1+            && s.c % crate::weights::I4_BLOCK == 0+            && positions >= INT8_DOT_MIN_POSITIONS+            && positions % 4 == 0+            && weight % 4 == 0+            && crate::knobs::get("int8_dot").as_deref() != Some("0");+        if !eligible {+            return None;+        }+        let existing = self.nodes.iter().find_map(|node| match node {+            Node::QuantizeBlocks { input: i, out } if *i == input => Some(*out),+            _ => None,+        });+        if existing.is_some() {+            return existing;+        }+        let out = self.tensor(Shape::new(s.c / 8 * 5, s.h, s.w));+        self.nodes.push(Node::QuantizeBlocks { input, out });+        Some(out)+    }++    /// The int8 dot-product GEMM and its staged input's offset when the builder staged one (see+    /// `stage_int8`); its 32 x 32 tiling is also the fp32 shader's `in1` 0 path, the fallback.+    fn int8_dot(+        kind: Kind,+        staged: Option<Id>,+        at: &dyn Fn(Id) -> Result<u32, String>,+    ) -> Result<(Kind, Option<u32>), String> {+        let staged_at = match staged {+            Some(id) if kind == Kind::ConvPointInt4 => Some(at(id)?).filter(|s| s % 8 == 0),+            _ => None,+        };+        Ok((if staged_at.is_some() { Kind::ConvPointInt4Dot } else { kind }, staged_at))+    }+}++/// Fewest positions an int4 GEMM needs to take the int8 dot-product path.+const INT8_DOT_MIN_POSITIONS: u32 = 8;\ No newline at end of file
library/ml/src/main/rust/src/nets/mod_part9.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part9.rs b/library/ml/src/main/rust/src/nets/mod_part9.rsindex 5272033332..a46838caf9 100644--- a/library/ml/src/main/rust/src/nets/mod_part9.rs+++ b/library/ml/src/main/rust/src/nets/mod_part9.rs@@ -27,6 +27,7 @@ impl<'a> Builder<'a> {                 res,                 shift,                 quant_scale,+                staged,             } => {                 let (si, so) = (shape(*input), shape(*out));                 // The same test `Node::Conv` applies below, less the two cases that cannot arise@@ -84,6 +85,7 @@ impl<'a> Builder<'a> {                     && (si.c * kernel.1) % 16 == 0                     && *weight % 4 == 0;                 let kind = if row_gemm { Kind::ConvPointInt8 } else { kind };+                let (kind, staged_at) = Self::int8_dot(kind, *staged, at)?;                 // Too few 32 x 32 tiles to fill the GPU: two channels per invocation instead of                 // four, bit-identical. See `split_rows` in conv_point_int8.comp. On a Pixel 8,                 // splitting everything under 256 tiles took Supertonic's sampler 2199 -> 1521 ms.@@ -146,7 +148,7 @@ impl<'a> Builder<'a> {                     Kind::ConvPointQ2K => {                         so.c.div_ceil(CONV_POINT_INT8_TILE >> q2k_split) * positions.div_ceil(CONV_POINT_INT8_TILE)                     }-                    Kind::ConvPointInt8 | Kind::ConvPointInt4 => int8_tiles,+                    Kind::ConvPointInt8 | Kind::ConvPointInt4 | Kind::ConvPointInt4Dot => int8_tiles,                     _ => so.len(),                 };                 ops.push(Op::Dispatch {@@ -183,7 +185,7 @@ impl<'a> Builder<'a> {                         // `nets::reference` can serve all three kinds from one `conv_int8`, whose                         // arithmetic is identical once the geometry above holds.                         kh: kernel.0,-                        kw: kernel.1,+                        kw: staged_at.unwrap_or(kernel.1),                         stride_h: stride.0,                         stride_w: stride.1,                         dil_h: dilation.0,@@ -207,7 +209,7 @@ impl<'a> Builder<'a> {                         Kind::ConvVecInt8                         | Kind::ConvPointInt8                         | Kind::ConvVecInt4-                        | Kind::ConvPointInt4+                        | Kind::ConvPointInt4 | Kind::ConvPointInt4Dot                         | Kind::ConvVecQ2K                         | Kind::ConvPointQ2K => count * 64,                         Kind::ConvInt8 if int8_blocked => {
library/ml/src/main/rust/src/nets/mod_part9b.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part9b.rs b/library/ml/src/main/rust/src/nets/mod_part9b.rsindex 66afaaba0e..724fbd0c3c 100644--- a/library/ml/src/main/rust/src/nets/mod_part9b.rs+++ b/library/ml/src/main/rust/src/nets/mod_part9b.rs@@ -347,6 +347,26 @@ impl<'a> Builder<'a> {                     invocations: 64,                 });             }+            Node::QuantizeBlocks { input, out } => {+                let (si, so) = (shape(*input), shape(*out));+                let count = si.c / crate::weights::I4_BLOCK * si.h * si.w;+                ops.push(Op::Dispatch {+                    kind: Kind::QuantizeBlocks,+                    push: Push {+                        in0: at(*input)?,+                        out: at(*out)?,+                        in_c: si.c,+                        in_h: si.h,+                        in_w: si.w,+                        out_c: so.c,+                        out_h: so.h,+                        out_w: so.w,+                        count,+                        ..Push::default()+                    },+                    invocations: count,+                });+            }             Node::Quantize { input, out, scale } => {                 let so = shape(*out);                 ops.push(Op::Dispatch {
library/ml/src/main/rust/src/nets/reference_part1.rs
diff --git a/library/ml/src/main/rust/src/nets/reference_part1.rs b/library/ml/src/main/rust/src/nets/reference_part1.rsindex 8411bd11f8..944a3257b2 100644--- a/library/ml/src/main/rust/src/nets/reference_part1.rs+++ b/library/ml/src/main/rust/src/nets/reference_part1.rs@@ -93,6 +93,8 @@ impl Reference {                         self.conv_int8(push)                     }                     Kind::ConvVecInt4 | Kind::ConvPointInt4 => self.conv_int4(push),+                    Kind::ConvPointInt4Dot => self.conv_int4_dot(push),+                    Kind::QuantizeBlocks => Ok(()),                     Kind::ConvQ2K | Kind::ConvPointQ2K | Kind::ConvVecQ2K => self.conv_q2k(push),                 },             };
library/ml/src/main/rust/src/nets/reference_part11.rs
diff --git a/library/ml/src/main/rust/src/nets/reference_part11.rs b/library/ml/src/main/rust/src/nets/reference_part11.rsindex 38fc6fd3bb..d676353df9 100644--- a/library/ml/src/main/rust/src/nets/reference_part11.rs+++ b/library/ml/src/main/rust/src/nets/reference_part11.rs@@ -65,4 +65,54 @@ impl Reference {         }         Ok(())     }++    /// `conv_point_int4_dot.comp`: the input quantised per position per 32-tap block to int8+    /// (`quantize_blocks.comp`'s rounding), exact integer block sums, then+    /// `acc += isum * (ascale * wscale)`. Read from the fp16 input, which the op keeps live, so+    /// [`Kind::QuantizeBlocks`] has nothing to do here.+    fn conv_int4_dot(&mut self, p: &Push) -> Result<(), String> {+        let block = crate::weights::I4_BLOCK;+        let blocks = p.in_c / block;+        let positions = p.out_h * p.out_w;+        let mut staged = vec![(0.0f32, [0i32; 32]); (blocks * positions) as usize];+        for b in 0..blocks {+            for position in 0..positions {+                let mut v = [0.0f32; 32];+                for (t, slot) in v.iter_mut().enumerate() {+                    *slot = self.load(p.in0, (b * block + t as u32) * positions + position)?;+                }+                let amax = v.iter().fold(0.0f32, |m, x| m.max(x.abs()));+                let inv = if amax > 0.0 { 127.0 / amax } else { 0.0 };+                let mut q = [0i32; 32];+                for (slot, x) in q.iter_mut().zip(v) {+                    *slot = ((x * inv).round_ties_even() as i32).clamp(-127, 127);+                }+                if let Some(cell) = staged.get_mut((b * positions + position) as usize) {+                    *cell = (amax / 127.0, q);+                }+            }+        }+        for oc in 0..p.out_c {+            let shift = self.fused_shift(p, oc)?;+            for position in 0..positions {+                let mut acc = 0.0f32;+                for b in 0..blocks {+                    let (ascale, q) = staged+                        .get((b * positions + position) as usize)+                        .copied()+                        .ok_or("staged block out of range")?;+                    let mut isum = 0i32;+                    for (t, x) in q.iter().enumerate() {+                        isum += x * i32::from(self.int4(p.weight, oc * p.in_c + b * block + t as u32)?);+                    }+                    acc += isum as f32 * (ascale * self.weight(p.act_weight, oc * blocks + b)?);+                }+                let biased = acc + self.weight(p.bias, oc)?;+                let index = oc * positions + position;+                let folded = activate(biased, p.act, 0.0) + self.fused_res(p, index)? + shift;+                self.store(p.out, index, self.fused_quant(p, folded)?)?;+            }+        }+        Ok(())+    } }
library/ml/src/main/rust/src/vulkan/context.rs
diff --git a/library/ml/src/main/rust/src/vulkan/context.rs b/library/ml/src/main/rust/src/vulkan/context.rsindex 88a1c195db..21ab9ba41f 100644--- a/library/ml/src/main/rust/src/vulkan/context.rs+++ b/library/ml/src/main/rust/src/vulkan/context.rs@@ -60,6 +60,10 @@ pub struct Context {     pub queue_family_index: u32,     /// The three device limits the weights buffer has to fit inside.     pub limits: Limits,+    /// `VK_KHR_shader_integer_dot_product` is enabled, so the int8-dot int4 GEMM can run.+    ///+    /// Optional: the Vulkan 1.1 floor does not have it. `MODELRUNNER_INT8_DOT=0` turns it off.+    pub int_dot: bool,     /// Guards the queue above.     ///     /// `VkQueue` is *externally synchronised* in the Vulkan sense: the application must not@@ -229,16 +233,26 @@ impl Context {         let queue_info = vk::DeviceQueueCreateInfo::default()             .queue_family_index(queue_family_index)             .queue_priorities(&priorities);-        let extensions = [ash::khr::shader_float16_int8::NAME.as_ptr()];+        let int_dot = Self::supports_int_dot(&instance, physical_device)+            && crate::knobs::get("int8_dot").as_deref() != Some("0");+        let mut extensions = vec![ash::khr::shader_float16_int8::NAME.as_ptr()];+        if int_dot {+            extensions.push(ash::khr::shader_integer_dot_product::NAME.as_ptr());+        }         let mut float16 =             vk::PhysicalDeviceShaderFloat16Int8Features::default().shader_float16(true);         let mut storage16 =             vk::PhysicalDevice16BitStorageFeatures::default().storage_buffer16_bit_access(true);-        let device_info = vk::DeviceCreateInfo::default()+        let mut dot =+            vk::PhysicalDeviceShaderIntegerDotProductFeatures::default().shader_integer_dot_product(true);+        let mut device_info = vk::DeviceCreateInfo::default()             .queue_create_infos(std::slice::from_ref(&queue_info))             .enabled_extension_names(&extensions)             .push_next(&mut float16)             .push_next(&mut storage16);+        if int_dot {+            device_info = device_info.push_next(&mut dot);+        }         let device = match instance.create_device(physical_device, &device_info, None) {             Ok(d) => d,             Err(e) => {@@ -256,6 +270,7 @@ impl Context {             queue,             queue_family_index,             limits,+            int_dot,             queue_lock: Mutex::new(()),             shaders: Mutex::new(None),         })@@ -315,6 +330,30 @@ impl Context {         float16.shader_float16 == vk::TRUE && storage16.storage_buffer16_bit_access == vk::TRUE     } +    /// Whether `VK_KHR_shader_integer_dot_product` is present with its feature and packed 4x8+    /// signed dot products are hardware-accelerated. Emulated ones would be slower than fp32.+    unsafe fn supports_int_dot(instance: &ash::Instance, physical_device: vk::PhysicalDevice) -> bool {+        let has_extension = instance+            .enumerate_device_extension_properties(physical_device)+            .is_ok_and(|all| {+                all.iter().any(|e| {+                    CStr::from_ptr(e.extension_name.as_ptr())+                        == ash::khr::shader_integer_dot_product::NAME+                })+            });+        if !has_extension {+            return false;+        }+        let mut dot = vk::PhysicalDeviceShaderIntegerDotProductFeatures::default();+        let mut features = vk::PhysicalDeviceFeatures2::default().push_next(&mut dot);+        instance.get_physical_device_features2(physical_device, &mut features);+        let mut fast = vk::PhysicalDeviceShaderIntegerDotProductProperties::default();+        let mut properties = vk::PhysicalDeviceProperties2::default().push_next(&mut fast);+        instance.get_physical_device_properties2(physical_device, &mut properties);+        dot.shader_integer_dot_product == vk::TRUE+            && fast.integer_dot_product4x8_bit_packed_signed_accelerated == vk::TRUE+    }+     unsafe fn has_layer(entry: &Entry, wanted: &CStr) -> bool {         entry             .enumerate_instance_layer_properties()
library/ml/src/main/rust/src/vulkan/parity.rs
diff --git a/library/ml/src/main/rust/src/vulkan/parity.rs b/library/ml/src/main/rust/src/vulkan/parity.rsindex e7f76408b0..0537f08cf6 100644--- a/library/ml/src/main/rust/src/vulkan/parity.rs+++ b/library/ml/src/main/rust/src/vulkan/parity.rs@@ -447,4 +447,5 @@ include!("parity_part10.rs"); include!("parity_part7.rs"); include!("parity_part8.rs"); include!("parity_part11.rs");-include!("parity_part12.rs");\ No newline at end of file+include!("parity_part12.rs");+include!("parity_part13.rs");\ No newline at end of file
library/ml/src/main/rust/src/vulkan/parity_part13.rs
diff --git a/library/ml/src/main/rust/src/vulkan/parity_part13.rs b/library/ml/src/main/rust/src/vulkan/parity_part13.rsnew file mode 100644index 0000000000..67ce254e24--- /dev/null+++ b/library/ml/src/main/rust/src/vulkan/parity_part13.rs@@ -0,0 +1,125 @@+// Device parity fixtures for the int4 GEMM on the int8 dot product (`conv_point_int4_dot.comp`,+// staged by `quantize_blocks.comp`). See `parity.rs` for the helpers.+//+// Three checks per shape: the device against the reference's int8 path (same quantisation, so+// the usual tolerance), the device against the fp32 int4 reference within a bound derived from+// the activation rounding, and the fallback (the fp32 pipeline under the same push, which is+// what a device without the extension runs) against the fp32 reference.++fn int4_dot_fixture(label: &str, out_channels: u32, in_channels: u32, positions: u32, act: Act) {+    let blocks = in_channels / 32;+    let kernel: Vec<i8> =+        (0..(out_channels * in_channels) as i32).map(|i| ((i * 7 + i / 5) % 16 - 8) as i8).collect();+    let scales: Vec<f32> =+        (0..out_channels * blocks).map(|i| 0.007_812_5 * (1.0 + (i % 5) as f32)).collect();+    let blob = write_mixed(+        graph::SUPERTONIC_VE,+        &[+            Fixture::I4(vec![out_channels, in_channels, 1, 1], kernel.clone()),+            Fixture::F16(vec![out_channels, blocks], scales.clone()),+            Fixture::F16(vec![out_channels], spread(out_channels as usize, 1.3)),+        ],+    );+    let weights = Weights::parse(&blob, graph::SUPERTONIC_VE).expect("the int4 fixture parses");+    let input = spread((in_channels * positions) as usize, 0.5);+    let build = |fp32: bool| {+        let mut builder = Builder::new(&weights);+        if fp32 {+            builder.fp32_int4();+        }+        let first = builder.input(Shape::new(in_channels, 1, positions));+        let last = builder.conv_int4(first, 0, out_channels, act);+        builder.finish(&[last]).expect("the int4 dot fixture plan builds")+    };+    let plan = build(false);+    let has = |plan: &Plan, kind: crate::nets::Kind| {+        plan.ops.iter().any(|op| matches!(op, crate::nets::Op::Dispatch { kind: k, .. } if *k == kind))+    };+    assert!(+        has(&plan, crate::nets::Kind::ConvPointInt4Dot) && has(&plan, crate::nets::Kind::QuantizeBlocks),+        "{label}: an aligned multi-position int4 GEMM must stage its input for the dot product",+    );+    crate::nets::tests::assert_no_aliasing(&plan);+    let data = weights.data().to_vec();+    let fp32 = run_multi(&build(true), &data, &[&input]).expect("the fp32 reference runs");+    let got = on_device(plan.clone(), data.clone(), &[&input]);+    if device().int_dot {+        compare(&format!("{label} vs the int8 reference"), plan.clone(), data.clone(), &[&input]);+    }+    let (fp32, got) = (&fp32[0], &got[0]);+    let mut worst = 0.0f32;+    for oc in 0..out_channels {+        for position in 0..positions {+            let mut bound = 0.0f32;+            for b in 0..blocks {+                let amax = (0..32)+                    .map(|t| input[((b * 32 + t) * positions + position) as usize].abs())+                    .fold(0.0f32, f32::max);+                let taps: f32 = (0..32)+                    .map(|t| f32::from(kernel[(oc * in_channels + b * 32 + t) as usize]).abs())+                    .sum();+                bound += scales[(oc * blocks + b) as usize] * taps * amax / 254.0;+            }+            let at = (oc * positions + position) as usize;+            let diff = (got[at] - fp32[at]).abs();+            worst = worst.max(diff);+            assert!(+                diff <= 1.2 * bound + 4e-3 * fp32[at].abs() + 1e-3,+                "{label}: channel {oc} position {position} is {} on the device and {} in fp32, \+                 past the int8 rounding bound {bound}",+                got[at],+                fp32[at],+            );+        }+    }+    eprintln!("{label}: max |int8 dot - fp32| = {worst}");+    let mut fallback = plan;+    for op in fallback.ops.iter_mut() {+        if let crate::nets::Op::Dispatch { kind, .. } = op {+            if *kind == crate::nets::Kind::ConvPointInt4Dot {+                *kind = crate::nets::Kind::ConvPointInt4;+            }+        }+    }+    compare(&format!("{label} on the fp32 fallback"), fallback, data, &[&input]);+}++#[test]+#[ignore = "needs a Vulkan device"]+fn the_int8_dot_int4_gemm_agrees_with_the_reference() {+    // Sliding `q_proj` at 200 tokens; a partial 32-position tile and a partial row tile under+    // GELU; the 12288-tap down projection (384 blocks) at the fewest positions that stage.+    int4_dot_fixture("an int8-dot 1536 -> 2048 gemm at 200 positions", 2048, 1536, 200, Act::None);+    int4_dot_fixture("an int8-dot ragged gemm at 36 positions", 1000, 2048, 36, Act::Gelu);+    int4_dot_fixture("an int8-dot 12288 -> 96 gemm at 8 positions", 96, 12288, 8, Act::None);+}++#[test]+fn int4_gemms_the_dot_shader_cannot_tile_stay_fp32() {+    let blob = write_mixed(+        graph::SUPERTONIC_VE,+        &[+            Fixture::I4(vec![64, 1536, 1, 1], vec![1; 64 * 1536]),+            Fixture::F16(vec![64, 48], vec![0.01; 64 * 48]),+            Fixture::F16(vec![64], vec![0.0; 64]),+        ],+    );+    let weights = Weights::parse(&blob, graph::SUPERTONIC_VE).expect("the int4 fixture parses");+    // Ragged positions, one position (decode), and too few positions.+    for positions in [37, 1, 4] {+        let mut builder = Builder::new(&weights);+        let first = builder.input(Shape::new(1536, 1, positions));+        let last = builder.conv_int4(first, 0, 64, Act::None);+        let plan = builder.finish(&[last]).expect("the plan builds");+        assert!(+            plan.ops.iter().all(|op| !matches!(+                op,+                crate::nets::Op::Dispatch {+                    kind: crate::nets::Kind::ConvPointInt4Dot | crate::nets::Kind::QuantizeBlocks,+                    ..+                }+            )),+            "{positions} positions must not take the int8 dot path",+        );+    }+}
library/ml/src/main/rust/src/vulkan/parity_part7.rs
diff --git a/library/ml/src/main/rust/src/vulkan/parity_part7.rs b/library/ml/src/main/rust/src/vulkan/parity_part7.rsindex 33149455ae..6ac348132b 100644--- a/library/ml/src/main/rust/src/vulkan/parity_part7.rs+++ b/library/ml/src/main/rust/src/vulkan/parity_part7.rs@@ -247,6 +247,7 @@ fn int4_gemm_fixture(label: &str, out_channels: u32, in_channels: u32, positions     let weights = Weights::parse(&blob, graph::SUPERTONIC_VE).expect("the int4 fixture parses");     let input = spread((in_channels * positions) as usize, 0.5);     let mut builder = Builder::new(&weights);+    builder.fp32_int4();     let first = builder.input(Shape::new(in_channels, 1, positions));     let last = builder.conv_int4(first, 0, out_channels, act);     let plan = builder.finish(&[last]).expect("the int4 gemm fixture plan builds");@@ -466,6 +467,7 @@ fn the_wide_int4_gemm_agrees_with_the_reference_at_gemma_prefill_shapes() {     );     let weights = Weights::parse(&blob, graph::SUPERTONIC_VE).expect("the int4 fixture parses");     let mut builder = Builder::new(&weights);+    builder.fp32_int4();     let first = builder.input(Shape::new(1536, 1, 200));     let last = builder.conv_int4(first, 0, 64, Act::None);     let plan = builder.finish(&[last]).expect("the plan builds");
library/ml/src/main/rust/src/vulkan/pipeline.rs
diff --git a/library/ml/src/main/rust/src/vulkan/pipeline.rs b/library/ml/src/main/rust/src/vulkan/pipeline.rsindex db6fc04ae9..79be9f2b17 100644--- a/library/ml/src/main/rust/src/vulkan/pipeline.rs+++ b/library/ml/src/main/rust/src/vulkan/pipeline.rs@@ -25,7 +25,7 @@ use ash::vk; use crate::nets::Kind;  use super::context::Context;-use super::pipeline_extra::{CONV_POINT_Q2K, CONV_Q2K, QUANTIZE};+use super::pipeline_extra::{CONV_POINT_Q2K, CONV_Q2K, QUANTIZE, QUANTIZE_BLOCKS}; use super::segment::Segment;  const CONV: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/conv.comp.spv"));@@ -92,7 +92,7 @@ const TOPK: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/topk.comp.spv")); /// Every shader, in the order `Shaders::create` destructures them (the Q2_K pair, /// `QUANTIZE`, and the `compute_pipeline` / `shader_module` helpers live in /// `pipeline_extra.rs` for length).-pub(crate) const SPIRV: [&[u8]; 48] = [+pub(crate) const SPIRV: [&[u8]; 49] = [     CONV,     CONV_TRANSPOSE,     MAXPOOL,@@ -141,6 +141,7 @@ pub(crate) const SPIRV: [&[u8]; 48] = [     ARGMAX,     ARGMAX_FOLD,     TOPK,+    QUANTIZE_BLOCKS, ];  /// Descriptors in one set: the arena, the weights as fp16, the weights as words, the step params.@@ -223,6 +224,9 @@ pub struct Shaders {     pub(crate) argmax: vk::Pipeline,     pub(crate) argmax_fold: vk::Pipeline,     pub(crate) topk: vk::Pipeline,+    pub(crate) quantize_blocks: vk::Pipeline,+    /// Null when the device lacks the int8 dot product; see [`Context::int_dot`].+    pub(crate) conv_point_int4_dot: vk::Pipeline, }  /// One net's descriptor sets, over the device-wide [`Shaders`].
library/ml/src/main/rust/src/vulkan/pipeline_extra.rs
diff --git a/library/ml/src/main/rust/src/vulkan/pipeline_extra.rs b/library/ml/src/main/rust/src/vulkan/pipeline_extra.rsindex 0e68cddf13..41b7154c1f 100644--- a/library/ml/src/main/rust/src/vulkan/pipeline_extra.rs+++ b/library/ml/src/main/rust/src/vulkan/pipeline_extra.rs@@ -17,6 +17,11 @@ pub(crate) const CONV_POINT_Q2K: &[u8] =     include_bytes!(concat!(env!("OUT_DIR"), "/conv_point_q2k.comp.spv")); pub(crate) const CONV_Q2K: &[u8] =     include_bytes!(concat!(env!("OUT_DIR"), "/conv_q2k.comp.spv"));+pub(crate) const QUANTIZE_BLOCKS: &[u8] =+    include_bytes!(concat!(env!("OUT_DIR"), "/quantize_blocks.comp.spv"));+/// Declares `DotProductKHR`, so it is built only on a device that enabled the extension.+const CONV_POINT_INT4_DOT: &[u8] =+    include_bytes!(concat!(env!("OUT_DIR"), "/conv_point_int4_dot.comp.spv"));  impl Shaders {     /// Compile every shader and build the two layouts. Called once per device.@@ -100,6 +105,17 @@ impl Shaders {         // `pipeline_cache`.         let (cache, seed) = super::pipeline_cache::open(device);         let started = std::time::Instant::now();+        let conv_point_int4_dot = if context.int_dot {+            match compute_pipeline(device, layout, cache, CONV_POINT_INT4_DOT) {+                Ok(pipeline) => pipeline,+                Err(e) => {+                    super::pipeline_cache::close(device, cache, &seed);+                    return Err(e);+                }+            }+        } else {+            vk::Pipeline::null()+        };         for spirv in SPIRV {             match compute_pipeline(device, layout, cache, spirv) {                 Ok(pipeline) => built.push(pipeline),@@ -107,6 +123,7 @@ impl Shaders {                     for pipeline in built {                         device.destroy_pipeline(pipeline, None);                     }+                    device.destroy_pipeline(conv_point_int4_dot, None);                     super::pipeline_cache::close(device, cache, &seed);                     return Err(e);                 }@@ -170,12 +187,14 @@ impl Shaders {             argmax,             argmax_fold,             topk,+            quantize_blocks,         ] = match <[vk::Pipeline; SPIRV.len()]>::try_from(built) {             Ok(all) => all,             Err(built) => {                 for pipeline in built {                     device.destroy_pipeline(pipeline, None);                 }+                device.destroy_pipeline(conv_point_int4_dot, None);                 return Err("wrong pipeline count".into());             }         };@@ -232,6 +251,8 @@ impl Shaders {             argmax,             argmax_fold,             topk,+            quantize_blocks,+            conv_point_int4_dot,         })     } @@ -261,6 +282,12 @@ impl Shaders {             Kind::GatedActivate => self.gated_activate,             Kind::ConvVecInt4 => self.conv_vec_int4,             Kind::ConvPointInt4 => self.conv_point_int4,+            // Same push and tiling as the fp32 shader's `in1` 0 path, which serves it otherwise.+            Kind::ConvPointInt4Dot if self.conv_point_int4_dot != vk::Pipeline::null() => {+                self.conv_point_int4_dot+            }+            Kind::ConvPointInt4Dot => self.conv_point_int4,+            Kind::QuantizeBlocks => self.quantize_blocks,             Kind::ConvVecQ2K => self.conv_vec_q2k,             Kind::ConvPointQ2K => self.conv_point_q2k,             Kind::ConvQ2K => self.conv_q2k,@@ -341,6 +368,8 @@ impl Shaders {             self.argmax,             self.argmax_fold,             self.topk,+            self.quantize_blocks,+            self.conv_point_int4_dot,         ] {             device.destroy_pipeline(pipeline, None);         }
library/ml/src/main/rust/src/vulkan/segment.rs
diff --git a/library/ml/src/main/rust/src/vulkan/segment.rs b/library/ml/src/main/rust/src/vulkan/segment.rsindex 4456e6f61e..6fa94a1819 100644--- a/library/ml/src/main/rust/src/vulkan/segment.rs+++ b/library/ml/src/main/rust/src/vulkan/segment.rs@@ -198,6 +198,7 @@ pub(crate) fn rebase_push(base: u64, kind: Kind, push: &Push) -> Push {                         | Kind::ConvVecInt8                         | Kind::ConvVecInt4                         | Kind::ConvPointInt4+                        | Kind::ConvPointInt4Dot                         | Kind::ConvQ2K                         | Kind::ConvVecQ2K                         | Kind::ConvPointQ2K
library/ml/src/main/rust/src/weights_part7.rs
diff --git a/library/ml/src/main/rust/src/weights_part7.rs b/library/ml/src/main/rust/src/weights_part7.rsindex d078ea08fc..b8d102636d 100644--- a/library/ml/src/main/rust/src/weights_part7.rs+++ b/library/ml/src/main/rust/src/weights_part7.rs@@ -186,8 +186,9 @@ impl Graph {                     res,                     shift,                     quant_scale,+                    staged,                 } => {-                    if res.is_some() || shift.is_some() {+                    if res.is_some() || shift.is_some() || staged.is_some() {                         return Err(format!(                             "emitter: node {i} carries a fused addend; emit before fusion"                         ));