sgl-project/sglang · error · ValueError

domain_id must be non-negative, got {domain_id}

Error message

domain_id must be non-negative, got {domain_id}

What it means

Action generation requires identifying an embodiment domain via sampling_params.domain_id. Explicit domain IDs must be non-negative integers because they index the domain embedding table; negative values are rejected.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py:635

                    "action_mode is set but the loaded Cosmos3 checkpoint has no "
                    "action modality (action_gen is False)."
                )
            self._prepare_action_latents(batch, generator, device, dtype)
        return batch

    def component_uses(
        self, server_args: ServerArgs, stage_name: str | None = None
    ) -> list[ComponentUse]:
        return [ComponentUse(self._component_stage_name(stage_name), "vae")]

    @staticmethod
    def _resolve_domain_id(batch: Req) -> int:
        """Resolve action embodiment domain ID; required for action generation."""
        domain_id = getattr(batch.sampling_params, "domain_id", None)
        if domain_id is not None:
            domain_id = int(domain_id)
            if domain_id < 0:
                raise ValueError(f"domain_id must be non-negative, got {domain_id}")
            return domain_id
        domain_name = getattr(batch.sampling_params, "domain_name", None)
        if domain_name:
            key = str(domain_name).strip().lower()
            if key not in EMBODIMENT_TO_DOMAIN_ID:
                raise ValueError(
                    f"Unknown action domain name {domain_name!r}. "
                    f"Valid names: {sorted(EMBODIMENT_TO_DOMAIN_ID)}"
                )
            return EMBODIMENT_TO_DOMAIN_ID[key]
        raise ValueError(
            "Cosmos3 action generation requires --domain-id or --domain-name."
        )

    def _prepare_action_latents(
        self,
        batch: Req,
        generator,

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass a valid non-negative domain_id (see EMBODIMENT_TO_DOMAIN_ID values)
  2. Omit domain_id and use domain_name instead so it is looked up from the registry
  3. Use a sentinel like None rather than -1 for 'unspecified'

Example fix

# before
sp.domain_id = -1

# after
sp.domain_id = None
sp.domain_name = 'franka'
Defensive patterns

Strategy: validation

Validate before calling

if sp.domain_id is not None:
    assert int(sp.domain_id) >= 0, 'domain_id must be non-negative'

Type guard

def valid_domain_id(v) -> bool:
    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 0)

Prevention

When it happens

Trigger: Passing sampling_params.domain_id = -1 (or any negative int) when action_mode is set; _resolve_domain_id converts to int then checks < 0.

Common situations: Using -1 or 0-based-vs-1-based confusion as a sentinel for 'unspecified'; passing a numpy int that evaluates negative after int() coercion.

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/287ab1085595edb7. Report an issue: GitHub.