sgl-project/sglang · error · ValueError
`sigmas` and `timesteps` should have the same length
Error message
`sigmas` and `timesteps` should have the same length
What it means
When both sigmas and timesteps are provided to set_timesteps they must describe the same schedule step-for-step; mismatched lengths raise this validation error before anything is assigned.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_flow_match_euler_discrete.py:311
mu (`float`, *optional*):
Determines the amount of shifting applied to sigmas when performing resolution-dependent timestep
shifting.
timesteps (`List[float]`, *optional*):
Custom values for timesteps to be used for each diffusion step. If `None`, the timesteps are computed
automatically.
"""
if self.config.use_dynamic_shifting and mu is None:
raise ValueError(
"`mu` must be passed when `use_dynamic_shifting` is set to be `True`"
)
if (
sigmas is not None
and timesteps is not None
and len(sigmas) != len(timesteps)
):
raise ValueError("`sigmas` and `timesteps` should have the same length")
if num_inference_steps is not None:
if (sigmas is not None and len(sigmas) != num_inference_steps) or (
timesteps is not None and len(timesteps) != num_inference_steps
):
raise ValueError(
"`sigmas` and `timesteps` should have the same length as num_inference_steps, if `num_inference_steps` is provided"
)
else:
if sigmas is not None:
num_inference_steps = len(sigmas)
elif timesteps is not None:
num_inference_steps = len(timesteps)
else:
raise ValueError(
"Either num_inference_steps, sigmas, or timesteps must be provided"
)
View on GitHub (pinned to 0132848349)
Solutions
- Make len(sigmas) == len(timesteps); trim or pad the terminal sigma accordingly
- Generate both from the same num_inference_steps and pass only one of them
- Validate lengths in your schedule-generation code before calling
Example fix
# before scheduler.set_timesteps(50, sigmas=sigmas, timesteps=ts) # len 51 vs 50 # after scheduler.set_timesteps(50, sigmas=sigmas[:-1], timesteps=ts)
Defensive patterns
Strategy: validation
Validate before calling
assert sigmas is None or timesteps is None or len(sigmas) == len(timesteps)
Prevention
- Decide one terminal-sigma convention and stick to it
- Generate sigmas and timesteps from the same source
When it happens
Trigger: Passing 50 sigmas (including terminal) with 49 timesteps, or reusing sigmas from one step count with timesteps from another.
Common situations: Custom schedules where users forget the terminal sigma (length N+1) versus N timesteps; mixing schedules generated for different num_inference_steps.
Related errors
- `sigmas` and `timesteps` should have the same length as num_
- kv-canary: {name} length must be {expected}, got {actual}
- pairs must be a torch.Tensor of shape [N, 2]
- pairs must be a torch.Tensor
- pairs length must be greater than 0
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2453a2bceb14771d.
Report an issue: GitHub.