sgl-project/sglang · error · ValueError

audio_cap must be non-negative, got {audio_cap}

Error message

audio_cap must be non-negative, got {audio_cap}

What it means

Raised by _build_video_cfg when audio_cap is negative. audio_cap caps the audio token ratio (process_audio is enabled when audio_cap > 0); negatives are invalid and rejected before building the config.

Source

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

def _build_video_cfg(
    *,
    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)

View on GitHub (pinned to 0132848349)

Solutions

  1. Set audio_cap to a non-negative float (default 1.0; 0 disables audio processing)
  2. If computing the cap dynamically, clamp with max(0.0, value)

Example fix

// before
video_config = {"audio_cap": tokens_audio - tokens_budget}  # negative
// after
video_config = {"audio_cap": max(0.0, tokens_audio - tokens_budget)}
Defensive patterns

Strategy: validation

Validate before calling

cap = cfg.get('audio_cap', 1.0)
assert isinstance(cap, (int, float)) and cap >= 0, f'audio_cap invalid: {cap}'

Type guard

def valid_audio_cap(cfg: dict) -> bool:
    cap = cfg.get('audio_cap', 1.0)
    return isinstance(cap, (int, float)) and not isinstance(cap, bool) and cap >= 0

Prevention

When it happens

Trigger: Passing video_config={"audio_cap": -1.0} (or any negative number) in a Dots Note Omni video request.

Common situations: Users misunderstand audio_cap as a boolean/integer flag or compute it as a difference that goes negative; the valid range is [0.0, ...) with 0 disabling audio processing.

Related errors


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