{"record":{"id":"30013b74eecb2eb9","repo":"huggingface/candle","slug":"metal-device-does-not-yet-support-f8e4m3","errorCode":null,"errorMessage":"Metal device does not yet support F8E4M3.","messagePattern":"Metal device does not yet support F8E4M3\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/sort.rs","lineNumber":193,"sourceCode":"        storage: &crate::MetalStorage,\n        layout: &crate::Layout,\n    ) -> Result<(crate::MetalStorage, crate::Shape)> {\n        use crate::backend::BackendStorage;\n        use crate::DType;\n\n        let name = {\n            if self.asc {\n                match storage.dtype() {\n                    DType::BF16 => \"asort_asc_bf16\",\n                    DType::F16 => \"asort_asc_f16\",\n                    DType::F32 => \"asort_asc_f32\",\n                    DType::F64 => \"asort_asc_f64\",\n                    DType::U8 => \"asort_asc_u8\",\n                    DType::U32 => \"asort_asc_u32\",\n                    DType::I16 => \"asort_asc_i16\",\n                    DType::I32 => \"asort_asc_i32\",\n                    DType::I64 => \"asort_asc_i64\",\n                    DType::F8E4M3 => crate::bail!(\"Metal device does not yet support F8E4M3.\"),\n                    DType::F6E2M3 | DType::F6E3M2 | DType::F4 | DType::F8E8M0 => {\n                        return Err(\n                            crate::Error::UnsupportedDTypeForOp(storage.dtype(), \"argsort\").bt(),\n                        )\n                    }\n                }\n            } else {\n                match storage.dtype() {\n                    DType::BF16 => \"asort_desc_bf16\",\n                    DType::F16 => \"asort_desc_f16\",\n                    DType::F32 => \"asort_desc_f32\",\n                    DType::F64 => \"asort_desc_f64\",\n                    DType::U8 => \"asort_desc_u8\",\n                    DType::U32 => \"asort_desc_u32\",\n                    DType::I16 => \"asort_desc_i16\",\n                    DType::I32 => \"asort_desc_i32\",\n                    DType::I64 => \"asort_desc_i64\",\n                    DType::F8E4M3 => crate::bail!(\"Metal device does not yet support F8E4M3.\"),","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/sort.rs#L175-L211","documentation":"The Metal argsort kernel set has no F8E4M3 variant, so metal_fwd explicitly bails when asked to argsort an F8E4M3 tensor. Other exotic float types (F6E2M3, F6E3M2, F4, F8E8M0) raise the related UnsupportedDTypeForOp error instead.","triggerScenarios":"Calling arg_sort (or sort that routes through argsort) on a tensor whose dtype is F8E4M3 while running on the Metal backend (Apple Silicon GPU).","commonSituations":"Casting activations/weights to fp8 (F8E4M3) for inference on macOS/Metal and then sorting logits or values; porting CUDA fp8 pipelines to Metal.","solutions":["Cast to a supported dtype before sorting: tensor.to_dtype(DType::F32)? then arg_sort","Perform the argsort on CPU (move the tensor with .to_device(&Device::Cpu)?)","Avoid fp8 tensors on the Metal backend for sort-like ops; keep them only where supported kernels exist"],"exampleFix":"// before\nlet idx = x.arg_sort(Ascending)?; // x: F8E4M3 on Metal\n// after\nlet idx = x.to_dtype(DType::F32)?.arg_sort(Ascending)?;","handlingStrategy":"fallback","validationCode":"if x.dtype() == candle::DType::F8E4M3 && x.device().is_metal() {\n    x = x.to_dtype(candle::DType::F32)?;\n}\nlet idx = x.arg_sort(Ascending)?;","typeGuard":null,"tryCatchPattern":"let idx = x.arg_sort(Ascending).or_else(|_| {\n    if x.device().is_metal() { x.to_dtype(candle::DType::F32)?.arg_sort(Ascending) } else { unreachable!() }\n})?;","preventionTips":["Avoid fp8 (F8E4M3) tensors on the Metal backend for sort/argsort","Cast to F32/F16 before GPU ops with limited dtype kernel coverage on Metal","Check candle's Metal kernel list before porting fp8 CUDA pipelines to macOS"],"tags":["candle","metal","argsort","fp8","unsupported"],"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"}