{"record":{"id":"09ef61f79eb8993c","repo":"huggingface/candle","slug":"is-a-dummy-type-and-cannot-be-converted-to-scal","errorCode":null,"errorMessage":"{} is a dummy type and cannot be converted to scalar","messagePattern":"(.+?) is a dummy type and cannot be converted to scalar","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/dummy_dtype.rs","lineNumber":49,"sourceCode":"        impl WithDType for $ty {\n            const DTYPE: DType = DType::$dtype;\n\n            fn from_f64(_v: f64) -> Self {\n                panic!(\n                    \"{} is a dummy type and cannot be constructed\",\n                    stringify!($ty)\n                )\n            }\n\n            fn to_f64(self) -> f64 {\n                panic!(\n                    \"{} is a dummy type and cannot be converted\",\n                    stringify!($ty)\n                )\n            }\n\n            fn to_scalar(self) -> crate::scalar::Scalar {\n                panic!(\n                    \"{} is a dummy type and cannot be converted to scalar\",\n                    stringify!($ty)\n                )\n            }\n\n            fn cpu_storage_ref(_data: &[Self]) -> crate::CpuStorageRef<'_> {\n                panic!(\n                    \"{} is a dummy type and does not support storage\",\n                    stringify!($ty)\n                )\n            }\n\n            fn to_cpu_storage_owned(_data: Vec<Self>) -> crate::CpuStorage {\n                panic!(\n                    \"{} is a dummy type and does not support storage\",\n                    stringify!($ty)\n                )\n            }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/dummy_dtype.rs#L31-L67","documentation":"Dummy types' WithDType::to_scalar implementation panics unconditionally: F6E2M3, F6E3M2, F4 and F8E8M0 cannot produce a Scalar because they are unimplemented placeholders in candle-core. Calling it on any dummy-typed value always aborts.","triggerScenarios":"Calling WithDType::to_scalar on a value of type F6E2M3/F6E3M2/F4/F8E8M0, or generic APIs that build a crate::scalar::Scalar from an element of a dummy-dtype tensor (e.g. scalar extraction from Tensor::get/allclose-style comparisons).","commonSituations":"Extracting a single value from a tensor loaded from an experimental MX-format safetensors checkpoint; generic comparison helpers that wrap elements in Scalar.","solutions":["Check tensor dtype and convert to a supported dtype (F32/BF16/F16) before extracting scalars.","Reject experimental MX dtypes at load time rather than processing them.","Use the typed Error path (cpu_storage_data/cpu_storage_as_slice return UnsupportedDTypeForOp) instead of the panicking value-level APIs when probing support.","Implement the format in a fork of candle if MX support is required."],"exampleFix":"// before\nlet s = dummy_val.to_scalar(); // panics\n// after\nif tensor.dtype() == DType::F32 { let s = tensor.flatten_all()?.get(0)?.to_scalar::<f32>()?; }","handlingStrategy":"validation","validationCode":"fn extract_scalar_f32(t: &Tensor) -> Result<f32> {\n    if !is_supported_dtype(t.dtype()) {\n        return Err(Error::UnsupportedDTypeForOp(t.dtype(), \"to_scalar\").bt());\n    }\n    t.flatten_all()?.get(0)?.to_scalar::<f32>()\n}","typeGuard":"fn is_supported_dtype(dtype: DType) -> bool {\n    !matches!(dtype, DType::F6E2M3 | DType::F6E3M2 | DType::F4 | DType::F8E8M0)\n}","tryCatchPattern":"let r = std::panic::catch_unwind(|| dummy_val.to_scalar());\nif r.is_err() { eprintln!(\"scalar extraction unsupported for dummy dtype\"); }","preventionTips":["Verify dtype before extracting scalars from tensors","Prefer the Result-returning WithDType methods (cpu_storage_data) when probing support","Convert unknown-dtype tensors to F32 before Scalar extraction","Avoid generic Scalar-building helpers over dummy-typed elements"],"tags":["rust","panic","unsupported-dtype","candle"],"backgroundTag":"unsupported-dtype","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}