sgl-project/sglang · error · ValueError

action output dimensions must be non-zero, got {tuple(action

Error message

action output dimensions must be non-zero, got {tuple(action_array.shape)}

What it means

Raised by action_generation_response while validating the `actions` field of the model output: after np.asarray(actions), any dimension of the array is zero (e.g. shape (0,), (H, 0), (0, H, D)). The response builder refuses to serialize an empty action tensor because it would emit zero data items.

Source

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

    req = prepare_request(server_args, sp)
    response = await async_scheduler_client.forward(req)
    if getattr(response, "error", None):
        raise RuntimeError(response.error)
    if response.output is None:
        raise RuntimeError("action policy returned no output")
    return response.output[0]


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",

View on GitHub (pinned to 0132848349)

Solutions

  1. Ensure the action policy actually produces non-empty output (check input observations and horizon settings)
  2. Fix sampling params so the generated horizon/action dimensions are > 0
  3. If writing tests, use realistic non-empty action arrays when mocking output

Example fix

# before
output = {"actions": np.zeros((0, 8))}
action_generation_response(output, server_args)  # ValueError

# after
output = {"actions": np.zeros((1, 8))}
action_generation_response(output, server_args)  # OK
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
arr = np.asarray(output["actions"])
if arr.size == 0 or any(s == 0 for s in arr.shape):
    raise ValueError("rejecting empty actions before response build")

Type guard

def has_nonzero_shape(actions) -> bool:
    a = np.asarray(actions)
    return a.ndim >= 1 and all(s > 0 for s in a.shape)

Prevention

When it happens

Trigger: Calling create_action_generation, action_realtime_ws, or action_generation_response directly with output['actions'] containing an empty list or an array with a zero dimension — e.g. the policy returned [] or an array of shape (0, D).

Common situations: Policy model returns an empty action list for degenerate input, horizon dimension collapses to 0 due to misconfigured sampling params, mocking/stubbing outputs in tests with empty arrays.

Related errors


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