{"record":{"id":"e06aef10146faf95","repo":"huggingface/candle","slug":"metal-strided-unary-name-dtype-not-implement","errorCode":null,"errorMessage":"Metal strided unary {name} {dtype:?} not implemented","messagePattern":"Metal strided unary (.+?) (.+?) not implemented","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/metal_backend/mod.rs","lineNumber":816,"sourceCode":"                (\"usin\", DType::BF16) => strided::sin::BFLOAT,\n                (\"usqr\", DType::BF16) => strided::sqr::BFLOAT,\n                (\"usqrt\", DType::BF16) => strided::sqrt::BFLOAT,\n                (\"uneg\", DType::BF16) => strided::neg::BFLOAT,\n                (\"uexp\", DType::BF16) => strided::exp::BFLOAT,\n                (\"ulog\", DType::BF16) => strided::log::BFLOAT,\n                (\"ugelu\", DType::BF16) => strided::gelu::BFLOAT,\n                (\"ugelu_erf\", DType::BF16) => strided::gelu_erf::BFLOAT,\n                (\"uerf\", DType::BF16) => strided::erf::BFLOAT,\n                (\"usilu\", DType::BF16) => strided::silu::BFLOAT,\n                (\"uabs\", DType::BF16) => strided::abs::BFLOAT,\n                (\"uceil\", DType::BF16) => strided::ceil::BFLOAT,\n                (\"ufloor\", DType::BF16) => strided::floor::BFLOAT,\n                (\"urelu\", DType::BF16) => strided::relu::BFLOAT,\n                (\"uround\", DType::BF16) => strided::round::BFLOAT,\n                (\"utanh\", DType::BF16) => strided::tanh::BFLOAT,\n\n                (name, dtype) => {\n                    crate::bail!(\"Metal strided unary {name} {dtype:?} not implemented\")\n                }\n            };\n            let dst = BufferOffset::zero_offset(&buffer);\n            candle_metal_kernels::call_unary_strided(\n                &device.device,\n                &encoder,\n                &device.kernels,\n                kernel_name,\n                layout.dims(),\n                src,\n                layout.stride(),\n                dst,\n            )\n            .map_err(MetalError::from)?;\n        }\n\n        Ok(Self::new(buffer, device.clone(), el_count, dtype))\n    }","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/metal_backend/mod.rs#L798-L834","documentation":"Same as the contiguous case but for strided unary ops on Metal: the (name, dtype) lookup in the strided table fails and the library bails. Non-contiguous tensors (views from transpose/slice) require the strided kernel set, which has even narrower dtype coverage.","triggerScenarios":"Applying a unary op to a non-contiguous Metal tensor whose (op, dtype) pair is not in the strided table, e.g. floor/round/tanh on strided integer tensors.","commonSituations":"Math on transposed or sliced activations in fp16/bf16 pipelines; rounding strided f32 tensors from custom sampling loops; integer strided views needing float ops.","solutions":["Call .contiguous() before the unary op so the contiguous kernel path is used","Cast to a supported dtype (F32/F16/BF16) before the op","Reorder ops so the unary op runs while the tensor is still contiguous","Run the op on CPU"],"exampleFix":"// before\nlet y = x_t.floor()?; // x_t is a transposed f16 view on Metal\n// after\nlet y = x_t.contiguous()?.floor()?;","handlingStrategy":"fallback","validationCode":"if !t.is_contiguous() { t = t.contiguous()?; }\nif !matches!(t.dtype(), DType::F32 | DType::F16 | DType::BF16) { t = t.to_dtype(DType::F32)?; }\nlet y = t.unary(op)?;","typeGuard":null,"tryCatchPattern":"match t.unary(op) {\n    Ok(y) => y,\n    Err(e) if e.to_string().contains(\"strided unary\") => t.contiguous()?.unary(op),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Materialize views (.contiguous()) before unary math on Metal","Avoid running unary ops on transposed/sliced integer tensors","Cast to a float dtype before the op"],"tags":["metal","gpu","unary-op","strided","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"}