{"record":{"id":"a4bd06734cbff002","repo":"huggingface/candle","slug":"temperature-must-be-non-negative-got","errorCode":null,"errorMessage":"Temperature must be non-negative, got {}","messagePattern":"Temperature must be non-negative, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/voxtral/model.rs","lineNumber":885,"sourceCode":"        // Forward through language model using forward_input_embed\n        self.language_model\n            .forward_input_embed(&inputs_embeds, index_pos, &mut cache.cache)\n    }\n\n    /// Generate text given audio input\n    pub fn generate(\n        &self,\n        input_ids: &Tensor,\n        input_features: Option<&Tensor>,\n        config: VoxtralGenerationConfig,\n    ) -> Result<Vec<u32>> {\n        // Validate inputs\n        if config.max_new_tokens == 0 {\n            return input_ids.i(0)?.to_vec1::<u32>(); // Get first batch\n        }\n\n        if config.temperature < 0.0 {\n            candle::bail!(\n                \"Temperature must be non-negative, got {}\",\n                config.temperature\n            );\n        }\n\n        if let Some(p) = config.top_p {\n            if !(0.0..=1.0).contains(&p) {\n                candle::bail!(\"top_p must be between 0 and 1, got {}\", p);\n            }\n        }\n\n        let mut final_cache = if let Some(cache) = config.cache {\n            cache\n        } else {\n            // Get the dtype from the language model by creating a small embedding\n            let dummy_token = Tensor::new(&[1u32], &config.device)?;\n            let dummy_embed = self.language_model.embed(&dummy_token)?;\n            let model_dtype = dummy_embed.dtype();","sourceCodeStart":867,"sourceCodeEnd":903,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/voxtral/model.rs#L867-L903","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Clamp the value before calling: config.temperature = config.temperature.max(0.0)","If the config came from a file/CLI, fix the stored value or add a deserialization validator","If sampling is not needed, ensure the temperature field is defaulted properly rather than set to -1 as 'unused'"],"exampleFix":"// before\nlet config = GenerationConfig { temperature: -0.7, ..Default::default() };\n// after\nlet config = GenerationConfig { temperature: 0.0, ..Default::default() }; // greedy","handlingStrategy":"validation","validationCode":"fn ensure_valid_temperature(t: f64) -> Result<f64, String> {\n    if t < 0.0 {\n        return Err(format!(\"Temperature must be non-negative, got {}\", t));\n    }\n    Ok(t)\n}","typeGuard":"fn is_valid_temperature(t: f64) -> bool { t.is_finite() && t >= 0.0 }","tryCatchPattern":"match ensure_valid_temperature(config.temperature) {\n    Ok(t) => run_generation(config.temperature = t),\n    Err(e) => eprintln!(\"invalid sampling config: {e}\"),\n}","preventionTips":["Use 0.0 for greedy decoding, never -1 or negative sentinels","Validate GenerationConfig at deserialization boundaries (serde custom validator)","Clamp temperature with .max(0.0) when it is computed dynamically","Add a unit test asserting configs with negative temperature are rejected at construction"],"tags":["rust","candle","validation","sampling-config"],"backgroundTag":null,"analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}