Skip to content

Commit 341f8b3

Browse files
committed
Fix ruff format check error
1 parent b0e04ed commit 341f8b3

27 files changed

Lines changed: 750 additions & 529 deletions

benchmarks/benchmark_throughput_autotune.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ def write_results_csv(
604604
baseline_fake_result: tuple[float, float] | None = None,
605605
baseline_enable_result: tuple[float, float] | None = None,
606606
op_backends: dict[str, list[str]] | None = None,
607-
per_op_backend_results: dict[str, dict[str, tuple[float, float] | None]] | None = None,
607+
per_op_backend_results: dict[str, dict[str, tuple[float, float] | None]]
608+
| None = None,
608609
) -> None:
609610
"""
610611
Write per-operator results into a CSV file, sorted by total throughput desc.
@@ -1089,7 +1090,11 @@ def main() -> None:
10891090
op_backends=tuned_op_backends,
10901091
per_op_backend_results=per_op_backend_results,
10911092
)
1092-
if val is not None and baseline_total is not None and (best_result is None or val[0] > best_result[0]):
1093+
if (
1094+
val is not None
1095+
and baseline_total is not None
1096+
and (best_result is None or val[0] > best_result[0])
1097+
):
10931098
best_result = val
10941099
best_backend = backend
10951100

benchmarks/benchmark_throughput_flagos.py

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,64 @@
1313
# scenarios (name, input_len, output_len, concurrency)
1414
SCENARIOS = [
1515
# from FlagScale
16-
("p128d128", 128, 128, 100),
17-
("p6144d128", 6144, 128, 100),
18-
("p30720d128", 30720, 128, 100),
19-
("p128d6144", 128, 6144, 100),
20-
("p6144d6144", 6144, 6144, 100),
21-
("p30720d6144", 30720, 6144, 100),
16+
("p128d128", 128, 128, 100),
17+
("p6144d128", 6144, 128, 100),
18+
("p30720d128", 30720, 128, 100),
19+
("p128d6144", 128, 6144, 100),
20+
("p6144d6144", 6144, 6144, 100),
21+
("p30720d6144", 30720, 6144, 100),
2222
# from FlagRelease
23-
("p4096d2048", 4096, 2048, 64),
23+
("p4096d2048", 4096, 2048, 64),
2424
# from vendors
25-
("p6144d1024", 6144, 1024, 100),
26-
("p4096d1024", 4096, 1024, 100),
27-
("p2048d1024", 2048, 1024, 100),
28-
("p1024d1024", 1024, 1024, 100),
25+
("p6144d1024", 6144, 1024, 100),
26+
("p4096d1024", 4096, 1024, 100),
27+
("p2048d1024", 2048, 1024, 100),
28+
("p1024d1024", 1024, 1024, 100),
2929
]
3030

3131
LOG_DIR = "vllm_bench_logs"
3232
os.makedirs(LOG_DIR, exist_ok=True)
3333

34-
NUM_RUNS = 4
34+
NUM_RUNS = 4
3535
# ====================
3636

37+
3738
def run_benchmark(name, input_len, output_len, concurrency, run_id):
3839
num_prompts = concurrency
3940
cmd = [
40-
"vllm", "bench", "serve",
41-
"--host", HOST,
42-
"--port", str(PORT),
43-
"--backend", BACKEND,
44-
"--model", SERVED_MODEL_NAME,
45-
"--tokenizer", "Qwen/Qwen3-Next-80B-A3B-Instruct",
46-
"--dataset-name", "random",
47-
"--endpoint", ENDPOINT,
41+
"vllm",
42+
"bench",
43+
"serve",
44+
"--host",
45+
HOST,
46+
"--port",
47+
str(PORT),
48+
"--backend",
49+
BACKEND,
50+
"--model",
51+
SERVED_MODEL_NAME,
52+
"--tokenizer",
53+
"Qwen/Qwen3-Next-80B-A3B-Instruct",
54+
"--dataset-name",
55+
"random",
56+
"--endpoint",
57+
ENDPOINT,
4858
"--ignore-eos",
4959
"--trust-remote-code",
50-
"--random-input-len", str(input_len),
51-
"--random-output-len", str(output_len),
52-
"--num-prompts", str(num_prompts),
53-
"--max-concurrency", str(concurrency)
60+
"--random-input-len",
61+
str(input_len),
62+
"--random-output-len",
63+
str(output_len),
64+
"--num-prompts",
65+
str(num_prompts),
66+
"--max-concurrency",
67+
str(concurrency),
5468
]
5569

5670
log_file = os.path.join(LOG_DIR, f"{name}_run{run_id}.log")
57-
print(f"\n[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] 🚀 Starting scenario: {name} (Run {run_id})")
71+
print(
72+
f"\n[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] 🚀 Starting scenario: {name} (Run {run_id})"
73+
)
5874
print(f" Input: {input_len}, Output: {output_len}, Concurrency: {concurrency}")
5975
print(f" Logging to: {log_file}")
6076
print(f" Command: {' '.join(cmd)}\n")
@@ -63,14 +79,20 @@ def run_benchmark(name, input_len, output_len, concurrency, run_id):
6379
result = subprocess.run(cmd, stdout=f, stderr=subprocess.STDOUT, text=True)
6480

6581
status = "✅ Success" if result.returncode == 0 else "❌ Failed"
66-
print(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {status}: {name} Run {run_id} (exit code: {result.returncode})\n")
82+
print(
83+
f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {status}: {name} Run {run_id} (exit code: {result.returncode})\n"
84+
)
85+
6786

6887
def main():
69-
print(f"🧪 Starting vLLM benchmark suite for {len(SCENARIOS)} scenarios, each repeated {NUM_RUNS} times...\n")
88+
print(
89+
f"🧪 Starting vLLM benchmark suite for {len(SCENARIOS)} scenarios, each repeated {NUM_RUNS} times...\n"
90+
)
7091
for name, inp, out, conc in SCENARIOS:
7192
for run_id in range(1, NUM_RUNS + 1):
7293
run_benchmark(name, inp, out, conc, run_id)
7394
print("🏁 All scenarios and runs completed. Logs saved in:", LOG_DIR)
7495

96+
7597
if __name__ == "__main__":
7698
main()

benchmarks/benchmark_throughput_flagos_statistics.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@
1414
"p6144d1024",
1515
"p4096d1024",
1616
"p2048d1024",
17-
"p1024d1024"
17+
"p1024d1024",
1818
]
1919

2020
LOG_DIR = "./vllm_bench_logs"
2121

22+
2223
def extract_throughputs(log_path):
2324
output_throughput = None
2425
total_throughput = None
2526
try:
26-
with open(log_path, 'r', encoding='utf-8') as f:
27+
with open(log_path, "r", encoding="utf-8") as f:
2728
content = f.read()
2829
except FileNotFoundError:
2930
return None, None
3031

31-
out_match = re.search(r'Output token throughput \(tok/s\):\s*([\d.]+)', content)
32-
tot_match = re.search(r'Total Token throughput \(tok/s\):\s*([\d.]+)', content)
32+
out_match = re.search(r"Output token throughput \(tok/s\):\s*([\d.]+)", content)
33+
tot_match = re.search(r"Total Token throughput \(tok/s\):\s*([\d.]+)", content)
3334

3435
if out_match:
3536
output_throughput = float(out_match.group(1))
@@ -38,6 +39,7 @@ def extract_throughputs(log_path):
3839

3940
return output_throughput, total_throughput
4041

42+
4143
def compute_extended_stats(values):
4244
valid_vals = [v for v in values if v is not None]
4345
if not valid_vals:
@@ -60,9 +62,10 @@ def compute_extended_stats(values):
6062
f"{median_val:.2f}",
6163
f"{max_val:.2f}",
6264
f"{stdev_val:.2f}",
63-
sigma_str
65+
sigma_str,
6466
)
6567

68+
6669
def main():
6770
# aligned output
6871
scene_width = 14
@@ -101,5 +104,6 @@ def main():
101104
)
102105
print(line)
103106

107+
104108
if __name__ == "__main__":
105109
main()

examples/offline_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if "USE_FLAGGEMS" in os.environ:
2121
print(f"USE_FLAGGEMS: {os.environ['USE_FLAGGEMS']}")
2222

23-
if __name__ == '__main__':
23+
if __name__ == "__main__":
2424
prompts = [
2525
"Hello, my name is",
2626
]
@@ -40,5 +40,5 @@
4040

4141
del llm
4242
torch.cuda.empty_cache()
43-
43+
4444
print("\n Reasoning complete, resources cleared.")

examples/qwen3_next_offline_inference.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010

1111
from vllm import LLM, SamplingParams
1212

13-
if __name__ == '__main__':
13+
if __name__ == "__main__":
1414
prompts = [
1515
"Hello, my name is",
1616
]
1717

1818
# Create a sampling params object.
1919
sampling_params = SamplingParams(max_tokens=10, temperature=0.0)
2020
# Create an LLM.
21-
llm = LLM(model="Qwen/Qwen3-Next-80B-A3B-Instruct", tensor_parallel_size=4, max_model_len=262144)
21+
llm = LLM(
22+
model="Qwen/Qwen3-Next-80B-A3B-Instruct",
23+
tensor_parallel_size=4,
24+
max_model_len=262144,
25+
)
2226

2327
# Generate texts from the prompts.
2428
outputs = llm.generate(prompts, sampling_params)
@@ -27,4 +31,3 @@
2731
prompt = output.prompt
2832
generated_text = output.outputs[0].text
2933
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
30-

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _read_requirements(filename: str) -> list[str]:
4444

4545

4646
setup(
47-
name='vllm_fl',
47+
name="vllm_fl",
4848
# Follow:
4949
# https://packaging.python.org/en/latest/specifications/version-specifiers
5050
version=VERSION,
@@ -73,7 +73,8 @@ def _read_requirements(filename: str) -> list[str]:
7373
python_requires=">=3.9",
7474
install_requires=get_requirements(),
7575
extras_require={},
76-
entry_points={'vllm.platform_plugins': ["fl = vllm_fl:register"],
77-
'vllm.general_plugins': ["fl = vllm_fl:register_model"]}
76+
entry_points={
77+
"vllm.platform_plugins": ["fl = vllm_fl:register"],
78+
"vllm.general_plugins": ["fl = vllm_fl:register_model"],
79+
},
7880
)
79-

tests/functional_tests/compilation/test_graph_capture.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_weak_ref_tensors_function(self):
2525
"""Test weak_ref_tensors function exists."""
2626
try:
2727
from vllm_fl.compilation.graph import weak_ref_tensors
28+
2829
assert weak_ref_tensors is not None
2930
except ImportError:
3031
pytest.skip("weak_ref_tensors not available")
@@ -110,6 +111,7 @@ class TestGraphCacheManagement:
110111

111112
def test_batch_descriptor_hashing(self):
112113
"""Test that batch descriptors can be used as dict keys."""
114+
113115
@dataclass(frozen=True)
114116
class MockBatchDescriptor:
115117
num_tokens: int

tests/functional_tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
def pytest_configure(config):
1212
"""Register custom markers."""
1313
config.addinivalue_line("markers", "gpu: marks tests as requiring GPU")
14-
config.addinivalue_line("markers", "multi_gpu: marks tests as requiring multiple GPUs")
15-
config.addinivalue_line("markers", "flaggems: marks tests as requiring flag_gems library")
14+
config.addinivalue_line(
15+
"markers", "multi_gpu: marks tests as requiring multiple GPUs"
16+
)
17+
config.addinivalue_line(
18+
"markers", "flaggems: marks tests as requiring flag_gems library"
19+
)
1620

1721

1822
@pytest.fixture(scope="session")

tests/functional_tests/distributed/test_collective_ops.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_communicator_fl_import(self):
2424
"""Test that CommunicatorFL can be imported."""
2525
try:
2626
from vllm_fl.distributed.communicator import CommunicatorFL
27+
2728
assert CommunicatorFL is not None
2829
except ImportError as e:
2930
pytest.skip(f"CommunicatorFL not available: {e}")
@@ -34,6 +35,7 @@ def test_pyflagcx_import(self):
3435
from vllm_fl.distributed.device_communicators.flagcx import (
3536
PyFlagcxCommunicator,
3637
)
38+
3739
assert PyFlagcxCommunicator is not None
3840
except ImportError as e:
3941
pytest.skip(f"PyFlagcxCommunicator not available: {e}")
@@ -49,7 +51,7 @@ def reference_all_reduce(tensors: list[torch.Tensor]) -> torch.Tensor:
4951

5052
@pytest.mark.skipif(
5153
not torch.cuda.is_available() or torch.cuda.device_count() < 2,
52-
reason="Multiple GPUs not available"
54+
reason="Multiple GPUs not available",
5355
)
5456
def test_all_reduce_sum_correctness(self):
5557
"""Test all_reduce sum produces correct results."""
@@ -69,8 +71,7 @@ class TestReduceScatterCorrectness:
6971

7072
@staticmethod
7173
def reference_reduce_scatter(
72-
input_tensor: torch.Tensor,
73-
world_size: int
74+
input_tensor: torch.Tensor, world_size: int
7475
) -> list[torch.Tensor]:
7576
"""Reference implementation of reduce_scatter."""
7677
# Split input into chunks
@@ -80,12 +81,14 @@ def reference_reduce_scatter(
8081

8182
def test_reduce_scatter_reference(self):
8283
"""Test reference reduce_scatter implementation."""
83-
input_tensor = torch.tensor([
84-
[1.0, 2.0],
85-
[3.0, 4.0],
86-
[5.0, 6.0],
87-
[7.0, 8.0],
88-
])
84+
input_tensor = torch.tensor(
85+
[
86+
[1.0, 2.0],
87+
[3.0, 4.0],
88+
[5.0, 6.0],
89+
[7.0, 8.0],
90+
]
91+
)
8992
world_size = 2
9093

9194
result = self.reference_reduce_scatter(input_tensor, world_size)
@@ -109,10 +112,12 @@ def test_all_gather_reference(self):
109112
torch.tensor([[1.0, 2.0]]),
110113
torch.tensor([[3.0, 4.0]]),
111114
]
112-
expected = torch.tensor([
113-
[1.0, 2.0],
114-
[3.0, 4.0],
115-
])
115+
expected = torch.tensor(
116+
[
117+
[1.0, 2.0],
118+
[3.0, 4.0],
119+
]
120+
)
116121

117122
result = self.reference_all_gather(tensors)
118123
assert torch.allclose(result, expected)
@@ -123,7 +128,7 @@ class TestSendRecvCorrectness:
123128

124129
@pytest.mark.skipif(
125130
not torch.cuda.is_available() or torch.cuda.device_count() < 2,
126-
reason="Multiple GPUs not available"
131+
reason="Multiple GPUs not available",
127132
)
128133
def test_send_recv_mock(self):
129134
"""Test send/recv with mocked communicator."""

tests/functional_tests/inference/test_offline_minicpm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def test_inference(self, tokenizer, audio_count):
8585
if audio_count > 0:
8686
mm_data = {
8787
"audio": [
88-
asset.audio_and_sample_rate
89-
for asset in AUDIO_ASSETS[:audio_count]
88+
asset.audio_and_sample_rate for asset in AUDIO_ASSETS[:audio_count]
9089
]
9190
}
9291

0 commit comments

Comments
 (0)