Update Optional[x] -> x | None and Union[x, y] to x | y (#26633)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Callable, Optional, Union
|
||||
from typing import TypeAlias
|
||||
|
||||
from vllm.logger import init_logger
|
||||
|
||||
@@ -9,17 +10,17 @@ logger = init_logger(__file__)
|
||||
|
||||
CHAT_TEMPLATES_DIR = Path(__file__).parent
|
||||
|
||||
ChatTemplatePath = Union[Path, Callable[[str], Optional[Path]]]
|
||||
ChatTemplatePath: TypeAlias = Path | Callable[[str], Path | None]
|
||||
|
||||
|
||||
def _get_qwen_chat_template_fallback(tokenizer_name_or_path: str) -> Optional[Path]:
|
||||
def _get_qwen_chat_template_fallback(tokenizer_name_or_path: str) -> Path | None:
|
||||
if tokenizer_name_or_path.endswith("-Chat"):
|
||||
return CHAT_TEMPLATES_DIR / "template_chatml.jinja"
|
||||
|
||||
return CHAT_TEMPLATES_DIR / "template_basic.jinja"
|
||||
|
||||
|
||||
def _get_minicpmv_chat_template_fallback(tokenizer_name_or_path: str) -> Optional[Path]:
|
||||
def _get_minicpmv_chat_template_fallback(tokenizer_name_or_path: str) -> Path | None:
|
||||
# MiniCPM-V-4.5 version uses a dedicated template
|
||||
if "4.5" in tokenizer_name_or_path or "4_5" in tokenizer_name_or_path:
|
||||
return CHAT_TEMPLATES_DIR / "template_minicpmv45.jinja"
|
||||
@@ -58,7 +59,7 @@ def register_chat_template_fallback_path(
|
||||
def get_chat_template_fallback_path(
|
||||
model_type: str,
|
||||
tokenizer_name_or_path: str,
|
||||
) -> Optional[Path]:
|
||||
) -> Path | None:
|
||||
chat_template = _MODEL_TYPE_TO_CHAT_TEMPLATE_FALLBACK.get(model_type)
|
||||
if callable(chat_template):
|
||||
chat_template = chat_template(tokenizer_name_or_path)
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from dataclasses import asdict
|
||||
from functools import cache, partial
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Literal, Optional, TypeVar, Union
|
||||
from typing import Any, Literal, TypeVar
|
||||
|
||||
import huggingface_hub
|
||||
from huggingface_hub import (
|
||||
@@ -47,7 +48,7 @@ MISTRAL_CONFIG_NAME = "params.json"
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def _get_hf_token() -> Optional[str]:
|
||||
def _get_hf_token() -> str | None:
|
||||
"""
|
||||
Get the HuggingFace token from environment variable.
|
||||
|
||||
@@ -108,10 +109,10 @@ _AUTO_CONFIG_KWARGS_OVERRIDES: dict[str, dict[str, Any]] = {
|
||||
class HFConfigParser(ConfigParserBase):
|
||||
def parse(
|
||||
self,
|
||||
model: Union[str, Path],
|
||||
model: str | Path,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
code_revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
code_revision: str | None = None,
|
||||
**kwargs,
|
||||
) -> tuple[dict, PretrainedConfig]:
|
||||
kwargs["local_files_only"] = huggingface_hub.constants.HF_HUB_OFFLINE
|
||||
@@ -173,10 +174,10 @@ class HFConfigParser(ConfigParserBase):
|
||||
class MistralConfigParser(ConfigParserBase):
|
||||
def parse(
|
||||
self,
|
||||
model: Union[str, Path],
|
||||
model: str | Path,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
code_revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
code_revision: str | None = None,
|
||||
**kwargs,
|
||||
) -> tuple[dict, PretrainedConfig]:
|
||||
# This function loads a params.json config which
|
||||
@@ -247,8 +248,8 @@ def register_config_parser(config_format: str):
|
||||
... self,
|
||||
... model: Union[str, Path],
|
||||
... trust_remote_code: bool,
|
||||
... revision: Optional[str] = None,
|
||||
... code_revision: Optional[str] = None,
|
||||
... revision: str | None = None,
|
||||
... code_revision: str | None = None,
|
||||
... **kwargs,
|
||||
... ) -> tuple[dict, PretrainedConfig]:
|
||||
... raise NotImplementedError
|
||||
@@ -310,9 +311,9 @@ def with_retry(
|
||||
def list_repo_files(
|
||||
repo_id: str,
|
||||
*,
|
||||
revision: Optional[str] = None,
|
||||
repo_type: Optional[str] = None,
|
||||
token: Union[str, bool, None] = None,
|
||||
revision: str | None = None,
|
||||
repo_type: str | None = None,
|
||||
token: str | bool | None = None,
|
||||
) -> list[str]:
|
||||
def lookup_files() -> list[str]:
|
||||
# directly list files if model is local
|
||||
@@ -348,9 +349,9 @@ def file_exists(
|
||||
repo_id: str,
|
||||
file_name: str,
|
||||
*,
|
||||
repo_type: Optional[str] = None,
|
||||
revision: Optional[str] = None,
|
||||
token: Union[str, bool, None] = None,
|
||||
repo_type: str | None = None,
|
||||
revision: str | None = None,
|
||||
token: str | bool | None = None,
|
||||
) -> bool:
|
||||
file_list = list_repo_files(
|
||||
repo_id, repo_type=repo_type, revision=revision, token=token
|
||||
@@ -360,7 +361,7 @@ def file_exists(
|
||||
|
||||
# In offline mode the result can be a false negative
|
||||
def file_or_path_exists(
|
||||
model: Union[str, Path], config_name: str, revision: Optional[str]
|
||||
model: str | Path, config_name: str, revision: str | None
|
||||
) -> bool:
|
||||
if (local_path := Path(model)).exists():
|
||||
return (local_path / config_name).is_file()
|
||||
@@ -493,10 +494,10 @@ def maybe_override_with_speculators(
|
||||
model: str,
|
||||
tokenizer: str,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
vllm_speculative_config: Optional[dict[str, Any]] = None,
|
||||
revision: str | None = None,
|
||||
vllm_speculative_config: dict[str, Any] | None = None,
|
||||
**kwargs,
|
||||
) -> tuple[str, str, Optional[dict[str, Any]]]:
|
||||
) -> tuple[str, str, dict[str, Any] | None]:
|
||||
"""
|
||||
Resolve model configuration when speculators are detected.
|
||||
|
||||
@@ -551,13 +552,13 @@ def maybe_override_with_speculators(
|
||||
|
||||
|
||||
def get_config(
|
||||
model: Union[str, Path],
|
||||
model: str | Path,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
code_revision: Optional[str] = None,
|
||||
config_format: Union[str, ConfigFormat] = "auto",
|
||||
hf_overrides_kw: Optional[dict[str, Any]] = None,
|
||||
hf_overrides_fn: Optional[Callable[[PretrainedConfig], PretrainedConfig]] = None,
|
||||
revision: str | None = None,
|
||||
code_revision: str | None = None,
|
||||
config_format: str | ConfigFormat = "auto",
|
||||
hf_overrides_kw: dict[str, Any] | None = None,
|
||||
hf_overrides_fn: Callable[[PretrainedConfig], PretrainedConfig] | None = None,
|
||||
**kwargs,
|
||||
) -> PretrainedConfig:
|
||||
# Separate model folder from file path for GGUF models
|
||||
@@ -669,8 +670,8 @@ def get_config(
|
||||
|
||||
|
||||
def try_get_local_file(
|
||||
model: Union[str, Path], file_name: str, revision: Optional[str] = "main"
|
||||
) -> Optional[Path]:
|
||||
model: str | Path, file_name: str, revision: str | None = "main"
|
||||
) -> Path | None:
|
||||
file_path = Path(model) / file_name
|
||||
if file_path.is_file():
|
||||
return file_path
|
||||
@@ -687,7 +688,7 @@ def try_get_local_file(
|
||||
|
||||
|
||||
def get_hf_file_to_dict(
|
||||
file_name: str, model: Union[str, Path], revision: Optional[str] = "main"
|
||||
file_name: str, model: str | Path, revision: str | None = "main"
|
||||
):
|
||||
"""
|
||||
Downloads a file from the Hugging Face Hub and returns
|
||||
@@ -735,7 +736,7 @@ def get_hf_file_to_dict(
|
||||
|
||||
|
||||
@cache
|
||||
def get_pooling_config(model: str, revision: Optional[str] = "main") -> Optional[dict]:
|
||||
def get_pooling_config(model: str, revision: str | None = "main") -> dict | None:
|
||||
"""
|
||||
This function gets the pooling and normalize
|
||||
config from the model - only applies to
|
||||
@@ -799,7 +800,7 @@ def get_pooling_config(model: str, revision: Optional[str] = "main") -> Optional
|
||||
return None
|
||||
|
||||
|
||||
def get_pooling_config_name(pooling_name: str) -> Union[str, None]:
|
||||
def get_pooling_config_name(pooling_name: str) -> str | None:
|
||||
if "pooling_mode_" in pooling_name:
|
||||
pooling_name = pooling_name.replace("pooling_mode_", "")
|
||||
|
||||
@@ -820,7 +821,7 @@ def get_pooling_config_name(pooling_name: str) -> Union[str, None]:
|
||||
|
||||
@cache
|
||||
def get_sentence_transformer_tokenizer_config(
|
||||
model: Union[str, Path], revision: Optional[str] = "main"
|
||||
model: str | Path, revision: str | None = "main"
|
||||
):
|
||||
"""
|
||||
Returns the tokenization configuration dictionary for a
|
||||
@@ -958,9 +959,9 @@ def maybe_register_config_serialize_by_value() -> None:
|
||||
|
||||
|
||||
def get_hf_image_processor_config(
|
||||
model: Union[str, Path],
|
||||
hf_token: Optional[Union[bool, str]] = None,
|
||||
revision: Optional[str] = None,
|
||||
model: str | Path,
|
||||
hf_token: bool | str | None = None,
|
||||
revision: str | None = None,
|
||||
**kwargs,
|
||||
) -> dict[str, Any]:
|
||||
# ModelScope does not provide an interface for image_processor
|
||||
@@ -992,9 +993,9 @@ def get_hf_text_config(config: PretrainedConfig):
|
||||
def try_get_generation_config(
|
||||
model: str,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
config_format: Union[str, ConfigFormat] = "auto",
|
||||
) -> Optional[GenerationConfig]:
|
||||
revision: str | None = None,
|
||||
config_format: str | ConfigFormat = "auto",
|
||||
) -> GenerationConfig | None:
|
||||
try:
|
||||
return GenerationConfig.from_pretrained(
|
||||
model,
|
||||
@@ -1016,7 +1017,7 @@ def try_get_generation_config(
|
||||
def try_get_safetensors_metadata(
|
||||
model: str,
|
||||
*,
|
||||
revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
):
|
||||
get_safetensors_metadata_partial = partial(
|
||||
get_safetensors_metadata,
|
||||
@@ -1034,10 +1035,10 @@ def try_get_safetensors_metadata(
|
||||
|
||||
|
||||
def try_get_tokenizer_config(
|
||||
pretrained_model_name_or_path: Union[str, os.PathLike],
|
||||
pretrained_model_name_or_path: str | os.PathLike,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
revision: str | None = None,
|
||||
) -> dict[str, Any] | None:
|
||||
try:
|
||||
return get_tokenizer_config(
|
||||
pretrained_model_name_or_path,
|
||||
@@ -1051,7 +1052,7 @@ def try_get_tokenizer_config(
|
||||
def get_safetensors_params_metadata(
|
||||
model: str,
|
||||
*,
|
||||
revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Get the safetensors metadata for remote model repository.
|
||||
@@ -1112,7 +1113,7 @@ def _maybe_retrieve_max_pos_from_hf(model, revision, **kwargs) -> int:
|
||||
return max_position_embeddings
|
||||
|
||||
|
||||
def get_model_path(model: Union[str, Path], revision: Optional[str] = None):
|
||||
def get_model_path(model: str | Path, revision: str | None = None):
|
||||
if os.path.exists(model):
|
||||
return model
|
||||
assert huggingface_hub.constants.HF_HUB_OFFLINE
|
||||
@@ -1132,8 +1133,8 @@ def get_model_path(model: Union[str, Path], revision: Optional[str] = None):
|
||||
|
||||
|
||||
def get_hf_file_bytes(
|
||||
file_name: str, model: Union[str, Path], revision: Optional[str] = "main"
|
||||
) -> Optional[bytes]:
|
||||
file_name: str, model: str | Path, revision: str | None = "main"
|
||||
) -> bytes | None:
|
||||
"""Get file contents from HuggingFace repository as bytes."""
|
||||
file_path = try_get_local_file(model=model, file_name=file_name, revision=revision)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
@@ -12,10 +11,10 @@ class ConfigParserBase(ABC):
|
||||
@abstractmethod
|
||||
def parse(
|
||||
self,
|
||||
model: Union[str, Path],
|
||||
model: str | Path,
|
||||
trust_remote_code: bool,
|
||||
revision: Optional[str] = None,
|
||||
code_revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
code_revision: str | None = None,
|
||||
**kwargs,
|
||||
) -> tuple[dict, PretrainedConfig]:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
from transformers.models.qwen2 import Qwen2Config
|
||||
@@ -57,7 +57,7 @@ class DotsOCRConfig(Qwen2Config):
|
||||
self,
|
||||
image_token_id=151665,
|
||||
video_token_id=151656,
|
||||
vision_config: Optional[dict] = None,
|
||||
vision_config: dict | None = None,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import os
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers import AutoConfig, PretrainedConfig
|
||||
|
||||
@@ -14,12 +13,12 @@ class EAGLEConfig(PretrainedConfig):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
model: Union[PretrainedConfig, dict, None] = None,
|
||||
truncated_vocab_size: Optional[int] = None,
|
||||
method: Optional[str] = "eagle",
|
||||
model: PretrainedConfig | dict | None = None,
|
||||
truncated_vocab_size: int | None = None,
|
||||
method: str | None = "eagle",
|
||||
**kwargs,
|
||||
):
|
||||
model_config: Union[PretrainedConfig, DeepseekV2Config, None]
|
||||
model_config: PretrainedConfig | DeepseekV2Config | None
|
||||
if isinstance(model, dict):
|
||||
archs = model.get("architectures", [])
|
||||
target_archs = ["DeepseekV2ForCausalLM", "DeepseekV3ForCausalLM"]
|
||||
@@ -84,7 +83,7 @@ class EAGLEConfig(PretrainedConfig):
|
||||
@classmethod
|
||||
def from_pretrained(
|
||||
cls,
|
||||
pretrained_model_name_or_path: Union[str, os.PathLike],
|
||||
pretrained_model_name_or_path: str | os.PathLike,
|
||||
**kwargs,
|
||||
) -> "EAGLEConfig":
|
||||
config_dict, kwargs = cls.get_config_dict(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# Adapted from https://huggingface.co/moonshotai/Kimi-VL-A3B-Instruct/blob/main/configuration_kimi_vl.py
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
@@ -14,8 +13,8 @@ class KimiVLConfig(PretrainedConfig):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vision_config: Optional[Union[dict, MoonViTConfig]] = None,
|
||||
text_config: Optional[Union[dict, DeepseekV2Config]] = None,
|
||||
vision_config: dict | MoonViTConfig | None = None,
|
||||
text_config: dict | DeepseekV2Config | None = None,
|
||||
ignore_index: int = -100,
|
||||
media_placeholder_token_id: int = 163605,
|
||||
pad_token_id: int = 0,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import Optional
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
@@ -115,7 +114,7 @@ class Lfm2MoeConfig(PretrainedConfig):
|
||||
use_expert_bias: bool = True,
|
||||
routed_scaling_factor: float = 1.0,
|
||||
norm_topk_prob: bool = True,
|
||||
layer_types: Optional[list[str]] = None,
|
||||
layer_types: list[str] | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
self.vocab_size = vocab_size
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import os
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
@@ -18,7 +17,7 @@ class MedusaConfig(PretrainedConfig):
|
||||
num_hidden_layers: int = 1,
|
||||
max_paths: int = 64,
|
||||
topk: int = 10,
|
||||
truncated_vocab_size: Optional[int] = None,
|
||||
truncated_vocab_size: int | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
self.hidden_size = hidden_size
|
||||
@@ -39,7 +38,7 @@ class MedusaConfig(PretrainedConfig):
|
||||
@classmethod
|
||||
def from_pretrained(
|
||||
cls,
|
||||
pretrained_model_name_or_path: Union[str, os.PathLike],
|
||||
pretrained_model_name_or_path: str | os.PathLike,
|
||||
**kwargs,
|
||||
) -> "MedusaConfig":
|
||||
config_dict, kwargs = cls.get_config_dict(
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
from transformers.models.qwen2_5_omni.configuration_qwen2_5_omni import (
|
||||
@@ -36,15 +35,15 @@ class DashengConfig(PretrainedConfig):
|
||||
self,
|
||||
embed_dim: int = 768,
|
||||
outputdim: int = 527,
|
||||
patch_size: Union[int, tuple[int, int]] = 16,
|
||||
patch_stride: Union[int, tuple[int, int]] = 16,
|
||||
patch_size: int | tuple[int, int] = 16,
|
||||
patch_stride: int | tuple[int, int] = 16,
|
||||
input_channels: int = 1,
|
||||
target_length: int = 1012,
|
||||
depth: int = 12,
|
||||
num_heads: int = 12,
|
||||
mlp_ratio: float = 4.0,
|
||||
qkv_bias: bool = True,
|
||||
init_values: Optional[float] = None,
|
||||
init_values: float | None = None,
|
||||
drop_rate: float = 0.0,
|
||||
attn_drop_rate: float = 0.0,
|
||||
f_min: float = 0.0,
|
||||
@@ -86,10 +85,10 @@ class MiDashengLMConfig(PretrainedConfig):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
audio_encoder_config: Optional[dict] = None,
|
||||
audio_encoder_config: dict | None = None,
|
||||
subsample_factor: int = 5,
|
||||
text_config: Optional[dict] = None,
|
||||
audio_token_id: Optional[int] = None,
|
||||
text_config: dict | None = None,
|
||||
audio_token_id: int | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
self.audio_encoder_config = DashengConfig(**(audio_encoder_config or {}))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
@@ -19,7 +18,7 @@ class MLPSpeculatorConfig(PretrainedConfig):
|
||||
emb_dim: int = 4096,
|
||||
inner_dim: int = 0,
|
||||
n_predict: int = 3,
|
||||
top_k_tokens_per_head: Optional[list[int]] = None,
|
||||
top_k_tokens_per_head: list[int] | None = None,
|
||||
n_candidates: int = 5,
|
||||
tie_weights: bool = False,
|
||||
scale_input: bool = False,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# adapted from https://huggingface.co/AIDC-AI/Ovis2-1B/blob/main/configuration_aimv2.py
|
||||
# and https://huggingface.co/AIDC-AI/Ovis2-1B/blob/main/configuration_ovis.py
|
||||
# Ovis Config with AimV2 config registration removed for Transformers compatibility
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from transformers import AutoConfig, PretrainedConfig
|
||||
|
||||
@@ -76,7 +76,7 @@ class BaseVisualTokenizerConfig(PretrainedConfig):
|
||||
tau=1.0,
|
||||
depths=None,
|
||||
drop_cls_token=False,
|
||||
backbone_config: Optional[Union[PretrainedConfig, dict]] = None,
|
||||
backbone_config: PretrainedConfig | dict | None = None,
|
||||
hidden_stride: int = 1,
|
||||
**kwargs,
|
||||
):
|
||||
@@ -142,8 +142,8 @@ class OvisConfig(PretrainedConfig):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
llm_config: Optional[Union[PretrainedConfig, dict]] = None,
|
||||
visual_tokenizer_config: Optional[Union[PretrainedConfig, dict]] = None,
|
||||
llm_config: PretrainedConfig | dict | None = None,
|
||||
visual_tokenizer_config: PretrainedConfig | dict | None = None,
|
||||
multimodal_max_length=8192,
|
||||
hidden_size=None,
|
||||
conversation_formatter_class=None,
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Radio vision model configuration"""
|
||||
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
from transformers.utils import logging
|
||||
|
||||
@@ -60,9 +58,9 @@ class RadioConfig(PretrainedConfig):
|
||||
initializer_factor: float = 1.0,
|
||||
hidden_act: str = "gelu",
|
||||
max_img_size: int = 2048,
|
||||
norm_mean: Union[tuple[float, float, float], list] = OPENAI_CLIP_MEAN,
|
||||
norm_std: Union[tuple[float, float, float], list] = OPENAI_CLIP_STD,
|
||||
reg_tokens: Optional[int] = None,
|
||||
norm_mean: tuple[float, float, float] | list = OPENAI_CLIP_MEAN,
|
||||
norm_std: tuple[float, float, float] | list = OPENAI_CLIP_STD,
|
||||
reg_tokens: int | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
self.model_name = model_name
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import os
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
@@ -18,7 +18,7 @@ class SpeculatorsConfig(PretrainedConfig):
|
||||
@classmethod
|
||||
def from_pretrained(
|
||||
cls,
|
||||
pretrained_model_name_or_path: Union[str, os.PathLike],
|
||||
pretrained_model_name_or_path: str | os.PathLike,
|
||||
**kwargs,
|
||||
) -> "SpeculatorsConfig":
|
||||
"""Load speculators Eagle config and convert to vLLM format."""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
@@ -53,7 +53,7 @@ class Step3TextConfig(PretrainedConfig):
|
||||
moe_num_experts: int = 48,
|
||||
moe_top_k: int = 3,
|
||||
rope_theta: float = 500000,
|
||||
rope_scaling: Optional[dict[str, Any]] = None,
|
||||
rope_scaling: dict[str, Any] | None = None,
|
||||
max_position_embedding: int = 65536,
|
||||
share_expert_dim: int = 5120,
|
||||
share_q_dim: int = 2048,
|
||||
@@ -147,8 +147,8 @@ class Step3VLConfig(PretrainedConfig):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vision_config: Optional[Union[dict, Step3VisionEncoderConfig]] = None,
|
||||
text_config: Optional[Union[dict, Step3TextConfig]] = None,
|
||||
vision_config: dict | Step3VisionEncoderConfig | None = None,
|
||||
text_config: dict | Step3TextConfig | None = None,
|
||||
understand_projector_stride: int = 1,
|
||||
projector_bias: bool = True,
|
||||
image_token_id: int = 128001,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
# Adapted from https://github.com/fixie-ai/ultravox/blob/ecd58c4041030bae2ad15aa6bcf04ab43199ea02/ultravox/model/ultravox_config.py
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
import transformers
|
||||
|
||||
@@ -50,10 +50,10 @@ class UltravoxConfig(transformers.PretrainedConfig):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
audio_config: Optional[dict[str, Any]] = None,
|
||||
text_config: Optional[dict[str, Any]] = None,
|
||||
audio_model_id: Optional[str] = None,
|
||||
text_model_id: Optional[str] = None,
|
||||
audio_config: dict[str, Any] | None = None,
|
||||
text_config: dict[str, Any] | None = None,
|
||||
audio_model_id: str | None = None,
|
||||
text_model_id: str | None = None,
|
||||
ignore_index: int = -100,
|
||||
audio_token_index: int = 32000,
|
||||
hidden_size: int = 4096,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from .tokenizer import AnyTokenizer
|
||||
|
||||
|
||||
def _replace_none_with_empty(tokens: list[Optional[str]]):
|
||||
def _replace_none_with_empty(tokens: list[str | None]):
|
||||
for i, token in enumerate(tokens):
|
||||
if token is None:
|
||||
tokens[i] = ""
|
||||
@@ -111,7 +110,7 @@ def convert_ids_list_to_tokens(
|
||||
def detokenize_incrementally(
|
||||
tokenizer: AnyTokenizer,
|
||||
all_input_ids: list[int],
|
||||
prev_tokens: Optional[list[str]],
|
||||
prev_tokens: list[str] | None,
|
||||
prefix_offset: int,
|
||||
read_offset: int,
|
||||
skip_special_tokens: bool = False,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import os
|
||||
from typing import Optional, Union
|
||||
|
||||
from transformers.dynamic_module_utils import get_class_from_dynamic_module
|
||||
|
||||
@@ -14,18 +13,18 @@ logger = init_logger(__name__)
|
||||
def try_get_class_from_dynamic_module(
|
||||
class_reference: str,
|
||||
pretrained_model_name_or_path: str,
|
||||
cache_dir: Optional[Union[str, os.PathLike]] = None,
|
||||
cache_dir: str | os.PathLike | None = None,
|
||||
force_download: bool = False,
|
||||
resume_download: Optional[bool] = None,
|
||||
proxies: Optional[dict[str, str]] = None,
|
||||
token: Optional[Union[bool, str]] = None,
|
||||
revision: Optional[str] = None,
|
||||
resume_download: bool | None = None,
|
||||
proxies: dict[str, str] | None = None,
|
||||
token: bool | str | None = None,
|
||||
revision: str | None = None,
|
||||
local_files_only: bool = False,
|
||||
repo_type: Optional[str] = None,
|
||||
code_revision: Optional[str] = None,
|
||||
repo_type: str | None = None,
|
||||
code_revision: str | None = None,
|
||||
warn_on_fail: bool = True,
|
||||
**kwargs,
|
||||
) -> Optional[type]:
|
||||
) -> type | None:
|
||||
"""
|
||||
As `transformers.dynamic_module_utils.get_class_from_dynamic_module`,
|
||||
but ignoring any errors.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from functools import lru_cache
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from transformers import (
|
||||
AutoFeatureExtractor,
|
||||
@@ -45,7 +45,7 @@ class HashableList(list):
|
||||
return hash(tuple(self))
|
||||
|
||||
|
||||
def _get_processor_factory_fn(processor_cls: Union[type, tuple[type, ...]]):
|
||||
def _get_processor_factory_fn(processor_cls: type | tuple[type, ...]):
|
||||
if isinstance(processor_cls, tuple) or processor_cls == ProcessorMixin:
|
||||
return AutoProcessor.from_pretrained
|
||||
if hasattr(processor_cls, "from_pretrained"):
|
||||
@@ -56,7 +56,7 @@ def _get_processor_factory_fn(processor_cls: Union[type, tuple[type, ...]]):
|
||||
|
||||
def _merge_mm_kwargs(
|
||||
model_config: "ModelConfig",
|
||||
processor_cls: Union[type, tuple[type, ...]],
|
||||
processor_cls: type | tuple[type, ...],
|
||||
/,
|
||||
**kwargs,
|
||||
):
|
||||
@@ -86,9 +86,9 @@ def _merge_mm_kwargs(
|
||||
def get_processor(
|
||||
processor_name: str,
|
||||
*args: Any,
|
||||
revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
trust_remote_code: bool = False,
|
||||
processor_cls: Union[type[_P], tuple[type[_P], ...]] = ProcessorMixin,
|
||||
processor_cls: type[_P] | tuple[type[_P], ...] = ProcessorMixin,
|
||||
**kwargs: Any,
|
||||
) -> _P:
|
||||
"""Load a processor for the given model name via HuggingFace."""
|
||||
@@ -146,7 +146,7 @@ cached_get_processor = lru_cache(get_processor)
|
||||
|
||||
def cached_processor_from_config(
|
||||
model_config: "ModelConfig",
|
||||
processor_cls: Union[type[_P], tuple[type[_P], ...]] = ProcessorMixin,
|
||||
processor_cls: type[_P] | tuple[type[_P], ...] = ProcessorMixin,
|
||||
**kwargs: Any,
|
||||
) -> _P:
|
||||
return cached_get_processor(
|
||||
@@ -161,7 +161,7 @@ def cached_processor_from_config(
|
||||
def get_feature_extractor(
|
||||
processor_name: str,
|
||||
*args: Any,
|
||||
revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
trust_remote_code: bool = False,
|
||||
**kwargs: Any,
|
||||
):
|
||||
@@ -211,7 +211,7 @@ def cached_feature_extractor_from_config(
|
||||
def get_image_processor(
|
||||
processor_name: str,
|
||||
*args: Any,
|
||||
revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
trust_remote_code: bool = False,
|
||||
**kwargs: Any,
|
||||
):
|
||||
@@ -261,9 +261,9 @@ def cached_image_processor_from_config(
|
||||
def get_video_processor(
|
||||
processor_name: str,
|
||||
*args: Any,
|
||||
revision: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
trust_remote_code: bool = False,
|
||||
processor_cls_overrides: Optional[type[_V]] = None,
|
||||
processor_cls_overrides: type[_V] | None = None,
|
||||
**kwargs: Any,
|
||||
):
|
||||
"""Load a video processor for the given model name via HuggingFace."""
|
||||
@@ -300,7 +300,7 @@ cached_get_video_processor = lru_cache(get_video_processor)
|
||||
|
||||
def cached_video_processor_from_config(
|
||||
model_config: "ModelConfig",
|
||||
processor_cls: Optional[type[_V]] = None,
|
||||
processor_cls: type[_V] | None = None,
|
||||
**kwargs: Any,
|
||||
):
|
||||
return cached_get_video_processor(
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from functools import cached_property
|
||||
from typing import Union
|
||||
|
||||
import PIL
|
||||
import torch
|
||||
@@ -104,9 +103,10 @@ class OvisProcessor(ProcessorMixin):
|
||||
def __call__(
|
||||
self,
|
||||
images: ImageInput = None,
|
||||
text: Union[
|
||||
TextInput, PreTokenizedInput, list[TextInput], list[PreTokenizedInput]
|
||||
] = None,
|
||||
text: TextInput
|
||||
| PreTokenizedInput
|
||||
| list[TextInput]
|
||||
| list[PreTokenizedInput] = None,
|
||||
**kwargs: Unpack[OvisProcessorKwargs],
|
||||
) -> BatchFeature:
|
||||
"""
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import math
|
||||
from functools import cached_property
|
||||
from typing import Optional, Union
|
||||
|
||||
import numpy as np
|
||||
import PIL
|
||||
@@ -99,10 +98,11 @@ class Ovis2_5Processor(ProcessorMixin):
|
||||
def __call__(
|
||||
self,
|
||||
images: ImageInput = None,
|
||||
videos: Union[np.ndarray, list[ImageInput]] = None,
|
||||
text: Union[
|
||||
TextInput, PreTokenizedInput, list[TextInput], list[PreTokenizedInput]
|
||||
] = None,
|
||||
videos: np.ndarray | list[ImageInput] = None,
|
||||
text: TextInput
|
||||
| PreTokenizedInput
|
||||
| list[TextInput]
|
||||
| list[PreTokenizedInput] = None,
|
||||
**kwargs: Unpack[Ovis2_5ProcessorKwargs],
|
||||
) -> BatchFeature:
|
||||
"""
|
||||
@@ -376,12 +376,12 @@ class Ovis2_5Processor(ProcessorMixin):
|
||||
|
||||
def preprocess_multidata(
|
||||
self,
|
||||
images: Optional[Union[PIL.Image.Image, list[PIL.Image.Image]]] = None,
|
||||
video: Optional[Union[list[PIL.Image.Image], np.ndarray]] = None,
|
||||
convert_to_rgb: Optional[bool] = True,
|
||||
images: PIL.Image.Image | list[PIL.Image.Image] | None = None,
|
||||
video: list[PIL.Image.Image] | np.ndarray | None = None,
|
||||
convert_to_rgb: bool | None = True,
|
||||
min_pixels: int = MIN_PIXELS,
|
||||
max_pixels: int = MAX_PIXELS,
|
||||
return_tensors: Optional[str] = "pt",
|
||||
return_tensors: str | None = "pt",
|
||||
):
|
||||
is_video = False
|
||||
if images is not None:
|
||||
|
||||
@@ -5,7 +5,6 @@ import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
from typing import Optional
|
||||
|
||||
from vllm import envs
|
||||
from vllm.assets.base import get_cache_dir
|
||||
@@ -88,8 +87,8 @@ class ObjectStorageModel:
|
||||
def pull_files(
|
||||
self,
|
||||
model_path: str = "",
|
||||
allow_pattern: Optional[list[str]] = None,
|
||||
ignore_pattern: Optional[list[str]] = None,
|
||||
allow_pattern: list[str] | None = None,
|
||||
ignore_pattern: list[str] | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Pull files from object storage into the temporary directory.
|
||||
|
||||
@@ -34,7 +34,7 @@ def _filter_ignore(paths: list[str], patterns: list[str]) -> list[str]:
|
||||
def glob(
|
||||
s3: Optional["BaseClient"] = None,
|
||||
path: str = "",
|
||||
allow_pattern: Optional[list[str]] = None,
|
||||
allow_pattern: list[str] | None = None,
|
||||
) -> list[str]:
|
||||
"""
|
||||
List full file names from S3 path and filter by allow pattern.
|
||||
@@ -58,8 +58,8 @@ def glob(
|
||||
def list_files(
|
||||
s3: "BaseClient",
|
||||
path: str,
|
||||
allow_pattern: Optional[list[str]] = None,
|
||||
ignore_pattern: Optional[list[str]] = None,
|
||||
allow_pattern: list[str] | None = None,
|
||||
ignore_pattern: list[str] | None = None,
|
||||
) -> tuple[str, str, list[str]]:
|
||||
"""
|
||||
List files from S3 path and filter by pattern.
|
||||
|
||||
@@ -7,7 +7,7 @@ import os
|
||||
import warnings
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
from typing import TYPE_CHECKING, Any, TypeAlias
|
||||
|
||||
import huggingface_hub
|
||||
from transformers import AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast
|
||||
@@ -30,14 +30,14 @@ else:
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
AnyTokenizer = Union[PreTrainedTokenizer, PreTrainedTokenizerFast, TokenizerBase]
|
||||
AnyTokenizer: TypeAlias = PreTrainedTokenizer | PreTrainedTokenizerFast | TokenizerBase
|
||||
|
||||
|
||||
def decode_tokens(
|
||||
tokenizer: AnyTokenizer,
|
||||
token_ids: list[int],
|
||||
*,
|
||||
skip_special_tokens: Optional[bool] = None,
|
||||
skip_special_tokens: bool | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
Backend-agnostic equivalent of HF's
|
||||
@@ -56,9 +56,9 @@ def encode_tokens(
|
||||
tokenizer: AnyTokenizer,
|
||||
text: str,
|
||||
*,
|
||||
truncation: Optional[bool] = None,
|
||||
max_length: Optional[int] = None,
|
||||
add_special_tokens: Optional[bool] = None,
|
||||
truncation: bool | None = None,
|
||||
max_length: int | None = None,
|
||||
add_special_tokens: bool | None = None,
|
||||
) -> list[int]:
|
||||
"""
|
||||
Backend-agnostic equivalent of HF's
|
||||
@@ -137,12 +137,12 @@ def get_cached_tokenizer(tokenizer: AnyTokenizer) -> AnyTokenizer:
|
||||
|
||||
|
||||
def get_tokenizer(
|
||||
tokenizer_name: Union[str, Path],
|
||||
tokenizer_name: str | Path,
|
||||
*args,
|
||||
tokenizer_mode: str = "auto",
|
||||
trust_remote_code: bool = False,
|
||||
revision: Optional[str] = None,
|
||||
download_dir: Optional[str] = None,
|
||||
revision: str | None = None,
|
||||
download_dir: str | None = None,
|
||||
**kwargs,
|
||||
) -> AnyTokenizer:
|
||||
"""Gets a tokenizer for the given model name via HuggingFace or ModelScope."""
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import importlib
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.entrypoints.chat_utils import ChatCompletionMessageParam
|
||||
@@ -71,11 +71,11 @@ class TokenizerBase(ABC):
|
||||
@abstractmethod
|
||||
def __call__(
|
||||
self,
|
||||
text: Union[str, list[str], list[int]],
|
||||
text_pair: Optional[str] = None,
|
||||
text: str | list[str] | list[int],
|
||||
text_pair: str | None = None,
|
||||
add_special_tokens: bool = False,
|
||||
truncation: bool = False,
|
||||
max_length: Optional[int] = None,
|
||||
max_length: int | None = None,
|
||||
):
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -92,7 +92,7 @@ class TokenizerBase(ABC):
|
||||
self,
|
||||
text: str,
|
||||
truncation: bool = False,
|
||||
max_length: Optional[int] = None,
|
||||
max_length: int | None = None,
|
||||
) -> list[int]:
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -100,9 +100,9 @@ class TokenizerBase(ABC):
|
||||
def encode(
|
||||
self,
|
||||
text: str,
|
||||
truncation: Optional[bool] = None,
|
||||
max_length: Optional[int] = None,
|
||||
add_special_tokens: Optional[bool] = None,
|
||||
truncation: bool | None = None,
|
||||
max_length: int | None = None,
|
||||
add_special_tokens: bool | None = None,
|
||||
) -> list[int]:
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -110,7 +110,7 @@ class TokenizerBase(ABC):
|
||||
def apply_chat_template(
|
||||
self,
|
||||
messages: list["ChatCompletionMessageParam"],
|
||||
tools: Optional[list[dict[str, Any]]] = None,
|
||||
tools: list[dict[str, Any]] | None = None,
|
||||
**kwargs,
|
||||
) -> list[int]:
|
||||
raise NotImplementedError()
|
||||
@@ -120,9 +120,7 @@ class TokenizerBase(ABC):
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def decode(
|
||||
self, ids: Union[list[int], int], skip_special_tokens: bool = True
|
||||
) -> str:
|
||||
def decode(self, ids: list[int] | int, skip_special_tokens: bool = True) -> str:
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.transformers_utils.tokenizer_base import TokenizerBase
|
||||
@@ -90,10 +90,10 @@ def truncate_tool_call_ids(request: "MistralChatCompletionRequest"):
|
||||
|
||||
def _prepare_apply_chat_template_tools_and_messages(
|
||||
messages: list["ChatCompletionMessageParam"],
|
||||
tools: Optional[list[dict[str, Any]]] = None,
|
||||
tools: list[dict[str, Any]] | None = None,
|
||||
continue_final_message: bool = False,
|
||||
add_generation_prompt: bool = False,
|
||||
) -> tuple[list["ChatCompletionMessageParam"], Optional[list[dict[str, Any]]]]:
|
||||
) -> tuple[list["ChatCompletionMessageParam"], list[dict[str, Any]] | None]:
|
||||
if add_generation_prompt and continue_final_message:
|
||||
raise ValueError(
|
||||
"Cannot set both `add_generation_prompt` and "
|
||||
@@ -144,7 +144,7 @@ def validate_request_params(request: "ChatCompletionRequest"):
|
||||
raise ValueError("chat_template is not supported for Mistral tokenizers.")
|
||||
|
||||
|
||||
def _tekken_token_to_id(tokenizer: "Tekkenizer", t: Union[str, bytes]) -> int:
|
||||
def _tekken_token_to_id(tokenizer: "Tekkenizer", t: str | bytes) -> int:
|
||||
from mistral_common.tokens.tokenizers.tekken import Tekkenizer
|
||||
|
||||
assert isinstance(tokenizer, Tekkenizer), type(tokenizer)
|
||||
@@ -197,7 +197,7 @@ class MistralTokenizer(TokenizerBase):
|
||||
|
||||
@classmethod
|
||||
def from_pretrained(
|
||||
cls, path_or_repo_id: str, *, revision: Optional[str] = None
|
||||
cls, path_or_repo_id: str, *, revision: str | None = None
|
||||
) -> "MistralTokenizer":
|
||||
from transformers.tokenization_mistral_common import (
|
||||
MistralCommonTokenizer as TransformersMistralTokenizer,
|
||||
@@ -298,11 +298,11 @@ class MistralTokenizer(TokenizerBase):
|
||||
|
||||
def __call__(
|
||||
self,
|
||||
text: Union[str, list[str], list[int]],
|
||||
text_pair: Optional[str] = None,
|
||||
text: str | list[str] | list[int],
|
||||
text_pair: str | None = None,
|
||||
add_special_tokens: bool = False,
|
||||
truncation: bool = False,
|
||||
max_length: Optional[int] = None,
|
||||
max_length: int | None = None,
|
||||
):
|
||||
return self.transformers_tokenizer(
|
||||
text=text,
|
||||
@@ -327,7 +327,7 @@ class MistralTokenizer(TokenizerBase):
|
||||
self,
|
||||
text: str,
|
||||
truncation: bool = False,
|
||||
max_length: Optional[int] = None,
|
||||
max_length: int | None = None,
|
||||
) -> list[int]:
|
||||
# Mistral Tokenizers should not add special tokens
|
||||
return self.transformers_tokenizer.encode(
|
||||
@@ -337,9 +337,9 @@ class MistralTokenizer(TokenizerBase):
|
||||
def encode(
|
||||
self,
|
||||
text: str,
|
||||
truncation: Optional[bool] = None,
|
||||
max_length: Optional[int] = None,
|
||||
add_special_tokens: Optional[bool] = None,
|
||||
truncation: bool | None = None,
|
||||
max_length: int | None = None,
|
||||
add_special_tokens: bool | None = None,
|
||||
) -> list[int]:
|
||||
if add_special_tokens is not None:
|
||||
return self.transformers_tokenizer.encode(
|
||||
@@ -359,7 +359,7 @@ class MistralTokenizer(TokenizerBase):
|
||||
def apply_chat_template(
|
||||
self,
|
||||
messages: list["ChatCompletionMessageParam"],
|
||||
tools: Optional[list[dict[str, Any]]] = None,
|
||||
tools: list[dict[str, Any]] | None = None,
|
||||
**kwargs,
|
||||
) -> list[int]:
|
||||
add_generation_prompt = kwargs.pop("add_generation_prompt", False)
|
||||
@@ -384,9 +384,7 @@ class MistralTokenizer(TokenizerBase):
|
||||
return_dict=False,
|
||||
)
|
||||
|
||||
def decode(
|
||||
self, ids: Union[list[int], int], skip_special_tokens: bool = True
|
||||
) -> str:
|
||||
def decode(self, ids: list[int] | int, skip_special_tokens: bool = True) -> str:
|
||||
return self.transformers_tokenizer.decode(
|
||||
ids, skip_special_tokens=skip_special_tokens
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ import struct
|
||||
from functools import cache
|
||||
from os import PathLike
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from vllm.envs import VLLM_MODEL_REDIRECT_PATH
|
||||
from vllm.logger import init_logger
|
||||
@@ -18,7 +18,7 @@ def is_s3(model_or_path: str) -> bool:
|
||||
return model_or_path.lower().startswith("s3://")
|
||||
|
||||
|
||||
def check_gguf_file(model: Union[str, PathLike]) -> bool:
|
||||
def check_gguf_file(model: str | PathLike) -> bool:
|
||||
"""Check if the file is a GGUF model."""
|
||||
model = Path(model)
|
||||
if not model.is_file():
|
||||
@@ -38,8 +38,8 @@ def check_gguf_file(model: Union[str, PathLike]) -> bool:
|
||||
|
||||
def modelscope_list_repo_files(
|
||||
repo_id: str,
|
||||
revision: Optional[str] = None,
|
||||
token: Union[str, bool, None] = None,
|
||||
revision: str | None = None,
|
||||
token: str | bool | None = None,
|
||||
) -> list[str]:
|
||||
"""List files in a modelscope repo."""
|
||||
from modelscope.hub.api import HubApi
|
||||
@@ -57,7 +57,7 @@ def modelscope_list_repo_files(
|
||||
return files
|
||||
|
||||
|
||||
def _maybe_json_dict(path: Union[str, PathLike]) -> dict[str, str]:
|
||||
def _maybe_json_dict(path: str | PathLike) -> dict[str, str]:
|
||||
with open(path) as f:
|
||||
try:
|
||||
return json.loads(f.read())
|
||||
@@ -65,7 +65,7 @@ def _maybe_json_dict(path: Union[str, PathLike]) -> dict[str, str]:
|
||||
return dict[str, str]()
|
||||
|
||||
|
||||
def _maybe_space_split_dict(path: Union[str, PathLike]) -> dict[str, str]:
|
||||
def _maybe_space_split_dict(path: str | PathLike) -> dict[str, str]:
|
||||
parsed_dict = dict[str, str]()
|
||||
with open(path) as f:
|
||||
for line in f.readlines():
|
||||
@@ -104,7 +104,7 @@ def maybe_model_redirect(model: str) -> str:
|
||||
return model
|
||||
|
||||
|
||||
def parse_safetensors_file_metadata(path: Union[str, PathLike]) -> dict[str, Any]:
|
||||
def parse_safetensors_file_metadata(path: str | PathLike) -> dict[str, Any]:
|
||||
with open(path, "rb") as f:
|
||||
length_of_metadata = struct.unpack("<Q", f.read(8))[0]
|
||||
metadata = json.loads(f.read(length_of_metadata).decode("utf-8"))
|
||||
|
||||
Reference in New Issue
Block a user