sgl-project/sglang · error · ValueError

audio_sr must be positive, got {audio_sr}

Error message

audio_sr must be positive, got {audio_sr}

What it means

Raised by _build_video_cfg when audio_sr (audio sample rate) is <= 0. The sample rate is used when resampling/normalizing the audio track of the video, so it must be a positive integer (default 16000).

Source

Thrown at python/sglang/srt/multimodal/processors/dots_note_omni.py:60

    *,
    seq: int,
    audio_cap: float,
    audio_sr: int,
    max_new_tokens: int,
) -> dict[str, Any]:
    if seq <= 0:
        raise ValueError(f"seq must be positive, got {seq}")
    if max_new_tokens < 0:
        raise ValueError(f"max_new_tokens must be non-negative, got {max_new_tokens}")
    if max_new_tokens >= seq:
        raise ValueError(
            "max_new_tokens must leave room for input: "
            f"max_new_tokens={max_new_tokens}, seq={seq}"
        )
    if audio_cap < 0:
        raise ValueError(f"audio_cap must be non-negative, got {audio_cap}")
    if audio_sr <= 0:
        raise ValueError(f"audio_sr must be positive, got {audio_sr}")

    return {
        "process_audio": audio_cap > 0,
        "seq_length": seq - max_new_tokens,
        "reserve_interleave": True,
        "audio_token_ratio_cap": float(audio_cap),
        "audio_sample_rate": int(audio_sr),
        "video_jpeg_quality": int(os.environ.get("XHS_VIDEO_JPEG_QUALITY", "85")),
    }


def _video_payload(raw_video) -> tuple[bytes, str]:
    if isinstance(raw_video, VideoData):
        raw_video = raw_video.url
    raw_url = raw_video.get("url") if isinstance(raw_video, dict) else raw_video
    video_bytes = get_video_bytes(raw_url)
    return video_bytes, hashlib.sha1(video_bytes).hexdigest()

View on GitHub (pinned to 0132848349)

Solutions

  1. Keep audio_sr at its default 16000 unless the model card says otherwise
  2. To disable audio, set audio_cap=0 (process_audio), not audio_sr=0
  3. Ensure any dynamically built video_config keeps audio_sr a positive integer

Example fix

// before
video_config = {"audio_cap": 0, "audio_sr": 0}
// after
video_config = {"audio_cap": 0, "audio_sr": 16000}
Defensive patterns

Strategy: validation

Validate before calling

sr = cfg.get('audio_sr', 16000)
assert isinstance(sr, int) and sr > 0, f'audio_sr must be positive, got {sr}'

Type guard

def valid_audio_sr(cfg: dict) -> bool:
    sr = cfg.get('audio_sr', 16000)
    return isinstance(sr, int) and sr > 0

Prevention

When it happens

Trigger: Passing video_config={"audio_sr": 0} or a negative value in a video request, typically while trying to disable audio handling.

Common situations: Users pass audio_sr=0 thinking it disables audio (audio_cap=0 is the correct switch), or forward a corrupted/unset config value.

Related errors


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