Skip to content

Conversation

@nicole-lihui
Copy link
Collaborator

part of #44

The default 128k maxTokens causes OOM on 50GB GPUs for long-context inference.

https://huggingface.co/zai-org/glm-4-9b-chat/blob/main/generation_config.json

image

@gemini-code-assist
Copy link

Summary of Changes

Hello @nicole-lihui, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical memory issue encountered when deploying the glm-4-9b-chat model on GPUs with 50GB memory, particularly during long-context inference. By configuring specific runtime parameters, the model's memory footprint is optimized, ensuring stable operation and preventing Out-Of-Memory errors without altering the model's theoretical maximum token capacity.

Highlights

  • GPU Memory Optimization: Introduced custom runtime arguments --max-num-batched-tokens and --max-model-len set to 32768 for the glm-4-9b-chat model deployment configuration.
  • Out-of-Memory Prevention: These changes are specifically designed to prevent Out-Of-Memory (OOM) errors when performing long-context inference on 50GB GPUs, addressing a known issue.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to resolve an out-of-memory issue on 50GB GPUs for the glm-4-9b-chat model by limiting the token processing capacity. It introduces customRuntimeArgs to set --max-model-len and --max-num-batched-tokens for the vLLM runtime. While this is a good step, I've pointed out a significant inconsistency where spec.config.maxTokens is not updated to match the new runtime limit, which could lead to runtime errors and a poor user experience. I've recommended aligning these values for consistency.

Comment on lines 9 to 11
- customRuntimeArgs:
- --max-num-batched-tokens=32768 # default
- --max-model-len=32768

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While adding --max-model-len=32768 correctly configures the vLLM runtime to prevent out-of-memory errors, there's an inconsistency with spec.config.maxTokens which remains at 128000 on line 7. This can lead to a confusing user experience or runtime errors if a user requests a number of tokens to generate that is valid according to maxTokens but exceeds the max-model-len limit when combined with the prompt length.

To ensure consistency and prevent unexpected failures, spec.config.maxTokens should be aligned with max-model-len. I recommend reducing spec.config.maxTokens to 32768. Since this line is not part of the current changes, please consider amending this pull request to include this change.

Reason: The default 128k maxTokens causes OOM on 50GB GPUs for long-context inference.
@nicole-lihui nicole-lihui force-pushed the reduce-maxtokens-glm-4-9b-chat branch from fd96c01 to 7d1edc3 Compare October 21, 2025 10:10
deployments:
- customRuntimeArgs: []
- customRuntimeArgs:
- --max-num-batched-tokens=32768 # Reduce maxTokens from 128k to 32k to fit 50GB GPU and avoid OOM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般不要设置到最大长度,单机的情况下可以不修改。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants