Skip to content

Commit 3504b67

Browse files
hmellorlulmer
authored andcommitted
Update deprecated Python 3.8 typing (vllm-project#13971)
Signed-off-by: Louis Ulmer <ulmerlouis@gmail.com>
1 parent 0919314 commit 3504b67

File tree

300 files changed

+2294
-2347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+2294
-2347
lines changed

benchmarks/backend_request_func.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
import traceback
88
from dataclasses import dataclass, field
9-
from typing import List, Optional, Union
9+
from typing import Optional, Union
1010

1111
import aiohttp
1212
import huggingface_hub.constants
@@ -41,8 +41,8 @@ class RequestFuncOutput:
4141
latency: float = 0.0
4242
output_tokens: int = 0
4343
ttft: float = 0.0 # Time to first token
44-
itl: List[float] = field(
45-
default_factory=list) # List of inter-token latencies
44+
itl: list[float] = field(
45+
default_factory=list) # list of inter-token latencies
4646
tpot: float = 0.0 # avg next-token latencies
4747
prompt_len: int = 0
4848
error: str = ""

benchmarks/benchmark_guided.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import random
88
import time
9-
from typing import List
109

1110
import datasets
1211
import pandas as pd
@@ -39,7 +38,7 @@ class SampleRequest:
3938
completion: str = None
4039

4140

42-
def run_vllm(requests: List[SampleRequest],
41+
def run_vllm(requests: list[SampleRequest],
4342
engine_args: EngineArgs,
4443
n: int,
4544
guided_decoding_rate: float = 1.0,
@@ -54,8 +53,8 @@ def run_vllm(requests: List[SampleRequest],
5453
" prompt_len and expected_output_len for all requests.")
5554

5655
# Add the requests to the engine.
57-
prompts: List[str] = []
58-
sampling_params: List[SamplingParams] = []
56+
prompts: list[str] = []
57+
sampling_params: list[SamplingParams] = []
5958
# create a list containing random selected true or false
6059
guided_decoding_req_idx = random.sample(
6160
range(len(requests)), int(len(requests) * guided_decoding_rate))
@@ -110,7 +109,7 @@ def run_vllm(requests: List[SampleRequest],
110109

111110

112111
async def run_vllm_async(
113-
requests: List[SampleRequest],
112+
requests: list[SampleRequest],
114113
engine_args: AsyncEngineArgs,
115114
n: int,
116115
guided_decoding_rate: float = 1.0,
@@ -129,8 +128,8 @@ async def run_vllm_async(
129128
" prompt_len and expected_output_len for all requests.")
130129

131130
# Add the requests to the engine.
132-
prompts: List[str] = []
133-
sampling_params: List[SamplingParams] = []
131+
prompts: list[str] = []
132+
sampling_params: list[SamplingParams] = []
134133
guided_decoding_req_idx = random.sample(
135134
range(len(requests)), int(len(requests) * guided_decoding_rate))
136135

@@ -203,7 +202,7 @@ async def run_vllm_async(
203202

204203

205204
def sample_requests(tokenizer: PreTrainedTokenizerBase,
206-
args: argparse.Namespace) -> List[SampleRequest]:
205+
args: argparse.Namespace) -> list[SampleRequest]:
207206
if args.dataset == 'json':
208207
if args.json_schema_path is None:
209208
dir_path = os.path.dirname(os.path.realpath(__file__))
@@ -287,7 +286,7 @@ def sample_requests(tokenizer: PreTrainedTokenizerBase,
287286

288287
elif args.dataset == "xgrammar_bench":
289288
args.warmup = False
290-
requests: List[SampleRequest] = []
289+
requests: list[SampleRequest] = []
291290
dataset = datasets.load_dataset("NousResearch/json-mode-eval",
292291
split="train")
293292
print(f"dataset has {len(dataset)} entries")

benchmarks/benchmark_latency.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import time
99
from pathlib import Path
10-
from typing import Any, Dict, List, Optional
10+
from typing import Any, Optional
1111

1212
import numpy as np
1313
import torch
@@ -22,7 +22,7 @@
2222

2323

2424
def save_to_pytorch_benchmark_format(args: argparse.Namespace,
25-
results: Dict[str, Any]) -> None:
25+
results: dict[str, Any]) -> None:
2626
pt_records = convert_to_pytorch_benchmark_format(
2727
args=args,
2828
metrics={"latency": results["latencies"]},
@@ -57,7 +57,7 @@ def main(args: argparse.Namespace):
5757
dummy_prompt_token_ids = np.random.randint(10000,
5858
size=(args.batch_size,
5959
args.input_len))
60-
dummy_prompts: List[PromptType] = [{
60+
dummy_prompts: list[PromptType] = [{
6161
"prompt_token_ids": batch
6262
} for batch in dummy_prompt_token_ids.tolist()]
6363

benchmarks/benchmark_prefix_caching.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import json
3232
import random
3333
import time
34-
from typing import List, Optional, Tuple
34+
from typing import Optional
3535

3636
from transformers import PreTrainedTokenizerBase
3737

@@ -77,9 +77,9 @@ def sample_requests_from_dataset(
7777
dataset_path: str,
7878
num_requests: int,
7979
tokenizer: PreTrainedTokenizerBase,
80-
input_length_range: Tuple[int, int],
80+
input_length_range: tuple[int, int],
8181
fixed_output_len: Optional[int],
82-
) -> List[Request]:
82+
) -> list[Request]:
8383
if fixed_output_len is not None and fixed_output_len < 4:
8484
raise ValueError("output_len too small")
8585

@@ -99,7 +99,7 @@ def sample_requests_from_dataset(
9999
assert min_len >= 0 and max_len >= min_len, "input_length_range too small"
100100

101101
# Filter out sequences that are too long or too short
102-
filtered_requests: List[Request] = []
102+
filtered_requests: list[Request] = []
103103

104104
for i in range(len(dataset)):
105105
if len(filtered_requests) == num_requests:
@@ -122,10 +122,10 @@ def sample_requests_from_dataset(
122122
def sample_requests_from_random(
123123
num_requests: int,
124124
tokenizer: PreTrainedTokenizerBase,
125-
input_length_range: Tuple[int, int],
125+
input_length_range: tuple[int, int],
126126
fixed_output_len: Optional[int],
127127
prefix_len: int,
128-
) -> List[Request]:
128+
) -> list[Request]:
129129

130130
requests = []
131131
prefix_token_ids = sample_tokens(tokenizer, prefix_len)
@@ -144,9 +144,9 @@ def sample_requests_from_random(
144144
return requests
145145

146146

147-
def repeat_and_sort_requests(requests: List[Request],
147+
def repeat_and_sort_requests(requests: list[Request],
148148
repeat_count: int,
149-
sort: bool = False) -> List[str]:
149+
sort: bool = False) -> list[str]:
150150
repeated_requests = requests * repeat_count
151151
if sort:
152152
repeated_requests.sort(key=lambda x: x[1])

benchmarks/benchmark_prioritization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
import random
77
import time
8-
from typing import List, Optional, Tuple
8+
from typing import Optional
99

1010
from transformers import AutoTokenizer, PreTrainedTokenizerBase
1111

@@ -23,7 +23,7 @@ def sample_requests(
2323
num_requests: int,
2424
tokenizer: PreTrainedTokenizerBase,
2525
fixed_output_len: Optional[int],
26-
) -> List[Tuple[str, int, int]]:
26+
) -> list[tuple[str, int, int]]:
2727
if fixed_output_len is not None and fixed_output_len < 4:
2828
raise ValueError("output_len too small")
2929

@@ -40,7 +40,7 @@ def sample_requests(
4040
random.shuffle(dataset)
4141

4242
# Filter out sequences that are too long or too short
43-
filtered_dataset: List[Tuple[str, int, int]] = []
43+
filtered_dataset: list[tuple[str, int, int]] = []
4444
for i in range(len(dataset)):
4545
if len(filtered_dataset) == num_requests:
4646
break
@@ -68,7 +68,7 @@ def sample_requests(
6868

6969

7070
def run_vllm(
71-
requests: List[Tuple[str, int, int]],
71+
requests: list[tuple[str, int, int]],
7272
n: int,
7373
engine_args: EngineArgs,
7474
) -> float:

0 commit comments

Comments
 (0)