sgl-project/sglang · error · ValueError

reference audio sample rate must be positive

Error message

reference audio sample rate must be positive

What it means

For pure-audio materials, _load_waveform requires an explicit positive source sample rate (there is no default for the 'audio' chain). The rate is needed to decide whether resampling to MINIMAX_H3_AUDIO_SAMPLE_RATE is required.

Source

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

    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}"
        )

    command = [
        "ffmpeg",
        "-v",
        "error",
    ]
    if start_time_seconds > 0:
        command += ["-ss", f"{start_time_seconds:.9g}"]

View on GitHub (pinned to 0132848349)

Solutions

  1. Probe the file (e.g. with torchaudio.info or ffprobe) and set source_sample_rate before encoding
  2. Default to a sane value like 44100 or 48000 only if you know the corpus
  3. Fix the material-builder code path that omits the rate for audio chains

Example fix

// before
material.source_sample_rate = None  # audio chain -> ValueError

// after
info = torchaudio.info(path)
material.source_sample_rate = info.sample_rate
Defensive patterns

Strategy: type-guard

Validate before calling

def has_audio_rate(material) -> bool:
    return material.material_chain != "audio" or (
        material.source_sample_rate is not None and int(material.source_sample_rate) > 0
    )

Type guard

def valid_audio_material(m) -> bool:
    return m.material_chain != "audio" or (m.source_sample_rate or 0) > 0

Prevention

When it happens

Trigger: Calling minimax_h3_encode_reference_audio_rows with material_chain='audio' and source_sample_rate=None, 0, or negative; video chains default to 44100 and do not hit this.

Common situations: Building audio materials without probing the file's sample rate, or a probe step that failed silently and left the field None.

Related errors


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