{"record":{"id":"7594355452814a80","repo":"sgl-project/sglang","slug":"glm-image-ar-returned-too-few-output-ids-got-act","errorCode":null,"errorMessage":"GLM-Image AR returned too few output_ids: got {actual_output_len}, need at least {expected_output_len} (large_image_offset={large_image_offset}, token_h={token_h}, token_w={token_w}).","messagePattern":"GLM-Image AR returned too few output_ids: got (.+?), need at least (.+?) \\(large_image_offset=(.+?), token_h=(.+?), token_w=(.+?)\\)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py","lineNumber":384,"sourceCode":"            logger.error(\n                \"SGLang encoder request to %s failed: %s\",\n                server_args.srt_encoder_url,\n                e,\n            )\n            raise\n        return response.json()\n\n    def _extract_prior_token_ids(\n        self,\n        generated_ids: Any,\n        generation_shape: tuple[int, int, int],\n        device: torch.device,\n    ) -> torch.Tensor:\n        large_image_offset, token_h, token_w = generation_shape\n        expected_output_len = large_image_offset + token_h * token_w\n        actual_output_len = 0 if generated_ids is None else len(generated_ids)\n        if actual_output_len < expected_output_len:\n            raise RuntimeError(\n                \"GLM-Image AR returned too few output_ids: \"\n                f\"got {actual_output_len}, need at least {expected_output_len} \"\n                f\"(large_image_offset={large_image_offset}, \"\n                f\"token_h={token_h}, token_w={token_w}).\"\n            )\n\n        prior_token_ids_d32 = torch.tensor(\n            generated_ids[large_image_offset : large_image_offset + token_h * token_w],\n            device=device,\n        )\n        return self._upsample_token_ids(prior_token_ids_d32, token_h, token_w)\n\n    def generate_prior_tokens(\n        self,\n        prompt: str,\n        height: int,\n        width: int,\n        server_args: ServerArgs,","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py#L366-L402","documentation":"The GLM-Image autoregressive (AR) stage produced fewer output token ids than required to fill the requested image token grid. The expected length is large_image_offset + token_h * token_w, derived from the requested resolution; anything shorter means the AR model stopped (e.g. emitted EOS) or was capped by max_new_tokens before covering the full latent grid. This is a hard RuntimeError because downstream stages cannot slice a full token grid from a truncated output.","triggerScenarios":"Calling generate_prior_tokens / generate_prior_tokens_batch with max_new_tokens set below grid_h*grid_w + 1; the AR server returning early because EOS was sampled; a mismatch between the requested image size (token_h/token_w) and the sampling params sent to the AR endpoint; or generated_ids being None/empty from a failed generation.","commonSituations":"Custom height/width that produce a larger token grid than the configured max_new_tokens; using an external SGLang encoder/AR server whose sampling params truncate output; model version change altering the large-image offset convention; batch requests where one item exhausts its token budget early.","solutions":["Verify max_new_tokens is exactly grid_h * grid_w + 1 (the +1 accounts for EOS) before calling the AR stage","Check the requested height/width and the resulting token_h/token_w so the grid matches the token budget","If using an external AR server, inspect its response body to confirm output_ids length and that EOS is not terminating generation early","Upgrade/align the GLM-Image AR model version so large_image_offset matches the checkpoint convention","Retry the request after lowering resolution until output length reliably covers the grid"],"exampleFix":"# before\nsampling_params = {\"max_new_tokens\": 1024}  # grid needs 36*36+1 = 1297\n\n# after\nexpected = large_image_offset + token_h * token_w\nsampling_params = {\"max_new_tokens\": expected + 1}  # +1 for EOS","handlingStrategy":"validation","validationCode":"expected = large_image_offset + token_h * token_w\nmax_new_tokens = expected + 1  # +1 for EOS\nif sampling_params.get(\"max_new_tokens\", 0) < expected + 1:\n    raise ValueError(f\"max_new_tokens {sampling_params.get('max_new_tokens')} < required {expected + 1}\")","typeGuard":null,"tryCatchPattern":"except RuntimeError as e:\n    if \"too few output_ids\" in str(e):\n        lower_resolution_and_retry()  # smaller token grid\n    else:\n        raise","preventionTips":["Always compute max_new_tokens from the token grid, never hard-code it","Validate requested height/width maps to a token grid within the AR context limit","Log actual vs expected output length on every AR call to catch drift early"],"tags":["glm-image","autoregressive","token-length","image-generation","runtimeerror"],"backgroundTag":"truncated-generation-output","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}