sgl-project/sglang · error · ValueError

Passing integer indices as timesteps is not supported.

Error message

Passing integer indices as timesteps is not supported.

What it means

The consistency flow-match variant of step() enforces the same rule as 1749: timesteps are continuous floats, and integer indices cannot be mapped to a sigma. Passed timesteps must come from scheduler.timesteps as floats.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/schedulers/hunyuan3d_scheduler.py:338

    def _init_step_index(self, timestep: Union[float, torch.Tensor]):
        if self.begin_index is None:
            if isinstance(timestep, torch.Tensor):
                timestep = timestep.to(self.timesteps.device)
            self._step_index = self.index_for_timestep(timestep)
        else:
            self._step_index = self._begin_index

    def step(
        self,
        model_output: torch.FloatTensor,
        timestep: Union[float, torch.FloatTensor],
        sample: torch.FloatTensor,
        generator: Optional[torch.Generator] = None,
        return_dict: bool = True,
    ) -> Union[Hunyuan3DConsistencyFlowMatchSchedulerOutput, Tuple]:
        """Perform one step of the consistency flow matching scheduler."""
        if isinstance(timestep, (int, torch.IntTensor, torch.LongTensor)):
            raise ValueError("Passing integer indices as timesteps is not supported.")

        if self.step_index is None:
            self._init_step_index(timestep)

        sample = sample.to(torch.float32)

        sigma = self.sigmas_[self.step_index]
        sigma_next = self.sigmas_[self.step_index + 1]

        prev_sample = sample + (sigma_next - sigma) * model_output
        prev_sample = prev_sample.to(model_output.dtype)

        pred_original_sample = sample + (1.0 - sigma) * model_output
        pred_original_sample = pred_original_sample.to(model_output.dtype)

        self._step_index += 1

        if not return_dict:

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass float values from scheduler.timesteps
  2. Cast before calling: float(t) or t.to(torch.float32)
  3. Audit shared loop code for index-based timestep passing

Example fix

# before
sample = scheduler.step(model_output, step_idx, sample).prev_sample
# after
sample = scheduler.step(model_output, scheduler.timesteps[step_idx], sample).prev_sample
Defensive patterns

Strategy: type-guard

Validate before calling

t = float(scheduler.timesteps[step_idx])
scheduler.step(model_output, t, sample)

Type guard

def as_float_timestep(t):
    return float(t) if isinstance(t, (int, np.integer)) else t

Prevention

When it happens

Trigger: Calling the consistency scheduler's step with an int or integer tensor timestep, e.g. an enumerate index or an int-cast numpy value.

Common situations: Shared denoising loop code reused across the standard and consistency schedulers where one path yields ints.

Related errors


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