Skip to content

Commit 8c946ce

Browse files
authored
Update deprecated type hinting in vllm/transformers_utils (vllm-project#18058)
Signed-off-by: Harry Mellor <[email protected]>
1 parent ff334ca commit 8c946ce

17 files changed

+98
-102
lines changed

vllm/transformers_utils/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
from functools import cache
88
from pathlib import Path
9-
from typing import Any, Callable, Dict, Literal, Optional, Type, Union
9+
from typing import Any, Callable, Literal, Optional, Union
1010

1111
import huggingface_hub
1212
from huggingface_hub import hf_hub_download
@@ -55,11 +55,11 @@
5555

5656
logger = init_logger(__name__)
5757

58-
_CONFIG_REGISTRY_OVERRIDE_HF: Dict[str, Type[PretrainedConfig]] = {
58+
_CONFIG_REGISTRY_OVERRIDE_HF: dict[str, type[PretrainedConfig]] = {
5959
"mllama": MllamaConfig
6060
}
6161

62-
_CONFIG_REGISTRY: Dict[str, Type[PretrainedConfig]] = {
62+
_CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = {
6363
"chatglm": ChatGLMConfig,
6464
"cohere2": Cohere2Config,
6565
"dbrx": DbrxConfig,
@@ -199,7 +199,7 @@ def patch_rope_scaling(config: PretrainedConfig) -> None:
199199
patch_rope_scaling_dict(rope_scaling)
200200

201201

202-
def patch_rope_scaling_dict(rope_scaling: Dict[str, Any]) -> None:
202+
def patch_rope_scaling_dict(rope_scaling: dict[str, Any]) -> None:
203203
if "rope_type" in rope_scaling and "type" in rope_scaling:
204204
rope_type = rope_scaling["rope_type"]
205205
rope_type_legacy = rope_scaling["type"]
@@ -748,7 +748,7 @@ def get_hf_image_processor_config(
748748
hf_token: Optional[Union[bool, str]] = None,
749749
revision: Optional[str] = None,
750750
**kwargs,
751-
) -> Dict[str, Any]:
751+
) -> dict[str, Any]:
752752
# ModelScope does not provide an interface for image_processor
753753
if VLLM_USE_MODELSCOPE:
754754
return dict()

vllm/transformers_utils/configs/arctic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
""" Arctic model configuration"""
99

1010
from dataclasses import asdict, dataclass
11-
from typing import Any, Dict
11+
from typing import Any
1212

1313
from transformers.configuration_utils import PretrainedConfig
1414
from transformers.utils import logging
@@ -192,14 +192,14 @@ def __init__(
192192
)
193193

194194
@classmethod
195-
def from_dict(cls, config_dict: Dict[str, Any], **kwargs) -> "ArcticConfig":
195+
def from_dict(cls, config_dict: dict[str, Any], **kwargs) -> "ArcticConfig":
196196
result = super().from_dict(config_dict, **kwargs)
197197
config = result[0] if isinstance(result, tuple) else result
198198
if isinstance(config.quantization, dict):
199199
config.quantization = ArcticQuantizationConfig(**config.quantization)
200200
return result
201201

202-
def to_dict(self) -> Dict[str, Any]:
202+
def to_dict(self) -> dict[str, Any]:
203203
ret = super().to_dict()
204204
if isinstance(ret["quantization"], ArcticQuantizationConfig):
205205
ret["quantization"] = asdict(ret["quantization"])

vllm/transformers_utils/configs/cohere2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Cohere2Config(PretrainedConfig):
6161
Whether to tie weight embeddings
6262
rope_theta (`float`, *optional*, defaults to 10000.0):
6363
The base period of the RoPE embeddings.
64-
rope_scaling (`Dict`, *optional*):
64+
rope_scaling (`dict`, *optional*):
6565
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
6666
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
6767
accordingly.
@@ -86,11 +86,11 @@ class Cohere2Config(PretrainedConfig):
8686
`beta_slow` (`float`, *optional*):
8787
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
8888
ramp function. If unspecified, it defaults to 1.
89-
`short_factor` (`List[float]`, *optional*):
89+
`short_factor` (`list[float]`, *optional*):
9090
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
9191
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
9292
size divided by the number of attention heads divided by 2
93-
`long_factor` (`List[float]`, *optional*):
93+
`long_factor` (`list[float]`, *optional*):
9494
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
9595
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
9696
size divided by the number of attention heads divided by 2

vllm/transformers_utils/configs/deepseek_vl2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
# adapted from https://github.com/deepseek-ai/DeepSeek-VL2/blob/faf18023f24b962b32d9f0a2d89e402a8d383a78/deepseek_vl2/models/modeling_deepseek_vl_v2.py#L115-L268
4-
from typing import Tuple
54

65
from transformers.configuration_utils import PretrainedConfig
76

@@ -191,12 +190,12 @@ class DeepseekVLV2Config(PretrainedConfig):
191190

192191
tile_tag: str = "2D"
193192
global_view_pos: str = "head"
194-
candidate_resolutions: Tuple[Tuple[int, int]] = ((384, 384), )
193+
candidate_resolutions: tuple[tuple[int, int]] = ((384, 384), )
195194

196195
def __init__(self,
197196
tile_tag: str = "tile_tag",
198197
global_view_pos: str = "head",
199-
candidate_resolutions: Tuple[Tuple[int,
198+
candidate_resolutions: tuple[tuple[int,
200199
int]] = ((384, 384), ),
201200
**kwargs):
202201
super().__init__(**kwargs)

vllm/transformers_utils/configs/exaone.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
# limitations under the License.
1818
"""Exaone model configuration"""
1919

20-
from typing import Dict
21-
2220
from transformers.configuration_utils import PretrainedConfig
2321
from transformers.utils import logging
2422

2523
logger = logging.get_logger(__name__)
2624

27-
EXAONE_PRETRAINED_CONFIG_ARCHIVE_MAP: Dict[str, str] = {}
25+
EXAONE_PRETRAINED_CONFIG_ARCHIVE_MAP: dict[str, str] = {}
2826

2927

3028
class ExaoneConfig(PretrainedConfig):

vllm/transformers_utils/configs/jais.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class JAISConfig(PretrainedConfig):
9898
Scale attention weights by dividing by hidden_size instead of
9999
sqrt(hidden_size). Need to set scale_attn_weights to `True` as
100100
well.
101-
alibi_scaling (`Dict`, *optional*):
101+
alibi_scaling (`dict`, *optional*):
102102
Dictionary containing the scaling configuration for ALiBi
103103
embeddings. Currently only supports linear
104104
scaling strategy. Can specify either the scaling `factor` (must be
@@ -108,7 +108,7 @@ class JAISConfig(PretrainedConfig):
108108
formats are `{"type": strategy name, "factor": scaling factor}` or
109109
`{"type": strategy name,
110110
"train_seq_len": training sequence length}`.
111-
architectures (`List`, *optional*, defaults to ['JAISLMHeadModel']):
111+
architectures (`list`, *optional*, defaults to ['JAISLMHeadModel']):
112112
architecture names for Jais.
113113
114114
Example:

vllm/transformers_utils/configs/mlp_speculator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
from typing import List, Optional
3+
from typing import Optional
44

55
from transformers import PretrainedConfig
66

@@ -17,7 +17,7 @@ def __init__(self,
1717
emb_dim: int = 4096,
1818
inner_dim: int = 0,
1919
n_predict: int = 3,
20-
top_k_tokens_per_head: Optional[List[int]] = None,
20+
top_k_tokens_per_head: Optional[list[int]] = None,
2121
n_candidates: int = 5,
2222
tie_weights: bool = False,
2323
scale_input: bool = False,
@@ -34,7 +34,7 @@ def __init__(self,
3434
the inner dimension of the model. If 0, will be the emb_dim.
3535
n_predict: int
3636
the number of lookaheads for the speculator
37-
top_k_tokens_per_head: List[int]
37+
top_k_tokens_per_head: list[int]
3838
Number of tokens to consider from each head when forming the
3939
candidate tree.
4040
For each candidate branch in the tree, head n produces topk[n]

vllm/transformers_utils/configs/mpt.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# https://huggingface.co/mosaicml/mpt-7b/blob/main/configuration_mpt.py
55
"""A HuggingFace-style model configuration."""
66
import warnings
7-
from typing import Any, Dict, Optional, Union
7+
from typing import Any, Optional, Union
88

99
from transformers import PretrainedConfig
1010

11-
attn_config_defaults: Dict = {
11+
attn_config_defaults: dict = {
1212
'attn_type': 'multihead_attention',
1313
'attn_pdrop': 0.0,
1414
'attn_impl': 'triton',
@@ -20,8 +20,8 @@
2020
'alibi': False,
2121
'alibi_bias_max': 8
2222
}
23-
ffn_config_defaults: Dict = {'ffn_type': 'mptmlp'}
24-
init_config_defaults: Dict = {
23+
ffn_config_defaults: dict = {'ffn_type': 'mptmlp'}
24+
init_config_defaults: dict = {
2525
'name': 'kaiming_normal_',
2626
'fan_mode': 'fan_in',
2727
'init_nonlinearity': 'relu',
@@ -52,15 +52,15 @@ def __init__(self,
5252
resid_pdrop: float = 0.0,
5353
emb_pdrop: float = 0.0,
5454
learned_pos_emb: bool = True,
55-
attn_config: Dict = attn_config_defaults,
56-
ffn_config: Dict = ffn_config_defaults,
55+
attn_config: dict = attn_config_defaults,
56+
ffn_config: dict = ffn_config_defaults,
5757
init_device: str = 'cpu',
5858
logit_scale: Optional[Union[float, str]] = None,
5959
no_bias: bool = False,
6060
embedding_fraction: float = 1.0,
6161
norm_type: str = 'low_precision_layernorm',
6262
use_cache: bool = False,
63-
init_config: Dict = init_config_defaults,
63+
init_config: dict = init_config_defaults,
6464
fc_type: str = 'torch',
6565
verbose: Optional[int] = None,
6666
**kwargs: Any):
@@ -102,8 +102,8 @@ def __init__(self,
102102
self._validate_config()
103103

104104
def _set_config_defaults(
105-
self, config: Dict[str, Any],
106-
config_defaults: Dict[str, Any]) -> Dict[str, Any]:
105+
self, config: dict[str, Any],
106+
config_defaults: dict[str, Any]) -> dict[str, Any]:
107107
for (k, v) in config_defaults.items():
108108
if k not in config:
109109
config[k] = v

vllm/transformers_utils/configs/solar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class SolarConfig(PretrainedConfig):
108108
Whether to tie weight embeddings
109109
rope_theta (`float`, *optional*, defaults to 10000.0):
110110
The base period of the RoPE embeddings.
111-
rope_scaling (`Dict`, *optional*):
111+
rope_scaling (`dict`, *optional*):
112112
Dictionary containing the scaling configuration for
113113
the RoPE embeddings.
114114
Currently supports two scaling

vllm/transformers_utils/configs/ultravox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
# Adapted from https://github.com/fixie-ai/ultravox/blob/ecd58c4041030bae2ad15aa6bcf04ab43199ea02/ultravox/model/ultravox_config.py
4-
from typing import Any, Dict, Optional
4+
from typing import Any, Optional
55

66
import transformers
77

@@ -48,8 +48,8 @@ class UltravoxConfig(transformers.PretrainedConfig):
4848

4949
def __init__(
5050
self,
51-
audio_config: Optional[Dict[str, Any]] = None,
52-
text_config: Optional[Dict[str, Any]] = None,
51+
audio_config: Optional[dict[str, Any]] = None,
52+
text_config: Optional[dict[str, Any]] = None,
5353
audio_model_id: Optional[str] = None,
5454
text_model_id: Optional[str] = None,
5555
ignore_index: int = -100,
@@ -58,8 +58,8 @@ def __init__(
5858
stack_factor: int = 8,
5959
norm_init: float = 0.4,
6060
projector_act: str = "swiglu",
61-
text_model_lora_config: Optional[Dict[str, Any]] = None,
62-
audio_model_lora_config: Optional[Dict[str, Any]] = None,
61+
text_model_lora_config: Optional[dict[str, Any]] = None,
62+
audio_model_lora_config: Optional[dict[str, Any]] = None,
6363
projector_ln_mid: bool = False,
6464
**kwargs,
6565
):

vllm/transformers_utils/detokenizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
from typing import Dict, List, Optional
3+
from typing import Optional
44

55
from vllm.sequence import (VLLM_INVALID_TOKEN_ID, Logprob, SamplingParams,
66
Sequence, SequenceGroup)
@@ -22,7 +22,7 @@ def get_tokenizer_for_seq(self, sequence: Sequence) -> AnyTokenizer:
2222
return self.tokenizer_group.get_lora_tokenizer(sequence.lora_request)
2323

2424
def decode_prompt_logprobs_inplace(self, seq_group: SequenceGroup,
25-
prompt_logprobs: List[Optional[Dict[
25+
prompt_logprobs: list[Optional[dict[
2626
int, Logprob]]],
2727
position_offset: int) -> None:
2828
"""Decodes the logprobs for the prompt of a sequence group.
@@ -49,7 +49,7 @@ def decode_prompt_logprobs_inplace(self, seq_group: SequenceGroup,
4949
read_offset = 0
5050
next_iter_prefix_offset = 0
5151
next_iter_read_offset = 0
52-
next_iter_tokens: List[str] = []
52+
next_iter_tokens: list[str] = []
5353
prev_tokens = None
5454

5555
for token_position_in_logprob, prompt_logprobs_for_token in enumerate(

vllm/transformers_utils/detokenizer_utils.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
from typing import List, Optional, Tuple
3+
from typing import Optional
44

55
from .tokenizer import AnyTokenizer
66

77

8-
def _replace_none_with_empty(tokens: List[Optional[str]]):
8+
def _replace_none_with_empty(tokens: list[Optional[str]]):
99
for i, token in enumerate(tokens):
1010
if token is None:
1111
tokens[i] = ""
1212

1313

1414
def _convert_tokens_to_string_with_added_encoders(
1515
tokenizer: AnyTokenizer,
16-
output_tokens: List[str],
16+
output_tokens: list[str],
1717
skip_special_tokens: bool,
1818
spaces_between_special_tokens: bool,
1919
) -> str:
@@ -22,8 +22,8 @@ def _convert_tokens_to_string_with_added_encoders(
2222
# NOTE(woosuk): The following code is slow because it runs a for loop over
2323
# the output_tokens. In Python, running a for loop over a list can be slow
2424
# even when the loop body is very simple.
25-
sub_texts: List[str] = []
26-
current_sub_text: List[str] = []
25+
sub_texts: list[str] = []
26+
current_sub_text: list[str] = []
2727
all_special_tokens = set(tokenizer.all_special_tokens)
2828
for token in output_tokens:
2929
if skip_special_tokens and token in all_special_tokens:
@@ -52,9 +52,9 @@ def _convert_tokens_to_string_with_added_encoders(
5252

5353
def convert_prompt_ids_to_tokens(
5454
tokenizer: AnyTokenizer,
55-
prompt_ids: List[int],
55+
prompt_ids: list[int],
5656
skip_special_tokens: bool = False,
57-
) -> Tuple[List[str], int, int]:
57+
) -> tuple[list[str], int, int]:
5858
"""Converts the prompt ids to tokens and returns the tokens and offsets
5959
for incremental detokenization.
6060
@@ -76,8 +76,8 @@ def convert_prompt_ids_to_tokens(
7676

7777
def convert_ids_list_to_tokens(
7878
tokenizer: AnyTokenizer,
79-
token_ids: List[int],
80-
) -> List[str]:
79+
token_ids: list[int],
80+
) -> list[str]:
8181
"""Detokenize the input ids individually.
8282
8383
Args:
@@ -98,13 +98,13 @@ def convert_ids_list_to_tokens(
9898
# under Apache 2.0 license
9999
def detokenize_incrementally(
100100
tokenizer: AnyTokenizer,
101-
all_input_ids: List[int],
102-
prev_tokens: Optional[List[str]],
101+
all_input_ids: list[int],
102+
prev_tokens: Optional[list[str]],
103103
prefix_offset: int,
104104
read_offset: int,
105105
skip_special_tokens: bool = False,
106106
spaces_between_special_tokens: bool = True,
107-
) -> Tuple[List[str], str, int, int]:
107+
) -> tuple[list[str], str, int, int]:
108108
"""Detokenizes the input ids incrementally and returns the new tokens
109109
and the new text.
110110

0 commit comments

Comments
 (0)