Skip to content

Commit 62ea664

Browse files
authored
[Lint]Style: Convert test/ to ruff format(Batch vllm-project#5) (vllm-project#6747)
### What this PR does / why we need it? | File Path | | :--- | | `tests/e2e/singlecard/compile/backend.py` | | `tests/e2e/singlecard/compile/test_graphex_norm_quant_fusion.py` | | `tests/e2e/singlecard/compile/test_graphex_qknorm_rope_fusion.py` | | `tests/e2e/singlecard/compile/test_norm_quant_fusion.py` | | `tests/e2e/singlecard/model_runner_v2/test_basic.py` | | `tests/e2e/singlecard/test_aclgraph_accuracy.py` | | `tests/e2e/singlecard/test_aclgraph_batch_invariant.py` | | `tests/e2e/singlecard/test_aclgraph_mem.py` | | `tests/e2e/singlecard/test_async_scheduling.py` | | `tests/e2e/singlecard/test_auto_fit_max_mode_len.py` | | `tests/e2e/singlecard/test_batch_invariant.py` | | `tests/e2e/singlecard/test_camem.py` | | `tests/e2e/singlecard/test_completion_with_prompt_embeds.py` | | `tests/e2e/singlecard/test_cpu_offloading.py` | | `tests/e2e/singlecard/test_guided_decoding.py` | | `tests/e2e/singlecard/test_ilama_lora.py` | | `tests/e2e/singlecard/test_llama32_lora.py` | | `tests/e2e/singlecard/test_models.py` | | `tests/e2e/singlecard/test_multistream_overlap_shared_expert.py` | | `tests/e2e/singlecard/test_quantization.py` | | `tests/e2e/singlecard/test_qwen3_multi_loras.py` | | `tests/e2e/singlecard/test_sampler.py` | | `tests/e2e/singlecard/test_vlm.py` | | `tests/e2e/singlecard/test_xlite.py` | | `tests/e2e/singlecard/utils.py` | ### Does this PR introduce _any_ user-facing change? ### How was this patch tested? - vLLM version: v0.15.0 - vLLM main: vllm-project@9562912 --------- Signed-off-by: MrZ20 <2609716663@qq.com>
1 parent 747484c commit 62ea664

26 files changed

Lines changed: 866 additions & 1059 deletions

pyproject.toml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,41 @@ plugins.md024.allow_different_nesting = true # no-duplicate-headers
4646
plugins.md029.enabled = false # ol-prefix
4747

4848
[tool.ruff]
49-
# TODO: according to PEP8, there should be 80 characters per line
49+
# TODO: according to PEP8, there should be 120 characters per line
5050
line-length = 120
5151
# Folder to be modified
5252
exclude = [
53-
"tests/**",
53+
# Batch (1)
54+
"tests/e2e/__init__.py",
55+
"tests/e2e/310p/",
56+
"tests/e2e/conftest.py",
57+
"tests/e2e/doctests/",
58+
"tests/e2e/model_utils.py",
59+
"tests/e2e/models/",
60+
"tests/e2e/multicard/2-cards/",
61+
62+
# Batch (2)
63+
"tests/e2e/multicard/4-cards/",
64+
"tests/e2e/nightly/multi_node/",
65+
66+
# Batch (3)
67+
"tests/e2e/nightly/single_node/models/",
68+
69+
# Batch (4)
70+
"tests/e2e/nightly/single_node/ops/",
71+
72+
# Batch (5)
73+
# "tests/e2e/singlecard/",
74+
75+
# Batch (6)
76+
"tests/e2e/nightly/single_node/ops/singlecard_ops/triton/",
77+
"tests/e2e/singlecard/pooling/",
78+
"tests/e2e/singlecard/spec_decode/",
79+
"tests/e2e/utils.py",
80+
"tests/e2e/vllm_interface/",
81+
"tests/e2e/weekly/",
82+
83+
"tests/ut/",
5484
]
5585

5686
[tool.ruff.lint]

tests/e2e/singlecard/compile/backend.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17+
from collections.abc import Callable, Sequence
1718
from copy import deepcopy
18-
from typing import Any, Callable, List, Optional, Sequence
19+
from typing import Any
1920

2021
import torch.fx as fx
2122
from torch._inductor.decomposition import select_decomp_table
@@ -37,7 +38,7 @@ class TestBackend:
3738
records the FX graph before and after the transformation.
3839
"""
3940

40-
def __init__(self, custom_passes: Optional[List[Any]] = None):
41+
def __init__(self, custom_passes: list[Any] | None = None):
4142
vllm_config = get_current_vllm_config()
4243
compile_config = vllm_config.compilation_config
4344
self.inductor_config = compile_config.inductor_compile_config
@@ -48,9 +49,7 @@ def __init__(self, custom_passes: Optional[List[Any]] = None):
4849
self.graph_pre_pass = None
4950
self.graph_post_pass = None
5051

51-
def post_pass(self,
52-
graph: fx.Graph,
53-
runtime_shape: int | None = None) -> fx.Graph:
52+
def post_pass(self, graph: fx.Graph, runtime_shape: int | None = None) -> fx.Graph:
5453
"""
5554
Apply custom graph transformation passes.
5655
"""
@@ -62,13 +61,13 @@ def post_pass(self,
6261
return graph
6362

6463
def compile(
65-
self,
66-
graph: fx.GraphModule,
67-
example_inputs: list[Any],
68-
compiler_config: dict[str, Any],
69-
runtime_shape: Optional[int] = None,
70-
key: Optional[str] = None
71-
) -> tuple[Optional[Callable], Optional[Any]]:
64+
self,
65+
graph: fx.GraphModule,
66+
example_inputs: list[Any],
67+
compiler_config: dict[str, Any],
68+
runtime_shape: int | None = None,
69+
key: str | None = None,
70+
) -> tuple[Callable | None, Any | None]:
7271
"""
7372
Compile the FX graph using vLLM's Ascend compiler interface.
7473
Wraps the post-pass logic into the inner_compile callback.
@@ -87,8 +86,7 @@ def compile_inner(graph, example_inputs):
8786
)
8887
return compiled_fn, None
8988

