{"record":{"id":"351878167d4adbbf","repo":"huggingface/candle","slug":"unsupported-const-set-f8e4m3","errorCode":null,"errorMessage":"unsupported const-set f8e4m3","messagePattern":"unsupported const-set f8e4m3","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/metal_backend/mod.rs","lineNumber":479,"sourceCode":"            l: &Layout,\n        ) -> 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,","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/metal_backend/mod.rs#L461-L497","documentation":"This error is thrown by candle's Metal backend when a constant-fill (const_set / fill_) operation is requested on an F8E4M3 (8-bit float) tensor. The Metal GPU kernels that write a scalar constant into a buffer are only generated for F16, BF16, F32, I64, U32 and U8, so F8E4M3 has no kernel to dispatch and the backend bails out instead of silently producing wrong data. It is a deliberate unimplemented-feature guard, not a user error in arguments.","triggerScenarios":"Calling Tensor::fill_ / const_set (e.g. via fill_, ones_like-with-fill, zero_-style in-place init) with deviceMetal on a tensor whose dtype is DType::F8E4M3, either on a contiguous layout (metal_backend/mod.rs:479) or a strided one (mod.rs:510).","commonSituations":"Quantized-model workloads on Apple Silicon: creating/initializing FP8 (F8E4M3) weights or scale buffers on a Metal device, converting a checkpoint to F8E4M3 and then initializing it with a constant, or generic code that fills a tensor without checking whether its dtype is Metal-supported.","solutions":["Fill the tensor in a supported dtype (e.g. F32) and then convert with to_dtype(DType::F8E4M3).","Create the F8E4M3 tensor on the CPU, fill it there, then move it to the Metal device with .to_device().","Use a construction API that writes data directly (Tensor::from_vec / from_slice) instead of const fill.","Contribute or wait for an F8E4M3 const-set Metal kernel in candle_metal_kernels."],"exampleFix":"// before\nlet t = Tensor::zeros((1024,), DType::F8E4M3, &device)?;\nt.fill_(0.5f64)?; // panics/errors: unsupported const-set f8e4m3\n// after\nlet t = Tensor::zeros((1024,), DType::F32, &device)?;\nt.fill_(0.5f64)?;\nlet t = t.to_dtype(DType::F8E4M3, device)?;","handlingStrategy":"validation","validationCode":"fn metal_const_set_supported(t: &candle_core::Tensor) -> Result<(), String> {\n    use candle_core::DType;\n    match t.dtype() {\n        DType::F16 | DType::BF16 | DType::F32 | DType::I64 | DType::U32 | DType::U8 => Ok(()),\n        other => Err(format!(\"const-set on Metal unsupported for dtype {:?}; fill in F32 then convert\", other)),\n    }\n}","typeGuard":"fn is_metal_fill_dtype(d: candle_core::DType) -> bool {\n    use candle_core::DType::*;\n    matches!(d, F16 | BF16 | F32 | I64 | U32 | U8)\n}","tryCatchPattern":"match t.fill_(v) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"unsupported const-set\") => {\n        let mut t = Tensor::zeros(t.shape(), DType::F32, t.device())?;\n        t.fill_(v)?;\n        t.to_dtype(DType::F8E4M3, t.device())?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Never const-fill FP8 (F8E4M3) tensors directly on Metal; build them from F32 then convert.","Centralize tensor creation in a helper that checks dtype support for the target device.","Keep a support matrix of candle ops x dtypes x backends for the ops you use.","Pin and review candle Metal backend changes when upgrading versions."],"tags":["metal","gpu","unsupported-dtype","fp8","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"}