sgl-project/sglang · error · ValueError

raw_action_dim must be in [1, {action_dim}], got {raw_action

Error message

raw_action_dim must be in [1, {action_dim}], got {raw_action_dim}

What it means

Cosmos3 validates that --raw-action-dim lies in (0, action_dim], where action_dim is the model's internal action latent dimension. A value of 0, negative, or larger than action_dim breaks the projection from raw action space into latents, so it is rejected with a ValueError before tensor allocation.

Source

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

                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

        noise = torch.randn(
            batch_dim,
            action_chunk_size,
            action_dim,
            generator=generator,
            device=device,
            dtype=dtype,

View on GitHub (pinned to 0132848349)

Solutions

  1. Check the model's action_dim (config) and set --raw-action-dim to a value in [1, action_dim]
  2. Use get_raw_action_dim(embodiment) from cosmos3_action.py to look up the correct value for your embodiment
  3. Log/int the parsed flag value to catch CLI parsing mistakes like scientific notation or float strings

Example fix

# before
--raw-action-dim 0
# after
--raw-action-dim 7  # franka-panda gripper+arm dims, must be <= action_dim
Defensive patterns

Strategy: validation

Validate before calling

assert 0 < int(raw_action_dim) <= action_dim, f"raw_action_dim must be in [1, {action_dim}]"

Type guard

def valid_raw_action_dim(v: int, action_dim: int) -> bool:
    return isinstance(v, int) and 0 < v <= action_dim

Prevention

When it happens

Trigger: Passing --raw-action-dim 0, a negative number, or a value exceeding the model's action_dim to the server, then issuing any action request that reaches _prepare_action_latents.

Common situations: Typo in the flag value; using an embodiment's joint count (e.g. 32) against a model whose action_dim is smaller; forgetting that raw dims are padded up to action_dim and assuming larger is fine.

Related errors


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