huggingface/candle · error

cannot find {s} in metadata

Error message

cannot find {s} in metadata

What it means

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.

Source

Thrown at candle-transformers/src/models/quantized_qwen3.rs:470

    embed_tokens: Embedding,
    layers: Vec<LayerWeights>,
    norm: RmsNorm,
    lm_head: QMatMul,
    device: Device,
    dtype: DType,
    span: tracing::Span,
    span_output: tracing::Span,
}

impl ModelWeights {
    pub fn from_gguf<R: Read + Seek>(
        ct: gguf_file::Content,
        reader: &mut R,
        device: &Device,
    ) -> Result<Self> {
        let mut gg = Gguf::new(ct, reader, device.clone());
        let md_get = |s: &str| match gg.metadata().get(s) {
            None => candle::bail!("cannot find {s} in metadata"),
            Some(v) => Ok(v),
        };

        let num_attention_heads = md_get("qwen3.attention.head_count")?.to_u32()? as usize;
        let num_kv_heads = md_get("qwen3.attention.head_count_kv")?.to_u32()? as usize;
        let head_dim = md_get("qwen3.attention.key_length")?.to_u32()? as usize;
        let num_layers = md_get("qwen3.block_count")?.to_u32()? as usize;
        let hidden_size = md_get("qwen3.embedding_length")?.to_u32()? as usize;
        let max_position_embeddings = md_get("qwen3.context_length")?.to_u32()? as usize;
        let rms_norm_eps = md_get("qwen3.attention.layer_norm_rms_epsilon")?.to_f32()? as f64;
        let rope_freq_base = md_get("qwen3.rope.freq_base")?.to_f32()? as f64;

        let dtype = match gg.metadata().get("general.dtype") {
            Some(v) => match v.to_u32() {
                Ok(0) => DType::F32,
                Ok(1) => DType::F16,
                _ => DType::F16,
            },

View on GitHub (pinned to d5fee525bf)

Solutions

  1. 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)
  2. Re-quantize/re-export the model with a converter that emits the qwen3.* metadata keys
  3. Use the loader matching the file's actual architecture (e.g. quantized_qwen2) instead of quantized_qwen3

Example fix

// before (file has qwen2.* keys)
let model = quantized_qwen3::Model::from_gguf(content, &mut file, &device)?;
// after (verify architecture first, use matching loader)
let arch = content.metadata.get("general.architecture")?.to_string()?;
assert_eq!(arch, "qwen3");
let model = quantized_qwen3::Model::from_gguf(content, &mut file, &device)?;
Defensive patterns

Strategy: validation

Validate before calling

fn has_qwen3_metadata(md: &std::collections::HashMap<String, gguf_file::Value>) -> bool {
    ["qwen3.attention.head_count", "qwen3.attention.head_count_kv", "qwen3.attention.key_length"]
        .iter().all(|k| md.contains_key(*k))
}

Type guard

fn md<'a>(gg: &'a Gguf, key: &str) -> Option<&'a gguf_file::Value> {
    gg.metadata().get(key)
}

Try / catch

match quantized_qwen3::Model::from_gguf(content, &mut file, &device) {
    Ok(m) => m,
    Err(e) if e.to_string().contains("cannot find") => {
        anyhow::bail!("GGUF missing qwen3.* metadata: {e}; re-convert the model")
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: 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'.

Common situations: 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.

Related errors


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