{"record":{"id":"b53010188dba2767","repo":"sgl-project/sglang","slug":"height-width-must-be-divisible-by-patch-size-ae-sc","errorCode":null,"errorMessage":"height/width must be divisible by patch_size*ae_scale_factor={patch}","messagePattern":"height/width must be divisible by patch_size\\*ae_scale_factor=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ideogram.py","lineNumber":149,"sourceCode":"            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)\n        position_ids = torch.zeros(batch_size, total_seq_len, 3, dtype=torch.long)\n        segment_ids = torch.full(","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ideogram.py#L131-L167","documentation":"The Ideogram stage requires height and width to be divisible by patch_size * ae_scale_factor (the latent-space compression granularity). Non-divisible dimensions would produce fractional latent grid sizes, so they are rejected up front.","triggerScenarios":"Passing height/width divisible in-range values that are not multiples of cfg.patch_size * cfg.ae_scale_factor, e.g. 1000 when patch granularity is 16 (2 patch * 8 ae scale).","commonSituations":"Arbitrary user-supplied sizes like 333 or 700; changing patch_size or ae_scale_factor in config without re-rounding the client's dimensions; porting sizes from a model with a different VAE scale factor.","solutions":["Round height/width to the nearest multiple of cfg.patch_size * cfg.ae_scale_factor","Use canonical sizes that are multiples of the granularity (e.g. 256-step sizes within [256,2048])"],"exampleFix":"# before\nh, w = 1000, 768\n# after\npatch = cfg.patch_size * cfg.ae_scale_factor\nh = round(h / patch) * patch\nw = round(w / patch) * patch","handlingStrategy":"validation","validationCode":"patch = cfg.patch_size * cfg.ae_scale_factor\nheight = round(height / patch) * patch\nwidth = round(width / patch) * patch\nassert height % patch == 0 and width % patch == 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Snap dimensions to the model's latent granularity before requests","Expose only precomputed valid resolutions to users"],"tags":["ideogram","image-resolution","divisibility","validation"],"backgroundTag":"dimension-not-divisible-by-patch-size","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}