90-
def __call__(self, gm: fx.GraphModule,
91-
example_inputs: Optional[List[Any]]):
89+
def __call__(self, gm: fx.GraphModule, example_inputs: list[Any] | None):
9290
"""
9391
Make the backend callable by torch.compile().
9492
Returns a compiled executable function.
@@ -103,17 +101,11 @@ def __call__(self, gm: fx.GraphModule,
103101
)
104102
return compiled_fn
105103

106-
def find_nodes_by_target(self, graph: fx.GraphModule,
107-
target: OpOverload) -> List[fx.Node]:
104+
def find_nodes_by_target(self, graph: fx.GraphModule, target: OpOverload) -> list[fx.Node]:
108105
"""Helper to find all FX nodes that call a specific operator."""
109-
return [
110-
node for node in graph.graph.nodes
111-
if hasattr(node, 'target') and node.target == target
112-
]
113-
114-
def check_before_ops(self,
115-
ops: Sequence[OpOverload],
116-
fully_replaced: bool = True):
106+
return [node for node in graph.graph.nodes if hasattr(node, "target") and node.target == target]
107+
108+
def check_before_ops(self, ops: Sequence[OpOverload], fully_replaced: bool = True):
117109
"""
118110
Verify that the original (unfused) operators exist before the pass
119111
and are fully removed afterward (if fully_replaced=True).

