{"record":{"id":"f30c375b0cd38395","repo":"huggingface/candle","slug":"metal-contiguous-unary-name-dtype-not-implem","errorCode":null,"errorMessage":"Metal contiguous unary {name} {dtype:?} not implemented","messagePattern":"Metal contiguous unary (.+?) (.+?) not implemented","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/metal_backend/mod.rs","lineNumber":743,"sourceCode":"                (\"usilu\", DType::BF16) => contiguous::silu::BFLOAT,\n                (\"usin\", DType::F16) => contiguous::sin::HALF,\n                (\"usin\", DType::F32) => contiguous::sin::FLOAT,\n                (\"usin\", DType::BF16) => contiguous::sin::BFLOAT,\n                (\"usqr\", DType::F16) => contiguous::sqr::HALF,\n                (\"usqr\", DType::F32) => contiguous::sqr::FLOAT,\n                (\"usqr\", DType::BF16) => contiguous::sqr::BFLOAT,\n                (\"usqrt\", DType::F16) => contiguous::sqrt::HALF,\n                (\"usqrt\", DType::F32) => contiguous::sqrt::FLOAT,\n                (\"usqrt\", DType::BF16) => contiguous::sqrt::BFLOAT,\n                (\"utanh\", DType::F16) => contiguous::tanh::HALF,\n                (\"utanh\", DType::F32) => contiguous::tanh::FLOAT,\n                (\"utanh\", DType::BF16) => contiguous::tanh::BFLOAT,\n                (\"usign\", DType::F16) => contiguous::sign::HALF,\n                (\"usign\", DType::F32) => contiguous::sign::FLOAT,\n                (\"usign\", DType::BF16) => contiguous::sign::BFLOAT,\n                (\"usign\", DType::I64) => contiguous::sign::I64,\n                (name, dtype) => {\n                    crate::bail!(\"Metal contiguous unary {name} {dtype:?} not implemented\")\n                }\n            };\n\n            candle_metal_kernels::call_unary_contiguous(\n                &device.device,\n                &encoder,\n                &device.kernels,\n                kernel_name,\n                dtype.size_in_bytes(),\n                el_count,\n                src,\n                &buffer,\n            )\n            .map_err(MetalError::from)?;\n        } else {\n            use candle_metal_kernels::unary::strided;\n            let kernel_name = match (B::KERNEL, dtype) {\n                (\"ucos\", DType::F32) => strided::cos::FLOAT,","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/metal_backend/mod.rs#L725-L761","documentation":"Metal contiguous unary ops (neg, exp, tanh, sign, etc.) are dispatched via a (op-name, dtype) kernel table. Requesting a unary op for a dtype without a matching Metal kernel hits this bail. Coverage is limited mostly to F32/F16/BF16 (and a few integer cases like sign on I64).","triggerScenarios":"Applying any unary op (exp, log, sin, sqrt, sign, relu, ...) to a Metal tensor whose dtype lacks a kernel, e.g. u8::sqrt or i64::exp via the contiguous path.","commonSituations":"Integer tensors on Metal being passed through math ops; fp16 model running an op implemented only for f32; quantized/int8 tensors needing float-only math.","solutions":["Cast the tensor to F32 (or F16/BF16) before the unary op, cast back afterwards","Perform the unary op on CPU for that tensor","Use a dtype supported for that specific op on Metal","Check candle_metal_kernels unary coverage and upgrade candle for newer kernels"],"exampleFix":"// before\nlet y = x_i64.exp()?; // fails on Metal\n// after\nlet y = x_i64.to_dtype(DType::F32)?.exp()?.to_dtype(DType::I64)?;","handlingStrategy":"fallback","validationCode":"const METAL_UNARY_FLOAT_ONLY: [&str; 2] = [\"exp\", \"log\"]; // ops without integer kernels\nlet needs_float = METAL_UNARY_FLOAT_ONLY.contains(op_name);\nif needs_float && !matches!(t.dtype(), DType::F32 | DType::F16 | DType::BF16) {\n    t = t.to_dtype(DType::F32)?;\n}","typeGuard":null,"tryCatchPattern":"match t.unary(op) {\n    Ok(y) => y,\n    Err(e) if e.to_string().contains(\"unary\") && e.to_string().contains(\"not implemented\") => {\n        let orig = t.dtype();\n        t.to_dtype(DType::F32)?.unary(op)?.to_dtype(orig)?\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Cast integer tensors to float before math-heavy GPU sections","Restrict Metal pipelines to F32/F16/BF16 for activations","Test every op in your graph on the Metal backend before deployment"],"tags":["metal","gpu","unary-op","dtype","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"}