{"record":{"id":"1c476b7edb92d869","repo":"huggingface/candle","slug":"metal-strided-to-dtype-left-right-not-impl","errorCode":null,"errorMessage":"Metal strided to_dtype {left:?} {right:?} not implemented","messagePattern":"Metal strided to_dtype (.+?) (.+?) not implemented","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/metal_backend/mod.rs","lineNumber":650,"sourceCode":"                (DType::I64, DType::BF16) => \"cast_i64_bf16_strided\",\n                (DType::I64, DType::F16) => \"cast_i64_f16_strided\",\n                (DType::I64, DType::U32) => \"cast_i64_u32_strided\",\n                (DType::I64, DType::U8) => \"cast_i64_u8_strided\",\n\n                (DType::U32, DType::BF16) => \"cast_u32_bf16_strided\",\n                (DType::U32, DType::F16) => \"cast_u32_f16_strided\",\n                (DType::U32, DType::F32) => \"cast_u32_f32_strided\",\n                (DType::U32, DType::I64) => \"cast_u32_i64_strided\",\n                (DType::U32, DType::U8) => \"cast_u32_u8_strided\",\n\n                (DType::U8, DType::BF16) => \"cast_u8_bf16_strided\",\n                (DType::U8, DType::F16) => \"cast_u8_f16_strided\",\n                (DType::U8, DType::F32) => \"cast_u8_f32_strided\",\n                (DType::U8, DType::I64) => \"cast_u8_i64_strided\",\n                (DType::U8, DType::U32) => \"cast_u8_u32_strided\",\n\n                (left, right) => {\n                    crate::bail!(\"Metal strided to_dtype {left:?} {right:?} not implemented\")\n                }\n            };\n            candle_metal_kernels::call_cast_strided(\n                &device.device,\n                &encoder,\n                &device.kernels,\n                kernel_name,\n                layout.dims(),\n                src,\n                layout.stride(),\n                &buffer,\n            )\n            .map_err(MetalError::from)?;\n        }\n        Ok(Self::new(buffer, device.clone(), el_count, dtype))\n    }\n\n    fn unary_impl<B: UnaryOpT>(&self, layout: &Layout) -> Result<Self> {","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/metal_backend/mod.rs#L632-L668","documentation":"The strided (non-contiguous) Metal to_dtype path has its own kernel table; a cast between dtype pairs missing from that table triggers this bail. Strided layouts arise from slicing, transposing, or other view ops, so the same cast may work contiguous but fail strided.","triggerScenarios":"Calling to_dtype on a non-contiguous Metal tensor (e.g. after transpose/slice/narrow) with a dtype pair absent from the strided cast table.","commonSituations":"Casting a transposed activation map to fp16 on Metal; converting slices of embedding tables; working with permuted tensors in inference graphs.","solutions":["Make the tensor contiguous first: tensor.contiguous()?.to_dtype(dtype)?","Cast before the op that creates the strided layout","Cast on CPU and move back to Metal","Use a dtype pair present in the strided cast table"],"exampleFix":"// before\nlet t = tensor.transpose(0, 1)?.to_dtype(DType::F16)?;\n// after\nlet t = tensor.transpose(0, 1)?.contiguous()?.to_dtype(DType::F16)?;","handlingStrategy":"fallback","validationCode":"if !tensor.is_contiguous() {\n    tensor = tensor.contiguous()?; // use contiguous cast path\n}\ntensor = tensor.to_dtype(target)?;","typeGuard":null,"tryCatchPattern":"match strided_tensor.to_dtype(target) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"strided to_dtype\") => {\n        strided_tensor.contiguous()?.to_dtype(target)?\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Call .contiguous() after transpose/slice before dtype conversion","Cast tensors while they are still contiguous in the dataflow","Keep GPU tensors in dtypes with full strided cast coverage (F32/F16/BF16)"],"tags":["metal","gpu","dtype-cast","strided","candle"],"backgroundTag":"unsupported-dtype-cast","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}