Skip to content

Commit b893d66

Browse files
authored
Fix per file ruff ignores related to simplification (vllm-project#26259)
Signed-off-by: Harry Mellor <[email protected]>
1 parent 6b6e987 commit b893d66

32 files changed

+47
-191
lines changed

pyproject.toml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -101,40 +101,6 @@ include = ["vllm*"]
101101
"vllm/v1/engine/utils.py" = ["E501"]
102102
"vllm/v1/utils.py" = ["E501"]
103103
"vllm/v1/worker/gpu_model_runner.py" = ["E501"]
104-
## Simplification rules
105-
"tests/distributed/test_expert_placement.py" = ["SIM108"]
106-
"tests/kernels/attention/test_cutlass_mla_decode.py" = ["SIM108"]
107-
"tests/kernels/attention/test_flashmla.py" = ["SIM108"]
108-
"tests/kernels/attention/test_lightning_attn.py" = ["SIM108"]
109-
"tests/kernels/moe/test_pplx_moe.py" = ["SIM108"]
110-
"tests/kernels/quantization/test_cutlass_scaled_mm.py" = ["SIM108"]
111-
"tests/kernels/test_onednn.py" = ["SIM108"]
112-
"tests/kernels/utils.py" = ["SIM108"]
113-
"tests/multimodal/test_processing.py" = ["SIM108"]
114-
"vllm/attention/ops/triton_reshape_and_cache_flash.py" = ["SIM108"]
115-
"vllm/distributed/parallel_state.py" = ["SIM108"]
116-
"vllm/entrypoints/chat_utils.py" = ["SIM108"]
117-
"vllm/entrypoints/llm.py" = ["SIM108"]
118-
"vllm/executor/ray_distributed_executor.py" = ["SIM108", "SIM112"]
119-
"vllm/model_executor/layers/batch_invariant.py" = ["SIM108"]
120-
"vllm/model_executor/layers/fla/ops/chunk_o.py" = ["SIM108"]
121-
"vllm/model_executor/layers/fused_moe/fused_moe.py" = ["SIM108"]
122-
"vllm/model_executor/layers/fused_moe/layer.py" = ["SIM108"]
123-
"vllm/model_executor/layers/fused_moe/modular_kernel.py" = ["SIM108"]
124-
"vllm/model_executor/layers/fused_moe/rocm_aiter_fused_moe.py" = ["SIM108"]
125-
"vllm/model_executor/layers/layernorm.py" = ["SIM108"]
126-
"vllm/model_executor/layers/lightning_attn.py" = ["SIM108"]
127-
"vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py" = ["SIM103"]
128-
"vllm/model_executor/layers/quantization/compressed_tensors/utils.py" = ["SIM110"]
129-
"vllm/model_executor/layers/quantization/quark/utils.py" = ["SIM110"]
130-
"vllm/utils/__init__.py" = ["SIM108"]
131-
"vllm/v1/sample/ops/bad_words.py" = ["SIM108"]
132-
"vllm/v1/sample/rejection_sampler.py" = ["SIM108"]
133-
"vllm/v1/worker/tpu_model_runner.py" = ["SIM108"]
134-
"vllm/_custom_ops.py" = ["SIM108"]
135-
"tools/profiler/print_layerwise_table.py" = ["SIM118"]
136-
## Loop variable binding issues
137-
"tests/kernels/mamba/test_mamba_ssm_ssd.py" = ["B023"]
138104
# End of temporary ignores
139105

140106
[tool.ruff.lint]

tests/distributed/test_expert_placement.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ def verify_round_robin_pattern(expert_map, ep_rank, ep_size, global_num_experts)
1212
base_experts = global_num_experts // ep_size
1313
remainder = global_num_experts % ep_size
1414

15-
if ep_rank < remainder:
16-
local_num_experts = base_experts + 1
17-
else:
18-
local_num_experts = base_experts
15+
local_num_experts = base_experts + 1 if ep_rank < remainder else base_experts
1916

2017
# Expected expert IDs for this rank in round_robin pattern
2118
# For non-divisible cases, ranks with extra experts start earlier

tests/kernels/attention/test_cutlass_mla_decode.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ def test_cutlass_mla_decode(
6666
b, s_q, mean_sk, h_q, h_kv, d, dv, block_size, causal, varlen, torch_dtype
6767
):
6868
device = torch.device("cuda:0")
69-
if torch_dtype == torch.float8_e4m3fn:
70-
init_dtype = torch.bfloat16
71-
else:
72-
init_dtype = torch_dtype
69+
init_dtype = torch.bfloat16 if torch_dtype == torch.float8_e4m3fn else torch_dtype
7370
torch.set_default_dtype(init_dtype)
7471
torch.set_default_device(device)
7572
torch.cuda.set_device(device)

tests/kernels/attention/test_flashmla.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ def test_flash_mla(
5252
b, s_q, mean_sk, h_q, h_kv, d, dv, block_size, causal, varlen, torch_dtype
5353
):
5454
device = torch.device("cuda:0")
55-
if torch_dtype == torch.float8_e4m3fn:
56-
init_dtype = torch.bfloat16
57-
else:
58-
init_dtype = torch_dtype
55+
init_dtype = torch.bfloat16 if torch_dtype == torch.float8_e4m3fn else torch_dtype
5956
torch.set_default_dtype(init_dtype)
6057
torch.set_default_device(device)
6158
torch.cuda.set_device(device)

tests/kernels/attention/test_lightning_attn.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ def reference_lightning_attention(q, k, v, ed, block_size, kv_history):
3333

3434
# More efficient implementation
3535
# Convert decay factors to matrix form
36-
if ed.dim() == 1:
37-
decay = torch.exp(-ed).view(1, -1, 1, 1)
38-
else:
39-
decay = torch.exp(-ed)
36+
decay = torch.exp(-ed).view(1, -1, 1, 1) if ed.dim() == 1 else torch.exp(-ed)
4037

4138
for b in range(B):
4239
for step in range(S):

tests/kernels/moe/test_pplx_moe.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,7 @@ def _pplx_moe(
705705
with set_current_vllm_config(vllm_config), override_config(moe_config):
706706
topk_weight, topk_ids, _ = fused_topk(a, score, topk, False)
707707

708-
if shared_experts is not None:
709-
shared_output = shared_experts(a)
710-
else:
711-
shared_output = None
708+
shared_output = shared_experts(a) if shared_experts is not None else None
712709

713710
torch_output = torch_experts(
714711
a,

tests/kernels/quantization/test_cutlass_scaled_mm.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ def cutlass_fp8_gemm_helper(
8888
# make scales K-major for blockwise quant, doesn't affect 1D scales
8989
scale_b = scale_b.t().contiguous().t()
9090

91-
if use_bias:
92-
bias = torch.rand((n,), device=device, dtype=out_dtype) * 10
93-
else:
94-
bias = None
91+
bias = torch.rand((n,), device=device, dtype=out_dtype) * 10 if use_bias else None
9592

9693
out = ops.cutlass_scaled_mm(a, b, scale_a, scale_b, out_dtype, bias)
9794
baseline = baseline_scaled_mm(a, b, scale_a, scale_b, out_dtype, bias)
@@ -122,10 +119,7 @@ def cutlass_int8_gemm_helper(
122119
scale_a = torch.randn(a_scales_shape, device=device, dtype=torch.float32)
123120
scale_b = torch.randn(b_scales_shape, device=device, dtype=torch.float32)
124121

125-
if use_bias:
126-
bias = torch.rand((n,), device=device, dtype=out_dtype) * 10
127-
else:
128-
bias = None
122+
bias = torch.rand((n,), device=device, dtype=out_dtype) * 10 if use_bias else None
129123

130124
out = ops.cutlass_scaled_mm(a, b, scale_a, scale_b, out_dtype, bias)
131125
baseline = baseline_scaled_mm(a, b, scale_a, scale_b, out_dtype, bias)

tests/kernels/test_onednn.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ def onednn_int8_gemm_test_helper(
8484
azp = None
8585
azp_adj = None
8686

87-
if use_bias:
88-
bias = torch.rand((n,), device=device, dtype=out_dtype) * 10
89-
else:
90-
bias = None
87+
bias = torch.rand((n,), device=device, dtype=out_dtype) * 10 if use_bias else None
9188

9289
handler = ops.create_onednn_scaled_mm(
9390
b,

tests/kernels/utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,13 +963,9 @@ def make_test_metadata(
963963
None if encoder_seq_lens is None else (sum(encoder_seq_lens))
964964
)
965965

966-
if cross_test_params is None:
967-
cross_kv_mmap = None
968-
else:
969-
# Encoder/decoder or encoder-only models only:
970-
# * Extract *cross-attention* slot_mapping and block table
971-
# (kv_mmap)
972-
cross_kv_mmap = cross_test_params.kv_mmap
966+
# For encoder/decoder or encoder-only models only, extract *cross-attention*
967+
# slot_mapping and block table (kv_mmap)
968+
cross_kv_mmap = None if cross_test_params is None else cross_test_params.kv_mmap
973969

974970
attn_backend_obj = make_backend(attn_backend.name)
975971

tests/multimodal/test_processing.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,7 @@ def test_limit_mm_per_prompt_dummy(model_id, limit, num_supported, is_valid):
941941

942942
profiler = MultiModalProfiler(processor)
943943

944-
if is_valid:
945-
exc_ctx = nullcontext()
946-
else:
947-
exc_ctx = pytest.raises(ValueError, match="At most")
944+
exc_ctx = nullcontext() if is_valid else pytest.raises(ValueError, match="At most")
948945

949946
with exc_ctx:
950947
profiler.get_decoder_dummy_data(
@@ -985,10 +982,7 @@ def test_limit_mm_per_prompt_apply(model_id, num_images, limit, is_valid):
985982
else:
986983
mm_data = {"image": [image] * num_images}
987984

988-
if is_valid:
989-
exc_ctx = nullcontext()
990-
else:
991-
exc_ctx = pytest.raises(ValueError, match="At most")
985+
exc_ctx = nullcontext() if is_valid else pytest.raises(ValueError, match="At most")
992986

993987
with exc_ctx:
994988
processor.apply(

0 commit comments

Comments
 (0)