sgl-project/sglang · error · ValueError

MiniMax H3 num_steps must be > 0

Error message

MiniMax H3 num_steps must be > 0

What it means

The same sigma-computation function requires num_steps > 0, since the timestep ladder needs at least one step. Zero or negative steps cannot produce a linspace and would break the scheduler's cached timestep plans.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/time_request.py:40

    if out_t < 2 or (out_t - 2) % 5 != 0:
        raise ValueError("MiniMax H3 video latent T must be 1 or match 5n+2")
    return 17 * ((int(out_t) - 2) // 5) + 5


def minimax_h3_audio_latent_t(duration_seconds: float) -> int:
    # Rounding happens at the 40 Hz audio latent boundary.
    return int(round(float(duration_seconds) * 40.0))


def minimax_h3_time_shift_sigmas(
    *,
    num_steps: int = 50,
    shift_scale: float = 6.0,
) -> list[float]:
    if shift_scale <= 0:
        raise ValueError("MiniMax H3 shift_scale must be > 0")
    if num_steps <= 0:
        raise ValueError("MiniMax H3 num_steps must be > 0")

    import torch

    # The rectified-flow sigma range is fixed at [1.0, 0.0].
    base = torch.linspace(
        1.0,
        0.0,
        int(num_steps),
        device="cpu",
        dtype=torch.float32,
    )
    shifted = float(shift_scale) * base / (1 + (float(shift_scale) - 1) * base)
    shifted, _ = torch.unique_consecutive(shifted, return_counts=True)
    # A one-point request is still exactly one point.  Normal serving uses
    # multiple points, but preserving the requested cardinality keeps
    # ``num_inference_steps`` the sole schedule-size control.
    if num_steps > 1 and shifted[-1].item() > 0.0:
        shifted = torch.cat([shifted, torch.tensor([0.0], dtype=shifted.dtype)])

View on GitHub (pinned to 0132848349)

Solutions

  1. Set num_steps to a positive integer (typical values 30-50 for MiniMax H3)
  2. Check the key name your payload uses for step count and map it to num_steps
  3. Validate sampling params with validate_sampling_params before calling the pipeline

Example fix

# before
minimax_h3_time_shift_sigmas(num_steps=0, shift_scale=6.0)

# after
minimax_h3_time_shift_sigmas(num_steps=50, shift_scale=6.0)
Defensive patterns

Strategy: validation

Validate before calling

steps = int(params.get("num_steps", 50))
if steps <= 0:
    raise ValueError("num_steps must be > 0")
sigmas = minimax_h3_time_shift_sigmas(num_steps=steps, shift_scale=shift_scale)

Type guard

def is_valid_num_steps(x: Any) -> bool:
    return isinstance(x, int) and not isinstance(x, bool) and x > 0

Try / catch

catch ValueError and default num_steps to 50 with a logged warning

Prevention

When it happens

Trigger: Calling minimax_h3_time_shift_sigmas(num_steps=0) or with a negative int; passing sampling params with steps=0/missing from the request so a default of 0 is computed; a plan-generation path (_generate_sigmas_from_plan, _cache_timestep_plans) receiving an unset num_steps.

Common situations: CLI/config omitting num_steps while a zero-valued default leaks in; passing steps=0 intending 'auto'; JSON payload using 'num_steps' vs 'steps' key mismatch so the value reads as 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/cd8eb7bb17320f72. Report an issue: GitHub.