A high-performance inference engine for AI models
Formatting discovery fix (#464)
uuuvn857d7946ec6c
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex b9b3fd3ee..f22f0219b 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -31,6 +31,10 @@ jobs:with:linters: true+ - name: Check backend-uzu rustfmt discovery+ if: ${{ always() && steps.setup.outcome == 'success' }}+ run: RUSTUP_TOOLCHAIN=nightly ./scripts/check-rustfmt-discovery.sh+- name: Check Rust formattingif: ${{ always() && steps.setup.outcome == 'success' }}run: cargo +nightly fmt --checkdiff --git a/crates/backend-uzu/tests/performance/kernel/bench_entry.rs b/crates/backend-uzu/tests/performance/kernel/bench_entry.rsindex d3fd71b67..07d481836 100644--- a/crates/backend-uzu/tests/performance/kernel/bench_entry.rs+++ b/crates/backend-uzu/tests/performance/kernel/bench_entry.rs@@ -19,4 +19,9 @@ fn bench_runner(benches: &[&dyn Fn()]) {use proc_macros::__internal_uzu_bench as uzu_bench;-include!("mod.rs");+#[macro_use]+#[path = "../../common/mod.rs"]+mod common;++#[path = "mod.rs"]+mod kernel;diff --git a/crates/backend-uzu/tests/performance/kernel/matmul/gemm_bench.rs b/crates/backend-uzu/tests/performance/kernel/matmul/gemm_bench.rsindex 797c04223..7ff7b2da4 100644--- a/crates/backend-uzu/tests/performance/kernel/matmul/gemm_bench.rs+++ b/crates/backend-uzu/tests/performance/kernel/matmul/gemm_bench.rs@@ -27,14 +27,13 @@ use crate::{#[uzu_bench]fn bench_gemm(c: &mut Criterion) {let context = MetalContext::new().expect("Metal context");- let mut kernel =- <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(- &context,- bf16::data_type(),- bf16::data_type(),- bf16::data_type(),- )- .expect("MatmulKernel");+ let mut kernel = <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(+ &context,+ bf16::data_type(),+ bf16::data_type(),+ bf16::data_type(),+ )+ .expect("MatmulKernel");let mut group = c.benchmark_group(format!("{}/Kernel/Matmul/GEMM", type_short_name::<Metal>()));diff --git a/crates/backend-uzu/tests/performance/kernel/matmul/quant_gemm_bench.rs b/crates/backend-uzu/tests/performance/kernel/matmul/quant_gemm_bench.rsindex 2a6573cd2..89caacbb3 100644--- a/crates/backend-uzu/tests/performance/kernel/matmul/quant_gemm_bench.rs+++ b/crates/backend-uzu/tests/performance/kernel/matmul/quant_gemm_bench.rs@@ -35,14 +35,13 @@ fn bench_unified_quant_typed<T: ArrayElement + Float>(let (m, k, n) = (shape.m, shape.k, shape.n);let input = QuantInput::<T>::new(m, k, n, group_size, bits, quant_method, 42);let mut buffers = QuantBuffers::<Metal, T>::allocate(context, &input);- let mut matmul =- <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(- context,- T::data_type(),- T::data_type(),- T::data_type(),- )- .unwrap();+ let mut matmul = <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(+ context,+ T::data_type(),+ T::data_type(),+ T::data_type(),+ )+ .unwrap();let mut group =c.benchmark_group(format!("{}/Kernel/UnifiedQuantizedGemm/{}", type_short_name::<Metal>(), label));@@ -51,11 +50,7 @@ fn bench_unified_quant_typed<T: ArrayElement + Float>(iter_encode_loop::<Metal, _>(context, b, |encoder| {matmul.gemm- .encode_dispatch_path(- quant_arguments(&mut buffers, &input),- GemmDispatchPath::Simdgroup,- encoder,- )+ .encode_dispatch_path(quant_arguments(&mut buffers, &input), GemmDispatchPath::Simdgroup, encoder).expect("encode unified quant matmul");});});diff --git a/crates/backend-uzu/tests/performance/kernel/matmul/qwen3_bench.rs b/crates/backend-uzu/tests/performance/kernel/matmul/qwen3_bench.rsindex d6770cb57..3486dbb2c 100644--- a/crates/backend-uzu/tests/performance/kernel/matmul/qwen3_bench.rs+++ b/crates/backend-uzu/tests/performance/kernel/matmul/qwen3_bench.rs@@ -31,20 +31,18 @@ fn bench_qwen3_layers_typed<T: ArrayElement + Float>(bits: u32,quant_method: QuantizationMethod,) {- let mut group =- c.benchmark_group(format!("{}/Kernel/Qwen3Layers/{}", type_short_name::<Metal>(), label));+ let mut group = c.benchmark_group(format!("{}/Kernel/Qwen3Layers/{}", type_short_name::<Metal>(), label));for (layer, shape) in qwen3_layer_shapes(bits) {let (m, k, n) = (shape.m, shape.k, shape.n);let input = QuantInput::<T>::new(m, k, n, group_size, bits, quant_method, 42);let mut buffers = QuantBuffers::<Metal, T>::allocate(context, &input);- let mut matmul =- <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(- context,- T::data_type(),- T::data_type(),- T::data_type(),- )- .unwrap();+ let mut matmul = <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(+ context,+ T::data_type(),+ T::data_type(),+ T::data_type(),+ )+ .unwrap();group.throughput(Throughput::Elements((m * n * k) as u64));group.bench_function(BenchmarkId::from_parameter(format!("{layer}_{shape}")), |b| {diff --git a/crates/backend-uzu/tests/performance/kernel/mod.rs b/crates/backend-uzu/tests/performance/kernel/mod.rsindex 58b255470..104d81618 100644--- a/crates/backend-uzu/tests/performance/kernel/mod.rs+++ b/crates/backend-uzu/tests/performance/kernel/mod.rs@@ -1,7 +1,3 @@-#[macro_use]-#[path = "../../common/mod.rs"]-mod common;-mod matmul;mod rms_norm_bench;mod sampling;diff --git a/crates/backend-uzu/tests/unit/kernel/activation_mul_test.rs b/crates/backend-uzu/tests/unit/kernel/activation_mul_test.rsindex be814eea0..5b5d839e4 100644--- a/crates/backend-uzu/tests/unit/kernel/activation_mul_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/activation_mul_test.rs@@ -1,7 +1,5 @@use std::fmt::{Debug, Display};-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement, DataType,backends::{@@ -9,6 +7,8 @@ use backend_uzu::{cpu::Cpu,},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::{diff --git a/crates/backend-uzu/tests/unit/kernel/activation_test.rs b/crates/backend-uzu/tests/unit/kernel/activation_test.rsindex 2f6c83fde..ea0d8299a 100644--- a/crates/backend-uzu/tests/unit/kernel/activation_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/activation_test.rs@@ -1,7 +1,5 @@use std::fmt::{Debug, Display};-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement, DataType,backends::{@@ -9,6 +7,8 @@ use backend_uzu::{cpu::Cpu,},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::{diff --git a/crates/backend-uzu/tests/unit/kernel/attention/attention_fallback_test.rs b/crates/backend-uzu/tests/unit/kernel/attention/attention_fallback_test.rsindex f71ae2dea..cd14d256a 100644--- a/crates/backend-uzu/tests/unit/kernel/attention/attention_fallback_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/attention/attention_fallback_test.rs@@ -1,4 +1,3 @@-use backend_uzu::{DataType,backends::{@@ -44,10 +43,22 @@ fn make_inputs() -> (Box<[bf16]>, Box<[bf16]>, Box<[bf16]>) {}// Ground truth: fused single-pass attention on the CPU backend.-fn reference(q: &[bf16], k: &[bf16], v: &[bf16], scale: f32) -> Vec<bf16> {+fn reference(+ q: &[bf16],+ k: &[bf16],+ v: &[bf16],+ scale: f32,+) -> Vec<bf16> {let ctx = <Cpu as Backend>::Context::new().unwrap();let kernel = <<Cpu as Backend>::Kernels as Kernels>::AttentionSinglePassKernel::new(- &ctx, DataType::BF16, HEAD_DIM, false, false, true, false, false,+ &ctx,+ DataType::BF16,+ HEAD_DIM,+ false,+ false,+ true,+ false,+ false,).unwrap();let qa = alloc_allocation_with_data::<Cpu, bf16>(&ctx, q);@@ -56,8 +67,24 @@ fn reference(q: &[bf16], k: &[bf16], v: &[bf16], scale: f32) -> Vec<bf16> {let mut out = alloc_allocation::<Cpu, bf16>(&ctx, (NUM_HEADS * SUFFIX * HEAD_DIM) as usize);let mut enc = Encoder::new(ctx.as_ref()).unwrap();kernel.encode(- &qa, &ka, &va, &mut out, GQA, SEQ, SEQ * HEAD_DIM, HEAD_DIM, SEQ * HEAD_DIM, HEAD_DIM, None,- scale, None::<&Allocation<Cpu>>, None, None::<&Allocation<Cpu>>, NUM_HEADS, SUFFIX, &mut enc,+ &qa,+ &ka,+ &va,+ &mut out,+ GQA,+ SEQ,+ SEQ * HEAD_DIM,+ HEAD_DIM,+ SEQ * HEAD_DIM,+ HEAD_DIM,+ None,+ scale,+ None::<&Allocation<Cpu>>,+ None,+ None::<&Allocation<Cpu>>,+ NUM_HEADS,+ SUFFIX,+ &mut enc,);enc.end_encoding().submit().wait_until_completed().unwrap();allocation_to_vec::<Cpu, bf16>(&out)@@ -65,19 +92,32 @@ fn reference(q: &[bf16], k: &[bf16], v: &[bf16], scale: f32) -> Vec<bf16> {// Production fallback pipeline (matmul → scatter → softmax → matmul → scatter)// driven directly via the kernel-cache traits, for backends other than CPU.-fn pipeline_output<B: Backend>(q: &[bf16], k: &[bf16], v: &[bf16], scale: f32) -> Vec<bf16> {+fn pipeline_output<B: Backend>(+ q: &[bf16],+ k: &[bf16],+ v: &[bf16],+ scale: f32,+) -> Vec<bf16> {let ctx = B::Context::new().unwrap();let softmax = <<B as Backend>::Kernels as Kernels>::SoftmaxKernel::new(&ctx, DataType::BF16, false).unwrap();- let scatter_scores =- <<B as Backend>::Kernels as Kernels>::AttentionFallbackScatterScoresKernel::new(- &ctx, DataType::BF16, false, true, false, false,- )- .unwrap();+ let scatter_scores = <<B as Backend>::Kernels as Kernels>::AttentionFallbackScatterScoresKernel::new(+ &ctx,+ DataType::BF16,+ false,+ true,+ false,+ false,+ )+ .unwrap();let scatter_values =<<B as Backend>::Kernels as Kernels>::AttentionFallbackScatterValuesKernel::new(&ctx, DataType::BF16).unwrap();- let mut matmul =- <<B as Backend>::Kernels as ManualKernels>::MatmulKernel::new(&ctx, DataType::BF16, DataType::BF16, DataType::BF16)- .unwrap();+ let mut matmul = <<B as Backend>::Kernels as ManualKernels>::MatmulKernel::new(+ &ctx,+ DataType::BF16,+ DataType::BF16,+ DataType::BF16,+ )+ .unwrap();let qa = alloc_allocation_with_data::<B, bf16>(&ctx, q);let ka = alloc_allocation_with_data::<B, bf16>(&ctx, k);@@ -120,8 +160,17 @@ fn pipeline_output<B: Backend>(q: &[bf16], k: &[bf16], v: &[bf16], scale: f32) -).expect("encode failed");scatter_scores.encode(- &grp_s, &mut scores, None, None::<&Allocation<B>>, None,- g, GQA, SEQ, SUFFIX, GQA * SUFFIX * SEQ, &mut enc,+ &grp_s,+ &mut scores,+ None,+ None::<&Allocation<B>>,+ None,+ g,+ GQA,+ SEQ,+ SUFFIX,+ GQA * SUFFIX * SEQ,+ &mut enc,);}softmax.encode(&mut scores, None::<&Allocation<B>>, SEQ, NUM_HEADS, SUFFIX, &mut enc);@@ -146,10 +195,7 @@ fn pipeline_output<B: Backend>(q: &[bf16], k: &[bf16], v: &[bf16], scale: f32) -&mut enc,).expect("encode failed");- scatter_values.encode(- &grp_o, &mut out, g, GQA, SUFFIX, NUM_HEADS, HEAD_DIM,- GQA * SUFFIX * HEAD_DIM, &mut enc,- );+ scatter_values.encode(&grp_o, &mut out, g, GQA, SUFFIX, NUM_HEADS, HEAD_DIM, GQA * SUFFIX * HEAD_DIM, &mut enc);}enc.end_encoding().submit().wait_until_completed().unwrap();allocation_to_vec::<B, bf16>(&out)diff --git a/crates/backend-uzu/tests/unit/kernel/attention/attention_single_pass_test.rs b/crates/backend-uzu/tests/unit/kernel/attention/attention_single_pass_test.rsindex 951c29f92..0335d21f9 100644--- a/crates/backend-uzu/tests/unit/kernel/attention/attention_single_pass_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/attention/attention_single_pass_test.rs@@ -1,7 +1,5 @@use std::fmt::{Debug, Display};-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement, DataType,backends::{@@ -9,6 +7,8 @@ use backend_uzu::{cpu::Cpu,},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::{diff --git a/crates/backend-uzu/tests/unit/kernel/attention/attention_two_pass_test.rs b/crates/backend-uzu/tests/unit/kernel/attention/attention_two_pass_test.rsindex 2f796c08d..dd259e4d7 100644--- a/crates/backend-uzu/tests/unit/kernel/attention/attention_two_pass_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/attention/attention_two_pass_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -108,15 +106,9 @@ fn get_first_pass_output<T: ArrayElement + Float, B: Backend>(input: &FirstPassIlet sums_size = total_offsets * TOTAL_BLOCKS_COUNT as usize;let maxs_size = total_offsets * TOTAL_BLOCKS_COUNT as usize;- let mut partials = context- .create_array_uninitialized(&[partials_size], DataType::F32)- .into_allocation();- let mut sums = context- .create_array_uninitialized(&[sums_size], DataType::F32)- .into_allocation();- let mut maxs = context- .create_array_uninitialized(&[maxs_size], DataType::F32)- .into_allocation();+ let mut partials = context.create_array_uninitialized(&[partials_size], DataType::F32).into_allocation();+ let mut sums = context.create_array_uninitialized(&[sums_size], DataType::F32).into_allocation();+ let mut maxs = context.create_array_uninitialized(&[maxs_size], DataType::F32).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(@@ -209,9 +201,7 @@ fn get_second_pass_output<T: ArrayElement + Float, B: Backend>(input: &SecondPaslet maxs_array = context.create_array_from(&[input.maxs.len()], &input.maxs);let output_size = (input.suffix_length * input.num_heads * input.head_dim) as usize;- let mut output = context- .create_array_uninitialized(&[output_size], T::data_type())- .into_allocation();+ let mut output = context.create_array_uninitialized(&[output_size], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/attention/attention_update_kv_cache_test.rs b/crates/backend-uzu/tests/unit/kernel/attention/attention_update_kv_cache_test.rsindex d7aaed133..0b7ca09e6 100644--- a/crates/backend-uzu/tests/unit/kernel/attention/attention_update_kv_cache_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/attention/attention_update_kv_cache_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -40,18 +38,12 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,let cache_size = input.num_groups as usize * input.max_sequence_length as usize * input.head_dim as usize;- let rotated_keys = input- .rotated_keys- .as_ref()- .map(|rk| context.create_array_from(&[rk.len()], rk).into_allocation());+ let rotated_keys =+ input.rotated_keys.as_ref().map(|rk| context.create_array_from(&[rk.len()], rk).into_allocation());let qkv_array = context.create_array_from(&[input.qkv.len()], &input.qkv);- let mut key_cache = context- .create_array_from(&[cache_size], &input.key_cache)- .into_allocation();- let mut value_cache = context- .create_array_from(&[cache_size], &input.value_cache)- .into_allocation();+ let mut key_cache = context.create_array_from(&[cache_size], &input.key_cache).into_allocation();+ let mut value_cache = context.create_array_from(&[cache_size], &input.value_cache).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(@@ -69,10 +61,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,);encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&key_cache),- crate::common::helpers::allocation_to_vec(&value_cache),- )+ (crate::common::helpers::allocation_to_vec(&key_cache), crate::common::helpers::allocation_to_vec(&value_cache))}fn get_test_data_basic<T: ArrayElement + Float>(keys_in_place: bool) -> Input<T> {diff --git a/crates/backend-uzu/tests/unit/kernel/attention/sigmoid_gate_test.rs b/crates/backend-uzu/tests/unit/kernel/attention/sigmoid_gate_test.rsindex c0c9e50e3..48cef79d3 100644--- a/crates/backend-uzu/tests/unit/kernel/attention/sigmoid_gate_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/attention/sigmoid_gate_test.rs@@ -29,18 +29,11 @@ fn get_output<T: ArrayElement + Float, B: Backend>(.expect("Failed to create SigmoidGateKernel");let gate_array = context.create_array_from(&[size], &gate_data.to_vec().into_boxed_slice());- let mut output = context- .create_array_from(&[size], &output_data.to_vec().into_boxed_slice())- .into_allocation();+ let mut output = context.create_array_from(&[size], &output_data.to_vec().into_boxed_slice()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");let total_elements = config.suffix_length * config.num_heads * config.head_dim;- kernel.encode(- gate_array.allocation(),- &mut output,- total_elements,- &mut encoder,- );+ kernel.encode(gate_array.allocation(), &mut output, total_elements, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();crate::common::helpers::allocation_to_vec(&output)diff --git a/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rs b/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rsindex 66835a6bc..fe7fc1008 100644--- a/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rs@@ -16,15 +16,17 @@ use backend_uzu::{},};-use super::super::common::audio::{- fsq_reference::{fsq_decode_reference, fsq_encode_reference},- ops_reference::{- CausalConv1dSpec, CausalConvTranspose1dSpec, Conv1dSpec, HalfSnakeSpec, PadMode,- causal_conv_transpose1d_causal_pad_reference, causal_conv_transpose1d_reference, causal_conv1d_reference,- conv1d_reference, half_snake_reference,+use crate::{+ common::audio::{+ fsq_reference::{fsq_decode_reference, fsq_encode_reference},+ ops_reference::{+ CausalConv1dSpec, CausalConvTranspose1dSpec, Conv1dSpec, HalfSnakeSpec, PadMode,+ causal_conv_transpose1d_causal_pad_reference, causal_conv_transpose1d_reference, causal_conv1d_reference,+ conv1d_reference, half_snake_reference,+ },},+ uzu_test,};-use crate::uzu_test;macro_rules! borrow_array_buffer {($name:ident = $array:expr) => {@@ -91,8 +93,7 @@ fn audio_conv1d_replicate_matches_reference_f32() {let mut lengths = context.create_array_zeros(&[batch_size], DataType::I32);lengths.as_slice_mut::<i32>().copy_from_slice(&lengths_out);- let mut output =- context.create_array_zeros(&[batch_size, cout, seq_len_out], DataType::F32).into_allocation();+ let mut output = context.create_array_zeros(&[batch_size, cout, seq_len_out], DataType::F32).into_allocation();let expected = conv1d_reference(Conv1dSpec {input: &input_values,weight: &weight_values,@@ -185,9 +186,7 @@ fn audio_causal_conv1d_matches_reference_f32() {let mut lengths_array = context.create_array_zeros(&[batch_size], DataType::I32);lengths_array.as_slice_mut::<i32>().copy_from_slice(&lengths);- let mut output = context- .create_array_zeros(&[batch_size, cout, seq_len], DataType::F32)- .into_allocation();+ let mut output = context.create_array_zeros(&[batch_size, cout, seq_len], DataType::F32).into_allocation();let expected = causal_conv1d_reference(CausalConv1dSpec {input: &input_values,weight: &weight_values,@@ -264,13 +263,10 @@ fn audio_causal_conv_transpose1d_matches_reference_f32() {let weight_values: Vec<f32> = (0..weight_len).map(|i| ((i as f32) * 0.07).cos() * 0.2).collect();let bias_values: Vec<f32> = vec![0.01, -0.02];- let mut input =- context.create_array_zeros(&[batch_size, cin, seq_len_in], DataType::F32);+ let mut input = context.create_array_zeros(&[batch_size, cin, seq_len_in], DataType::F32);input.as_slice_mut::<f32>().copy_from_slice(&input_values);- let mut weight = context.create_array_zeros(- &[cout, cin / groups, kernel_size],- DataType::F32);+ let mut weight = context.create_array_zeros(&[cout, cin / groups, kernel_size], DataType::F32);weight.as_slice_mut::<f32>().copy_from_slice(&weight_values);let mut bias = context.create_array_zeros(&[cout], DataType::F32);@@ -279,11 +275,7 @@ fn audio_causal_conv_transpose1d_matches_reference_f32() {let mut lengths = context.create_array_zeros(&[batch_size], DataType::I32);lengths.as_slice_mut::<i32>().copy_from_slice(&lengths_out);- let mut output = context- .create_array_zeros(- &[batch_size, cout, seq_len_out],- DataType::F32)- .into_allocation();+ let mut output = context.create_array_zeros(&[batch_size, cout, seq_len_out], DataType::F32).into_allocation();let expected = causal_conv_transpose1d_reference(CausalConvTranspose1dSpec {input: &input_values,weight: &weight_values,@@ -391,27 +383,19 @@ fn audio_causal_conv_transpose1d_causal_pad_matches_reference_f32() {("NCS", 0_i32, [batch_size, cin, seq_len_in], input_values_ncs.as_slice()),("NSC", 1_i32, [batch_size, seq_len_in, cin], input_values_nsc.as_slice()),] {- let mut input =- context.create_array_zeros(&input_shape, DataType::F32);+ let mut input = context.create_array_zeros(&input_shape, DataType::F32);input.as_slice_mut::<f32>().copy_from_slice(input_values);- let mut weight = context.create_array_zeros(- &[cout, cin / groups, kernel_size],- DataType::F32);+ let mut weight = context.create_array_zeros(&[cout, cin / groups, kernel_size], DataType::F32);weight.as_slice_mut::<f32>().copy_from_slice(&weight_values);let mut bias = context.create_array_zeros(&[cout], DataType::F32);bias.as_slice_mut::<f32>().copy_from_slice(&bias_values);- let mut lengths =- context.create_array_zeros(&[batch_size], DataType::I32);+ let mut lengths = context.create_array_zeros(&[batch_size], DataType::I32);lengths.as_slice_mut::<i32>().copy_from_slice(&lengths_out);- let mut output = context- .create_array_zeros(- &[batch_size, cout, seq_len_out],- DataType::F32)- .into_allocation();+ let mut output = context.create_array_zeros(&[batch_size, cout, seq_len_out], DataType::F32).into_allocation();run_command_buffer(&context, |command_buffer| {borrow_array_buffer!(input_buffer = input);@@ -472,18 +456,7 @@ fn audio_leaky_relu_matches_reference_f32() {borrow_array_buffer!(input_buffer = input);borrow_array_buffer!(alpha_buffer = alpha);borrow_array_buffer_mut!(output_buffer = output);- kernel.encode(- input_buffer,- alpha_buffer,- output_buffer,- 1,- n as i32,- 0,- slope,- eps,- 1,- command_buffer,- );+ kernel.encode(input_buffer, alpha_buffer, output_buffer, 1, n as i32, 0, slope, eps, 1, command_buffer);});let got = allocation_to_vec::<Metal, f32>(&output);@@ -583,16 +556,13 @@ fn audio_half_snake_matches_reference_f32() {let input_values: Vec<f32> = (0..n).map(|i| (i as f32 * 0.01 - 3.2).sin()).collect();let alpha_values: Vec<f32> = (0..snake_channels).map(|i| 0.5 + i as f32 * 0.1).collect();- let mut input =- context.create_array_zeros(&[batch_size, channels, seq_len], DataType::F32);+ let mut input = context.create_array_zeros(&[batch_size, channels, seq_len], DataType::F32);input.as_slice_mut::<f32>().copy_from_slice(&input_values);let mut alpha = context.create_array_zeros(&[snake_channels], DataType::F32);alpha.as_slice_mut::<f32>().copy_from_slice(&alpha_values);- let mut output = context- .create_array_zeros(&[batch_size, channels, seq_len], DataType::F32)- .into_allocation();+ let mut output = context.create_array_zeros(&[batch_size, channels, seq_len], DataType::F32).into_allocation();run_command_buffer(&context, |command_buffer| {borrow_array_buffer!(input_buffer = input);@@ -703,9 +673,7 @@ fn audio_norm_ncs_matches_reference_f32() {let mut lengths = context.create_array_zeros(&[batch_size], DataType::I32);lengths.as_slice_mut::<i32>().copy_from_slice(&lengths_values);- let mut output = context- .create_array_zeros(&[batch_size, channels, seq_len], DataType::F32)- .into_allocation();+ let mut output = context.create_array_zeros(&[batch_size, channels, seq_len], DataType::F32).into_allocation();run_command_buffer(&context, |command_buffer| {borrow_array_buffer!(input_buffer = input);@@ -768,11 +736,8 @@ fn audio_fsq_decode_matches_reference() {let mut lengths = context.create_array_zeros(&[batch_size], DataType::I32);lengths.as_slice_mut::<i32>().copy_from_slice(&[2]);- let mut output = context- .create_array_zeros(- &[batch_size, num_groups * codebook_dim, seq_len],- DataType::F32)- .into_allocation();+ let mut output =+ context.create_array_zeros(&[batch_size, num_groups * codebook_dim, seq_len], DataType::F32).into_allocation();run_command_buffer(&context, |command_buffer| {borrow_array_buffer!(tokens_buffer = tokens);@@ -825,17 +790,13 @@ fn audio_fsq_encode_matches_reference() {];let lengths_values = vec![3_i32];- let mut input = context.create_array_zeros(- &[batch_size, num_groups * codebook_dim, seq_len],- DataType::F32);+ let mut input = context.create_array_zeros(&[batch_size, num_groups * codebook_dim, seq_len], DataType::F32);input.as_slice_mut::<f32>().copy_from_slice(&input_values);let mut lengths = context.create_array_zeros(&[batch_size], DataType::I32);lengths.as_slice_mut::<i32>().copy_from_slice(&lengths_values);- let mut tokens = context- .create_array_zeros(&[batch_size, num_groups, seq_len], DataType::I32)- .into_allocation();+ let mut tokens = context.create_array_zeros(&[batch_size, num_groups, seq_len], DataType::I32).into_allocation();run_command_buffer(&context, |command_buffer| {borrow_array_buffer!(input_buffer = input);diff --git a/crates/backend-uzu/tests/unit/kernel/delta_net_test.rs b/crates/backend-uzu/tests/unit/kernel/delta_net_test.rsindex 78b32d9e2..7f7e6115d 100644--- a/crates/backend-uzu/tests/unit/kernel/delta_net_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/delta_net_test.rs@@ -181,8 +181,7 @@ fn test_delta_net_conv_scan() {let padded_len = (tap_count + suffix_len) * total_proj_dim;let mut padded_array = context.create_array_zeros(&[padded_len], DataType::F32).into_allocation();- let mut state_out_array =- context.create_array_zeros(&[conv_dim * tap_count], DataType::F32).into_allocation();+ let mut state_out_array = context.create_array_zeros(&[conv_dim * tap_count], DataType::F32).into_allocation();let pack_kernel =<<Metal as Backend>::Kernels as Kernels>::Conv1dPackKernel::new(&context, DataType::F32).expect("pack");@@ -313,15 +312,11 @@ fn run_prefill_with_norm_gate(let norm_weight_array = context.create_array_from(&[norm_weight.len()], norm_weight);let mut state_array = context.create_array_from(&[state.len()], state).into_allocation();let mut out_array = context.create_array_zeros(&[suffix_len * value_dim], DataType::F32).into_allocation();- let mut q_norm_array =- context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();- let mut k_norm_array =- context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();+ let mut q_norm_array = context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();+ let mut k_norm_array = context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();- let mut beta_array =- context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();- let mut decay_array =- context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut beta_array = context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut decay_array = context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();let prep_k = <<Metal as Backend>::Kernels as Kernels>::DeltaNetPrefillPrepKernel::new(&context,@@ -386,10 +381,7 @@ fn run_prefill_with_norm_gate();encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&out_array),- crate::common::helpers::allocation_to_vec(&state_array),- )+ (crate::common::helpers::allocation_to_vec(&out_array), crate::common::helpers::allocation_to_vec(&state_array))}fn test_prefill_norm_gate_impl(@@ -480,10 +472,8 @@ fn test_delta_net_prefill_prep() {let cpu_dt_bias = cpu_ctx.create_array_from(&[dt_bias.len()], &dt_bias);let mut cpu_q = cpu_ctx.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();let mut cpu_k = cpu_ctx.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();- let mut cpu_beta =- cpu_ctx.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();- let mut cpu_decay =- cpu_ctx.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut cpu_beta = cpu_ctx.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut cpu_decay = cpu_ctx.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();let cpu_prep = <<Cpu as Backend>::Kernels as Kernels>::DeltaNetPrefillPrepKernel::new(&cpu_ctx,@@ -519,15 +509,11 @@ fn test_delta_net_prefill_prep() {let in_proj_array = context.create_array_from(&[in_proj.len()], &in_proj);let a_log_array = context.create_array_from(&[a_log.len()], &a_log);let dt_bias_array = context.create_array_from(&[dt_bias.len()], &dt_bias);- let mut q_norm_array =- context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();- let mut k_norm_array =- context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();+ let mut q_norm_array = context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();+ let mut k_norm_array = context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();- let mut beta_array =- context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();- let mut decay_array =- context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut beta_array = context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut decay_array = context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();let prep_k = <<Metal as Backend>::Kernels as Kernels>::DeltaNetPrefillPrepKernel::new(&context,@@ -593,15 +579,11 @@ fn bench_delta_net_prefill() {let dt_bias_array = context.create_array_from(&[dt_bias.len()], &dt_bias);let norm_weight_array = context.create_array_from(&[norm_weight.len()], &norm_weight);let mut out_array = context.create_array_zeros(&[suffix_len * value_dim], DataType::F32).into_allocation();- let mut q_norm_array =- context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();- let mut k_norm_array =- context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();-- let mut beta_array =- context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();- let mut decay_array =- context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut q_norm_array = context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();+ let mut k_norm_array = context.create_array_zeros(&[suffix_len * key_dim], DataType::F32).into_allocation();++ let mut beta_array = context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();+ let mut decay_array = context.create_array_zeros(&[suffix_len * num_v_heads], DataType::F32).into_allocation();let num_dv_groups = (head_v_dim as u32 + 7) / 8;diff --git a/crates/backend-uzu/tests/unit/kernel/embedding/embedding_rows_sum_test.rs b/crates/backend-uzu/tests/unit/kernel/embedding/embedding_rows_sum_test.rsindex 89342d224..e8df16804 100644--- a/crates/backend-uzu/tests/unit/kernel/embedding/embedding_rows_sum_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/embedding/embedding_rows_sum_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -107,9 +105,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {let token_indices_array = context.create_array_from(&[input.num_rows as usize], &input.token_indices);let weights_array =context.create_array_from(&[input.total_rows as usize, input.model_dim as usize], &input.weights);- let mut output = context- .create_array_uninitialized(&[input.model_dim as usize], T::data_type())- .into_allocation();+ let mut output = context.create_array_uninitialized(&[input.model_dim as usize], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/embedding/full_precision_embedding_test.rs b/crates/backend-uzu/tests/unit/kernel/embedding/full_precision_embedding_test.rsindex 23012072c..f1c6c4fda 100644--- a/crates/backend-uzu/tests/unit/kernel/embedding/full_precision_embedding_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/embedding/full_precision_embedding_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::Debug,-};+use std::fmt::Debug;use backend_uzu::{ArrayContextExt, ArrayElement,@@ -58,9 +56,8 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {let token_ids_array = context.create_array_from(&[input.batch_size], &input.token_ids);let weights_array = context.create_array_from(&[input.vocab_size, input.model_dim], &input.weights);- let mut output = context- .create_array_uninitialized(&[input.batch_size, input.model_dim], T::data_type())- .into_allocation();+ let mut output =+ context.create_array_uninitialized(&[input.batch_size, input.model_dim], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to get encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/hadamard_transform_test.rs b/crates/backend-uzu/tests/unit/kernel/hadamard_transform_test.rsindex e4a455737..fe0dd2d0a 100644--- a/crates/backend-uzu/tests/unit/kernel/hadamard_transform_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/hadamard_transform_test.rs@@ -1,13 +1,9 @@-use std::{- fmt::Debug,-};+use std::fmt::Debug;use backend_uzu::{ArrayContextExt, ArrayElement,backends::common::{- Backend, Context, Encoder, Kernels,- gpu_types::HadamardTransformOrder,- kernel::HadamardTransformKernel,+ Backend, Context, Encoder, Kernels, gpu_types::HadamardTransformOrder, kernel::HadamardTransformKernel,},};use half::{bf16, f16};@@ -112,9 +108,7 @@ fn run_kernel<T: ArrayElement + Float, B: Backend>(input: &TestInput<T>) -> Vec<.expect("Failed to create HadamardTransformKernel");let total_elements = input.batch_count * input.channel_count;- let mut data = context- .create_array_from(&[total_elements], &input.data)- .into_allocation();+ let mut data = context.create_array_from(&[total_elements], &input.data).into_allocation();let factors_array = context.create_array_from::<i32>(&[input.channel_count], &input.factors);let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");diff --git a/crates/backend-uzu/tests/unit/kernel/kv_cache_update_test.rs b/crates/backend-uzu/tests/unit/kernel/kv_cache_update_test.rsindex f0c644f01..515282736 100644--- a/crates/backend-uzu/tests/unit/kernel/kv_cache_update_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/kv_cache_update_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement,@@ -59,10 +57,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,);encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&keys),- crate::common::helpers::allocation_to_vec(&values),- )+ (crate::common::helpers::allocation_to_vec(&keys), crate::common::helpers::allocation_to_vec(&values))}/// Single swap between two different positions.diff --git a/crates/backend-uzu/tests/unit/kernel/layer_norm_test.rs b/crates/backend-uzu/tests/unit/kernel/layer_norm_test.rsindex d19549361..908008427 100644--- a/crates/backend-uzu/tests/unit/kernel/layer_norm_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/layer_norm_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -127,14 +125,13 @@ fn get_output<.expect("Failed to create LayerNormKernel");let input_size = input.input.len();- let input_buffer = (!input.in_place).then(|| context.create_array_from(&[input_size], &input.input).into_allocation());+ let input_buffer =+ (!input.in_place).then(|| context.create_array_from(&[input_size], &input.input).into_allocation());let scales_array = context.create_array_from(&[input.scales.len()], &input.scales);let mut output = match input.in_place {true => context.create_array_from(&[input_size], &input.output).into_allocation(),- false => context- .create_array_uninitialized(&[input_size], OUT::data_type())- .into_allocation(),+ false => context.create_array_uninitialized(&[input_size], OUT::data_type()).into_allocation(),};let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");diff --git a/crates/backend-uzu/tests/unit/kernel/matmul/dispatch_paths_test.rs b/crates/backend-uzu/tests/unit/kernel/matmul/dispatch_paths_test.rsindex e42e22718..2222bc0dd 100644--- a/crates/backend-uzu/tests/unit/kernel/matmul/dispatch_paths_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/matmul/dispatch_paths_test.rs@@ -5,7 +5,10 @@ use std::fmt::{Debug, Display};use backend_uzu::{ArrayElement,backends::{- common::{Backend, Context, kernel::ManualKernels, kernel::matmul::MatmulKernel},+ common::{+ Backend, Context,+ kernel::{ManualKernels, matmul::MatmulKernel},+ },metal::{DeviceExt, GemmDispatchPath, Metal, MetalContext},},};@@ -36,12 +39,7 @@ fn check_case<T: ArrayElement + Float + Debug + Display>(let input = deterministic_input::<T>(case);let expected = cpu_reference::<T>(&input);let actual = run_metal::<T>(context, kernel, &input, path);- assert_eq_float(- &expected,- &actual,- tolerance,- &format!("{path:?} dtype={} {case:?}", std::any::type_name::<T>()),- );+ assert_eq_float(&expected, &actual, tolerance, &format!("{path:?} dtype={} {case:?}", std::any::type_name::<T>()));}fn run_matrix<T: ArrayElement + Float + Debug + Display>(@@ -55,7 +53,7 @@ fn run_matrix<T: ArrayElement + Float + Debug + Display>(T::data_type(),T::data_type(),)- .expect("MatmulKernel");+ .expect("MatmulKernel");for path in gemm_paths_for_hw(&context) {for shape in all_correctness_shapes() {let case = case_for_shape(shape);@@ -73,10 +71,7 @@ fn matches_cpu_reference_bf16(#[case] ab_scale: f32,#[case] accumulate: bool,) {- run_matrix::<bf16>(- |shape| Case::new(shape).with_ab_scale(ab_scale).with_accumulate(accumulate),- 1.0,- );+ run_matrix::<bf16>(|shape| Case::new(shape).with_ab_scale(ab_scale).with_accumulate(accumulate), 1.0);}#[test]diff --git a/crates/backend-uzu/tests/unit/kernel/matmul/gemv_test.rs b/crates/backend-uzu/tests/unit/kernel/matmul/gemv_test.rsindex 0a0a962fd..da18eee56 100644--- a/crates/backend-uzu/tests/unit/kernel/matmul/gemv_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/matmul/gemv_test.rs@@ -63,13 +63,9 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {.create_allocation(input.m * input.n * std::mem::size_of::<T>(), AllocationType::Global).expect("Failed to create allocation");- let mut kernel = <B::Kernels as ManualKernels>::MatmulKernel::new(- &context,- T::data_type(),- T::data_type(),- T::data_type(),- )- .expect("Failed to create MatmulKernel");+ let mut kernel =+ <B::Kernels as ManualKernels>::MatmulKernel::new(&context, T::data_type(), T::data_type(), T::data_type())+ .expect("Failed to create MatmulKernel");let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kerneldiff --git a/crates/backend-uzu/tests/unit/kernel/matmul/quant_dispatch_test.rs b/crates/backend-uzu/tests/unit/kernel/matmul/quant_dispatch_test.rsindex 47fdc23df..63fafc949 100644--- a/crates/backend-uzu/tests/unit/kernel/matmul/quant_dispatch_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/matmul/quant_dispatch_test.rs@@ -90,19 +90,19 @@ fn run_parity<T: ArrayElement + Float + Debug + Display>(}#[rstest]-#[case::gs16_4bit_zp_prefill ( 64, 256, 64, 16, 4, QuantizationMethod::ScaleZeroPoint)]-#[case::gs32_4bit_mlx_prefill ( 64, 256, 64, 32, 4, QuantizationMethod::ScaleBias)]-#[case::gs64_4bit_mlx_prefill ( 64, 256, 64, 64, 4, QuantizationMethod::ScaleBias)]-#[case::gs128_4bit_mlx_prefill( 64, 256, 64, 128, 4, QuantizationMethod::ScaleBias)]-#[case::gs32_8bit_mlx_prefill ( 64, 256, 64, 32, 8, QuantizationMethod::ScaleBias)]-#[case::gs64_8bit_zp_prefill ( 64, 256, 64, 64, 8, QuantizationMethod::ScaleZeroPoint)]-#[case::gs128_8bit_zp_prefill ( 64, 256, 64, 128, 8, QuantizationMethod::ScaleZeroPoint)]+#[case::gs16_4bit_zp_prefill(64, 256, 64, 16, 4, QuantizationMethod::ScaleZeroPoint)]+#[case::gs32_4bit_mlx_prefill(64, 256, 64, 32, 4, QuantizationMethod::ScaleBias)]+#[case::gs64_4bit_mlx_prefill(64, 256, 64, 64, 4, QuantizationMethod::ScaleBias)]+#[case::gs128_4bit_mlx_prefill(64, 256, 64, 128, 4, QuantizationMethod::ScaleBias)]+#[case::gs32_8bit_mlx_prefill(64, 256, 64, 32, 8, QuantizationMethod::ScaleBias)]+#[case::gs64_8bit_zp_prefill(64, 256, 64, 64, 8, QuantizationMethod::ScaleZeroPoint)]+#[case::gs128_8bit_zp_prefill(64, 256, 64, 128, 8, QuantizationMethod::ScaleZeroPoint)]#[case::gs32_4bit_symmetric_prefill(64, 256, 64, 32, 4, QuantizationMethod::ScaleSymmetric)]#[case::gs64_8bit_symmetric_prefill(64, 256, 64, 64, 8, QuantizationMethod::ScaleSymmetric)]-#[case::gs32_4bit_mlx_decode ( 8, 256, 64, 32, 4, QuantizationMethod::ScaleBias)]-#[case::gs16_4bit_zp_decode ( 8, 256, 64, 16, 4, QuantizationMethod::ScaleZeroPoint)]-#[case::gs64_4bit_zp_decode ( 8, 256, 64, 64, 4, QuantizationMethod::ScaleZeroPoint)]-#[case::gs32_unaligned_n ( 64, 256, 96, 32, 4, QuantizationMethod::ScaleBias)]+#[case::gs32_4bit_mlx_decode(8, 256, 64, 32, 4, QuantizationMethod::ScaleBias)]+#[case::gs16_4bit_zp_decode(8, 256, 64, 16, 4, QuantizationMethod::ScaleZeroPoint)]+#[case::gs64_4bit_zp_decode(8, 256, 64, 64, 4, QuantizationMethod::ScaleZeroPoint)]+#[case::gs32_unaligned_n(64, 256, 96, 32, 4, QuantizationMethod::ScaleBias)]fn parity_bf16(#[case] m: usize,#[case] k: usize,@@ -123,15 +123,14 @@ fn parity_bf16_gs32_4bit_mlx_with_bias() {let bias_t: Vec<bf16> = bias_f32.iter().map(|&v| bf16::from_f32(v)).collect();let mut buffers = QuantBuffers::<Metal, bf16>::allocate(&context, &input);- let bias_pp_buf =- crate::common::helpers::alloc_allocation_with_data::<Metal, bf16>(&context, &bias_t);+ let bias_pp_buf = crate::common::helpers::alloc_allocation_with_data::<Metal, bf16>(&context, &bias_t);let mut matmul = <<Metal as Backend>::Kernels as ManualKernels>::MatmulKernel::new(&context,bf16::data_type(),bf16::data_type(),bf16::data_type(),)- .expect("MatmulMetalKernel");+ .expect("MatmulMetalKernel");let mut encoder = Encoder::<Metal>::new(&context).expect("encoder");let mut args = quant_arguments(&mut buffers, &input);@@ -141,10 +140,7 @@ fn parity_bf16_gs32_4bit_mlx_with_bias() {bias: Some(&bias_pp_buf),rht_factors: None,};- matmul- .gemm- .encode_dispatch_path(args, GemmDispatchPath::Simdgroup, &mut encoder)- .expect("encode quant with bias");+ matmul.gemm.encode_dispatch_path(args, GemmDispatchPath::Simdgroup, &mut encoder).expect("encode quant with bias");encoder.end_encoding().submit().wait_until_completed().unwrap();let actual = allocation_to_vec::<Metal, bf16>(&buffers.y);@@ -169,7 +165,7 @@ fn quant_gemm_nonzero_b_offset_returns_unsupported_layout() {bf16::data_type(),bf16::data_type(),)- .expect("MatmulMetalKernel");+ .expect("MatmulMetalKernel");let mut encoder = Encoder::<Metal>::new(&context).expect("encoder");let mut args = quant_arguments(&mut buffers, &input);@@ -182,7 +178,12 @@ fn quant_gemm_nonzero_b_offset_returns_unsupported_layout() {.and_then(|s| s.downcast_ref::<MatmulError<Metal>>()).expect("expected MatmulError source");assert!(- matches!(matmul, MatmulError::UnsupportedLayout { path: "QuantGemm" }),+ matches!(+ matmul,+ MatmulError::UnsupportedLayout {+ path: "QuantGemm"+ }+ ),"got {matmul:?}");}@@ -198,7 +199,7 @@ fn quant_gemm_accumulate_returns_unsupported_dop() {bf16::data_type(),bf16::data_type(),)- .expect("MatmulMetalKernel");+ .expect("MatmulMetalKernel");let mut encoder = Encoder::<Metal>::new(&context).expect("encoder");let mut args = quant_arguments(&mut buffers, &input);diff --git a/crates/backend-uzu/tests/unit/kernel/mod.rs b/crates/backend-uzu/tests/unit/kernel/mod.rsindex 4844ae5a7..0135b5223 100644--- a/crates/backend-uzu/tests/unit/kernel/mod.rs+++ b/crates/backend-uzu/tests/unit/kernel/mod.rs@@ -1,7 +1,3 @@-#[macro_use]-#[path = "../../common/mod.rs"]-mod common;-mod activation_mul_test;mod activation_test;mod attention;@@ -15,8 +11,8 @@ mod matmul;mod moe;mod pooling;mod qk_unpack_test;-mod quant_matmul;mod qkv_norm_test;+mod quant_matmul;mod rms_norm_test;mod rope_test;mod sampling;diff --git a/crates/backend-uzu/tests/unit/kernel/moe/moe_counts_offsets_fused_test.rs b/crates/backend-uzu/tests/unit/kernel/moe/moe_counts_offsets_fused_test.rsindex 3413c8151..4a5f496df 100644--- a/crates/backend-uzu/tests/unit/kernel/moe/moe_counts_offsets_fused_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/moe/moe_counts_offsets_fused_test.rs@@ -1,4 +1,3 @@-use rand::{RngExt, SeedableRng, rngs::StdRng};use backend_uzu::{ArrayContextExt, ArrayElement,backends::{@@ -6,6 +5,7 @@ use backend_uzu::{cpu::Cpu,},};+use rand::{RngExt, SeedableRng, rngs::StdRng};use crate::uzu_test;@@ -45,8 +45,7 @@ fn get_output<B: Backend>(let mut offsets = context.create_array_uninitialized(&[e + 1], u32::data_type()).into_allocation();let mut sum_k = context.create_array_uninitialized(&[1], u32::data_type()).into_allocation();let num_tiles = e.div_ceil(512).max(1);- let mut partials =- context.create_array_uninitialized(&[num_tiles * 512], u32::data_type()).into_allocation();+ let mut partials = context.create_array_uninitialized(&[num_tiles * 512], u32::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/moe/moe_finalize_test.rs b/crates/backend-uzu/tests/unit/kernel/moe/moe_finalize_test.rsindex e7afacf71..62c601ee7 100644--- a/crates/backend-uzu/tests/unit/kernel/moe/moe_finalize_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/moe/moe_finalize_test.rs@@ -1,6 +1,3 @@-use half::bf16;-use num_traits::Float;-use rand::{RngExt, SeedableRng, rngs::StdRng};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,backends::{@@ -8,6 +5,9 @@ use backend_uzu::{cpu::Cpu,},};+use half::bf16;+use num_traits::Float;+use rand::{RngExt, SeedableRng, rngs::StdRng};use crate::{common::{assert::assert_eq_float, helpers::create_context},diff --git a/crates/backend-uzu/tests/unit/kernel/moe/moe_gather_test.rs b/crates/backend-uzu/tests/unit/kernel/moe/moe_gather_test.rsindex f3cd8f653..46ecd3448 100644--- a/crates/backend-uzu/tests/unit/kernel/moe/moe_gather_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/moe/moe_gather_test.rs@@ -1,10 +1,7 @@use backend_uzu::{ArrayElement,backends::{- common::{- Backend, Encoder,- kernel::moe::MoeGatherKernel,- },+ common::{Backend, Encoder, kernel::moe::MoeGatherKernel},cpu::Cpu,},};diff --git a/crates/backend-uzu/tests/unit/kernel/moe/moe_router_topk_test.rs b/crates/backend-uzu/tests/unit/kernel/moe/moe_router_topk_test.rsindex 669f465ad..68cca23fd 100644--- a/crates/backend-uzu/tests/unit/kernel/moe/moe_router_topk_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/moe/moe_router_topk_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::Debug,-};+use std::fmt::Debug;use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -50,10 +48,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>();encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&ids),- crate::common::helpers::allocation_to_vec(&probs),- )+ (crate::common::helpers::allocation_to_vec(&ids), crate::common::helpers::allocation_to_vec(&probs))}fn run_router_topk_once<B: Backend, T: ArrayElement + Debug + Float>(diff --git a/crates/backend-uzu/tests/unit/kernel/moe/moe_scatter_test.rs b/crates/backend-uzu/tests/unit/kernel/moe/moe_scatter_test.rsindex 7cd64b7b3..483328896 100644--- a/crates/backend-uzu/tests/unit/kernel/moe/moe_scatter_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/moe/moe_scatter_test.rs@@ -1,6 +1,3 @@-use half::bf16;-use num_traits::Float;-use rand::{RngExt, SeedableRng, rngs::StdRng};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,backends::{@@ -14,6 +11,9 @@ use backend_uzu::{cpu::Cpu,},};+use half::bf16;+use num_traits::Float;+use rand::{RngExt, SeedableRng, rngs::StdRng};use crate::{common::helpers::create_context, uzu_test};@@ -105,8 +105,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>(let ctx = create_context::<B>();// top-k- let (topk_ids, topk_probs) =- get_output_topk::<B, T>(ctx.as_ref(), input, weights, bias, t, d_model, e, k);+ let (topk_ids, topk_probs) = get_output_topk::<B, T>(ctx.as_ref(), input, weights, bias, t, d_model, e, k);// fusedlet mut offsets = ctx.create_array_uninitialized(&[e + 1], DataType::U32).into_allocation();@@ -116,16 +115,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>(let fused_kernel =<<B as Backend>::Kernels as Kernels>::MoeCountsOffsetsFusedKernel::new(&ctx).expect("fused kernel");let mut encoder = Encoder::new(ctx.as_ref()).expect("Failed to create encoder");- fused_kernel.encode(- &topk_ids,- &mut offsets,- &mut sumk,- &mut partials,- t as u32,- e as u32,- k as u32,- &mut encoder,- );+ fused_kernel.encode(&topk_ids, &mut offsets, &mut sumk, &mut partials, t as u32, e as u32, k as u32, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();// scatter basesdiff --git a/crates/backend-uzu/tests/unit/kernel/pooling/pooling_cls_test.rs b/crates/backend-uzu/tests/unit/kernel/pooling/pooling_cls_test.rsindex 052f29639..c6ca341bb 100644--- a/crates/backend-uzu/tests/unit/kernel/pooling/pooling_cls_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/pooling/pooling_cls_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -50,9 +48,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {let output_len = (input.batch_size * input.hidden_dim) as usize;let input_array = context.create_array_from(&[input_len], &input.input);- let mut output = context- .create_array_uninitialized(&[output_len], T::data_type())- .into_allocation();+ let mut output = context.create_array_uninitialized(&[output_len], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/pooling/pooling_mean_test.rs b/crates/backend-uzu/tests/unit/kernel/pooling/pooling_mean_test.rsindex bb93185a0..ed592a6e2 100644--- a/crates/backend-uzu/tests/unit/kernel/pooling/pooling_mean_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/pooling/pooling_mean_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -50,9 +48,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {let output_len = (input.batch_size * input.hidden_dim) as usize;let input_array = context.create_array_from(&[input_len], &input.input);- let mut output = context- .create_array_uninitialized(&[output_len], T::data_type())- .into_allocation();+ let mut output = context.create_array_uninitialized(&[output_len], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/rms_norm_test.rs b/crates/backend-uzu/tests/unit/kernel/rms_norm_test.rsindex 816d88b50..b70a37547 100644--- a/crates/backend-uzu/tests/unit/kernel/rms_norm_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/rms_norm_test.rs@@ -6,7 +6,7 @@ use std::{use backend_uzu::{ArrayContextExt, ArrayElement, DataType,backends::{- common::{Allocation, Context, Encoder, Kernels, kernel::RMSNormKernel, Backend},+ common::{Allocation, Backend, Context, Encoder, Kernels, kernel::RMSNormKernel},cpu::Cpu,},};@@ -139,14 +139,13 @@ fn get_output<.expect("Failed to create RMSNormKernel");let input_size = input.input.len();- let input_buffer = (!input.in_place).then(|| context.create_array_from(&[input_size], &input.input).into_allocation());+ let input_buffer =+ (!input.in_place).then(|| context.create_array_from(&[input_size], &input.input).into_allocation());let scales_array = context.create_array_from(&[input.scales.len()], &input.scales);let mut output = match input.in_place {true => context.create_array_from(&[input_size], &input.output).into_allocation(),- false => context- .create_array_uninitialized(&[input_size], OutputT::data_type())- .into_allocation(),+ false => context.create_array_uninitialized(&[input_size], OutputT::data_type()).into_allocation(),};let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");@@ -169,11 +168,7 @@ fn get_output<let host_elapsed_ms = instant.elapsed().as_secs_f64() * 1e3;let gpu_elapsed_ms = completed.gpu_execution_time();- (- crate::common::helpers::allocation_to_vec(&output),- host_elapsed_ms,- gpu_elapsed_ms,- )+ (crate::common::helpers::allocation_to_vec(&output), host_elapsed_ms, gpu_elapsed_ms)}fn test_internal<@@ -393,7 +388,11 @@ fn test_edge_f16_f16_f16_f16() {test_edge::<f16, f16, f16, f16>();}-fn run_scaled_rms<B: Backend>(with_shortcut: bool, scale_residual_sum: bool, scale_output: bool) -> (Vec<f32>, Vec<f32>) {+fn run_scaled_rms<B: Backend>(+ with_shortcut: bool,+ scale_residual_sum: bool,+ scale_output: bool,+) -> (Vec<f32>, Vec<f32>) {let (batch, dim) = (2usize, 64usize);let total = batch * dim;let mut rng = SmallRng::seed_from_u64(99);diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/argmax_test_old.rs b/crates/backend-uzu/tests/unit/kernel/sampling/argmax_test_old.rsindex 3790951f6..70fcd55da 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/argmax_test_old.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/argmax_test_old.rs@@ -1,7 +1,4 @@-use std::{- fmt::Display,- mem::size_of,-};+use std::{fmt::Display, mem::size_of};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -72,13 +69,7 @@ fn get_output_single<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vlet mut output = context.create_array_uninitialized(&[input.batch_size as usize], DataType::U32).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");- kernel.encode(- logits_array.allocation(),- &mut output,- input.batch_size,- input.vocab_size,- &mut encoder,- );+ kernel.encode(logits_array.allocation(), &mut output, input.batch_size, input.vocab_size, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();@@ -114,13 +105,7 @@ fn get_output_two_pass<T: ArrayElement + Float, B: Backend>(input: &Input<T>) ->input.vocab_size,&mut encoder,);- final_kernel.encode(- &partial_results,- &mut output,- input.batch_size,- input.vocab_size,- &mut encoder,- );+ final_kernel.encode(&partial_results, &mut output, input.batch_size, input.vocab_size, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/bitmask_test.rs b/crates/backend-uzu/tests/unit/kernel/sampling/bitmask_test.rsindex 3a227373e..a0174feeb 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/bitmask_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/bitmask_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/gumbel_test.rs b/crates/backend-uzu/tests/unit/kernel/sampling/gumbel_test.rsindex c51363f0c..0bbcfd451 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/gumbel_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/gumbel_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement,diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/min_p_test.rs b/crates/backend-uzu/tests/unit/kernel/sampling/min_p_test.rsindex f6d37afbd..106ea571a 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/min_p_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/min_p_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -57,14 +55,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {};let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");- kernel.encode(- logits_buffer.as_ref(),- &mut output,- input.batch_size,- input.vocab_size,- input.min_p,- &mut encoder,- );+ kernel.encode(logits_buffer.as_ref(), &mut output, input.batch_size, input.vocab_size, input.min_p, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();crate::common::helpers::allocation_to_vec(&output)diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/temperature_test.rs b/crates/backend-uzu/tests/unit/kernel/sampling/temperature_test.rsindex 1ee3ad552..96e4355da 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/temperature_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/temperature_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/test_argmax.rs b/crates/backend-uzu/tests/unit/kernel/sampling/test_argmax.rsindex 1bf6e5bb6..6f99954bf 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/test_argmax.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/test_argmax.rs@@ -1,17 +1,18 @@use std::mem::{MaybeUninit, size_of};-use num_traits::{Float, NumCast};-use proptest::prelude::*;-use rand::{RngExt, SeedableRng, rngs::SmallRng};-use rand_distr::Normal;use backend_uzu::{- ArrayContextExt, ArrayElement, DataType, dispatch_dtype,+ ArrayContextExt, ArrayElement, DataType,backends::common::{AllocationType, Backend, Context, Encoder, Kernels,gpu_types::ArgmaxPair,kernel::{ArgmaxFinalKernel, ArgmaxMainKernel, ArgmaxSingleKernel},},+ dispatch_dtype,};+use num_traits::{Float, NumCast};+use proptest::prelude::*;+use rand::{RngExt, SeedableRng, rngs::SmallRng};+use rand_distr::Normal;use crate::{common::{@@ -43,10 +44,7 @@ fn do_argmax_backend<B: Backend, T: ArrayElement + Float>() -> Result<ArgmaxTestResults, TestCaseError> {let logits_buffer = context.create_array_from(&[logits.len()], logits).into_allocation();let mut twopass_partial_results_buffer = context- .create_allocation(- batch_size * vocab_size.div_ceil(4096) * size_of::<ArgmaxPair>(),- AllocationType::Global,- )+ .create_allocation(batch_size * vocab_size.div_ceil(4096) * size_of::<ArgmaxPair>(), AllocationType::Global).unwrap();let mut single_output_buffer = context.create_array_uninitialized(&[batch_size], DataType::U32).into_allocation();let mut twopass_output_buffer = context.create_array_uninitialized(&[batch_size], DataType::U32).into_allocation();diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/top_k_test.rs b/crates/backend-uzu/tests/unit/kernel/sampling/top_k_test.rsindex d5c800731..6206b57f7 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/top_k_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/top_k_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -63,14 +61,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {};let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");- kernel.encode(- logits_buffer.as_ref(),- &mut output,- input.batch_size,- input.vocab_size,- input.top_k,- &mut encoder,- );+ kernel.encode(logits_buffer.as_ref(), &mut output, input.batch_size, input.vocab_size, input.top_k, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();diff --git a/crates/backend-uzu/tests/unit/kernel/sampling/top_p_test.rs b/crates/backend-uzu/tests/unit/kernel/sampling/top_p_test.rsindex a5dbf16da..b1b13e119 100644--- a/crates/backend-uzu/tests/unit/kernel/sampling/top_p_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/sampling/top_p_test.rs@@ -3,9 +3,6 @@ use std::{fmt::{Debug, Display},};-use half::{bf16, f16};-use num_traits::Float;-use rand::{RngExt, SeedableRng, rngs::StdRng, seq::SliceRandom};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,backends::{@@ -17,6 +14,9 @@ use backend_uzu::{},session::parameter::{SamplingMethod, SamplingProcessingOrder},};+use half::{bf16, f16};+use num_traits::Float;+use rand::{RngExt, SeedableRng, rngs::StdRng, seq::SliceRandom};use crate::{common::helpers::{alloc_allocation_with_data, allocation_to_vec},@@ -73,14 +73,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {};let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");- kernel.encode(- logits_buffer.as_ref(),- &mut output,- input.batch_size,- input.vocab_size,- input.top_p,- &mut encoder,- );+ kernel.encode(logits_buffer.as_ref(), &mut output, input.batch_size, input.vocab_size, input.top_p, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();@@ -357,8 +350,7 @@ fn test_topp_sampling_statistical_large() {let context = <B as Backend>::Context::new().expect("Failed to create Context");- let kernel =- SamplingKernel::<B>::new(&context, DataType::F32).expect("Failed to create sampling kernel");+ let kernel = SamplingKernel::<B>::new(&context, DataType::F32).expect("Failed to create sampling kernel");let mut rng = StdRng::seed_from_u64(42);let mut logits = vec![0.0f32; BATCH * VOCAB];@@ -445,8 +437,7 @@ fn perf_topp_128k_vocab() {let context = <B as Backend>::Context::new().expect("Failed to create Context");- let kernel =- SamplingKernel::<B>::new(&context, DataType::F32).expect("Failed to create sampling kernel");+ let kernel = SamplingKernel::<B>::new(&context, DataType::F32).expect("Failed to create sampling kernel");let mut rng = StdRng::seed_from_u64(123);let mut logits = vec![0.0f32; BATCH * VOCAB];diff --git a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_decode_test.rs b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_decode_test.rsindex 47da37472..5e8e47668 100644--- a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_decode_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_decode_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -59,8 +57,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(context.create_array_uninitialized(&[state_allocation_size], T::data_type()).into_allocation()};- let state_array =- (!state_in_place).then(|| context.create_array_from(&[state_allocation_size], &state_data));+ let state_array = (!state_in_place).then(|| context.create_array_from(&[state_allocation_size], &state_data));let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(@@ -79,10 +76,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>();encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&out),- crate::common::helpers::allocation_to_vec(&next_state),- )+ (crate::common::helpers::allocation_to_vec(&out), crate::common::helpers::allocation_to_vec(&next_state))}fn get_test_data_basic<T: ArrayElement + Float>(diff --git a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_pack_test.rs b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_pack_test.rsindex d9c935afc..5883b51cf 100644--- a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_pack_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_pack_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -34,9 +32,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> Vec<T> {let padded_rows = (input.state_stride + input.suffix_len) as usize;let padded_size = padded_rows * input.model_dim as usize;- let mut padded = context- .create_array_uninitialized(&[padded_size], T::data_type())- .into_allocation();+ let mut padded = context.create_array_uninitialized(&[padded_size], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_prefill_test.rs b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_prefill_test.rsindex 8723c762a..29c1e3f44 100644--- a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_prefill_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_prefill_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -39,14 +37,10 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,let b_array = input.b.as_ref().map(|b| context.create_array_from(&[b.len()], b));let out_size = input.suffix_len as usize * input.model_dim as usize;- let mut out = context- .create_array_uninitialized(&[out_size], T::data_type())- .into_allocation();+ let mut out = context.create_array_uninitialized(&[out_size], T::data_type()).into_allocation();let state_out_size = input.model_dim as usize * input.state_stride as usize;- let mut state_out = context- .create_array_uninitialized(&[state_out_size], T::data_type())- .into_allocation();+ let mut state_out = context.create_array_uninitialized(&[state_out_size], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(@@ -65,10 +59,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,);encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&out),- crate::common::helpers::allocation_to_vec(&state_out),- )+ (crate::common::helpers::allocation_to_vec(&out), crate::common::helpers::allocation_to_vec(&state_out))}fn get_test_data_basic<T: ArrayElement + Float>(diff --git a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_trie_test.rs b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_trie_test.rsindex c0a5bc778..3e24fd421 100644--- a/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_trie_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/short_conv/short_conv_trie_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -31,9 +29,8 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,let context = B::Context::new().expect("Failed to create Context");let has_bias = input.b.is_some();- let kernel =- <<B as Backend>::Kernels as Kernels>::ShortConvTrieKernel::new(&context, T::data_type(), has_bias)- .expect("Failed to create ShortConvTrieKernel");+ let kernel = <<B as Backend>::Kernels as Kernels>::ShortConvTrieKernel::new(&context, T::data_type(), has_bias)+ .expect("Failed to create ShortConvTrieKernel");let in_proj_array = context.create_array_from(&[input.in_proj.len()], &input.in_proj);let w_array = context.create_array_from(&[input.w.len()], &input.w);@@ -48,21 +45,15 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,let base_state_size = model_dim * state_stride;let base_state_allocation_size = base_state_size.max(1);- let base_state_data: Vec<T> = input- .base_state- .iter()- .copied()- .chain(std::iter::repeat(T::zero()))- .take(base_state_allocation_size)- .collect();+ let base_state_data: Vec<T> =+ input.base_state.iter().copied().chain(std::iter::repeat(T::zero())).take(base_state_allocation_size).collect();let base_state_array = context.create_array_from(&[base_state_allocation_size], &base_state_data);let parents_array = context.create_array_from(&[input.parents.len()], &input.parents);let suffix_state_size = suffix_len * model_dim * state_stride;- let mut suffix_state = context- .create_array_uninitialized(&[suffix_state_size.max(1)], T::data_type())- .into_allocation();+ let mut suffix_state =+ context.create_array_uninitialized(&[suffix_state_size.max(1)], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(@@ -82,10 +73,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,);encoder.end_encoding().submit().wait_until_completed().unwrap();- (- crate::common::helpers::allocation_to_vec(&out),- crate::common::helpers::allocation_to_vec(&suffix_state),- )+ (crate::common::helpers::allocation_to_vec(&out), crate::common::helpers::allocation_to_vec(&suffix_state))}/// Linear chain: node 0 has parent -1 (root), node i has parent i-1.diff --git a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_decode_test.rs b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_decode_test.rsindex 0825c539e..f3ba3fab9 100644--- a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_decode_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_decode_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -141,8 +139,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>(input: &Input<T>) -> Output<T}} else {let state_array = context.create_array_from(&[state_size], &input.state);- let mut next_state =- context.create_array_uninitialized(&[state_size], T::data_type()).into_allocation();+ let mut next_state = context.create_array_uninitialized(&[state_size], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_pack_test.rs b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_pack_test.rsindex 1e2de9263..edb53cf5d 100644--- a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_pack_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_pack_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,diff --git a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_scan_test.rs b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_scan_test.rsindex 8f3d56f8f..3a9c7448a 100644--- a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_scan_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_conv1d_scan_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -96,8 +94,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>(input: &Input<T>) -> Output<Tlet mut x_out = context.create_array_uninitialized(&[x_out_size], T::data_type()).into_allocation();let mut b_out = context.create_array_uninitialized(&[b_out_size], T::data_type()).into_allocation();let mut c_out = context.create_array_uninitialized(&[c_out_size], T::data_type()).into_allocation();- let mut state_out =- context.create_array_uninitialized(&[state_size], T::data_type()).into_allocation();+ let mut state_out = context.create_array_uninitialized(&[state_size], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_prefill_test.rs b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_prefill_test.rsindex 0269536f6..fa09f8abb 100644--- a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_prefill_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_prefill_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,diff --git a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_split_inproj_test.rs b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_split_inproj_test.rsindex 0d15b3a64..cbf2edd05 100644--- a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_split_inproj_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_split_inproj_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -65,8 +63,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>(input: &Input<T>) -> Output<Tlet input_array = context.create_array_from(&[input.input.len()], &input.input);let z_bias_array = context.create_array_from(&[input.z_bias.len()], &input.z_bias);- let mut conv_out =- context.create_array_uninitialized(&[conv_out_size], T::data_type()).into_allocation();+ let mut conv_out = context.create_array_uninitialized(&[conv_out_size], T::data_type()).into_allocation();let mut z_out = context.create_array_uninitialized(&[z_out_size], T::data_type()).into_allocation();let mut dt_out = context.create_array_uninitialized(&[dt_out_size], T::data_type()).into_allocation();diff --git a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_update_test.rs b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_update_test.rsindex a71cc9955..0437cac09 100644--- a/crates/backend-uzu/tests/unit/kernel/ssm/ssm_update_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/ssm/ssm_update_test.rs@@ -1,6 +1,4 @@-use std::{- fmt::{Debug, Display},-};+use std::fmt::{Debug, Display};use backend_uzu::{ArrayContextExt, ArrayElement, DataType,@@ -137,8 +135,7 @@ fn get_output<B: Backend, T: ArrayElement + Float>(input: &Input<T>) -> Output<T}} else {let state_array = context.create_array_from(&[ns_size], &input.state);- let mut next_state =- context.create_array_uninitialized(&[ns_size], T::data_type()).into_allocation();+ let mut next_state = context.create_array_uninitialized(&[ns_size], T::data_type()).into_allocation();let mut encoder = Encoder::new(context.as_ref()).expect("Failed to create encoder");kernel.encode(diff --git a/crates/backend-uzu/tests/unit/kernel/tensor_add_bias_test.rs b/crates/backend-uzu/tests/unit/kernel/tensor_add_bias_test.rsindex 11be8260e..0ee745255 100644--- a/crates/backend-uzu/tests/unit/kernel/tensor_add_bias_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/tensor_add_bias_test.rs@@ -1,11 +1,11 @@use std::fmt::Debug;-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement,backends::common::{Backend, Context, Encoder, Kernels, kernel::TensorAddBiasKernel},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::helpers::{alloc_allocation, alloc_allocation_with_data, allocation_to_vec},@@ -60,9 +60,13 @@ fn get_output<T: ArrayElement + Float, B: Backend>() -> Vec<T> {let context = B::Context::new().expect("Failed to create Context");- let kernel =- <<B as Backend>::Kernels as Kernels>::TensorAddBiasKernel::new(&context, T::data_type(), T::data_type(), in_place)- .expect("Failed to create TensorAddBiasKernel");+ let kernel = <<B as Backend>::Kernels as Kernels>::TensorAddBiasKernel::new(+ &context,+ T::data_type(),+ T::data_type(),+ in_place,+ )+ .expect("Failed to create TensorAddBiasKernel");let size = input.length as usize;let input_allocation = (!in_place).then(|| alloc_allocation_with_data::<B, T>(&context, &input.input));diff --git a/crates/backend-uzu/tests/unit/kernel/tensor_add_scale_test.rs b/crates/backend-uzu/tests/unit/kernel/tensor_add_scale_test.rsindex 3000f4e38..71a933b8a 100644--- a/crates/backend-uzu/tests/unit/kernel/tensor_add_scale_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/tensor_add_scale_test.rs@@ -1,7 +1,5 @@use std::fmt::{Debug, Display};-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement, DataType,backends::{@@ -9,6 +7,8 @@ use backend_uzu::{cpu::Cpu,},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::{diff --git a/crates/backend-uzu/tests/unit/kernel/tensor_add_swap_test.rs b/crates/backend-uzu/tests/unit/kernel/tensor_add_swap_test.rsindex 69b25307d..f994ba958 100644--- a/crates/backend-uzu/tests/unit/kernel/tensor_add_swap_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/tensor_add_swap_test.rs@@ -1,11 +1,11 @@use std::fmt::Debug;-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement,backends::common::{Backend, Context, Encoder, Kernels, kernel::TensorAddSwapKernel},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::helpers::{alloc_allocation_with_data, allocation_to_vec},@@ -54,10 +54,7 @@ fn get_output<T: ArrayElement + Float, B: Backend>(input: &Input<T>) -> (Vec<T>,kernel.encode(&mut skip_allocation, &mut main_allocation, input.length, &mut encoder);encoder.end_encoding().submit().wait_until_completed().unwrap();- (- allocation_to_vec::<B, T>(&skip_allocation),- allocation_to_vec::<B, T>(&main_allocation),- )+ (allocation_to_vec::<B, T>(&skip_allocation), allocation_to_vec::<B, T>(&main_allocation))}fn test<T: ArrayElement + Float + Debug>() {diff --git a/crates/backend-uzu/tests/unit/kernel/tensor_copy_test.rs b/crates/backend-uzu/tests/unit/kernel/tensor_copy_test.rsindex a3653860d..6dc20b105 100644--- a/crates/backend-uzu/tests/unit/kernel/tensor_copy_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/tensor_copy_test.rs@@ -1,11 +1,11 @@use std::fmt::Debug;-use half::{bf16, f16};-use num_traits::Float;use backend_uzu::{ArrayElement,backends::common::{Backend, Context, Encoder, Kernels, kernel::TensorCopyKernel},};+use half::{bf16, f16};+use num_traits::Float;use crate::{common::helpers::{alloc_allocation, alloc_allocation_with_data, allocation_to_vec},diff --git a/crates/backend-uzu/tests/unit/kernel/test_entry.rs b/crates/backend-uzu/tests/unit/kernel/test_entry.rsindex 66881e54b..f2a00ab03 100644--- a/crates/backend-uzu/tests/unit/kernel/test_entry.rs+++ b/crates/backend-uzu/tests/unit/kernel/test_entry.rs@@ -1,3 +1,8 @@use proc_macros::{__internal_uzu_ignored as uzu_bench, __internal_uzu_test as uzu_test};-include!("mod.rs");+#[macro_use]+#[path = "../../common/mod.rs"]+mod common;++#[path = "mod.rs"]+mod kernel;diff --git a/crates/backend-uzu/tests/unit/kernel/token_copy_test.rs b/crates/backend-uzu/tests/unit/kernel/token_copy_test.rsindex 6e02a485c..e9713c9d1 100644--- a/crates/backend-uzu/tests/unit/kernel/token_copy_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/token_copy_test.rs@@ -1,8 +1,6 @@-use backend_uzu::{- backends::common::{- Backend, Context, Encoder, Kernels,- kernel::{TokenCopySampledKernel, TokenCopyToResultsKernel},- },+use backend_uzu::backends::common::{+ Backend, Context, Encoder, Kernels,+ kernel::{TokenCopySampledKernel, TokenCopyToResultsKernel},};use crate::{diff --git a/scripts/check-rustfmt-discovery.sh b/scripts/check-rustfmt-discovery.shnew file mode 100755index 000000000..603f7ddde--- /dev/null+++ b/scripts/check-rustfmt-discovery.sh@@ -0,0 +1,50 @@+#!/usr/bin/env bash+set -euo pipefail++ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"+cd "$ROOT_DIR"++PACKAGE="backend-uzu"+CRATE_DIR="crates/backend-uzu"++normalize_paths() {+ perl -MCwd=abs_path -ne 'chomp; my $path = abs_path($_); print "$path\n" if defined $path'+}++relative_paths() {+ ROOT="${ROOT_DIR}/" perl -ne 'chomp; s/^\Q$ENV{"ROOT"}\E//; print "$_\n"'+}++fmt_status=0+fmt_output="$(cargo fmt -p "$PACKAGE" --check -- --verbose 2>&1)" || fmt_status=$?++all_files="$(find "$CRATE_DIR" -type f -name '*.rs' -print | normalize_paths | sort -u)"+discovered_files="$(+ printf '%s\n' "$fmt_output" |+ sed -n 's/^Formatting //p' |+ normalize_paths |+ sort -u+)"++missing_files="$(comm -23 <(printf '%s\n' "$all_files") <(printf '%s\n' "$discovered_files"))"++if [[ -n "$missing_files" ]]; then+ all_count="$(printf '%s\n' "$all_files" | sed '/^$/d' | wc -l | tr -d ' ')"+ discovered_count="$(printf '%s\n' "$discovered_files" | sed '/^$/d' | wc -l | tr -d ' ')"+ missing_count="$(printf '%s\n' "$missing_files" | sed '/^$/d' | wc -l | tr -d ' ')"++ {+ printf 'cargo fmt -p %s did not discover every Rust file under %s.\n' "$PACKAGE" "$CRATE_DIR"+ printf 'Discovered %s of %s files; missing %s:\n' "$discovered_count" "$all_count" "$missing_count"+ printf '%s\n' "$missing_files" | relative_paths+ } >&2+ exit 1+fi++if ((fmt_status != 0)); then+ printf '%s\n' "$fmt_output" >&2+ exit "$fmt_status"+fi++all_count="$(printf '%s\n' "$all_files" | sed '/^$/d' | wc -l | tr -d ' ')"+printf 'cargo fmt -p %s discovers all %s Rust files under %s.\n' "$PACKAGE" "$all_count" "$CRATE_DIR"