{"record":{"id":"65b799c2af9b2400","repo":"sgl-project/sglang","slug":"input-ids-must-be-1-d-got-list-input-ids-shape","errorCode":null,"errorMessage":"input_ids must be 1-D, got {list(input_ids.shape)}","messagePattern":"input_ids must be 1-D, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/encoders/minimax_h3_qwen3vl.py","lineNumber":339,"sourceCode":"            output_hidden_states=False,\n            return_dict=True,\n            use_cache=False,\n            **kwargs,\n        )\n        return BaseEncoderOutput(last_hidden_state=outputs.last_hidden_state)\n\n    @torch.no_grad()\n    def encode_ids(\n        self,\n        input_ids: torch.Tensor,\n        *,\n        pixel_values: torch.Tensor | None = None,\n        image_grid_thw: torch.Tensor | None = None,\n        pixel_values_videos: torch.Tensor | None = None,\n        video_grid_thw: torch.Tensor | None = None,\n    ) -> torch.Tensor:\n        if input_ids.dim() != 1:\n            raise ValueError(f\"input_ids must be 1-D, got {list(input_ids.shape)}\")\n        if (pixel_values is None) != (image_grid_thw is None):\n            raise ValueError(\"pixel_values and image_grid_thw must be given together\")\n        if (pixel_values_videos is None) != (video_grid_thw is None):\n            raise ValueError(\n                \"pixel_values_videos and video_grid_thw must be given together\"\n            )\n\n        host_ids = input_ids.to(device=\"cpu\", dtype=torch.long)[None]\n        host_image_grid_thw = (\n            image_grid_thw.to(device=\"cpu\", dtype=torch.long)\n            if image_grid_thw is not None\n            else None\n        )\n        host_video_grid_thw = (\n            video_grid_thw.to(device=\"cpu\", dtype=torch.long)\n            if video_grid_thw is not None\n            else None\n        )","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/encoders/minimax_h3_qwen3vl.py#L321-L357","documentation":"encode_ids requires a 1-D input_ids tensor (a single flattened sequence). Passing batched (2-D) or higher-rank token id tensors raises this immediately.","triggerScenarios":"Calling encode_ids(input_ids) with input_ids.dim() != 1, e.g. a [1, seq_len] batched tensor straight from a tokenizer with return_tensors='pt'.","commonSituations":"Feeding tokenizer output shaped (batch, seq) without squeezing; adapting code from batched encoders like Qwen3VLForConditionalGeneration which use 2-D inputs.","solutions":["Squeeze/flatten: input_ids = input_ids.reshape(-1) or input_ids[0] before calling encode_ids","Loop over the batch, calling encode_ids once per sequence"],"exampleFix":"# before\nout = encoder.encode_ids(tokenizer(...)[\"input_ids\"])  # shape [1, N]\n# after\nids = tokenizer(...)[\"input_ids\"].reshape(-1)\nout = encoder.encode_ids(ids)","handlingStrategy":"type-guard","validationCode":"assert input_ids.dim() == 1, f\"need 1-D ids, got {tuple(input_ids.shape)}\"","typeGuard":"def is_flat_ids(t: torch.Tensor) -> bool:\n    return isinstance(t, torch.Tensor) and t.dim() == 1","tryCatchPattern":null,"preventionTips":["Standardize on flattened ids at your call boundary (reshape(-1))","Wrap tokenizer outputs with a squeeze helper"],"tags":["minimax-h3","encode-ids","input-shape","rank-mismatch"],"backgroundTag":"input-shape-validation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}