{"record":{"id":"b9339693206970b7","repo":"huggingface/candle","slug":"cannot-find-s-in-metadata-b93396","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_moe.rs","lineNumber":253,"sourceCode":"pub struct GGUFQWenMoE {\n    tok_embeddings: Embedding,\n    layers: Vec<LayerWeights>,\n    norm: RmsNorm,\n    output: QMatMul,\n    dtype: DType,\n    device: Device,\n}\n\nimpl GGUFQWenMoE {\n    pub fn from_gguf<R: std::io::Seek + std::io::Read>(\n        ct: gguf_file::Content,\n        reader: &mut R,\n        device: &Device,\n        dtype: DType,\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        let arch = md_get(\"general.architecture\")?.to_string()?;\n\n        let head_count =\n            md_get(format!(\"{arch}.attention.head_count\").as_str())?.to_u32()? as usize;\n        let head_count_kv =\n            md_get(format!(\"{arch}.attention.head_count_kv\").as_str())?.to_u32()? as usize;\n\n        let head_dim = md_get(format!(\"{arch}.attention.key_length\").as_str());\n        let embedding_length =\n            md_get(format!(\"{arch}.embedding_length\").as_str())?.to_u32()? as usize;\n        let head_dim = if let Ok(head_dim) = head_dim {\n            head_dim.to_u32()? as usize\n        } else {\n            embedding_length / head_count\n        };\n        let context_length = md_get(format!(\"{arch}.context_length\").as_str())?.to_u32()? as usize;","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/quantized_qwen3_moe.rs#L235-L271","documentation":"Thrown by quantized_qwen3_moe::Model::from_gguf when a metadata key required by the MoE loader is missing from the GGUF content. Unlike the dense loader, this one first reads general.architecture and then builds keys like '{arch}.attention.head_count' dynamically, so any missing '{arch}.*' key (head counts, expert counts, feed_forward sizes, etc.) triggers this bail.","triggerScenarios":"Calling quantized_qwen3_moe::Model::from_gguf with a GGUF whose metadata lacks general.architecture, or any '{arch}.attention.head_count', '{arch}.attention.head_count_kv', '{arch}.expert_count', '{arch}.expert_used_count' or similar derived key.","commonSituations":"Loading a MoE GGUF exported by a tool that omits expert metadata; passing a non-MoE or differently-prefixed GGUF to the MoE loader; hand-edited GGUF metadata.","solutions":["Dump the GGUF metadata and confirm general.architecture plus all '{arch}.*' keys the MoE loader expects (attention head counts, expert_count, expert_used_count, feed_forward lengths)","Re-convert the checkpoint with an up-to-date exporter that writes complete qwen3-moe metadata","Load with the correct model module for the file's architecture (e.g. quantized_qwen3 for dense files)"],"exampleFix":"// before (missing expert keys in a dense qwen3 GGUF)\nlet model = quantized_qwen3_moe::Model::from_gguf(content, &mut file, &device, dtype)?;\n// after (route by architecture)\nlet arch = content.metadata.get(\"general.architecture\")?.to_string()?;\nlet model = match arch.as_str() {\n    \"qwen3moe\" | \"qwen3-moe\" => quantized_qwen3_moe::Model::from_gguf(content, &mut file, &device, dtype)?,\n    _ => quantized_qwen3::Model::from_gguf(content, &mut file, &device)?,\n};","handlingStrategy":"validation","validationCode":"let arch = content.metadata.get(\"general.architecture\")?.to_string()?;\nlet head_count_key = format!(\"{arch}.attention.head_count\");\nif !content.metadata.contains_key(&head_count_key) {\n    anyhow::bail!(\"GGUF lacks {head_count_key}; wrong loader or incomplete conversion\");\n}","typeGuard":"fn moe_keys_present(md: &std::collections::HashMap<String, gguf_file::Value>, arch: &str) -> bool {\n    md.contains_key(&format!(\"{arch}.expert_count\"))\n        && md.contains_key(&format!(\"{arch}.attention.head_count\"))\n}","tryCatchPattern":"match quantized_qwen3_moe::Model::from_gguf(content, &mut file, &device, dtype) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"cannot find\") => {\n        anyhow::bail!(\"incomplete MoE GGUF metadata: {e}\")\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Read general.architecture first and route to the matching model module","Validate expert_count/expert_used_count keys exist for MoE files","Re-convert with the latest llama.cpp/convert script if keys are missing"],"tags":["rust","candle","gguf","moe","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"}