huggingface/candle · error
empty codebooks
Error message
empty codebooks
What it means
The quantizer/dequantizer accumulation helper sums per-codebook contributions into an Option<Tensor>; if there were zero codebooks to iterate over, sum stays None and the function bails with 'empty codebooks'. It guarantees the function never silently returns an empty result, but indicates the model config defined no codebooks.
Source
Thrown at candle-transformers/src/models/snac.rs:718
Ok((z_q, codes))
}
#[allow(clippy::wrong_self_convention)]
fn from_codes(&self, codes: &[&Tensor]) -> Result<Tensor> {
let mut sum = None;
for (quantizer, codes) in self.quantizers.iter().zip(codes.iter()) {
let z_p_i = quantizer.decode_code(codes)?;
let z_q_i = z_p_i.apply(&quantizer.out_proj)?;
let z_q_i = repeat_interleave(&z_q_i, quantizer.stride, D::Minus1)?;
let s = match sum {
None => z_q_i,
Some(s) => (s + z_q_i)?,
};
sum = Some(s)
}
match sum {
Some(s) => Ok(s),
None => candle::bail!("empty codebooks"),
}
}
}
fn gcd(mut a: usize, mut b: usize) -> usize {
while b != 0 {
let t = b;
b = a % b;
a = t;
}
a
}
fn lcm(a: usize, b: usize) -> usize {
a / gcd(a, b) * b
}
// https://github.com/hubertsiuzdak/snac/blob/main/snac/snac.pyView on GitHub (pinned to d5fee525bf)
Solutions
- Verify the SNAC config specifies a positive number of codebooks (e.g. codebook_size/quantizer count > 0)
- Check VarBuilder checkpoint keys match expected codebook naming so all codebooks load
- Inspect how the codebooks vector is populated; ensure it is filled before forward is called
Example fix
// before let quantizer = SnacQuantizer::new(cfg_with_zero_codebooks, vb)?; // after assert!(cfg.num_codebooks > 0); let quantizer = SnacQuantizer::new(cfg, vb)?;
Defensive patterns
Strategy: validation
Validate before calling
if cfg.num_codebooks == 0 {
return Err(anyhow::anyhow!("SNAC config must define at least one codebook"));
} Try / catch
match quantizer.forward(&z) {
Ok(out) => out,
Err(e) if e.to_string().contains("empty codebooks") => {
anyhow::bail!("SNAC quantizer has no codebooks loaded — check checkpoint keys")
}
Err(e) => return Err(e.into()),
} Prevention
- Validate codebook count > 0 right after config load
- Log the number of codebook weights successfully loaded from VarBuilder
- Use vb.pp prefixes matching the checkpoint layout and assert on missing tensors
When it happens
Trigger: Calling the forward/dequantize path of the SNAC quantizer with a model whose codebook list is empty (no codebook weights loaded or codebook count 0 in config).
Common situations: Constructing Snac/quantizer from a config with num_quantizers=0; VarBuilder names mismatching so codebook weights are never loaded into the vector; partially initialized model used before loading weights.
Related errors
- SpectralNorm is not supported yet.
- GroupNorm doesn't support causal evaluation.
- pad-mode 'reflect' is not supported
- seanet lstm is not supported
- Not enough audio embeddings: need {}, got {}. Input sequence
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/92e882924494a8ab.
Report an issue: GitHub.