{"record":{"id":"188a29f34528103f","repo":"sgl-project/sglang","slug":"name-must-be-finite","errorCode":null,"errorMessage":"{name} must be finite","messagePattern":"(.+?) must be finite","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_minimax_h3_euler_ancestral.py","lineNumber":12,"sourceCode":"# SPDX-License-Identifier: Apache-2.0\nfrom __future__ import annotations\n\nimport math\nfrom typing import Any\n\nimport torch\n\n\ndef _require_finite_tensor(tensor: torch.Tensor, name: str) -> None:\n    if not bool(torch.isfinite(tensor).all().item()):\n        raise ValueError(f\"{name} must be finite\")\n\n\ndef _validate_unit_timestep(timestep: torch.Tensor, name: str) -> None:\n    if not isinstance(timestep, torch.Tensor):\n        raise ValueError(f\"{name} must be a torch.Tensor\")\n    if not torch.is_floating_point(timestep):\n        raise ValueError(f\"{name} must be a floating point tensor\")\n    _require_finite_tensor(timestep, name)\n    out_of_range = (timestep < 0) | (timestep > 1)\n    if bool(out_of_range.any().item()):\n        raise ValueError(f\"{name} must be in [0, 1]\")\n\n\ndef _validate_sigma(value: float, name: str) -> float:\n    sigma = float(value)\n    if not math.isfinite(sigma):\n        raise ValueError(f\"{name} must be finite\")\n    if sigma < 0.0:","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_minimax_h3_euler_ancestral.py#L1-L30","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)"],"exampleFix":"# before\nx0 = minimax_h3_rf_v_to_x0(xt, v, timestep)  # ValueError: v must be finite\n\n# after\nif not torch.isfinite(v).all():\n    v = torch.nan_to_num(v, nan=0.0, posinf=0.0, neginf=0.0)\nx0 = minimax_h3_rf_v_to_x0(xt, v, timestep)","handlingStrategy":"validation","validationCode":"assert torch.isfinite(xt).all() and torch.isfinite(v).all(), \"non-finite inputs to scheduler\"","typeGuard":"def all_finite(*ts: torch.Tensor) -> bool:\n    return all(bool(torch.isfinite(t).all().item()) for t in ts)","tryCatchPattern":"try:\n    x0 = minimax_h3_rf_v_to_x0(xt, v, t)\nexcept ValueError as e:\n    if \"must be finite\" in str(e):\n        v = torch.nan_to_num(v)\n        x0 = minimax_h3_rf_v_to_x0(xt, v, t)\n    else:\n        raise","preventionTips":["Monitor isfinite on model outputs each step during debugging","Avoid extreme guidance/eta values and fp16 compute for this scheduler"],"tags":["diffusion","scheduler","nan","numerical-stability","validation"],"backgroundTag":"tensor-not-finite","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}