{"record":{"id":"2afaca23fc4d75c0","repo":"sgl-project/sglang","slug":"width-and-height-must-be-non-zero-got-width-widt","errorCode":null,"errorMessage":"width and height must be non-zero, got width={width}, height={height}.","messagePattern":"width and height must be non-zero, got width=(.+?), height=(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3_action.py","lineNumber":119,"sourceCode":"def get_raw_action_dim(embodiment: str) -> int:\n    key = embodiment.lower().strip()\n    if key not in EMBODIMENT_TO_RAW_ACTION_DIM:\n        raise ValueError(\n            f\"No raw action dim for Cosmos3 embodiment {embodiment!r}. Expected one \"\n            f\"of {sorted(EMBODIMENT_TO_RAW_ACTION_DIM)}.\"\n        )\n    return EMBODIMENT_TO_RAW_ACTION_DIM[key]\n\n\ndef canonical_aspect_ratio(width: int, height: int) -> str:\n    \"\"\"Canonical ``\"W,H\"`` aspect string for the action caption.\"\"\"\n    for sizes in VIDEO_RES_SIZE_INFO.values():\n        for aspect, (cand_w, cand_h) in sizes.items():\n            if width == cand_w and height == cand_h:\n                return aspect\n    divisor = math.gcd(width, height)\n    if divisor == 0:\n        raise ValueError(\n            f\"width and height must be non-zero, got width={width}, height={height}.\"\n        )\n    return f\"{width // divisor},{height // divisor}\"\n\n\ndef build_action_prompt(\n    description: str | list[str],\n    view_point: str,\n    num_frames: int,\n    fps: float,\n    height: int,\n    width: int,\n) -> str | list[str]:\n    \"\"\"Render the structured JSON action caption the action checkpoints expect.\"\"\"\n    duration_seconds = num_frames / fps\n    minutes, secs = divmod(round(duration_seconds), 60)\n    if isinstance(description, (list, tuple)):\n        descriptions = [str(d) for d in description]","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3_action.py#L101-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set explicit non-zero width/height in the request (ideally one from VIDEO_RES_SIZE_INFO to get a named aspect)","Default resolution in the client when the field is absent rather than letting 0 through","Debug where the 0 originates: log the batch's resolution fields before build_action_prompt"],"exampleFix":"# before\nprompt = build_action_prompt(..., width=0, height=0)\n# after\nprompt = build_action_prompt(..., width=1280, height=720)","handlingStrategy":"validation","validationCode":"assert width > 0 and height > 0, f\"need non-zero resolution, got {width}x{height}\"","typeGuard":"def has_valid_resolution(w: int, h: int) -> bool:\n    return isinstance(w, int) and isinstance(h, int) and w > 0 and h > 0","tryCatchPattern":null,"preventionTips":["Default to a known resolution (e.g. from VIDEO_RES_SIZE_INFO) when the request omits one","Fail fast in request parsing on 0x0 rather than deep in prompt building","Log resolution fields in request dumps for debugging"],"tags":["cosmos3","resolution","aspect-ratio","validation"],"backgroundTag":"zero-dimension-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}