{"record":{"id":"fe52cf584674e958","repo":"sgl-project/sglang","slug":"number-of-inference-steps-is-none-you-need-to-c-fe52cf","errorCode":null,"errorMessage":"Number of inference steps is 'None', you need to call 'set_timesteps' after creating the scheduler","messagePattern":"Number of inference steps is 'None', you need to call 'set_timesteps' after creating the scheduler","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_unipc_multistep.py","lineNumber":1113,"sourceCode":"\n        Args:\n            model_output (`torch.Tensor`):\n                The direct output from learned diffusion model.\n            timestep (`int`):\n                The current discrete timestep in the diffusion chain.\n            sample (`torch.Tensor`):\n                A current instance of a sample created by the diffusion process.\n            return_dict (`bool`):\n                Whether or not to return a [`~schedulers.scheduling_utils.SchedulerOutput`] or `tuple`.\n\n        Returns:\n            [`~schedulers.scheduling_utils.SchedulerOutput`] or `tuple`:\n                If return_dict is `True`, [`~schedulers.scheduling_utils.SchedulerOutput`] is returned, otherwise a\n                tuple is returned where the first element is the sample tensor.\n\n        \"\"\"\n        if self.num_inference_steps is None:\n            raise ValueError(\n                \"Number of inference steps is 'None', you need to call 'set_timesteps' after creating the scheduler\"\n            )\n\n        if self.step_index is None:\n            self._init_step_index(timestep)\n\n        use_corrector = (\n            self.step_index > 0\n            and self.step_index - 1 not in self.disable_corrector\n            and self.last_sample is not None\n        )\n\n        model_output_convert = self.convert_model_output(model_output, sample=sample)\n        if use_corrector:\n            sample = self.multistep_uni_c_bh_update(\n                this_model_output=model_output_convert,\n                last_sample=self.last_sample,\n                this_sample=sample,","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_unipc_multistep.py#L1095-L1131","documentation":"scheduler.step() requires a timestep grid; num_inference_steps is None until set_timesteps() has been called. The scheduler is stateful and steps through precomputed sigmas indexed by step_index, so stepping before initialization has no valid sigma schedule.","triggerScenarios":"Calling scheduler.step(model_output, t, sample) before scheduler.set_timesteps(num_inference_steps) in the denoise loop.","commonSituations":"Custom sampling loops that skip set_timesteps; refactoring a pipeline and dropping the init call; reusing a scheduler across runs where timesteps were reset to None.","solutions":["Call scheduler.set_timesteps(num_inference_steps) once before the denoising loop","Order pipeline code: create scheduler -> set_timesteps -> loop step()","If re-running generation, re-call set_timesteps each run"],"exampleFix":"// before\nfor t in sched.timesteps:\n    out = sched.step(model_output, t, latents)\n// after\nsched.set_timesteps(num_inference_steps=50)\nfor t in sched.timesteps:\n    out = sched.step(model_output, t, latents).prev_sample","handlingStrategy":"validation","validationCode":"assert sched.num_inference_steps is not None, \"call set_timesteps() before stepping\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always structure pipelines as: build scheduler -> set_timesteps -> denoise loop -> step()","Re-call set_timesteps when reusing a scheduler for a new generation"],"tags":["scheduler","diffusion","initialization","unipc"],"backgroundTag":"uninitialized-state-usage","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}