A high-performance inference engine for AI models
Smol backends/common cleanup (#465)
uuuvn711d2e21a705
diff --git a/crates/backend-uzu/src/audio/nanocodec/runtime.rs b/crates/backend-uzu/src/audio/nanocodec/runtime.rsindex e3b4758f5..e81a0eb44 100644--- a/crates/backend-uzu/src/audio/nanocodec/runtime.rs+++ b/crates/backend-uzu/src/audio/nanocodec/runtime.rs@@ -9,7 +9,7 @@ use std::{use serde::Deserialize;use crate::{- DataType, allocation_to_vec,+ DataType,array::{ArrayContextExt, size_for_shape},audio::{AudioCodecRuntime, AudioError, AudioPcmBatch, AudioResult, AudioTokenGrid},backends::common::{@@ -361,7 +361,7 @@ impl<B: Backend> NanoCodecFsqRuntime<B> {.map_err(|err| AudioError::Runtime(format!("failed to wait for FSQ decode command buffer: {err}")))?;Ok(DecodedPaddedAudio {- samples: allocation_to_vec::<B, f32>(&output),+ samples: output.copyout::<f32>(),channels: self.config.channels(),frames,lengths: lengths_usize,@@ -435,7 +435,7 @@ impl<B: Backend> NanoCodecFsqRuntime<B> {.wait_until_completed().map_err(|err| AudioError::Runtime(format!("failed to wait for FSQ encode command buffer: {err}")))?;- let encoded_tokens = allocation_to_vec::<B, i32>(&tokens);+ let encoded_tokens = tokens.copyout::<i32>();let mut tokens_u32 = vec![0_u32; encoded_tokens.len()];for (index, &token) in encoded_tokens.iter().enumerate() {if token < 0 {diff --git a/crates/backend-uzu/src/audio/nanocodec/runtime/profile.rs b/crates/backend-uzu/src/audio/nanocodec/runtime/profile.rsindex 6970aa9cf..641349d56 100644--- a/crates/backend-uzu/src/audio/nanocodec/runtime/profile.rs+++ b/crates/backend-uzu/src/audio/nanocodec/runtime/profile.rs@@ -1,7 +1,7 @@use std::sync::mpsc::Receiver;use super::*;-use crate::{allocation_to_vec, array::Array, backends::common::Allocation};+use crate::{array::Array, backends::common::Allocation};pub enum SubmittedDecodedPaddedAudio<B: Backend> {Ready(DecodedPaddedAudio),@@ -51,12 +51,10 @@ impl<B: Backend> SubmittedDecodedPaddedAudio<B> {})?;drop(retained_inputs);let samples_result: AudioResult<Vec<f32>> = match data_type {- DataType::F32 => Ok(allocation_to_vec::<B, f32>(&output)),- DataType::F16 => {- Ok(allocation_to_vec::<B, half::f16>(&output).iter().map(|&value| f32::from(value)).collect())- },+ DataType::F32 => Ok(output.copyout::<f32>()),+ DataType::F16 => Ok(output.copyout::<half::f16>().iter().map(|&value| f32::from(value)).collect()),DataType::BF16 => {- Ok(allocation_to_vec::<B, half::bf16>(&output).iter().map(|&value| f32::from(value)).collect())+ Ok(output.copyout::<half::bf16>().iter().map(|&value| f32::from(value)).collect())},dt => Err(AudioError::Runtime(format!("unsupported vocoder output dtype: {dt:?}"))),};diff --git a/crates/backend-uzu/src/backends/common/activation_config.rs b/crates/backend-uzu/src/backends/common/activation_config.rsdeleted file mode 100644index 3903d2609..000000000--- a/crates/backend-uzu/src/backends/common/activation_config.rs+++ /dev/null@@ -1,48 +0,0 @@-use proc_macros::uzu_config;--use crate::backends::common::gpu_types::ActivationType;--#[derive(Copy)]-#[uzu_config]-#[serde(tag = "type")]-pub enum ActivationConfig {- #[serde(rename = "SiLU")]- SILU {- alpha: f32,- },- #[serde(rename = "GELU")]- GELU {- approximate: bool,- },- #[serde(rename = "Identity")]- IDENTITY,-}--impl ActivationConfig {- pub fn act_type(&self) -> ActivationType {- match self {- ActivationConfig::SILU {- alpha: _,- } => ActivationType::SILU,- ActivationConfig::GELU {- approximate: true,- } => ActivationType::GELUApprox,- ActivationConfig::GELU {- approximate: false,- } => ActivationType::GELUExact,- ActivationConfig::IDENTITY => ActivationType::IDENTITY,- }- }-- pub fn alpha(&self) -> f32 {- match self {- ActivationConfig::SILU {- alpha,- } => *alpha,- ActivationConfig::GELU {- approximate: _,- } => 1.0,- ActivationConfig::IDENTITY => 1.0,- }- }-}diff --git a/crates/backend-uzu/src/backends/common/allocation_access.rs b/crates/backend-uzu/src/backends/common/allocation_access.rsdeleted file mode 100644index 11e98e9cb..000000000--- a/crates/backend-uzu/src/backends/common/allocation_access.rs+++ /dev/null@@ -1,60 +0,0 @@-use thiserror::Error;--use crate::{- ArrayElement,- backends::common::{Allocation, AsBufferRangeMut, AsBufferRangeRef, Backend, DenseBuffer},-};--#[derive(Debug, Clone, PartialEq, Eq, Error)]-pub enum AllocationAccessError {- #[error("allocation write length {write_len} exceeds allocation length {range_len}")]- WriteExceedsRange {- write_len: usize,- range_len: usize,- },-}--pub fn allocation_copy_from_slice<B: Backend, T: ArrayElement>(- allocation: &mut Allocation<B>,- data: &[T],-) -> Result<(), AllocationAccessError> {- let bytes = bytemuck::cast_slice(data);- if bytes.is_empty() {- return Ok(());- }- let destination = allocation_as_bytes_mut(allocation);- if bytes.len() > destination.len() {- return Err(AllocationAccessError::WriteExceedsRange {- write_len: bytes.len(),- range_len: destination.len(),- });- }- destination[..bytes.len()].copy_from_slice(bytes);- Ok(())-}--pub fn allocation_as_bytes<B: Backend>(allocation: &Allocation<B>) -> &[u8] {- let buffer_range = allocation.as_buffer_range_ref();- let range = buffer_range.range();- unsafe {- std::slice::from_raw_parts(- (buffer_range.buffer().cpu_ptr().as_ptr() as *const u8).add(range.start),- range.len(),- )- }-}--pub fn allocation_as_bytes_mut<B: Backend>(allocation: &mut Allocation<B>) -> &mut [u8] {- let buffer_range = allocation.as_buffer_range_mut();- let range = buffer_range.range();- unsafe {- std::slice::from_raw_parts_mut(- (buffer_range.buffer().cpu_ptr().as_ptr() as *mut u8).add(range.start),- range.len(),- )- }-}--pub fn allocation_to_vec<B: Backend, T: ArrayElement>(allocation: &Allocation<B>) -> Vec<T> {- bytemuck::cast_slice(allocation_as_bytes(allocation)).to_vec()-}diff --git a/crates/backend-uzu/src/backends/common/allocator/allocator.rs b/crates/backend-uzu/src/backends/common/allocator/allocator.rsindex e07e111b7..501c26625 100644--- a/crates/backend-uzu/src/backends/common/allocator/allocator.rs+++ b/crates/backend-uzu/src/backends/common/allocator/allocator.rs@@ -6,9 +6,12 @@ use std::{};use super::{RangeAllocationType, RangeAllocator};-use crate::backends::common::{- Backend, Buffer, Context,- buffer_range::{AsBufferRangeMut, AsBufferRangeRef, BufferRangeMut, BufferRangeRef},+use crate::{+ ArrayElement,+ backends::common::{+ Backend, Buffer, Context, DenseBuffer,+ buffer_range::{AsBufferRangeMut, AsBufferRangeRef, BufferRangeMut, BufferRangeRef},+ },};pub struct Allocation<B: Backend> {@@ -18,6 +21,17 @@ pub struct Allocation<B: Backend> {allocation_type: RangeAllocationType,}+impl<B: Backend> Allocation<B> {+ pub fn copyout<T: ArrayElement>(&self) -> Vec<T> {+ let buffer_range = self.as_buffer_range_ref();+ let (buffer, range) = (buffer_range.buffer(), buffer_range.range());+ let bytes = unsafe {+ std::slice::from_raw_parts((buffer.cpu_ptr().as_ptr() as *const u8).add(range.start), range.len())+ };+ bytemuck::cast_slice(bytes).to_vec()+ }+}+impl<B: Backend> AsBufferRangeRef for Allocation<B> {type Buffer = B::DenseBuffer;diff --git a/crates/backend-uzu/src/backends/common/kernel/mlp_gate_act_mul.rs b/crates/backend-uzu/src/backends/common/kernel/mlp_gate_act_mul.rsindex e22dfaf45..ba1a0ed53 100644--- a/crates/backend-uzu/src/backends/common/kernel/mlp_gate_act_mul.rs+++ b/crates/backend-uzu/src/backends/common/kernel/mlp_gate_act_mul.rs@@ -1,14 +1,13 @@use crate::{DataType,array::size_for_shape,- backends::common::{- ActivationConfig, Allocation, Backend, Encoder, Kernels, gpu_types::ActivationType, kernel::MlpGateActMulKernel,- },+ backends::common::{Allocation, Backend, Encoder, Kernels, gpu_types::ActivationType, kernel::MlpGateActMulKernel},+ config::activation::AnyActivation,};pub struct MlpGateActMulEncodable<B: Backend> {kernel: <B::Kernels as Kernels>::MlpGateActMulKernel,- activation: ActivationConfig,+ activation: AnyActivation,hidden_dim: usize,data_type: DataType,hadamard_factors: Option<Allocation<B>>,@@ -18,7 +17,7 @@ impl<B: Backend> MlpGateActMulEncodable<B> {pub fn new(context: &B::Context,data_type: DataType,- activation: ActivationConfig,+ activation: AnyActivation,hidden_dim: usize,hadamard_factors: Option<Allocation<B>>,) -> Result<Self, B::Error> {diff --git a/crates/backend-uzu/src/backends/common/mod.rs b/crates/backend-uzu/src/backends/common/mod.rsindex 24074b4a0..d64f9aa7d 100644--- a/crates/backend-uzu/src/backends/common/mod.rs+++ b/crates/backend-uzu/src/backends/common/mod.rs@@ -1,5 +1,3 @@-mod activation_config;-mod allocation_access;mod allocator;mod backend;mod buffer;@@ -13,10 +11,6 @@ mod hazard_tracker;pub mod kernel;mod sparse_buffer;-pub use activation_config::ActivationConfig;-pub use allocation_access::{- AllocationAccessError, allocation_as_bytes, allocation_as_bytes_mut, allocation_copy_from_slice, allocation_to_vec,-};pub use allocator::{Allocation, AllocationPool, AllocationType, Allocator};pub use backend::Backend;pub use buffer::{Buffer, BufferGpuAddressRangeExt};diff --git a/crates/backend-uzu/src/classifier/classifier.rs b/crates/backend-uzu/src/classifier/classifier.rsindex 179571fcb..00e079b91 100644--- a/crates/backend-uzu/src/classifier/classifier.rs+++ b/crates/backend-uzu/src/classifier/classifier.rs@@ -4,7 +4,7 @@ use std::{collections::HashMap, path::Path, time::Instant};use super::ActivationTrace;use super::{ClassificationOutput, ClassificationStats, ClassifierContext};use crate::{- DataType, allocation_to_vec,+ DataType,backends::common::{Allocation, AsBufferRangeRef, Backend, Encoder},config::model::classifier_model::ClassifierModelConfig,encodable_block::LayerArguments,@@ -211,13 +211,9 @@ impl<B: Backend> Classifier<B> {logits: &Allocation<B>,) -> Result<Box<[f32]>, Error> {match self.context.logits_data_type {- DataType::F32 => Ok(allocation_to_vec::<B, f32>(logits).into()),- DataType::F16 => {- Ok(allocation_to_vec::<B, half::f16>(logits).into_iter().map(|x| x.to_f32()).collect::<Box<[_]>>())- },- DataType::BF16 => {- Ok(allocation_to_vec::<B, half::bf16>(logits).into_iter().map(|x| x.to_f32()).collect::<Box<[_]>>())- },+ DataType::F32 => Ok(logits.copyout::<f32>().into()),+ DataType::F16 => Ok(logits.copyout::<half::f16>().into_iter().map(|x| x.to_f32()).collect::<Box<[_]>>()),+ DataType::BF16 => Ok(logits.copyout::<half::bf16>().into_iter().map(|x| x.to_f32()).collect::<Box<[_]>>()),data_type => {Err(Error::InvalidModelConfig(format!("unsupported classifier logits data type {data_type:?}")))},diff --git a/crates/backend-uzu/src/classifier/classifier_context.rs b/crates/backend-uzu/src/classifier/classifier_context.rsindex decd22795..151afa12a 100644--- a/crates/backend-uzu/src/classifier/classifier_context.rs+++ b/crates/backend-uzu/src/classifier/classifier_context.rs@@ -193,7 +193,7 @@ impl<B: Backend> ClassifierContext<B> {let prediction_head = ClassifierPredictionHead::new(context.as_ref(),prediction_head_dense,- prediction_head_config.activation.clone().into(),+ prediction_head_config.activation.clone(),model_shape.data_type,prediction_head_norm,prediction_head_final_linear,diff --git a/crates/backend-uzu/src/config/activation/mod.rs b/crates/backend-uzu/src/config/activation/mod.rsindex 66dfea909..89a19831b 100644--- a/crates/backend-uzu/src/config/activation/mod.rs+++ b/crates/backend-uzu/src/config/activation/mod.rs@@ -1,6 +1,6 @@use proc_macros::uzu_config_abstract;-use crate::backends::common::{ActivationConfig, gpu_types::ActivationType};+use crate::backends::common::gpu_types::ActivationType;pub mod gelu;pub mod identity;@@ -32,17 +32,3 @@ impl AnyActivation {}}}--impl From<AnyActivation> for ActivationConfig {- fn from(value: AnyActivation) -> Self {- match value {- AnyActivation::SiLU(config) => ActivationConfig::SILU {- alpha: config.alpha,- },- AnyActivation::GELU(config) => ActivationConfig::GELU {- approximate: config.approximate,- },- AnyActivation::Identity(_) => ActivationConfig::IDENTITY,- }- }-}diff --git a/crates/backend-uzu/src/encodable_block/mlp/mod.rs b/crates/backend-uzu/src/encodable_block/mlp/mod.rsindex c360dde6c..1dfcefee9 100644--- a/crates/backend-uzu/src/encodable_block/mlp/mod.rs+++ b/crates/backend-uzu/src/encodable_block/mlp/mod.rs@@ -66,7 +66,7 @@ impl<B: Backend> dyn Mlp<B> {let gate = MlpGateActMulEncodable::new(context,data_type,- dense_config.activation.clone().into(),+ dense_config.activation.clone(),hidden_dimension,down_input_hadamard_factors,)diff --git a/crates/backend-uzu/src/encodable_block/prediction_head.rs b/crates/backend-uzu/src/encodable_block/prediction_head.rsindex c918b2c3f..c4fe9e00c 100644--- a/crates/backend-uzu/src/encodable_block/prediction_head.rs+++ b/crates/backend-uzu/src/encodable_block/prediction_head.rs@@ -4,17 +4,18 @@ use crate::{DataType,array::size_for_shape,backends::common::{- ActivationConfig, Allocation, Backend, Encoder,+ Allocation, Backend, Encoder,gpu_types::ActivationType,kernel::{ActivationKernel, Kernels},},+ config::activation::AnyActivation,encodable_block::{Normalization, linear::Linear},};pub struct ClassifierPredictionHead<B: Backend> {dense: Box<dyn Linear<B>>,activation_kernel: <B::Kernels as Kernels>::ActivationKernel,- activation: ActivationConfig,+ activation: AnyActivation,activation_data_type: DataType,norm: Normalization<B>,readout: Box<dyn Linear<B>>,@@ -25,7 +26,7 @@ impl<B: Backend> ClassifierPredictionHead<B> {pub fn new(context: &B::Context,dense: Box<dyn Linear<B>>,- activation: ActivationConfig,+ activation: AnyActivation,activation_data_type: DataType,norm: Normalization<B>,readout: Box<dyn Linear<B>>,diff --git a/crates/backend-uzu/src/language_model/language_model_generator.rs b/crates/backend-uzu/src/language_model/language_model_generator.rsindex 85747dc7f..b2afb4538 100644--- a/crates/backend-uzu/src/language_model/language_model_generator.rs+++ b/crates/backend-uzu/src/language_model/language_model_generator.rs@@ -870,15 +870,8 @@ impl<B: Backend> LanguageModelGenerator<B> {sampling_output: &Allocation<B>,batch_size: usize,) -> Result<Vec<u64>, Error> {- let buffer_range = sampling_output.as_buffer_range_ref();- let range = buffer_range.range();- let values = unsafe {- std::slice::from_raw_parts(- (buffer_range.buffer().cpu_ptr().as_ptr() as *const u32).add(range.start / std::mem::size_of::<u32>()),- batch_size,- )- };- Ok(values.iter().map(|value| *value as u64).collect())+ let values = sampling_output.copyout::<u32>();+ Ok(values[..batch_size].iter().map(|value| u64::from(*value)).collect())}fn update_cache_layers(diff --git a/crates/backend-uzu/src/lib.rs b/crates/backend-uzu/src/lib.rsindex 06185d865..6e42bc8d3 100644--- a/crates/backend-uzu/src/lib.rs+++ b/crates/backend-uzu/src/lib.rs@@ -23,7 +23,6 @@ pub mod session;pub use array::{Array, ArrayContextExt};#[cfg(metal_backend)]pub use audio::{NanoCodecFsqRuntime, NanoCodecFsqRuntimeConfig};-pub use backends::common::{AllocationAccessError, allocation_copy_from_slice, allocation_to_vec};pub use data_type::{ArrayElement, DataType};pub use language_model::gumbel::{gumbel_float, revidx};pub use parameters::{ParameterLoader, read_safetensors_metadata};diff --git a/crates/backend-uzu/src/session/tts_session/decoder_runtime.rs b/crates/backend-uzu/src/session/tts_session/decoder_runtime.rsindex c29ed84ca..56acde130 100644--- a/crates/backend-uzu/src/session/tts_session/decoder_runtime.rs+++ b/crates/backend-uzu/src/session/tts_session/decoder_runtime.rs@@ -1,7 +1,7 @@use super::{decoder_support::*, *};use crate::{array::{Array, ArrayContextExt},- backends::common::{Allocation, AsBufferRangeRef, DenseBuffer},+ backends::common::{Allocation, AsBufferRangeRef},config::decoder::DecoderConfig,encodable_block::{DecoderArguments, DecoderDecodeInput, LayerArguments, Linear, SamplingInputs},forward_pass::token_inputs::TokenInputs,@@ -1210,12 +1210,7 @@ impl<B: Backend> TokenDecoderRunner<B> {}.into());}- let buffer_range = self.ctx.async_chain_results.as_buffer_range_ref();- let range = buffer_range.range();- Ok(unsafe {- *((buffer_range.buffer().cpu_ptr().as_ptr() as *const u8)- .add(range.start + slot * std::mem::size_of::<u32>()) as *const u32)- })+ Ok(self.ctx.async_chain_results.copyout::<u32>()[slot])}pub(super) fn take_instrumentation(&mut self) -> RunnerInstrumentation {@@ -1228,8 +1223,6 @@ impl<B: Backend> TokenDecoderRunner<B> {}fn read_sampled_token_from_sampling_output<B: Backend>(sampling_output: &Allocation<B>) -> Result<u64, Error> {- let buffer_range = sampling_output.as_buffer_range_ref();- let range = buffer_range.range();- let token = unsafe { *((buffer_range.buffer().cpu_ptr().as_ptr() as *const u8).add(range.start) as *const u32) };+ let token = sampling_output.copyout::<u32>()[0];Ok(u64::from(token))}diff --git a/crates/backend-uzu/tests/common/helpers.rs b/crates/backend-uzu/tests/common/helpers.rsindex 60c8bebde..e5b0ec8a2 100644--- a/crates/backend-uzu/tests/common/helpers.rs+++ b/crates/backend-uzu/tests/common/helpers.rs@@ -1,8 +1,11 @@use std::{mem::size_of, rc::Rc};use backend_uzu::{- ArrayElement, allocation_copy_from_slice,- backends::common::{Allocation, AllocationType, Backend, Buffer, Context, Encoder, SparseBuffer, SparseBufferExt},+ ArrayElement,+ backends::common::{+ Allocation, AllocationType, AsBufferRangeMut, Backend, Context, DenseBuffer, Encoder, SparseBuffer,+ SparseBufferExt,+ },};pub fn allocation_size_bytes<T>(elements_count: usize) -> usize {@@ -25,12 +28,12 @@ pub fn alloc_allocation_with_data<B: Backend, T: ArrayElement>(let mut allocation = context.create_allocation(allocation_size_bytes::<T>(data.len()), AllocationType::Global).expect("Failed to create allocation");- allocation_copy_from_slice(&mut allocation, data).expect("Failed to initialize allocation");+ write_allocation(&mut allocation, data);allocation}pub fn allocation_to_vec<B: Backend, T: ArrayElement>(allocation: &Allocation<B>) -> Vec<T> {- backend_uzu::allocation_to_vec(allocation)+ allocation.copyout()}pub fn allocation_prefix_to_vec<B: Backend, T: ArrayElement>(@@ -46,7 +49,17 @@ pub fn write_allocation<B: Backend, T: ArrayElement>(allocation: &mut Allocation<B>,data: &[T],) {- allocation_copy_from_slice(allocation, data).expect("Failed to write allocation")+ let bytes = bytemuck::cast_slice(data);+ let buffer_range = allocation.as_buffer_range_mut();+ let range = buffer_range.range();+ assert!(bytes.len() <= range.len(), "source data is larger than destination allocation");+ let destination = unsafe {+ std::slice::from_raw_parts_mut(+ (buffer_range.buffer().cpu_ptr().as_ptr() as *mut u8).add(range.start),+ range.len(),+ )+ };+ destination[..bytes.len()].copy_from_slice(bytes);}pub fn create_context<B: Backend>() -> Rc<<B as Backend>::Context> {diff --git a/crates/backend-uzu/tests/integration/tracer/trace_validator.rs b/crates/backend-uzu/tests/integration/tracer/trace_validator.rsindex f5a774f2a..4d9977880 100644--- a/crates/backend-uzu/tests/integration/tracer/trace_validator.rs+++ b/crates/backend-uzu/tests/integration/tracer/trace_validator.rs@@ -18,7 +18,7 @@ use backend_uzu::{ActivationTrace, AnyModelConfig, ArgmaxSampler, CacheLayers, Classifier, DecoderDecodeInput, KVCacheLayer,LanguageModelGeneratorContext, LogitsSampler, ParameterLoaderError, ParameterTree, Sampling, TokenInputs,},- Array, ArrayElement, DataType, ParameterLoader, allocation_to_vec,+ Array, ArrayElement, DataType, ParameterLoader,backends::common::{Allocation, AllocationType, Backend, Context, Encoder, kernel::kv_cache_update::KVCacheUpdate},read_safetensors_metadata,session::{@@ -698,7 +698,7 @@ impl<B: Backend> TraceValidator<B> {produced_shape: &[usize],transform: Option<ArrayTransform>,) -> TracerValidationMetrics {- let produced = allocation_to_vec::<B, Precision>(produced_allocation);+ let produced = produced_allocation.copyout::<Precision>();Self::validate_allocation_data_of_type(expected_array, &produced, produced_shape, transform)}diff --git a/crates/backend-uzu/tests/unit/backends/common/kernel/ssd_prefill_test.rs b/crates/backend-uzu/tests/unit/backends/common/kernel/ssd_prefill_test.rsindex e1d9b6b9a..92092e1ce 100644--- a/crates/backend-uzu/tests/unit/backends/common/kernel/ssd_prefill_test.rs+++ b/crates/backend-uzu/tests/unit/backends/common/kernel/ssd_prefill_test.rs@@ -1,5 +1,5 @@use crate::{- DataType, allocation_to_vec,+ DataType,backends::common::{Allocation, Backend, Context, Encoder, Kernels,gpu_types::ActivationType,@@ -14,6 +14,8 @@ use crate::{#[path = "../../../../common/mod.rs"]mod common;+use common::helpers::allocation_to_vec;+fn allocation_from_slice<B: Backend, T: crate::ArrayElement>(context: &B::Context,data: &[T],diff --git a/crates/backend-uzu/tests/unit/forward_pass/cache_layers_test.rs b/crates/backend-uzu/tests/unit/forward_pass/cache_layers_test.rsindex a4684da3a..494741929 100644--- a/crates/backend-uzu/tests/unit/forward_pass/cache_layers_test.rs+++ b/crates/backend-uzu/tests/unit/forward_pass/cache_layers_test.rs@@ -4,7 +4,7 @@ use std::{mem::size_of, ops::Range};use super::{CacheEntryIndex, CacheLayer, CacheLayers, LayerCacheBinding};use crate::{- DataType, allocation_copy_from_slice, allocation_to_vec,+ ArrayContextExt, DataType,backends::{common::{Allocation, AllocationType, Backend, Context, Encoder, SparseBuffer},metal::Metal,@@ -20,10 +20,7 @@ fn allocation_from_slice(context: &<Metal as Backend>::Context,data: &[f32],) -> Allocation<Metal> {- let mut allocation =- context.create_allocation(size_of_val(data), AllocationType::Global).expect("Failed to create allocation");- allocation_copy_from_slice(&mut allocation, data).expect("Failed to write allocation");- allocation+ context.create_array_from(&[data.len()], data).into_allocation()}fn copy_allocation_to_sparse_row(@@ -50,7 +47,7 @@ fn read_sparse_row(let mut encoder = Encoder::<Metal>::new(context).expect("Failed to create encoder");encoder.encode_copy(buffer, row_byte_range(row_size, row_index), &mut allocation, 0..row_size);submit_encoder(encoder);- allocation_to_vec(&allocation)+ allocation.copyout()}fn row_byte_range(diff --git a/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rs b/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rsindex fe7fc1008..88dfc7035 100644--- a/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rs+++ b/crates/backend-uzu/tests/unit/kernel/audio/audio_test.rs@@ -1,7 +1,7 @@#![cfg(metal_backend)]use backend_uzu::{- ArrayContextExt, DataType, allocation_to_vec,+ ArrayContextExt, DataType,backends::{common::{Backend, Context, Encoder, Kernels,@@ -17,13 +17,16 @@ use backend_uzu::{};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,+ 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,+ },},+ helpers::allocation_to_vec,},uzu_test,};