{"record":{"id":"151870eaf45cc149","repo":"huggingface/candle","slug":"timestep-out-of-this-schedulers-bounds-timestep","errorCode":null,"errorMessage":"timestep out of this schedulers bounds: {timestep}","messagePattern":"timestep out of this schedulers bounds: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs","lineNumber":162,"sourceCode":"            init_noise_sigma,\n            config,\n        })\n    }\n}\n\nimpl Scheduler for EulerAncestralDiscreteScheduler {\n    fn timesteps(&self) -> &[usize] {\n        self.timesteps.as_slice()\n    }\n\n    /// Ensures interchangeability with schedulers that need to scale the denoising model input\n    /// depending on the current timestep.\n    ///\n    /// Scales the denoising model input by `(sigma**2 + 1) ** 0.5` to match the K-LMS algorithm\n    fn scale_model_input(&self, sample: Tensor, timestep: usize) -> Result<Tensor> {\n        let step_index = match self.timesteps.iter().position(|&t| t == timestep) {\n            Some(i) => i,\n            None => bail!(\"timestep out of this schedulers bounds: {timestep}\"),\n        };\n\n        let sigma = self\n            .sigmas\n            .get(step_index)\n            .expect(\"step_index out of sigma bounds - this shouldn't happen\");\n\n        sample / ((sigma.powi(2) + 1.).sqrt())\n    }\n\n    /// Performs a backward step during inference.\n    fn step(&mut self, model_output: &Tensor, timestep: usize, sample: &Tensor) -> Result<Tensor> {\n        let step_index = self\n            .timesteps\n            .iter()\n            .position(|&p| p == timestep)\n            .ok_or_else(|| Error::Msg(\"timestep out of this schedulers bounds\".to_string()))?;\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs#L144-L180","documentation":"EulerAncestralDiscreteScheduler::scale_model_input looks up the requested timestep in its precomputed timesteps list to find the step_index used to index sigmas. If the timestep is not present in that list, the scheduler cannot compute sigma and bails. The scheduler only accepts exact timesteps it generated at construction time.","triggerScenarios":"Calling scale_model_input(sample, timestep) with a timestep value that is not exactly one of the entries in scheduler.timesteps (from set_timesteps/init), including off-by-one, float-rounded, or out-of-range values.","commonSituations":"Reimplementing a diffusion loop and computing timesteps independently instead of using scheduler.timesteps(); iterating a float sigma schedule and casting to usize differently than the scheduler; reusing a scheduler after re-initializing timesteps with a different step count.","solutions":["Only pass timesteps taken directly from scheduler.timesteps() (or the value yielded by the scheduler's iteration API)","Re-run set_timesteps(num_inference_steps) and use the resulting list verbatim","Check for integer truncation when converting float timesteps; match the scheduler's rounding"],"exampleFix":"// before\nfor t in 0..num_steps { scheduler.scale_model_input(x, t)?; }\n// after\nfor &t in scheduler.timesteps().iter() { scheduler.scale_model_input(x, t)?; }","handlingStrategy":"validation","validationCode":"if !scheduler.timesteps().iter().any(|&t| t == timestep) {\n    return Err(anyhow::anyhow!(\"timestep {} not in scheduler timesteps\", timestep));\n}","typeGuard":null,"tryCatchPattern":"let out = match scheduler.scale_model_input(sample, t) {\n    Ok(x) => x,\n    Err(e) if e.to_string().contains(\"out of this schedulers bounds\") => {\n        anyhow::bail!(\"use timesteps from scheduler.timesteps(), got {}\", t)\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Iterate scheduler.timesteps() directly instead of synthesizing timesteps","Call set_timesteps(num_steps) before the diffusion loop and reuse its output","Avoid float-to-usize casts that introduce rounding differences"],"tags":["rust","candle","stable-diffusion","scheduler","timestep"],"backgroundTag":"timestep-out-of-scheduler-bounds","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}