Skip to content

Conversation

@yeshsurya
Copy link
Contributor

@yeshsurya yeshsurya commented Oct 20, 2025

Purpose

  • Extract math utilities (cdiv, round_up, round_down, etc.) to math_utils.py
  • Extract argument parsing classes (FlexibleArgumentParser, etc.) to argparse_utils.py
  • Reduce init.py from 1,293 to 819 lines (37% reduction)
  • Maintain full backward compatibility via re-exports

Contributes to #26900

Test Plan

Verify that the refactoring of math and argparse utilities into separate modules (vllm/utils/math_utils.py and vllm/utils/argparse_utils.py)
maintains backward compatibility and does not break existing functionality

Test Result

tests/utils_/test_utils.py
Passed

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link
Contributor

@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 refactors math and argparse utilities into separate modules, which is a great step for improving code organization and maintainability. The changes correctly maintain backward compatibility by re-exporting the moved utilities. My review focuses on the newly created files, where I've identified a few issues: a missing type hint that could lead to a runtime error, a leftover debug print statement, and a couple of instances of incorrect string formatting for error and log messages. These issues could impact usability and debugging. I've provided specific suggestions to address them.


def round_down(x: int, y: int) -> int:
return (x // y) * y
# Math utilities - imported from math_utils module
Copy link
Member

Choose a reason for hiding this comment

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

Let's update vLLM code to use the new module-specific imports

@mergify
Copy link

mergify bot commented Oct 21, 2025

Documentation preview: https://vllm--27188.org.readthedocs.build/en/27188/

@mergify mergify bot added documentation Improvements or additions to documentation frontend performance Performance-related issues qwen Related to Qwen models gpt-oss Related to GPT-OSS models labels Oct 21, 2025
@yeshsurya yeshsurya force-pushed the feature/extract-argparse-utils branch from 81a9253 to 7b71513 Compare October 25, 2025 11:31
@mergify mergify bot removed the needs-rebase label Oct 25, 2025
@yeshsurya yeshsurya force-pushed the feature/extract-argparse-utils branch from 21c991b to 75c60a0 Compare October 25, 2025 11:49
Fixed syntax error where an incomplete 'from vllm.utils import ('
statement was left in the file, causing compilation failures.

Signed-off-by: Yeshwanth Surya <[email protected]>
- Remove unused imports from vllm/utils/__init__.py (argparse, collections, regex)
- Add missing 'cache' import from functools
- Fix duplicate imports in multiple files causing F811 redefinition errors:
  - tests/kernels/attention/test_deepgemm_attention.py
  - vllm/model_executor/layers/fused_moe/config.py
  - vllm/model_executor/layers/fused_moe/layer.py
  - vllm/v1/attention/backends/flashinfer.py
  - vllm/v1/worker/tpu_model_runner.py

All imports now use the specific module paths (e.g., vllm.utils.math_utils)
instead of importing from vllm.utils directly.

Signed-off-by: Yeshwanth Surya <[email protected]>
@yeshsurya yeshsurya force-pushed the feature/extract-argparse-utils branch from 5a024f8 to 9b5a5fc Compare October 25, 2025 12:00
Fixed import ordering in three files to comply with ruff's isort rules:
- vllm/entrypoints/utils.py: Reordered transformers_utils before utils imports
- vllm/utils/__init__.py: Moved platform_utils after specialized module imports
- vllm/utils/deep_gemm.py: Reordered import_utils before math_utils

These changes resolve the ruff-check failures in the pre-commit hooks.

Signed-off-by: yeshsurya <[email protected]>
@yeshsurya yeshsurya force-pushed the feature/extract-argparse-utils branch from ef0d520 to 92535f8 Compare October 25, 2025 12:32
@DarkLight1337
Copy link
Member

/gemini review

Copy link
Contributor

@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 refactors the codebase by extracting math and argparse utilities into separate modules, vllm/utils/math_utils.py and vllm/utils/argparse_utils.py respectively. This is a good improvement for code organization and maintainability. The changes are well-executed, with imports updated across the codebase and backward compatibility maintained through re-exports in vllm/utils/__init__.py. I have reviewed the changes and found no issues. The refactoring is clean and a positive step for the project's structure.

Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@github-project-automation github-project-automation bot moved this from To Triage to Ready in gpt-oss Issues & Enhancements Oct 26, 2025
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) October 26, 2025 07:21
@vllm-bot vllm-bot merged commit 71b1c8b into vllm-project:main Oct 26, 2025
19 of 22 checks passed
xuhaolei pushed a commit to ZJU-REAL/EasySteer-vllm-v1 that referenced this pull request Oct 27, 2025
ilmarkov pushed a commit to neuralmagic/vllm that referenced this pull request Nov 7, 2025
ZhengHongming888 pushed a commit to ZhengHongming888/vllm that referenced this pull request Nov 8, 2025
rtourgeman pushed a commit to rtourgeman/vllm that referenced this pull request Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation frontend gpt-oss Related to GPT-OSS models performance Performance-related issues qwen Related to Qwen models ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm speculative-decoding structured-output tpu Related to Google TPUs v1

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants