huggingface/candle · error

not a f64 {v:?}

Error message

not a f64 {v:?}

What it means

Value::to_f64 throws this when the Value holds any variant other than F64. GGUF metadata values are stored with an explicit type tag, and candle refuses implicit conversions between them. The message includes a Debug dump of the actual value so you can see what type is really there.

Source

Thrown at candle-core/src/quantized/gguf_file.rs:294

    pub fn to_i64(&self) -> Result<i64> {
        match self {
            Self::I64(v) => Ok(*v),
            v => crate::bail!("not a i64 {v:?}"),
        }
    }

    pub fn to_f32(&self) -> Result<f32> {
        match self {
            Self::F32(v) => Ok(*v),
            v => crate::bail!("not a f32 {v:?}"),
        }
    }

    pub fn to_f64(&self) -> Result<f64> {
        match self {
            Self::F64(v) => Ok(*v),
            v => crate::bail!("not a f64 {v:?}"),
        }
    }

    pub fn to_bool(&self) -> Result<bool> {
        match self {
            Self::Bool(v) => Ok(*v),
            v => crate::bail!("not a bool {v:?}"),
        }
    }

    pub fn to_vec(&self) -> Result<&Vec<Value>> {
        match self {
            Self::Array(v) => Ok(v),
            v => crate::bail!("not a vec {v:?}"),
        }
    }

    pub fn to_string(&self) -> Result<&String> {

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Use .to_f32() if the value was written as F32 (the usual GGUF float width).
  2. Read the actual variant from the error text and call the corresponding accessor.
  3. Match on the Value enum to accept both F32 and F64 explicitly.
  4. Regenerate the GGUF file writing the field as ValueType::F64.

Example fix

// before
let freq_base = value.to_f64()?;
// after
let freq_base = match value {
    gguf_file::Value::F64(v) => v,
    gguf_file::Value::F32(v) => v as f64,
    other => candle_core::bail!("unexpected rope.freq_base {other:?}"),
};
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_f64(v: &gguf_file::Value) -> bool { matches!(v, gguf_file::Value::F64(_)) }
if !is_f64(value) { bail!("expected f64 metadata, got {value:?}"); }

Type guard

fn as_f64(v: &gguf_file::Value) -> Option<f64> {
    if let gguf_file::Value::F64(x) = v { Some(*x) } else { None }
}

Try / catch

let f = match value.to_f64() {
    Ok(f) => f,
    Err(_) => value.to_f32().map(|x| x as f64).unwrap_or(DEFAULT_FREQ_BASE),
};

Prevention

When it happens

Trigger: Calling .to_f64() on a metadata value that is F32, an integer type (U8..I64), String, Bool, or Array — e.g. reading 'rope.freq_base' that a writer emitted as f32.

Common situations: Reading GGUF files from tools (llama.cpp converters) that store floats as f32 by default; assuming a field is f64 because Rust literals default to f64; parsing a hand-built GGUF test file with the wrong ValueType.

Related errors


AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02). Data as JSON: /api/errors/b7ffa8e0d0209a4a. Report an issue: GitHub.