From 6f8584091e4b8d4afc49f386a5861b0094348822 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 5 Jan 2024 14:28:08 +0100 Subject: [PATCH] Cleanup. --- candle-core/examples/tensor-tools.rs | 25 +------------------------ candle-core/src/metal_backend.rs | 2 +- candle-core/src/quantized/mod.rs | 6 ++---- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/candle-core/examples/tensor-tools.rs b/candle-core/examples/tensor-tools.rs index 88079cb208..01901f9f30 100644 --- a/candle-core/examples/tensor-tools.rs +++ b/candle-core/examples/tensor-tools.rs @@ -11,13 +11,7 @@ enum QuantizationMode { } impl QuantizationMode { - fn quantize( - &self, - name: &str, - tensor: QTensor, - dtype: GgmlDType, - // default: fn(&Tensor) -> Result, - ) -> Result { + fn quantize(&self, name: &str, tensor: QTensor, dtype: GgmlDType) -> Result { match self { Self::Llama => { // Same behavior as the llama.cpp quantization. @@ -28,7 +22,6 @@ impl QuantizationMode { QTensor::quantize(&tensor, GgmlDType::Q6K) } else { QTensor::quantize(&tensor, dtype) - // default(&tensor) } } else { Ok(tensor) @@ -261,22 +254,6 @@ fn run_quantize_safetensors( println!("tensors: {}", tensors.len()); let dtype = q.dtype(); - // let quantize_fn = match q { - // Quantization::Q4_0 => QTensor::quantize::, - // Quantization::Q4_1 => QTensor::quantize::, - // Quantization::Q5_0 => QTensor::quantize::, - // Quantization::Q5_1 => QTensor::quantize::, - // Quantization::Q8_0 => QTensor::quantize::, - // Quantization::Q8_1 => QTensor::quantize::, - // Quantization::Q2k => QTensor::quantize::, - // Quantization::Q3k => QTensor::quantize::, - // Quantization::Q4k => QTensor::quantize::, - // Quantization::Q5k => QTensor::quantize::, - // Quantization::Q6k => QTensor::quantize::, - // Quantization::Q8k => QTensor::quantize::, - // Quantization::F16 => QTensor::quantize::, - // Quantization::F32 => QTensor::quantize::, - // }; let block_size = dtype.block_size(); let qtensors = tensors diff --git a/candle-core/src/metal_backend.rs b/candle-core/src/metal_backend.rs index 8e98b5e200..06fea7b5ba 100644 --- a/candle-core/src/metal_backend.rs +++ b/candle-core/src/metal_backend.rs @@ -131,7 +131,7 @@ impl MetalDevice { &self.device } - pub fn fence(&self) -> &metal::Fence { + pub(crate) fn fence(&self) -> &metal::Fence { &self.fence } diff --git a/candle-core/src/quantized/mod.rs b/candle-core/src/quantized/mod.rs index c16cf86935..1dc5fe8f74 100644 --- a/candle-core/src/quantized/mod.rs +++ b/candle-core/src/quantized/mod.rs @@ -29,14 +29,12 @@ impl Device { fn qzeros(&self, elem_count: usize, dtype: GgmlDType) -> Result { match self { Device::Cpu => { - let storage = dtype.zeros(elem_count); + let storage = dtype.cpu_zeros(elem_count); Ok(QStorage::Cpu(storage)) } #[cfg(feature = "metal")] Device::Metal(metal) => { let size = elem_count * dtype.type_size() / dtype.block_size(); - // let cpu_storage = dtype.zeros(elem_count); - // assert_eq!(size, cpu_storage.size()); let buffer = metal.allocate_zeros(size)?; Ok(QStorage::Metal(metal::QMetalStorage::new( buffer, @@ -182,7 +180,7 @@ impl GgmlDType { } /// The block dtype - pub fn zeros(&self, elem_count: usize) -> Box { + pub fn cpu_zeros(&self, elem_count: usize) -> Box { match self { Self::F32 => Box::new(vec![f32::zeros(); elem_count]), Self::F16 => Box::new(vec![f16::zeros(); elem_count]),