huggingface/candle · error

Temperature must be non-negative, got {}

Error message

Temperature must be non-negative, got {}

What it means

This error is raised during Voxtral sampling setup when the requested generation temperature is negative. The library validates sampling parameters in candle_transformers/src/models/voxtral/model.rs:885 because a negative temperature is mathematically meaningless for softmax sampling (it would invert/negate probability logits), so candle::bail! aborts generation early with a clear message instead of producing garbage output.

Source

Thrown at candle-transformers/src/models/voxtral/model.rs:885

        // Forward through language model using forward_input_embed
        self.language_model
            .forward_input_embed(&inputs_embeds, index_pos, &mut cache.cache)
    }

    /// Generate text given audio input
    pub fn generate(
        &self,
        input_ids: &Tensor,
        input_features: Option<&Tensor>,
        config: VoxtralGenerationConfig,
    ) -> Result<Vec<u32>> {
        // Validate inputs
        if config.max_new_tokens == 0 {
            return input_ids.i(0)?.to_vec1::<u32>(); // Get first batch
        }

        if config.temperature < 0.0 {
            candle::bail!(
                "Temperature must be non-negative, got {}",
                config.temperature
            );
        }

        if let Some(p) = config.top_p {
            if !(0.0..=1.0).contains(&p) {
                candle::bail!("top_p must be between 0 and 1, got {}", p);
            }
        }

        let mut final_cache = if let Some(cache) = config.cache {
            cache
        } else {
            // Get the dtype from the language model by creating a small embedding
            let dummy_token = Tensor::new(&[1u32], &config.device)?;
            let dummy_embed = self.language_model.embed(&dummy_token)?;
            let model_dtype = dummy_embed.dtype();

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Set config.temperature to a non-negative value; use 0.0 for greedy/argmax decoding or typical values like 0.6-1.0 for sampling
  2. Clamp the value before calling: config.temperature = config.temperature.max(0.0)
  3. If the config came from a file/CLI, fix the stored value or add a deserialization validator
  4. If sampling is not needed, ensure the temperature field is defaulted properly rather than set to -1 as 'unused'

Example fix

// before
let config = GenerationConfig { temperature: -0.7, ..Default::default() };
// after
let config = GenerationConfig { temperature: 0.0, ..Default::default() }; // greedy
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_valid_temperature(t: f64) -> Result<f64, String> {
    if t < 0.0 {
        return Err(format!("Temperature must be non-negative, got {}", t));
    }
    Ok(t)
}

Type guard

fn is_valid_temperature(t: f64) -> bool { t.is_finite() && t >= 0.0 }

Try / catch

match ensure_valid_temperature(config.temperature) {
    Ok(t) => run_generation(config.temperature = t),
    Err(e) => eprintln!("invalid sampling config: {e}"),
}

Prevention

When it happens

Trigger: Calling the Voxtral generate entry point with a GenerationConfig whose temperature field is set to a negative value (e.g. -0.5). Note temperature == 0.0 is valid (greedy path), only < 0.0 triggers this.

Common situations: Hand-written configs where the author intended 0.0 (greedy) but typed a negative number; configs loaded from YAML/JSON with sentinel values like -1; code that computes temperature dynamically (e.g. subtracting a decay) and lets it go below zero.

Related errors


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