{"record":{"id":"1b0779135e8f25d7","repo":"huggingface/candle","slug":"top-p-must-be-between-0-and-1-got","errorCode":null,"errorMessage":"top_p must be between 0 and 1, got {}","messagePattern":"top_p must be between 0 and 1, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/voxtral/model.rs","lineNumber":893,"sourceCode":"        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();\n            VoxtralCache::new(true, model_dtype, &self.text_config, &config.device)?\n        };\n        let mut tokens = input_ids.i(0)?.to_vec1::<u32>()?; // Get first batch\n        let initial_len = tokens.len();\n\n        for idx in 0..config.max_new_tokens {\n            let (input, index_pos) = if idx == 0 {\n                (input_ids.clone(), 0)","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/voxtral/model.rs#L875-L911","documentation":"Raised when the optional top_p (nucleus sampling) value in the Voxtral GenerationConfig lies outside the closed interval [0.0, 1.0]. top_p is a cumulative-probability cutoff, so any value outside 0..=1 is invalid; the library checks this at candle_transformers/src/models/voxtral/model.rs:893 and bails before sampling starts.","triggerScenarios":"Calling Voxtral generation with Some(p) for config.top_p where p < 0.0 or p > 1.0 (e.g. top_p: Some(1.5) or Some(-0.1)). top_p = None skips the check entirely.","commonSituations":"Confusing top_p with top_k (an integer count) and passing a value like 50; scaling bugs that multiply top_p by a factor; hand-edited config files with percentages (e.g. 90 instead of 0.9); sentinel values like -1 meaning 'disabled' instead of using None.","solutions":["Set top_p to a value in 0.0..=1.0 (e.g. Some(0.9)); use None to disable nucleus sampling","Clamp before calling: config.top_p = config.top_p.map(|p| p.clamp(0.0, 1.0))","Fix deserialized config files so top_p is expressed as a fraction, not a percentage","If you meant to disable top-p filtering, set the field to None rather than 0 or a negative sentinel"],"exampleFix":"// before\nlet config = GenerationConfig { top_p: Some(50.0), ..Default::default() };\n// after\nlet config = GenerationConfig { top_p: Some(0.9), ..Default::default() };","handlingStrategy":"validation","validationCode":"fn ensure_valid_top_p(p: Option<f64>) -> Result<Option<f64>, String> {\n    match p {\n        Some(v) if !(0.0..=1.0).contains(&v) => {\n            Err(format!(\"top_p must be between 0 and 1, got {}\", v))\n        }\n        other => Ok(other),\n    }\n}","typeGuard":"fn is_valid_top_p(p: f64) -> bool { (0.0..=1.0).contains(&p) && p.is_finite() }","tryCatchPattern":"let top_p = ensure_valid_top_p(config.top_p)\n    .map_err(|e| eprintln!(\"invalid sampling config: {e}\"))\n    .ok();","preventionTips":["Remember top_p is a probability fraction (0.0-1.0), not a count or percentage","Use None to disable nucleus sampling instead of sentinel numbers","Clamp with .clamp(0.0, 1.0) when top_p is computed or user-supplied","Validate config fields when loading from JSON/YAML/CLI before running generation"],"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"}