huggingface/candle · error
{} is a dummy type and cannot be converted to scalar
Error message
{} is a dummy type and cannot be converted to scalar What it means
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.
Source
Thrown at candle-core/src/dummy_dtype.rs:49
impl WithDType for $ty {
const DTYPE: DType = DType::$dtype;
fn from_f64(_v: f64) -> Self {
panic!(
"{} is a dummy type and cannot be constructed",
stringify!($ty)
)
}
fn to_f64(self) -> f64 {
panic!(
"{} is a dummy type and cannot be converted",
stringify!($ty)
)
}
fn to_scalar(self) -> crate::scalar::Scalar {
panic!(
"{} is a dummy type and cannot be converted to scalar",
stringify!($ty)
)
}
fn cpu_storage_ref(_data: &[Self]) -> crate::CpuStorageRef<'_> {
panic!(
"{} is a dummy type and does not support storage",
stringify!($ty)
)
}
fn to_cpu_storage_owned(_data: Vec<Self>) -> crate::CpuStorage {
panic!(
"{} is a dummy type and does not support storage",
stringify!($ty)
)
}View on GitHub (pinned to d5fee525bf)
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.
Example fix
// before
let s = dummy_val.to_scalar(); // panics
// after
if tensor.dtype() == DType::F32 { let s = tensor.flatten_all()?.get(0)?.to_scalar::<f32>()?; } Defensive patterns
Strategy: validation
Validate before calling
fn extract_scalar_f32(t: &Tensor) -> Result<f32> {
if !is_supported_dtype(t.dtype()) {
return Err(Error::UnsupportedDTypeForOp(t.dtype(), "to_scalar").bt());
}
t.flatten_all()?.get(0)?.to_scalar::<f32>()
} Type guard
fn is_supported_dtype(dtype: DType) -> bool {
!matches!(dtype, DType::F6E2M3 | DType::F6E3M2 | DType::F4 | DType::F8E8M0)
} Try / catch
let r = std::panic::catch_unwind(|| dummy_val.to_scalar());
if r.is_err() { eprintln!("scalar extraction unsupported for dummy dtype"); } Prevention
- 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
When it happens
Trigger: 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).
Common situations: Extracting a single value from a tensor loaded from an experimental MX-format safetensors checkpoint; generic comparison helpers that wrap elements in Scalar.
Related errors
- {} is a dummy type and cannot be constructed
- {} is a dummy type and cannot be converted
- {} is a dummy type and does not support storage
- {} is a dummy type and does not support operations
- {} is a dummy type and does not support parsing
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/09ef61f79eb8993c.
Report an issue: GitHub.