huggingface/candle · error
top_p must be between 0 and 1, got {}
Error message
top_p must be between 0 and 1, got {} What it means
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.
Source
Thrown at candle-transformers/src/models/voxtral/model.rs:893
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();
VoxtralCache::new(true, model_dtype, &self.text_config, &config.device)?
};
let mut tokens = input_ids.i(0)?.to_vec1::<u32>()?; // Get first batch
let initial_len = tokens.len();
for idx in 0..config.max_new_tokens {
let (input, index_pos) = if idx == 0 {
(input_ids.clone(), 0)View on GitHub (pinned to d5fee525bf)
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
Example fix
// before
let config = GenerationConfig { top_p: Some(50.0), ..Default::default() };
// after
let config = GenerationConfig { top_p: Some(0.9), ..Default::default() }; Defensive patterns
Strategy: validation
Validate before calling
fn ensure_valid_top_p(p: Option<f64>) -> Result<Option<f64>, String> {
match p {
Some(v) if !(0.0..=1.0).contains(&v) => {
Err(format!("top_p must be between 0 and 1, got {}", v))
}
other => Ok(other),
}
} Type guard
fn is_valid_top_p(p: f64) -> bool { (0.0..=1.0).contains(&p) && p.is_finite() } Try / catch
let top_p = ensure_valid_top_p(config.top_p)
.map_err(|e| eprintln!("invalid sampling config: {e}"))
.ok(); Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Temperature must be non-negative, got {}
- text_embeddings cannot be empty
- {} is a dummy type and cannot be constructed
- {} is a dummy type and cannot be converted
- {} is a dummy type and cannot be converted to scalar
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/1b0779135e8f25d7.
Report an issue: GitHub.