sgl-project/sglang · error · ValueError

action_mode={mode!r} requires --raw-action-dim.

Error message

action_mode={mode!r} requires --raw-action-dim.

What it means

Raised by Cosmos3's _prepare_action_latents when an action-mode request (e.g. action-dynamics) carries no inline action tensor, so the stage must synthesize a placeholder clean-action tensor, but no --raw-action-dim was supplied. The raw action dim is needed to size the zero-filled action chunk. It is a configuration error: the CLI/server args omitted a required flag for the chosen action_mode.

Source

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

                )
            if action.shape[0] < action_chunk_size:
                pad = action[-1:].repeat(action_chunk_size - action.shape[0], 1)
                action = torch.cat([action, pad], dim=0)
            elif action.shape[0] > action_chunk_size:
                action = action[:action_chunk_size]
            if raw_action_dim is None:
                raw_action_dim = int(action.shape[-1])
            stats_path = getattr(sp, "action_stats_path", None)
            if stats_path is not None:
                method = getattr(sp, "action_normalization", "quantile")
                action = normalize_action(action, method, load_action_stats(stats_path))
            if action.shape[-1] < action_dim:
                pad = torch.zeros(action.shape[0], action_dim - action.shape[-1])
                action = torch.cat([action, pad], dim=-1)
            clean_action = action.to(device=device, dtype=dtype).unsqueeze(0)
        else:
            if raw_action_dim is None:
                raise ValueError(f"action_mode={mode!r} requires --raw-action-dim.")
            clean_action = torch.zeros(
                batch_dim, action_chunk_size, action_dim, device=device, dtype=dtype
            )

        raw_action_dim = int(raw_action_dim)
        if not 0 < raw_action_dim <= action_dim:
            raise ValueError(
                f"raw_action_dim must be in [1, {action_dim}], got {raw_action_dim}"
            )

        # condition_mask marks clean (given) action tokens. forward_dynamics
        # conditions on the whole action sequence; the others denoise it fully.
        condition_mask = torch.zeros(
            batch_dim, action_chunk_size, 1, device=device, dtype=dtype
        )
        if mode == ACTION_MODE_FORWARD_DYNAMICS:
            condition_mask[:] = 1.0

View on GitHub (pinned to 0132848349)

Solutions

  1. Add --raw-action-dim <N> to the server launch args, matching your embodiment's action dimension (see EMBODIMENT_TO_RAW_ACTION_DIM in cosmos3_action.py)
  2. Or pass an explicit action tensor in the request so the padding branch is used instead
  3. Verify server_args.pipeline_config actually propagates the flag to the stage

Example fix

# before
python -m sglang.launch_server --model cosmos3 --action-mode dynamics
# after
python -m sglang.launch_server --model cosmos3 --action-mode dynamics --raw-action-dim 7
Defensive patterns

Strategy: validation

Validate before calling

from sglang.multimodal_gen.runtime.pipelines_core.stages.model_specific_stages.cosmos3_action import get_raw_action_dim
assert server_args.raw_action_dim is not None or request_has_inline_actions(req), "--raw-action-dim required for this action_mode"

Type guard

def has_raw_action_dim(args) -> bool:
    return getattr(args, "raw_action_dim", None) is not None

Prevention

When it happens

Trigger: Sending a request whose action_mode implies generated/clean actions without an input action array, while launching the server without --raw-action-dim; _prepare_action_latents takes the else-branch that builds torch.zeros(batch, chunk, action_dim).

Common situations: Switching a Cosmos3 world-model pipeline from video-only to action-conditioned generation without adding the new CLI flag; copying an old launch script after upgrading to an action-aware sglang version.

Related errors


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