sgl-project/sglang · error · ValueError

reference audio duration bound must be positive

Error message

reference audio duration bound must be positive

What it means

When decoding reference audio with _load_waveform, an optional max_duration_seconds bound must be a positive finite float if provided. The bound caps ffmpeg decoding length for safety; non-positive or NaN/infinite bounds are rejected.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/reference_encoding.py:229

    max_duration_seconds: float | None = None,
    start_time_seconds: float = 0.0,
    source_sample_rate: int | None = None,
) -> tuple[torch.Tensor, int]:
    """Apply the audio material chain.

    Pure-audio references preserve their source rate while normalizing to
    stereo. Video-bearing references first extract 44.1 kHz stereo PCM. The
    audio VAE boundary then performs the single 32 kHz resample below. ffmpeg
    writes bounded interleaved float PCM directly to stdout, avoiding a
    temporary lossless file plus a second decode.
    """

    import numpy as np

    if max_duration_seconds is not None:
        max_duration_seconds = float(max_duration_seconds)
        if not math.isfinite(max_duration_seconds) or max_duration_seconds <= 0:
            raise ValueError("reference audio duration bound must be positive")
    start_time_seconds = float(start_time_seconds)
    if not math.isfinite(start_time_seconds) or start_time_seconds < 0:
        raise ValueError("reference audio start time must be non-negative")

    if material_chain == "audio":
        if source_sample_rate is None or int(source_sample_rate) <= 0:
            raise ValueError("reference audio sample rate must be positive")
        source_rate = int(source_sample_rate)
    elif material_chain in {
        "video.reference_preserve",
        "video_audio.reference_preserve",
    }:
        source_rate = 44100
    else:
        raise ValueError(
            f"unsupported MiniMax H3 audio material chain {material_chain!r}"
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. If you mean 'no bound', pass None instead of 0
  2. Compute bounds as max(0.0, end-start) plus a small epsilon, and pass None when the result is 0
  3. Validate the config value at load time

Example fix

// before
max_dur = end - start  # can be 0 or negative

// after
max_dur = (end - start) if end and end > start else None
Defensive patterns

Strategy: validation

Validate before calling

import math

def valid_bound(d):
    return d is None or (isinstance(d, (int, float)) and math.isfinite(d) and d > 0)

Prevention

When it happens

Trigger: Passing max_duration_seconds=0, a negative number, or float('nan') to minimax_h3_encode_reference_audio_rows or _load_waveform; also triggered by its tests exercising the bound.

Common situations: Duration computed as (end - start) going negative when the clip end precedes the start, or a config default of 0 meaning 'unbounded' but interpreted as a bound.

Related errors


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