sgl-project/sglang · error · ValueError

action output must have shape [H, D] or [B, H, D], got {tupl

Error message

action output must have shape [H, D] or [B, H, D], got {tuple(action_array.shape)}

What it means

Raised by action_generation_response when the action array, after zero-dimension checks, is neither 2-D (expected [H, D], auto-promoted to [1, H, D]) nor 3-D ([B, H, D]). Any other rank (0-D, 1-D, 4-D+) is rejected because the response format only supports single or batched action sequences with horizon and action-dim axes.

Source

Thrown at python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py:444


def action_generation_response(
    output: dict[str, Any],
    server_args: ServerArgs,
    *,
    preserve_numpy: bool = False,
) -> dict[str, Any]:
    actions = output["actions"]
    action_array = np.asarray(actions)
    if any(size == 0 for size in action_array.shape):
        raise ValueError(
            "action output dimensions must be non-zero, got "
            f"{tuple(action_array.shape)}"
        )
    if action_array.ndim == 2:
        action_array = action_array[None]
    elif action_array.ndim != 3:
        raise ValueError(
            "action output must have shape [H, D] or [B, H, D], got "
            f"{tuple(action_array.shape)}"
        )

    data = []
    for input_index, action_values in enumerate(action_array):
        action_shape = list(action_values.shape)
        if not preserve_numpy:
            action_values = action_values.tolist()
        action = {
            "type": "continuous",
            "dtype": "float32",
            "shape": action_shape,
            "values": action_values,
        }
        for name in ("action_mode", "domain_id", "raw_action_dim"):
            if output.get(name) is not None:
                action[name] = output[name]

View on GitHub (pinned to 0132848349)

Solutions

  1. Reshape the policy output to [H, D] (horizon, action_dim) or [B, H, D] before passing it in
  2. Check the action head's output reshaping code upstream for a missing horizon/batch axis
  3. If only a single action step is produced, expand dims: arr[None, :] to make it [1, D] -> [1, 1, D]

Example fix

# before
output = {"actions": np.zeros(8)}  # shape (8,) -> ValueError

# after
output = {"actions": np.zeros((1, 8))}  # [H=1, D=8] -> auto [1,1,8]
Defensive patterns

Strategy: type-guard

Validate before calling

import numpy as np
arr = np.asarray(output["actions"])
assert arr.ndim in (2, 3), f"bad action rank {arr.ndim}"

Type guard

def is_valid_action_shape(actions) -> bool:
    a = np.asarray(actions)
    return a.ndim in (2, 3) and all(s > 0 for s in a.shape)

Prevention

When it happens

Trigger: Calling action_generation_response (directly or via create_action_generation / action_realtime_ws) with output['actions'] shaped like a flat vector (D,), a scalar, or a 4-D array.

Common situations: Policy head emits a flat action vector per step instead of a sequence, wrong tensor reshaping upstream, tests feeding raw 1-D action vectors.

Related errors


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