{"record":{"id":"8e0b5f4ff1dd3681","repo":"huggingface/candle","slug":"not-a-f32-v","errorCode":null,"errorMessage":"not a f32 {v:?}","messagePattern":"not a f32 (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/gguf_file.rs","lineNumber":287,"sourceCode":"            Self::U8(v) => Ok(*v as u64),\n            Self::U16(v) => Ok(*v as u64),\n            Self::U32(v) => Ok(*v as u64),\n            Self::Bool(v) => Ok(*v as u64),\n            v => crate::bail!(\"not a u64 or upcastable to u64 {v:?}\"),\n        }\n    }\n\n    pub fn to_i64(&self) -> Result<i64> {\n        match self {\n            Self::I64(v) => Ok(*v),\n            v => crate::bail!(\"not a i64 {v:?}\"),\n        }\n    }\n\n    pub fn to_f32(&self) -> Result<f32> {\n        match self {\n            Self::F32(v) => Ok(*v),\n            v => crate::bail!(\"not a f32 {v:?}\"),\n        }\n    }\n\n    pub fn to_f64(&self) -> Result<f64> {\n        match self {\n            Self::F64(v) => Ok(*v),\n            v => crate::bail!(\"not a f64 {v:?}\"),\n        }\n    }\n\n    pub fn to_bool(&self) -> Result<bool> {\n        match self {\n            Self::Bool(v) => Ok(*v),\n            v => crate::bail!(\"not a bool {v:?}\"),\n        }\n    }\n\n    pub fn to_vec(&self) -> Result<&Vec<Value>> {","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/gguf_file.rs#L269-L305","documentation":"This error is thrown by Value::to_f32 in candle's GGUF reader when you ask a GGUF metadata value to be an f32 but the Value enum actually holds a different variant (e.g. String, U32, Array). GGUF metadata values are tagged unions, so conversion only succeeds when the variant matches exactly; candle bails instead of coercing. The {v:?} in the message prints the actual variant that was found.","triggerScenarios":"Calling .to_f32() on a Value read from a GGUF file whose metadata entry is not ValueType::F32, e.g. a model's 'embedding_length' stored as u32 (the common case) or a string field like 'general.architecture'.","commonSituations":"Hand-parsing GGUF headers with gguf_file::Content::read and assuming numeric fields are f32 when GGUF spec defaults them to u32/u64; reading a file produced by a converter that wrote f64 or u32; typos in field names picking up the wrong metadata entry.","solutions":["Call .to_u32()/.to_u64() instead if the field was written as an integer (most GGUF numeric metadata is u32).","Inspect the error's {v:?} payload to see the real variant and use the matching accessor (to_f64, to_string, to_vec, ...).","Match on the Value enum directly and handle multiple variants instead of using a fixed accessor.","Fix the GGUF writing side to emit ValueType::F32 if the field genuinely should be a float."],"exampleFix":"// before\nlet emb_len = value.to_f32()?;\n// after\nlet emb_len = match value {\n    gguf_file::Value::U32(v) => v as f32,\n    gguf_file::Value::F32(v) => v,\n    other => candle_core::bail!(\"unexpected embedding_length {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"fn is_f32(v: &gguf_file::Value) -> bool { matches!(v, gguf_file::Value::F32(_)) }\nif !is_f32(value) { bail!(\"expected f32 metadata, got {value:?}\"); }","typeGuard":"fn as_f32(v: &gguf_file::Value) -> Option<f32> {\n    if let gguf_file::Value::F32(x) = v { Some(*x) } else { None }\n}","tryCatchPattern":"let f = match value.to_f32() {\n    Ok(f) => f,\n    Err(e) => { eprintln!(\"gguf f32 field mismatch: {e}\"); return fallback_default; }\n};","preventionTips":["Match on the Value enum instead of calling fixed accessors when field types may vary","Remember GGUF numeric metadata is usually u32/u64, not f32","Log the Debug form of the Value on mismatch to identify the real type","Validate key types once after Content::read, before business logic"],"tags":["candle","gguf","type-mismatch"],"backgroundTag":"unexpected-value-type","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}