sgl-project/sglang · error · ValueError

rollout_noise_level must be a number, got {noise!r}

Error message

rollout_noise_level must be a number, got {noise!r}

What it means

The RL rollout sampling config validates rollout_noise_level (SDE noise strength) and rejects any value that is not an int or float. Booleans are explicitly rejected even though bool subclasses int in Python, because True/False as a noise level is almost always a mistake.

Source

Thrown at python/sglang/multimodal_gen/configs/post_training/rl_rollout.py:30

from sglang.multimodal_gen.utils import StoreBoolean

_VALID_ROLLOUT_SDE_TYPES = ("sde", "cps", "ode")


@dataclass
class RLRolloutArgs:
    """Rollout (log-prob trajectory) options used by SamplingParams and APIs."""

    rollout: bool = False
    rollout_sde_type: str = "sde"
    rollout_noise_level: float = 0.7
    rollout_log_prob_no_const: bool = False
    rollout_debug_mode: bool = False

    def validate(self) -> None:
        noise = self.rollout_noise_level
        if isinstance(noise, bool) or not isinstance(noise, (int, float)):
            raise ValueError(f"rollout_noise_level must be a number, got {noise!r}")
        if not math.isfinite(float(noise)):
            raise ValueError(f"rollout_noise_level must be finite, got {noise!r}")
        if float(noise) < 0.0:
            raise ValueError(f"rollout_noise_level must be non-negative, got {noise!r}")

        if self.rollout_sde_type not in _VALID_ROLLOUT_SDE_TYPES:
            raise ValueError(
                f"rollout_sde_type must be one of {_VALID_ROLLOUT_SDE_TYPES}, "
                f"got {self.rollout_sde_type!r}"
            )

    @classmethod
    def validate_sampling_params(cls, params: Any) -> None:
        """Validate rollout fields on a duck-typed object (e.g. ``SamplingParams``).

        Mirrors how ``ServerArgs`` runs ``NunchakuSVDQuantArgs.validate()`` from
        ``_adjust_quant_config`` instead of inlining checks in a large validator.
        """

View on GitHub (pinned to 0132848349)

Solutions

  1. Set rollout_noise_level to a plain number, e.g. 0.0 or 1.0
  2. If loading from YAML/JSON/CLI, coerce before validation: float(value) with the string handled explicitly
  3. If the field is optional in your flow, default it to 0.0 rather than leaving None

Example fix

# before
params.rollout_noise_level = "0.1"  # or True

# after
params.rollout_noise_level = 0.1
Defensive patterns

Strategy: type-guard

Validate before calling

from numbers import Real
assert isinstance(params.rollout_noise_level, Real) and not isinstance(params.rollout_noise_level, bool), "rollout_noise_level must be numeric"

Type guard

def is_valid_noise_level(v) -> bool:
    return isinstance(v, (int, float)) and not isinstance(v, bool)

Prevention

When it happens

Trigger: Setting rollout_noise_level=true/false, a string like "0.1", None, or any non-numeric value in RL rollout sampling params; validate() is invoked via validate_sampling_params before rollout starts.

Common situations: Passing a CLI/YAML value that stays a string (e.g. rollout_noise_level: "0.1" from config parsing); using a boolean flag by mistake (copied from rollout_debug_mode); templating configs that substitute None when the value is omitted.

Related errors


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