sgl-project/sglang · error · ValueError
vec must be 1D
Error message
vec must be 1D
What it means
_make_pairs_from_vector duplicates a 1D vector (timesteps or sigmas) into two stacked columns for the paired scheduler; a 2D+ tensor cannot be unambiguously paired. It is called internally by _refresh_pair_cache on self.timesteps/self.sigmas.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/schedulers/flow_match_pair.py:446
if self.reverse_sigmas:
base = 1 - base
if source == "timesteps":
return base * self.num_train_timesteps
return base
col0 = _build_column(visual_shift, visual_denoising_strength, visual_mu)
col1 = _build_column(audio_shift, audio_denoising_strength, audio_mu)
return torch.stack([col0, col1], dim=1)
_dual_sigma_shift._requires_source = True
self.set_pair_postprocess(_dual_sigma_shift)
return
raise ValueError(f"Unknown pair_postprocess name: {name}")
def _make_pairs_from_vector(self, vec: torch.Tensor) -> torch.Tensor:
if vec.ndim != 1:
raise ValueError("vec must be 1D")
return torch.stack([vec, vec], dim=1)
def get_pairs(self, source: str = "timesteps") -> torch.Tensor:
if source == "timesteps":
if self.pair_timesteps is None:
self._refresh_pair_cache()
return self.pair_timesteps
if source == "sigmas":
if self.pair_sigmas is None:
self._refresh_pair_cache()
return self.pair_sigmas
raise ValueError("source must be 'timesteps' or 'sigmas'")
def timestep_to_sigma(self, timestep: torch.Tensor | float) -> torch.Tensor:
"""Return sigma for a scalar timestep via nearest neighbor lookup.
Args:
timestep: Scalar timestep value.View on GitHub (pinned to 0132848349)
Solutions
- Ensure scheduler.timesteps and scheduler.sigmas remain 1D tensors
- Flatten or index the tensor before assigning it to the scheduler
- If pairing columns is needed, use the pair postprocess mechanism rather than 2D inputs
Example fix
# before sched.timesteps = timesteps_2d # (B, T) # after sched.timesteps = timesteps_2d.flatten() # or select sched.timesteps = timesteps_2d[0]
Defensive patterns
Strategy: type-guard
Validate before calling
assert sched.timesteps is None or sched.timesteps.ndim == 1 assert sched.sigmas is None or sched.sigmas.ndim == 1
Type guard
def is_1d(t: torch.Tensor) -> bool:
return isinstance(t, torch.Tensor) and t.ndim == 1 Prevention
- Never assign 2D schedules to timesteps/sigmas
- Flatten before assignment
When it happens
Trigger: Internal: timesteps or sigmas were set to a 2D tensor (e.g. via a custom postprocess or manual assignment) before _refresh_pair_cache runs (triggered by get_pairs or set_pair_postprocess).
Common situations: Assigning a batched schedule tensor directly to scheduler.timesteps; a custom set_timesteps override returning a 2D array.
Related errors
- pairs must be a torch.Tensor of shape [N, 2]
- [pred_noise_to_pred_video] Invalid timestep shape: {timestep
- `dt_bias` must have {HV * K} elements (got {dt_bias.numel()}
- `mixed_qkv` must be 2D (got ndim={mixed_qkv.ndim}).
- num_token_non_padded must be a single-element tensor, got sh
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/7994274b70b83e3e.
Report an issue: GitHub.