tests/e2e/singlecard/compile/test_graphex_norm_quant_fusion.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def register_pattern_safe(pattern_class, vllm_config, eps, pattern_key):
215215
try:
216216
# Import the required pass class
217217
from torch._inductor.pattern_matcher import PatternMatcherPass
218+
218219
pm_pass = PatternMatcherPass()
219220
pattern.register(pm_pass)
220221
_registered_patterns.add(pattern_key)
@@ -243,7 +244,7 @@ def test_rmsnorm_quant_fusion(
243244
sp_enable: bool,
244245
):
245246
# Check if fusion operator is available
246-
if not hasattr(torch.ops.npu, 'npu_add_rms_norm_quant'):
247+
if not hasattr(torch.ops.npu, "npu_add_rms_norm_quant"):
247248
pytest.skip("Fusion operator npu_add_rms_norm_quant not available, skipping test")
248249

249250
vllm_config = VllmConfig(model_config=ModelConfig(dtype=dtype))
@@ -266,7 +267,7 @@ def test_rmsnorm_quant_fusion(
266267
if not enable_custom_op():
267268
pytest.skip("Custom ops not available, skipping bias test")
268269
# Check if the bias operator exists
269-
if not hasattr(torch.ops._C_ascend, 'npu_add_rms_norm_bias'):
270+
if not hasattr(torch.ops._C_ascend, "npu_add_rms_norm_bias"):
270271
pytest.skip("Operator npu_add_rms_norm_bias not available, skipping bias test")
271272
if sp_enable:
272273
model = ModelSPWithBias(hidden_size, dtype, eps, device="npu")
@@ -281,13 +282,11 @@ def test_rmsnorm_quant_fusion(
281282
else:
282283
# The non-bias patterns currently use npu_add_rms_norm_bias in their pattern matching
283284
# so we need to skip if it's not available
284-
if not hasattr(torch.ops._C_ascend, 'npu_add_rms_norm_bias'):
285+
if not hasattr(torch.ops._C_ascend, "npu_add_rms_norm_bias"):
285286
pytest.skip("Operator npu_add_rms_norm_bias not available, skipping test")
286287
if sp_enable:
287288
model = ModelSPWithoutBias(hidden_size, dtype, eps, device="npu")
288-
register_pattern_safe(
289-
AddRMSNormQuantSPPattern, vllm_config, eps, "GraphEXAddRMSNormQuantSPPattern"
290-
)
289+
register_pattern_safe(AddRMSNormQuantSPPattern, vllm_config, eps, "GraphEXAddRMSNormQuantSPPattern")
291290
else:
292291
model = ModelWithoutBias(hidden_size, dtype, eps, device="npu")
293292
register_pattern_safe(AddRMSNormQuantPattern, vllm_config, eps, "GraphEXAddRMSNormQuantPattern")
@@ -302,5 +301,9 @@ def test_rmsnorm_quant_fusion(
302301
compiled_out, compiled_res = compiled_model(x)
303302

304303
# Verify output shapes are correct
305-
assert compiled_out.shape == (num_tokens, hidden_size), f"Expected shape {(num_tokens, hidden_size)}, got {compiled_out.shape}"
306-
assert compiled_res.shape == (num_tokens, hidden_size), f"Expected shape {(num_tokens, hidden_size)}, got {compiled_res.shape}"
304+
assert compiled_out.shape == (num_tokens, hidden_size), (
305+
f"Expected shape {(num_tokens, hidden_size)}, got {compiled_out.shape}"
306+
)
307+
assert compiled_res.shape == (num_tokens, hidden_size), (
308+
f"Expected shape {(num_tokens, hidden_size)}, got {compiled_res.shape}"
309+
)

tests/e2e/singlecard/compile/test_graphex_qknorm_rope_fusion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def test_rmsnorm_quant_fusion(
201201
vllm_config=vllm_config, head_dim=head_dim, num_heads=num_heads, num_kv_heads=num_kv_heads, eps=eps
202202
)
203203
from torch._inductor.pattern_matcher import PatternMatcherPass
204+
204205
pm_pass = PatternMatcherPass()
205206
fusion_pattern.register(pm_pass)
206207
model = model.to("npu")

0 commit comments

Comments
 (0)