{"record":{"id":"5f34e2158fb8634f","repo":"huggingface/candle","slug":"cannot-find-s-in-metadata-5f34e2","errorCode":null,"errorMessage":"cannot find {s} in metadata","messagePattern":"cannot find (.+?) in metadata","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/quantized_qwen3.rs","lineNumber":470,"sourceCode":"    embed_tokens: Embedding,\n    layers: Vec<LayerWeights>,\n    norm: RmsNorm,\n    lm_head: QMatMul,\n    device: Device,\n    dtype: DType,\n    span: tracing::Span,\n    span_output: tracing::Span,\n}\n\nimpl ModelWeights {\n    pub fn from_gguf<R: Read + Seek>(\n        ct: gguf_file::Content,\n        reader: &mut R,\n        device: &Device,\n    ) -> Result<Self> {\n        let mut gg = Gguf::new(ct, reader, device.clone());\n        let md_get = |s: &str| match gg.metadata().get(s) {\n            None => candle::bail!(\"cannot find {s} in metadata\"),\n            Some(v) => Ok(v),\n        };\n\n        let num_attention_heads = md_get(\"qwen3.attention.head_count\")?.to_u32()? as usize;\n        let num_kv_heads = md_get(\"qwen3.attention.head_count_kv\")?.to_u32()? as usize;\n        let head_dim = md_get(\"qwen3.attention.key_length\")?.to_u32()? as usize;\n        let num_layers = md_get(\"qwen3.block_count\")?.to_u32()? as usize;\n        let hidden_size = md_get(\"qwen3.embedding_length\")?.to_u32()? as usize;\n        let max_position_embeddings = md_get(\"qwen3.context_length\")?.to_u32()? as usize;\n        let rms_norm_eps = md_get(\"qwen3.attention.layer_norm_rms_epsilon\")?.to_f32()? as f64;\n        let rope_freq_base = md_get(\"qwen3.rope.freq_base\")?.to_f32()? as f64;\n\n        let dtype = match gg.metadata().get(\"general.dtype\") {\n            Some(v) => match v.to_u32() {\n                Ok(0) => DType::F32,\n                Ok(1) => DType::F16,\n                _ => DType::F16,\n            },","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/quantized_qwen3.rs#L452-L488","documentation":"Thrown by quantized_qwen3::Model::from_gguf when a required metadata key (e.g. qwen3.attention.head_count, head_count_kv, key_length, etc.) is absent from the GGUF file's Content metadata map. The loader reads hardcoded 'qwen3.*' keys, so a GGUF written for a different architecture or a nonstandard exporter cannot be loaded.","triggerScenarios":"Calling quantized_qwen3::Model::from_gguf on a GGUF file whose metadata lacks any 'qwen3.attention.*' / 'qwen3.*' key the loader reads; the md_get closure bails with 'cannot find {s} in metadata'.","commonSituations":"Loading a GGUF quantized with a tool that writes 'qwen2.*' or generic keys instead of 'qwen3.*'; using a merged/converted GGUF missing attention metadata; loading a GGUF of a different architecture with the qwen3 loader by mistake.","solutions":["Verify the GGUF's general.architecture is qwen3 and that qwen3.attention.head_count, head_count_kv, key_length and other qwen3.* keys exist (llama-gguf CLI or a hex/metadata dump)","Re-quantize/re-export the model with a converter that emits the qwen3.* metadata keys","Use the loader matching the file's actual architecture (e.g. quantized_qwen2) instead of quantized_qwen3"],"exampleFix":"// before (file has qwen2.* keys)\nlet model = quantized_qwen3::Model::from_gguf(content, &mut file, &device)?;\n// after (verify architecture first, use matching loader)\nlet arch = content.metadata.get(\"general.architecture\")?.to_string()?;\nassert_eq!(arch, \"qwen3\");\nlet model = quantized_qwen3::Model::from_gguf(content, &mut file, &device)?;","handlingStrategy":"validation","validationCode":"fn has_qwen3_metadata(md: &std::collections::HashMap<String, gguf_file::Value>) -> bool {\n    [\"qwen3.attention.head_count\", \"qwen3.attention.head_count_kv\", \"qwen3.attention.key_length\"]\n        .iter().all(|k| md.contains_key(*k))\n}","typeGuard":"fn md<'a>(gg: &'a Gguf, key: &str) -> Option<&'a gguf_file::Value> {\n    gg.metadata().get(key)\n}","tryCatchPattern":"match quantized_qwen3::Model::from_gguf(content, &mut file, &device) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"cannot find\") => {\n        anyhow::bail!(\"GGUF missing qwen3.* metadata: {e}; re-convert the model\")\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Inspect GGUF metadata (general.architecture) before choosing the loader","Use a current quantization tool that emits qwen3.* keys","Never hand-edit GGUF metadata keys"],"tags":["rust","candle","gguf","missing-metadata"],"backgroundTag":"missing-metadata-key","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}