sgl-project/sglang · error · ValueError

width and height must be non-zero, got width={width}, height

Error message

width and height must be non-zero, got width={width}, height={height}.

What it means

canonical_aspect_ratio reduces width/height by their GCD to an 'w,h' aspect string after failing to match a known resolution in VIDEO_RES_SIZE_INFO. If either dimension is 0, math.gcd is 0 and division is impossible, so it raises. Zero dimensions usually indicate unset/failed resolution resolution upstream.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3_action.py:119

def get_raw_action_dim(embodiment: str) -> int:
    key = embodiment.lower().strip()
    if key not in EMBODIMENT_TO_RAW_ACTION_DIM:
        raise ValueError(
            f"No raw action dim for Cosmos3 embodiment {embodiment!r}. Expected one "
            f"of {sorted(EMBODIMENT_TO_RAW_ACTION_DIM)}."
        )
    return EMBODIMENT_TO_RAW_ACTION_DIM[key]


def canonical_aspect_ratio(width: int, height: int) -> str:
    """Canonical ``"W,H"`` aspect string for the action caption."""
    for sizes in VIDEO_RES_SIZE_INFO.values():
        for aspect, (cand_w, cand_h) in sizes.items():
            if width == cand_w and height == cand_h:
                return aspect
    divisor = math.gcd(width, height)
    if divisor == 0:
        raise ValueError(
            f"width and height must be non-zero, got width={width}, height={height}."
        )
    return f"{width // divisor},{height // divisor}"


def build_action_prompt(
    description: str | list[str],
    view_point: str,
    num_frames: int,
    fps: float,
    height: int,
    width: int,
) -> str | list[str]:
    """Render the structured JSON action caption the action checkpoints expect."""
    duration_seconds = num_frames / fps
    minutes, secs = divmod(round(duration_seconds), 60)
    if isinstance(description, (list, tuple)):
        descriptions = [str(d) for d in description]

View on GitHub (pinned to 0132848349)

Solutions

  1. Set explicit non-zero width/height in the request (ideally one from VIDEO_RES_SIZE_INFO to get a named aspect)
  2. Default resolution in the client when the field is absent rather than letting 0 through
  3. Debug where the 0 originates: log the batch's resolution fields before build_action_prompt

Example fix

# before
prompt = build_action_prompt(..., width=0, height=0)
# after
prompt = build_action_prompt(..., width=1280, height=720)
Defensive patterns

Strategy: validation

Validate before calling

assert width > 0 and height > 0, f"need non-zero resolution, got {width}x{height}"

Type guard

def has_valid_resolution(w: int, h: int) -> bool:
    return isinstance(w, int) and isinstance(h, int) and w > 0 and h > 0

Prevention

When it happens

Trigger: build_action_prompt calling canonical_aspect_ratio with width=0 or height=0 — e.g. the request omitted resolution and a default of 0 propagated, or a video-info parse produced 0 for one axis.

Common situations: Missing resolution field in the action request payload; upstream metadata extraction failure yielding 0x0; new client code that forgets to set height/width for action prompts.

Related errors


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