sgl-project/sglang · error · ValueError

Number of inference steps is 'None', run 'set_timesteps' fir

Error message

Number of inference steps is 'None', run 'set_timesteps' first

What it means

The Helios scheduler's step() was called before set_timesteps(), so self.num_inference_steps is None. Like diffusers schedulers, the UniPC multistep solver needs a timestep schedule initialized before any denoising step can compute coefficients.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_helios.py:563

                torch.einsum("k,bkc...->bc...", rhos_c[:-1], D1s)
                if D1s is not None
                else 0
            )
            D1_t = model_t - m0
            x_t = x_t_ - sigma_t * B_h * (corr_res + rhos_c[-1] * D1_t)

        return x_t.to(x.dtype)

    def step_unipc(
        self,
        model_output,
        timestep=None,
        sample=None,
        return_dict: bool = True,
        **kwargs,
    ) -> HeliosSchedulerOutput | tuple:
        if self.num_inference_steps is None:
            raise ValueError(
                "Number of inference steps is 'None', run 'set_timesteps' first"
            )

        if self.step_index is None:
            self._step_index = 0

        use_corrector = (
            self.step_index > 0
            and self.step_index - 1 not in self.disable_corrector
            and self.last_sample is not None
        )

        model_output_convert = self.convert_model_output(model_output, sample=sample)

        if use_corrector:
            sample = self.multistep_uni_c_bh_update(
                this_model_output=model_output_convert,
                last_sample=self.last_sample,

View on GitHub (pinned to 0132848349)

Solutions

  1. Call scheduler.set_timesteps(num_inference_steps) before the first scheduler.step() in your denoise loop
  2. Verify num_inference_steps stays non-None across the loop (e.g. it wasn't cleared by reset_scheduler_history or a fresh pipeline run)
  3. If wrapping the scheduler, add an assertion/guard after init to fail fast with a clearer message

Example fix

// before
for t in timesteps:
    sample = scheduler.step(model_out, t, sample).prev_sample  # ValueError

// after
scheduler.set_timesteps(num_inference_steps=50)
for t in scheduler.timesteps:
    sample = scheduler.step(model_out, t, sample).prev_sample
Defensive patterns

Strategy: validation

Validate before calling

assert scheduler.num_inference_steps is not None, "call scheduler.set_timesteps(N) before stepping"

Type guard

def is_scheduler_ready(s) -> bool:
    return getattr(s, "num_inference_steps", None) is not None

Prevention

When it happens

Trigger: Calling scheduler.step(...) or step_unipc(...) on a HeliosScheduler without a prior scheduler.set_timesteps(num_inference_steps) call; or re-using a scheduler after reset without re-running set_timesteps.

Common situations: Custom denoise loops that skip the standard pipeline setup; copying scheduler code into a new runtime (multimodal_gen) and forgetting the timesteps init; resetting scheduler state between generations.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/36c75509e954dbfc. Report an issue: GitHub.