{"record":{"id":"ae803225a10845c1","repo":"huggingface/candle","slug":"not-implemented","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/mod.rs","lineNumber":258,"sourceCode":"\n    fn data(&self) -> Result<Cow<'_, [u8]>> {\n        match self {\n            QStorage::Cpu(storage) => {\n                let data_ptr = storage.as_ptr();\n                let size_in_bytes = storage.storage_size_in_bytes();\n                let data = unsafe { std::slice::from_raw_parts(data_ptr, size_in_bytes) };\n                Ok(Cow::from(data))\n            }\n            QStorage::Cuda(storage) => Ok(Cow::from(storage.data()?)),\n            QStorage::Metal(storage) => Ok(Cow::from(storage.data()?)),\n        }\n    }\n\n    pub fn device_ptr(&self) -> Result<*const u8> {\n        match self {\n            QStorage::Cuda(storage) => storage.device_ptr(),\n            QStorage::Metal(_) | QStorage::Cpu(_) => {\n                crate::bail!(\"not implemented\");\n            }\n        }\n    }\n\n    #[cfg(feature = \"cuda\")]\n    pub fn device_ptr_with_guard<'a>(\n        &'a self,\n        stream: &'a crate::cuda_backend::cudarc::driver::CudaStream,\n    ) -> Result<(\n        *const u8,\n        crate::cuda_backend::cudarc::driver::SyncOnDrop<'a>,\n    )> {\n        match self {\n            QStorage::Cuda(storage) => storage.device_ptr_with_guard(stream),\n            QStorage::Metal(_) | QStorage::Cpu(_) => {\n                crate::bail!(\"not implemented\");\n            }\n        }","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/mod.rs#L240-L276","documentation":"QStorage::device_ptr returns the raw device pointer of the underlying buffer, but only the CUDA backend implements it. Calling it on a Metal or Cpu quantized storage hits the unconditional bail 'not implemented'.","triggerScenarios":"Calling QTensor/QStorage::device_ptr() when the quantized tensor lives on CPU or Metal (typically from custom CUDA-interop code).","commonSituations":"Passing quantized weights to external CUDA kernels (e.g. llama.cpp style bindings) while the model was loaded on CPU or Metal.","solutions":["Only call device_ptr on CUDA-resident quantized tensors; check storage device first.","Move the tensor to the Cuda device before requesting the pointer (quantize onto Cuda).","For CPU access, use dequantize() to obtain f32 data instead of a raw pointer.","Use device_ptr_with_guard (also CUDA-only) if you need stream-synchronized access."],"exampleFix":"// before\nlet ptr = qtensor.storage().device_ptr()?; // fails on Metal/Cpu\n// after\nif matches!(tensor.device(), Device::Cuda(_)) {\n    let ptr = qtensor.storage().device_ptr()?;\n} else {\n    let f32_storage = qtensor.dequantize(tensor.elem_count())?;\n}","handlingStrategy":"type-guard","validationCode":"fn ensure_cuda_qstorage(s: &candle_core::quantized::QStorage) -> candle_core::Result<()> {\n    if !matches!(s, candle_core::quantized::QStorage::Cuda(_)) {\n        candle_core::bail!(\"device_ptr is CUDA-only\");\n    }\n    Ok(())\n}","typeGuard":"fn is_cuda_qstorage(s: &candle_core::quantized::QStorage) -> bool { matches!(s, candle_core::quantized::QStorage::Cuda(_)) }","tryCatchPattern":"match qtensor.storage().device_ptr() {\n    Ok(ptr) => use_raw_pointer(ptr),\n    Err(e) if e.to_string().contains(\"not implemented\") => {\n        // fall back to dequantized CPU access\n        let f32_data = qtensor.dequantize(&cpu_device)?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Only use device_ptr interop when weights are CUDA-resident","Check tensor.device() before raw pointer access","Use dequantize() for CPU/Metal data access"],"tags":["not-implemented","quantized","cuda","metal","cpu"],"backgroundTag":"operation-not-implemented-on-backend","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}