Skip to content

Conversation

@CatherineSue
Copy link
Collaborator

@CatherineSue CatherineSue commented Oct 15, 2025

Motivation

This PR adds F401 to ruff checks and removes unused imports accross python/sglang, excluding __init__.py.

Modifications

  • Added F821 to ruff checks - this catches undefined names/missing imports
  • Added python/sglang to ruff checks, excluded all init.py
  • Tried to fix all unused imports

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CatherineSue, 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 significantly improves the project's code quality and maintainability by refining the linting process. It integrates more comprehensive ruff checks for unused imports and undefined names across the core python/sglang codebase. This initiative has led to a substantial cleanup, removing redundant import statements and clarifying code dependencies, which ultimately results in a leaner, more robust, and easier-to-understand codebase.

Highlights

  • Ruff Configuration Update: The .pre-commit-config.yaml has been updated to include F821 (undefined names) alongside F401 (unused imports) in the ruff checks. This enhances the static analysis capabilities for Python code.
  • Expanded Linting Scope: The ruff linter's scope has been extended to cover the entire python/sglang directory. A new exclusion rule has been added to ignore __init__.py files from these checks, preventing unnecessary warnings in package initialization files.
  • Extensive Unused Import Removal: Numerous Python files across the python/sglang directory have been cleaned by removing unused import statements. This includes both direct removals and the addition of # noqa: F401 comments for imports that are intentionally present but not directly referenced in the code.
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.

import torch
import torch.fx as fx

import sglang.srt.compilation.weak_ref_tensor_jit
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure about this one.



if is_mla_preprocess_enabled():
import sgl_kernel_npu
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure about this one.

Copy link
Member

Choose a reason for hiding this comment

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

we need to keep this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added back in 17b44c5

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 is a great step towards improving code quality by enabling more ruff checks (F401 for unused imports and F821 for undefined names) across the python/sglang directory and cleaning up existing unused imports. The changes are extensive but mostly automated, which is good.

I've made a few suggestions to improve the clarity and maintainability of how noqa comments are used to suppress F401 warnings. Specifically, I've pointed out cases where blanket noqa comments on multi-line imports can be ambiguous and where single-line imports would be more readable.

Overall, this is a valuable cleanup effort. Thank you for this contribution!

- F821: missing imports
- Exclude all __init__.py
# Conflicts:
#	python/sglang/srt/disaggregation/decode.py
#	python/sglang/srt/disaggregation/prefill.py
#	python/sglang/srt/model_executor/npu_graph_runner.py
@CatherineSue
Copy link
Collaborator Author

Will take alook at the CI failures

@zhyncs zhyncs self-assigned this Oct 16, 2025
@CatherineSue
Copy link
Collaborator Author

Execute Notebooks is due to github connection issue.

unit-test-backend-8-gpu (1): test_disaggregation_hybrid_attention.py failed due to KV Transfer failure in disaggregation mode. It seems from mooncake. Not related to changes in disaggregation/prefill.py or decode.py.

unit-test-deepep-8-gpu: test_deepep_large.py failed due to InfiniBand GPU device mapping failure: GPU cannot map UAR of device mlx5_roce7 , not sure if it is relevant.

Started a CI rerun.

@CatherineSue
Copy link
Collaborator Author

CatherineSue commented Oct 16, 2025

Keep seeing RuntimeError: There is no current event loop in thread 'MainThread'. Cancelled workflow for now

@ping1jing2
Copy link
Collaborator

Keep seeing RuntimeError: There is no current event loop in thread 'MainThread'. Cancelled workflow for now

NPU CI has some network issue, we are handle it, you can ignore it first. If this PR break NPU code, we will fix it by ourself.

@CatherineSue
Copy link
Collaborator Author

CatherineSue commented Oct 17, 2025

@zhyncs zhyncs merged commit 6279744 into main Oct 17, 2025
100 of 108 checks passed
@zhyncs zhyncs deleted the chang/unused-imports branch October 17, 2025 23:49
leavelet pushed a commit to pkucnc/sglang that referenced this pull request Oct 27, 2025
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.

6 participants