Skip to content

[Core] Clarify memory variable naming in model runner - #20060

Merged
hnyls2002 merged 2 commits into
mainfrom
lsyin/tiny-cleanup-num-reqs
Mar 6, 2026
Merged

[Core] Clarify memory variable naming in model runner#20060
hnyls2002 merged 2 commits into
mainfrom
lsyin/tiny-cleanup-num-reqs

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Mar 6, 2026

Copy link
Copy Markdown
Collaborator
  • Rename min_per_gpu_memorypre_model_load_memory across init_torch_distributed, initialize, and init_memory_pool
  • Rename total_gpu_memorypre_model_load_memory in profile_max_num_token parameter
  • Rename available_gpu_memorypost_model_load_memory in profile_max_num_token local variable
  • Remove redundant parentheses around self.dp_size in model_runner.py

The memory calculation rest_memory = post_model_load_memory - pre_model_load_memory * (1 - mem_fraction_static) now reads clearly without needing to trace variable origins.

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@hnyls2002 hnyls2002 changed the title Tiny rename [Core] Clarify memory variable naming in model runner Mar 6, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 focuses on enhancing code readability and maintainability by performing a series of variable renames. The changes clarify the meaning of GPU memory-related variables, specifically distinguishing between memory available before and after the model loading process. This refactoring improves the semantic accuracy of the code, making it easier to understand the memory state at different stages of the model's lifecycle.

Highlights

  • Variable Renaming for Clarity: Renamed min_per_gpu_memory to pre_model_load_memory in model_runner.py to more accurately reflect that it represents the available GPU memory before the model is loaded.
  • Consistent Memory Naming: Updated the profile_max_num_token and init_memory_pool methods in model_runner_kv_cache_mixin.py to use pre_model_load_memory instead of total_gpu_memory for consistency with the new naming convention.
  • Post-Model Load Memory Distinction: Introduced post_model_load_memory in profile_max_num_token to clearly differentiate the available GPU memory after the model has been loaded from the memory available before loading.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/srt/model_executor/model_runner.py
    • Renamed min_per_gpu_memory to pre_model_load_memory in the __init__ method.
    • Updated the initialize method's parameter name from min_per_gpu_memory to pre_model_load_memory.
    • Modified the init_torch_distributed method to return pre_model_load_memory and updated its internal usage.
    • Adjusted the call to init_memory_pool to pass pre_model_load_memory.
  • python/sglang/srt/model_executor/model_runner_kv_cache_mixin.py
    • Renamed the profile_max_num_token method's parameter from total_gpu_memory to pre_model_load_memory.
    • Renamed the local variable available_gpu_memory to post_model_load_memory within profile_max_num_token.
    • Updated memory calculation logic in profile_max_num_token to use the new variable names.
    • Renamed the init_memory_pool method's parameter from total_gpu_memory to pre_model_load_memory.
    • Adjusted the call to profile_max_num_token to pass pre_model_load_memory.
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.

@github-actions github-actions Bot added the run-ci label Mar 6, 2026

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

Copy link
Copy Markdown
Contributor

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 focuses on improving the clarity of variable names related to GPU memory management within the model runner. Key variables like min_per_gpu_memory and total_gpu_memory have been consistently renamed to pre_model_load_memory, and available_gpu_memory to post_model_load_memory. These changes significantly enhance the readability of memory calculation logic, particularly in profile_max_num_token. The refactoring is well-executed and makes the code more self-documenting and easier to maintain. I have no further suggestions.

@hnyls2002
hnyls2002 merged commit 604db44 into main Mar 6, 2026
27 of 65 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/tiny-cleanup-num-reqs branch March 6, 2026 22:00
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
@hnyls2002 hnyls2002 mentioned this pull request Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant