{"record":{"id":"ad63e1fb00f3f68d","repo":"huggingface/candle","slug":"invalid-quantize-source-storage-locations-not-on","errorCode":null,"errorMessage":"Invalid quantize source storage locations: not on cpu","messagePattern":"Invalid quantize source storage locations: not on cpu","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/mod.rs","lineNumber":207,"sourceCode":"            (QStorage::Metal(storage), Storage::Metal(src)) => {\n                storage.quantize_imatrix(src, imatrix_weights, n_per_row)?\n            }\n            (QStorage::Cuda(storage), Storage::Cuda(src)) => {\n                storage.quantize_imatrix(src, imatrix_weights, n_per_row)?\n            }\n            _ => crate::bail!(\"Invalid quantize storage locations do not match\"),\n        }\n        Ok(())\n    }\n\n    fn quantize_onto(&mut self, src: &Storage) -> Result<()> {\n        match (self, src) {\n            (QStorage::Cpu(storage), Storage::Cpu(src)) => {\n                storage.from_float(src.as_slice::<f32>()?);\n            }\n            (QStorage::Metal(storage), Storage::Cpu(src)) => storage.quantize_onto(src)?,\n            (QStorage::Cuda(storage), Storage::Cpu(src)) => storage.quantize_onto(src)?,\n            _ => crate::bail!(\"Invalid quantize source storage locations: not on cpu\"),\n        }\n        Ok(())\n    }\n\n    fn quantize_imatrix_onto(\n        &mut self,\n        src: &Storage,\n        imatrix_weights: &[f32],\n        n_per_row: usize,\n    ) -> Result<()> {\n        match (self, src) {\n            (QStorage::Cpu(storage), Storage::Cpu(src)) => {\n                storage.from_float_imatrix(src.as_slice::<f32>()?, imatrix_weights, n_per_row);\n            }\n            (QStorage::Metal(storage), Storage::Cpu(src)) => {\n                storage.quantize_imatrix_onto(src, imatrix_weights, n_per_row)?\n            }\n            (QStorage::Cuda(storage), Storage::Cpu(src)) => {","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/mod.rs#L189-L225","documentation":"quantize_onto writes quantized data in place over a CPU source buffer; this variant requires the SOURCE storage to be on CPU (Metal/Cuda destinations quantize_onto a Cpu source). Any other combination, such as a GPU source storage, is rejected with this message.","triggerScenarios":"Calling quantize_onto where src is a Metal or Cuda Storage instead of a Cpu f32 storage.","commonSituations":"Trying to quantize directly from a GPU-resident tensor without first copying it to host memory.","solutions":["Copy the source tensor to CPU (to_device(&Device::Cpu)) before quantize_onto.","Or use the device-matched quantize()/quantize_imatrix() variants instead of quantize_onto.","Ensure the source is f32 and contiguous on CPU."],"exampleFix":"// before\nqstorage.quantize_onto(&gpu_storage)?;\n// after\nlet cpu_storage = gpu_tensor.to_device(&Device::Cpu)?;\nqstorage.quantize_onto(cpu_storage.as_slice::<f32>()?)?;","handlingStrategy":"validation","validationCode":"fn ensure_cpu_source(src: &candle_core::Storage) -> candle_core::Result<()> {\n    if !matches!(src, candle_core::Storage::Cpu(_)) {\n        candle_core::bail!(\"quantize_onto requires a CPU source storage\");\n    }\n    Ok(())\n}","typeGuard":"fn is_cpu_storage(s: &candle_core::Storage) -> bool { matches!(s, candle_core::Storage::Cpu(_)) }","tryCatchPattern":null,"preventionTips":["Copy tensors to CPU before quantize_onto","Prefer device-matched quantize() over quantize_onto when possible","Never quantize directly from GPU-resident buffers"],"tags":["device-mismatch","quantized","cpu"],"backgroundTag":"device-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}