{"record":{"id":"8c298bed137a6c68","repo":"sgl-project/sglang","slug":"height-width-must-be-between-256-and-2048","errorCode":null,"errorMessage":"height/width must be between 256 and 2048","messagePattern":"height/width must be between 256 and 2048","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ideogram.py","lineNumber":147,"sourceCode":"        )\n        encoded = self.tokenizers[0](\n            text, return_tensors=\"pt\", add_special_tokens=False\n        )\n        token_ids = encoded[\"input_ids\"][0]\n        num_text_tokens = int(token_ids.shape[0])\n        if num_text_tokens > max_text_tokens:\n            raise ValueError(\n                f\"prompt has {num_text_tokens} tokens, exceeds max_text_tokens={max_text_tokens}\"\n            )\n        return token_ids, num_text_tokens\n\n    def _build_inputs(self, prompts: list[str], height: int, width: int, server_args):\n        cfg = server_args.pipeline_config\n        tokenized = [self._tokenize(p, cfg.max_text_tokens) for p in prompts]\n        batch_size = len(prompts)\n        patch = cfg.patch_size * cfg.ae_scale_factor\n        if height < 256 or height > 2048 or width < 256 or width > 2048:\n            raise ValueError(\"height/width must be between 256 and 2048\")\n        if height % patch != 0 or width % patch != 0:\n            raise ValueError(\n                f\"height/width must be divisible by patch_size*ae_scale_factor={patch}\"\n            )\n        grid_h = height // patch\n        grid_w = width // patch\n        num_image_tokens = grid_h * grid_w\n        max_text_tokens = max(num_text for _, num_text in tokenized)\n        total_seq_len = max_text_tokens + num_image_tokens\n        device = get_local_torch_device()\n\n        h_idx = torch.arange(grid_h).view(-1, 1).expand(grid_h, grid_w).reshape(-1)\n        w_idx = torch.arange(grid_w).view(1, -1).expand(grid_h, grid_w).reshape(-1)\n        t_idx = torch.zeros_like(h_idx)\n        image_pos = torch.stack([t_idx, h_idx, w_idx], dim=1) + IMAGE_POSITION_OFFSET\n\n        token_ids = torch.zeros(batch_size, total_seq_len, dtype=torch.long)\n        text_position_ids = torch.zeros(batch_size, total_seq_len, 3, dtype=torch.long)","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ideogram.py#L129-L165","documentation":"The Ideogram stage validates requested image dimensions before building model inputs. Height and width must each lie in [256, 2048] pixels; anything outside that range is rejected because the model was trained only within that resolution range.","triggerScenarios":"Calling forward/generate with height or width below 256 or above 2048 (e.g. 128x128 thumbnails or 4096-wide panoramas).","commonSituations":"Defaulting to a square 1024 but allowing user-supplied sizes; UI sliders permitting out-of-range values; copying dimensions from another model (e.g. SDXL's 2048+) without clamping.","solutions":["Clamp height and width to [256, 2048]","Round the request to the nearest valid resolution (also respecting the patch divisibility rule)"],"exampleFix":"# before\nimg = stage(prompts=[p], height=240, width=1024)\n# after\nheight = min(max(height, 256), 2048)\nwidth = min(max(width, 256), 2048)\nimg = stage(prompts=[p], height=height, width=width)","handlingStrategy":"validation","validationCode":"if not (256 <= height <= 2048 and 256 <= width <= 2048):\n    height = min(max(height, 256), 2048)\n    width = min(max(width, 256), 2048)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp user-supplied dimensions at the API boundary","Restrict UI sliders to the supported range"],"tags":["ideogram","image-resolution","validation","out-of-range"],"backgroundTag":"image-dimension-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}