sgl-project/sglang · error · ValueError

--mamba-cache-philox-rounds must be non-negative.

Error message

--mamba-cache-philox-rounds must be non-negative.

What it means

--mamba-cache-philox-rounds controls Philox RNG rounds used when initializing/dropping Mamba (hybrid linear-attention) cache states; negative values are meaningless and rejected outright by the _handle_mamba_backend resolution step (0 is allowed, only < 0 raises).

Source

Thrown at python/sglang/srt/server_args.py:6749

    def _handle_nccl_pre_warm(self):
        # pre_warm_nccl is only used with CUDA or HIP hardware or NPU hardware
        cfg = resolving_view(self)
        if cfg.pre_warm_nccl and not (is_cuda() or is_hip() or is_npu()):
            logger.warning(
                "pre_warm_nccl is only applicable for CUDA or HIP hardware or NPU hardware. "
                "Ignoring pre_warm_nccl setting on current hardware."
            )
            self._declare("_handle_nccl_pre_warm", pre_warm_nccl=False)

    def _handle_grammar_backend(self):
        cfg = resolving_view(self)
        if cfg.grammar_backend is None:
            self._declare("_handle_grammar_backend", grammar_backend="xgrammar")

    def _handle_mamba_backend(self):
        cfg = resolving_view(self)
        if cfg.mamba_cache_philox_rounds < 0:
            raise ValueError("--mamba-cache-philox-rounds must be non-negative.")

        if cfg.mamba_max_states_per_path == 0 or cfg.mamba_max_states_per_path < -1:
            raise ValueError(
                "--mamba-max-states-per-path must be -1 (unlimited) or a positive "
                f"integer, got {cfg.mamba_max_states_per_path}."
            )

        if cfg.enable_mamba_cache_stochastic_rounding:
            if cfg.mamba_ssm_dtype != "float16":
                raise ValueError(
                    "Stochastic rounding for the Mamba SSM cache requires "
                    f"--mamba-ssm-dtype float16, got {cfg.mamba_ssm_dtype!r}. "
                    "Run with --mamba-ssm-dtype float16 or disable "
                    "--enable-mamba-cache-stochastic-rounding."
                )
            if not is_cuda():
                raise ValueError(
                    "Stochastic rounding for the Mamba SSM cache is only "

View on GitHub (pinned to 0132848349)

Solutions

  1. Set --mamba-cache-philox-rounds to 0 (default/off) or a positive round count
  2. Audit launch scripts/env templates that coerce unset values to -1
  3. If you meant unlimited states, use --mamba-max-states-per-path, not philox-rounds

Example fix

# before
python -m sglang.launch_server --model M --mamba-cache-philox-rounds -1
# after
python -m sglang.launch_server --model M --mamba-cache-philox-rounds 0
Defensive patterns

Strategy: validation

Validate before calling

if getattr(args, "mamba_cache_philox_rounds", 0) is not None:
    rounds = args.mamba_cache_philox_rounds or 0
    assert rounds >= 0, "--mamba-cache-philox-rounds must be non-negative"

Try / catch

try:
    ServerArgs(**kwargs)
except ValueError as e:
    if "philox" in str(e):
        kwargs["mamba_cache_philox_rounds"] = 0
        ServerArgs(**kwargs)
    else:
        raise

Prevention

When it happens

Trigger: Passing a negative integer to --mamba-cache-philox-rounds (e.g. --mamba-cache-philox-rounds -1) so that cfg.mamba_cache_philox_rounds < 0 when the mamba backend handler runs.

Common situations: Typos or env-var templating producing -1; users assuming -1 means 'unlimited/default' like the sibling flag --mamba-max-states-per-path which does accept -1; scripts defaulting unset numeric flags to -1.

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/118487f605af26bb. Report an issue: GitHub.