{"record":{"id":"d08482bac938fca7","repo":"huggingface/candle","slug":"unsupported-const-set-f64","errorCode":null,"errorMessage":"unsupported const-set f64","messagePattern":"unsupported const-set f64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/metal_backend/mod.rs","lineNumber":480,"sourceCode":"        ) -> Result<()> {\n            let device = self_.device();\n            let dtype = self_.dtype;\n            let shape = l.shape();\n            let el_count = shape.elem_count();\n            let encoder = device.command_encoder()?;\n            let dst = buffer_o(&self_.buffer, l, self_.dtype);\n\n            if l.is_contiguous() {\n                use candle_metal_kernels::unary::contiguous;\n                let kernel_name = match dtype {\n                    DType::F16 => contiguous::const_set::HALF,\n                    DType::BF16 => contiguous::const_set::BFLOAT,\n                    DType::F32 => contiguous::const_set::FLOAT,\n                    DType::I64 => contiguous::const_set::I64,\n                    DType::U32 => contiguous::const_set::U32,\n                    DType::U8 => contiguous::const_set::U8,\n                    DType::F8E4M3 => crate::bail!(\"unsupported const-set f8e4m3\"),\n                    DType::F64 => crate::bail!(\"unsupported const-set f64\"),\n                    DType::F4\n                    | DType::F6E2M3\n                    | DType::F6E3M2\n                    | DType::F8E8M0\n                    | DType::I16\n                    | DType::I32 => {\n                        return Err(Error::UnsupportedDTypeForOp(dtype, \"const-set\").bt())\n                    }\n                };\n                candle_metal_kernels::call_const_set_contiguous(\n                    &device.device,\n                    &encoder,\n                    &device.kernels,\n                    kernel_name,\n                    dtype.size_in_bytes(),\n                    el_count,\n                    s,\n                    dst,","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/metal_backend/mod.rs#L462-L498","documentation":"Thrown by candle's Metal backend when a const_set (fill_) is attempted on an F64 tensor. The generated Metal const-set kernels cover F16, BF16, F32, I64, U32 and U8 only; 64-bit float is not among them, so the backend rejects the op rather than running a missing kernel. Note F64 is generally second-class on Metal GPUs.","triggerScenarios":"Calling Tensor::fill_ / const_set with a Scalar::F64 on a tensor living on a Metal device, for either contiguous (metal_backend/mod.rs:480) or strided (mod.rs:511) layouts.","commonSituations":"Porting CUDA/CPU code that uses f64 tensors to macOS/Metal; scientific-computing defaults that assume f64; filling a float64 tensor with a constant before downcasting; code paths where the dtype was accidentally left at f64.","solutions":["Use F32 instead of F64: create/fill in DType::F32 and convert downstream if needed.","Fill the F64 tensor on CPU, then transfer to the Metal device with .to_device().","Cast to F32 with to_dtype, fill on Metal, cast back (accepting precision loss) only if an F64 result is truly required.","Run the operation on the CPU device instead of Metal for this step."],"exampleFix":"// before\nlet t = Tensor::zeros(shape, DType::F64, &metal_device)?;\nt.fill_(1.0f64)?; // unsupported const-set f64\n// after\nlet t = Tensor::zeros(shape, DType::F32, &metal_device)?;\nt.fill_(1.0f32)?;","handlingStrategy":"validation","validationCode":"fn ensure_fillable_on_metal(t: &candle_core::Tensor) -> Result<(), String> {\n    use candle_core::DType;\n    if t.device().is_metal() && t.dtype() == DType::F64 {\n        return Err(\"F64 const-set unsupported on Metal; use F32\".into());\n    }\n    Ok(())\n}","typeGuard":"fn is_metal_safe_fill_dtype(d: candle_core::DType) -> bool {\n    use candle_core::DType::*;\n    !matches!(d, F64 | F8E4M3 | F4 | F6E2M3 | F6E3M2 | F8E8M0 | I16 | I32)\n}","tryCatchPattern":"let filled = match t.fill_(v_f64) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"unsupported const-set f64\") => {\n        let mut t32 = t.to_dtype(DType::F32, t.device())?;\n        t32.fill_(v_f64)?;\n        t32\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Default to F32 for GPU (Metal) tensors; reserve F64 for CPU paths.","Check t.device() before choosing dtype in setup code.","Add an assert on dtype in tensor-construction helpers.","Test Metal pipelines for dtype-related failures in CI on macOS."],"tags":["metal","gpu","unsupported-dtype","f64","candle"],"backgroundTag":"unsupported-dtype-for-op","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}