{"record":{"id":"28a61cca9cb5542a","repo":"sgl-project/sglang","slug":"action-must-have-shape-t-d-got-tuple-action-s","errorCode":null,"errorMessage":"action must have shape [T, D], got {tuple(action.shape)}","messagePattern":"action must have shape \\[T, D\\], got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py","lineNumber":707,"sourceCode":"        if raw_action_dim is None:\n            embodiment = getattr(sp, \"domain_name\", None)\n            if embodiment:\n                raw_action_dim = get_raw_action_dim(embodiment)\n\n        if mode == ACTION_MODE_FORWARD_DYNAMICS:\n            raw = getattr(sp, \"action\", None)\n            if raw is None:\n                raise ValueError(\n                    \"action_mode='forward_dynamics' requires an 'action' array \"\n                    \"(list[list[float]] of shape [T, D]).\"\n                )\n            if isinstance(raw, str):\n                raw = json.loads(raw)\n            action = torch.as_tensor(np.asarray(raw), dtype=torch.float32)\n            if action.ndim == 3 and action.shape[0] == 1:\n                action = action.squeeze(0)\n            if action.ndim != 2:\n                raise ValueError(\n                    f\"action must have shape [T, D], got {tuple(action.shape)}\"\n                )\n            if action.shape[0] < action_chunk_size:\n                pad = action[-1:].repeat(action_chunk_size - action.shape[0], 1)\n                action = torch.cat([action, pad], dim=0)\n            elif action.shape[0] > action_chunk_size:\n                action = action[:action_chunk_size]\n            if raw_action_dim is None:\n                raw_action_dim = int(action.shape[-1])\n            stats_path = getattr(sp, \"action_stats_path\", None)\n            if stats_path is not None:\n                method = getattr(sp, \"action_normalization\", \"quantile\")\n                action = normalize_action(action, method, load_action_stats(stats_path))\n            if action.shape[-1] < action_dim:\n                pad = torch.zeros(action.shape[0], action_dim - action.shape[-1])\n                action = torch.cat([action, pad], dim=-1)\n            clean_action = action.to(device=device, dtype=dtype).unsqueeze(0)\n        else:","sourceCodeStart":689,"sourceCodeEnd":725,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py#L689-L725","documentation":"After converting the provided action array to a tensor (and squeezing a leading batch dim of 1), the stage requires ndim==2, i.e. shape [timesteps, action_dim]. Flat vectors, per-frame nested batches, or scalars fail this check.","triggerScenarios":"Passing sp.action as a flat list of D floats ([D]), a scalar, or a 3D array with batch dim != 1; each yields ndim != 2 after the squeeze.","commonSituations":"Supplying a single action step as a flat vector instead of [[...]], or sending multiple rollouts stacked along dim 0.","solutions":["Reshape the action data to [T, D]: wrap a single step as [[...]]","If sending a batched tensor, keep batch dim = 1 or split per-request","Validate action array shape client-side before submitting the request"],"exampleFix":"# before\nsp.action = [0.0, 1.0, 0.0]\n\n# after\nsp.action = [[0.0, 1.0, 0.0]]  # shape [1, 3]","handlingStrategy":"validation","validationCode":"import numpy as np\na = np.asarray(sp.action, dtype='float32')\nif a.ndim == 3 and a.shape[0] == 1: a = a[0]\nassert a.ndim == 2, f'action must be [T, D], got {a.shape}'","typeGuard":"def action_is_2d(action) -> bool:\n    import numpy as np\n    a = np.asarray(action)\n    if a.ndim == 3 and a.shape[0] == 1:\n        a = a[0]\n    return a.ndim == 2","tryCatchPattern":null,"preventionTips":["Always send [T, D] nested lists; wrap single steps as [[...]]","Never stack multiple rollows along dim 0; send one request per rollout"],"tags":["cosmos3","action-generation","tensor-shape","validation"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}