sgl-project/sglang · error · ValueError
{name} must be finite
Error message
{name} must be finite What it means
The minimax_h3 Euler ancestral scheduler validates that every element of xt/v/timestep tensors is finite before doing math. NaN or Inf anywhere in the tensor raises this ValueError, guarding against silently propagating NaNs through the flow-matching update.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_minimax_h3_euler_ancestral.py:12
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import math
from typing import Any
import torch
def _require_finite_tensor(tensor: torch.Tensor, name: str) -> None:
if not bool(torch.isfinite(tensor).all().item()):
raise ValueError(f"{name} must be finite")
def _validate_unit_timestep(timestep: torch.Tensor, name: str) -> None:
if not isinstance(timestep, torch.Tensor):
raise ValueError(f"{name} must be a torch.Tensor")
if not torch.is_floating_point(timestep):
raise ValueError(f"{name} must be a floating point tensor")
_require_finite_tensor(timestep, name)
out_of_range = (timestep < 0) | (timestep > 1)
if bool(out_of_range.any().item()):
raise ValueError(f"{name} must be in [0, 1]")
def _validate_sigma(value: float, name: str) -> float:
sigma = float(value)
if not math.isfinite(sigma):
raise ValueError(f"{name} must be finite")
if sigma < 0.0:View on GitHub (pinned to 0132848349)
Solutions
- Inspect model outputs each step with torch.isfinite(...).all() to find the first step that produces NaN/Inf
- Reduce guidance_scale (or eta/churn settings) that cause denoising divergence
- Run the model in fp32/bf16 instead of fp16 to avoid overflow
- Verify checkpoint and embeddings load cleanly (no NaNs at t=0)
Example fix
# before
x0 = minimax_h3_rf_v_to_x0(xt, v, timestep) # ValueError: v must be finite
# after
if not torch.isfinite(v).all():
v = torch.nan_to_num(v, nan=0.0, posinf=0.0, neginf=0.0)
x0 = minimax_h3_rf_v_to_x0(xt, v, timestep) Defensive patterns
Strategy: validation
Validate before calling
assert torch.isfinite(xt).all() and torch.isfinite(v).all(), "non-finite inputs to scheduler"
Type guard
def all_finite(*ts: torch.Tensor) -> bool:
return all(bool(torch.isfinite(t).all().item()) for t in ts) Try / catch
try:
x0 = minimax_h3_rf_v_to_x0(xt, v, t)
except ValueError as e:
if "must be finite" in str(e):
v = torch.nan_to_num(v)
x0 = minimax_h3_rf_v_to_x0(xt, v, t)
else:
raise Prevention
- Monitor isfinite on model outputs each step during debugging
- Avoid extreme guidance/eta values and fp16 compute for this scheduler
When it happens
Trigger: Passing a noisy sample xt, a model velocity output v, or a timestep tensor containing NaN/Inf to minimax_h3_rf_v_to_x0, minimax_h3_euler_eta0_step, or the validators. Usually the NaN originates from the model forward pass (diverged training-free CFG, fp16 overflow, bad guidance scale).
Common situations: fp16/bf16 numerical overflow in the denoising UNet/DiT producing NaN velocities; extremely high guidance_scale or eta causing divergence; corrupted checkpoints or NaN-inducing embeddings.
Related errors
- denoising_strength must be positive
- [pred_noise_to_pred_video] Invalid timestep shape: {timestep
- Validate failed: unsupported dtype: {t.dtype}
- Validate failed: unsupported tensor shape: {t.shape}.
- {output_batch.error}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/188a29f34528103f.
Report an issue: GitHub.