{"record":{"id":"b4272bebaef408db","repo":"sgl-project/sglang","slug":"name-must-be-a-torch-tensor-b4272b","errorCode":null,"errorMessage":"{name} must be a torch.Tensor","messagePattern":"(.+?) must be a torch\\.Tensor","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_minimax_h3_euler_ancestral.py","lineNumber":17,"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:\n        raise ValueError(f\"{name} must be non-negative\")\n    return sigma\n\n\ndef _validate_timestep_sigma_pair(","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_minimax_h3_euler_ancestral.py#L1-L35","documentation":"The validator _validate_unit_timestep requires the timestep argument to be an actual torch.Tensor, not a Python float/int or numpy array. The minimax_h3 flow-matching formulation normalizes timesteps to unit-scale tensors, so a scalar timestep passed straight from a discrete schedule breaks the API contract.","triggerScenarios":"Calling minimax_h3_rf_v_to_x0 or _validate_timestep_sigma_pair with timestep=0.7 (float), timestep=700 (int), or a numpy array instead of a torch tensor.","commonSituations":"Porting code from diffusers schedulers where step(model_output, timestep, sample) conventionally receives an int or scalar timestep; passing numpy floats or Python numbers from a hand-rolled denoise loop into this flow-matching scheduler, which needs tensors for its elementwise `1 - timestep` sigma computation.","solutions":["Wrap the timestep in a tensor: torch.tensor(t, dtype=torch.float32, device=xt.device)","Build the whole (timestep, sigma) schedule as float tensors once at schedule-construction time so the scheduler always receives tensors"],"exampleFix":"# before\nx0 = minimax_h3_rf_v_to_x0(xt, v, timestep=0.7)  # ValueError\n\n# after\nx0 = minimax_h3_rf_v_to_x0(xt, v, timestep=torch.tensor(0.7, device=xt.device))","handlingStrategy":"type-guard","validationCode":"assert isinstance(timestep, torch.Tensor), \"timestep must be a torch.Tensor\"","typeGuard":"def is_timestep_tensor(t) -> bool:\n    return isinstance(t, torch.Tensor)","tryCatchPattern":null,"preventionTips":["Wrap timesteps as tensors where the schedule is produced","Keep a helper that converts scalar timesteps to tensors once at schedule build time"],"tags":["diffusion","scheduler","type-validation","timestep"],"backgroundTag":"wrong-argument-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}