Add pydocstyle to the ruff rules (#52136)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Signed-off-by: Harry Mellor <hej.mellor@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -231,7 +231,6 @@ def _patch_hf_transformers_validate_rope():
|
||||
validate_rope() with the ignore_keys parameter work with newer versions of
|
||||
hf transformers (from v5 onwards)
|
||||
"""
|
||||
|
||||
if hasattr(PretrainedConfig.validate_rope, "__vllm_patched__"):
|
||||
return
|
||||
|
||||
@@ -489,10 +488,11 @@ def register_config_parser(config_format: str):
|
||||
"""Register a customized vllm config parser.
|
||||
When a config format is not supported by vllm, you can register a customized
|
||||
config parser to support it.
|
||||
Args:
|
||||
config_format (str): The config parser format name.
|
||||
Examples:
|
||||
|
||||
Args:
|
||||
config_format (str): The config parser format name.
|
||||
|
||||
Examples:
|
||||
>>> from vllm.transformers_utils.config import (get_config_parser,
|
||||
register_config_parser)
|
||||
>>> from vllm.transformers_utils.config_parser_base import ConfigParserBase
|
||||
@@ -511,6 +511,7 @@ def register_config_parser(config_format: str):
|
||||
>>>
|
||||
>>> type(get_config_parser("custom_config_parser"))
|
||||
<class 'CustomConfigParser'>
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
def _wrapper(config_parser_cls):
|
||||
@@ -538,7 +539,8 @@ def register_config_parser(config_format: str):
|
||||
|
||||
def set_default_rope_theta(config: PretrainedConfig, default_theta: float) -> None:
|
||||
"""Some models may have no rope_theta in their config but still use RoPE.
|
||||
This function sets a default rope_theta if it's missing."""
|
||||
This function sets a default rope_theta if it's missing.
|
||||
"""
|
||||
if getattr(config, "rope_parameters", None) is None:
|
||||
config.rope_parameters = {"rope_type": "default"}
|
||||
if "rope_theta" not in config.rope_parameters:
|
||||
@@ -547,8 +549,8 @@ def set_default_rope_theta(config: PretrainedConfig, default_theta: float) -> No
|
||||
|
||||
def patch_legacy_rope_type(rope_parameters: dict[str, Any] | None) -> None:
|
||||
"""Patch legacy RoPE type fields for backwards compatibility with
|
||||
older custom models which would otherwise fail to load."""
|
||||
|
||||
older custom models which would otherwise fail to load.
|
||||
"""
|
||||
# No RoPE parameters to patch
|
||||
if rope_parameters is None:
|
||||
return
|
||||
@@ -721,9 +723,7 @@ def is_encoder_decoder(config: PretrainedConfig) -> bool:
|
||||
|
||||
|
||||
def _maybe_update_auto_config_kwargs(kwargs: dict[str, Any], model_type: str):
|
||||
"""
|
||||
Update kwargs for AutoConfig initialization based on model_type
|
||||
"""
|
||||
"""Update kwargs for AutoConfig initialization based on model_type."""
|
||||
if model_type in _AUTO_CONFIG_KWARGS_OVERRIDES:
|
||||
kwargs.update(_AUTO_CONFIG_KWARGS_OVERRIDES[model_type])
|
||||
return kwargs
|
||||
@@ -748,8 +748,7 @@ def maybe_override_with_speculators(
|
||||
hf_token: bool | str | None = None,
|
||||
**kwargs,
|
||||
) -> tuple[str, str | None, dict[str, Any] | None]:
|
||||
"""
|
||||
Resolve model configuration when speculators are detected.
|
||||
"""Resolve model configuration when speculators are detected.
|
||||
|
||||
Checks if the provided model is a speculators model and if so, extracts
|
||||
the target model configuration and builds the speculative config.
|
||||
@@ -764,6 +763,7 @@ def maybe_override_with_speculators(
|
||||
|
||||
Returns:
|
||||
Tuple of (resolved_model, resolved_tokenizer, speculative_config)
|
||||
|
||||
"""
|
||||
kwargs["local_files_only"] = huggingface_hub.constants.HF_HUB_OFFLINE
|
||||
config_dict, _ = PretrainedConfig.get_config_dict(
|
||||
@@ -938,8 +938,7 @@ def get_pooling_config(
|
||||
model: str,
|
||||
revision: str | None = "main",
|
||||
) -> dict[str, Any] | None:
|
||||
"""
|
||||
This function gets the pooling and normalize
|
||||
"""This function gets the pooling and normalize
|
||||
config from the model - only applies to
|
||||
sentence-transformers models.
|
||||
|
||||
@@ -951,6 +950,7 @@ def get_pooling_config(
|
||||
Returns:
|
||||
A dictionary containing the pooling type and whether
|
||||
normalization is used, or None if no pooling configuration is found.
|
||||
|
||||
"""
|
||||
modules_file_name = "modules.json"
|
||||
|
||||
@@ -1035,19 +1035,17 @@ def parse_pooling_type(pooling_name: str):
|
||||
def get_sentence_transformer_tokenizer_config(
|
||||
model: str | Path, revision: str | None = "main"
|
||||
) -> dict[str, Any] | None:
|
||||
"""
|
||||
Returns the tokenization configuration dictionary for a
|
||||
"""Returns the tokenization configuration dictionary for a
|
||||
given Sentence Transformer BERT model.
|
||||
|
||||
Parameters:
|
||||
- model (str|Path): The name of the Sentence Transformer
|
||||
BERT model.
|
||||
- revision (str, optional): The revision of the m
|
||||
odel to use. Defaults to 'main'.
|
||||
Args:
|
||||
model (str|Path): The name of the Sentence Transformer BERT model.
|
||||
revision (str, optional): The revision of the model to use. Defaults to 'main'.
|
||||
|
||||
Returns:
|
||||
- dict: A dictionary containing the configuration parameters
|
||||
for the Sentence Transformer BERT model.
|
||||
|
||||
"""
|
||||
sentence_transformer_config_files = [
|
||||
"sentence_bert_config.json",
|
||||
@@ -1308,9 +1306,7 @@ def get_safetensors_params_metadata(
|
||||
*,
|
||||
revision: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Get the safetensors parameters metadata for remote/local model repository.
|
||||
"""
|
||||
"""Get the safetensors parameters metadata for remote/local model repository."""
|
||||
if (model_path := Path(model)).exists():
|
||||
return _read_safetensors_metadata_in_dir(model_path)
|
||||
|
||||
@@ -1354,6 +1350,7 @@ def checkpoint_has_lm_head(model: str, *, revision: str | None = None) -> bool |
|
||||
Returns:
|
||||
`None` if the checkpoint contents could not be determined, for example
|
||||
because it is not stored as safetensors.
|
||||
|
||||
"""
|
||||
metadata = get_safetensors_params_metadata(model, revision=revision)
|
||||
if not metadata:
|
||||
|
||||
@@ -6,14 +6,14 @@ from transformers import PretrainedConfig
|
||||
|
||||
|
||||
class AXK1Config(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a [`AXK1Model`].
|
||||
r"""This is the configuration class to store the configuration of a [`AXK1Model`].
|
||||
It is used to instantiate an A.X model according to the specified arguments,
|
||||
defining the model architecture. Instantiating a configuration with the defaults
|
||||
will yield a similar configuration to that of the A.X K1.
|
||||
Configuration objects inherit from [`PretrainedConfig`] and can be used to control
|
||||
the model outputs. Read the documentation from [`PretrainedConfig`] for more
|
||||
information.
|
||||
|
||||
Args:
|
||||
vocab_size (`int`, *optional*, defaults to 163840):
|
||||
Vocabulary size of the A.X K1 model. Defines the number of different
|
||||
@@ -112,6 +112,7 @@ class AXK1Config(PretrainedConfig):
|
||||
layers during self-attention.
|
||||
attention_dropout (`float`, *optional*, defaults to 0.0):
|
||||
The dropout ratio for the attention probabilities.
|
||||
|
||||
"""
|
||||
|
||||
model_type = "axk1"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Model configs may be defined in this directory for the following reasons:
|
||||
"""Model configs may be defined in this directory for the following reasons:
|
||||
|
||||
- There is no configuration file defined by HF Hub or Transformers library.
|
||||
- There is a need to override the existing config to support vLLM.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
ColPali configuration that extends PaliGemmaConfig with embedding projection
|
||||
"""ColPali configuration that extends PaliGemmaConfig with embedding projection
|
||||
fields. This allows ColPali models to be loaded without trust_remote_code
|
||||
by mapping their custom model_type (colpali) to a standard config class
|
||||
that vLLM understands.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
ColQwen3 configuration that extends Qwen3VLConfig with embedding projection
|
||||
"""ColQwen3 configuration that extends Qwen3VLConfig with embedding projection
|
||||
fields. This allows ColQwen3 models to be loaded without trust_remote_code
|
||||
by mapping their custom model_type (colqwen3, ops_colqwen3, etc.) to a
|
||||
standard config class that vLLM understands.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Config definitions for ExtractHiddenStatesModel, to be used with
|
||||
the extract_hidden_states spec decoding method."""
|
||||
the extract_hidden_states spec decoding method.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# 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.
|
||||
"""Falcon configuration"""
|
||||
"""Falcon configuration."""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
class HYV3Config(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a [`HYV3Model`].
|
||||
r"""This is the configuration class to store the configuration of a [`HYV3Model`].
|
||||
It is used to instantiate a HYV3 model (HY V3 MoE language model) according to
|
||||
the specified arguments.
|
||||
|
||||
@@ -93,6 +92,7 @@ class HYV3Config(PretrainedConfig):
|
||||
>>> config = HYV3Config()
|
||||
>>> model = HYV3Model(config)
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
model_type = "hy_v3"
|
||||
|
||||
@@ -52,6 +52,7 @@ class HYV4Config(PreTrainedConfig):
|
||||
below zero disable the clamp.
|
||||
num_nextn_predict_layers: Number of MTP layers in the checkpoint.
|
||||
mtp_loss_factor: Training-time MTP loss weight (unused at inference).
|
||||
|
||||
"""
|
||||
|
||||
model_type = "hy_v4"
|
||||
|
||||
@@ -21,8 +21,7 @@ from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
class HyperCLOVAXConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a
|
||||
r"""This is the configuration class to store the configuration of a
|
||||
[`HyperCLOVAXModel`]. It is used to instantiate a HyperCLOVAX model
|
||||
according to the specified arguments, defining the model architecture.
|
||||
Configuration objects inherit from [`PretrainedConfig`] and can be used
|
||||
@@ -166,6 +165,7 @@ class HyperCLOVAXConfig(PretrainedConfig):
|
||||
`get_rope`. When provided, takes precedence over `rope_theta`
|
||||
and `rope_scaling`. If `None`, it is derived from `rope_theta`
|
||||
and `rope_scaling` automatically.
|
||||
|
||||
"""
|
||||
|
||||
model_type = "hyperclovax"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Kimi-K2.5 Model Configuration.
|
||||
"""Kimi-K2.5 Model Configuration.
|
||||
|
||||
This configuration supports video-chunk as an internal modality type.
|
||||
A video-chunk is the smallest independently processable unit of video.
|
||||
@@ -73,6 +72,7 @@ class KimiK25Config(PretrainedConfig):
|
||||
ignore_index: The ignore index for the loss function.
|
||||
media_placeholder_token_id: The token ID for media placeholders.
|
||||
pad_token_id: The token ID for padding.
|
||||
|
||||
"""
|
||||
|
||||
model_type = "kimi_k25"
|
||||
|
||||
@@ -6,8 +6,7 @@ from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
class Lfm2MoeConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a [`Lfm2MoeModel`]. It is used to instantiate a LFM2 Moe
|
||||
r"""This is the configuration class to store the configuration of a [`Lfm2MoeModel`]. It is used to instantiate a LFM2 Moe
|
||||
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
||||
defaults will yield a similar configuration to that of the LFM2-8B-A1B model.
|
||||
e.g. [LiquidAI/LFM2-8B-A1B](https://huggingface.co/LiquidAI/LFM2-8B-A1B)
|
||||
@@ -85,7 +84,9 @@ class Lfm2MoeConfig(PretrainedConfig):
|
||||
|
||||
>>> # Accessing the model configuration
|
||||
>>> configuration = model.config
|
||||
```""" # noqa: E501
|
||||
```
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
model_type = "lfm2_moe"
|
||||
keys_to_ignore_at_inference = ["past_key_values"]
|
||||
|
||||
@@ -24,8 +24,7 @@ class MLPSpeculatorConfig(PretrainedConfig):
|
||||
scale_input: bool = False,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Initialize an MLPSpeculatorConfig
|
||||
"""Initialize an MLPSpeculatorConfig.
|
||||
|
||||
Args:
|
||||
vocab_size: int
|
||||
@@ -52,6 +51,7 @@ class MLPSpeculatorConfig(PretrainedConfig):
|
||||
scale_input: bool
|
||||
if True, will scale the initial hidden states from
|
||||
the base model.
|
||||
|
||||
"""
|
||||
if top_k_tokens_per_head is None:
|
||||
top_k_tokens_per_head = [5, 4, 3]
|
||||
|
||||
@@ -148,5 +148,6 @@ class Moondream3Config(PretrainedConfig):
|
||||
|
||||
Args:
|
||||
decoder: Ignored. Only used for encoder-decoder models.
|
||||
|
||||
"""
|
||||
return self.text_config
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# 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.
|
||||
"""Nemotron model configuration"""
|
||||
"""Nemotron model configuration."""
|
||||
|
||||
from transformers import PretrainedConfig
|
||||
from transformers.utils import logging
|
||||
@@ -24,8 +24,7 @@ logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
class NemotronConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a
|
||||
r"""This is the configuration class to store the configuration of a
|
||||
[`NemotronModel`]. It is used to instantiate a Nemotron model
|
||||
according to the specified arguments, defining the model architecture.
|
||||
Instantiating a configuration with the defaults will yield a similar
|
||||
@@ -114,7 +113,9 @@ class NemotronConfig(PretrainedConfig):
|
||||
>>> model = NemotronModel(configuration)
|
||||
>>> # Accessing the model configuration
|
||||
>>> configuration = model.config
|
||||
```"""
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
model_type = "nemotron"
|
||||
keys_to_ignore_at_inference = ["past_key_values"]
|
||||
@@ -193,9 +194,7 @@ class NemotronConfig(PretrainedConfig):
|
||||
)
|
||||
|
||||
def _rope_parameters_validation(self):
|
||||
"""
|
||||
Validate the `rope_parameters` configuration.
|
||||
"""
|
||||
"""Validate the `rope_parameters` configuration."""
|
||||
if self.rope_parameters is None:
|
||||
return
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# 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.
|
||||
"""NemotronH model configuration"""
|
||||
"""NemotronH model configuration."""
|
||||
|
||||
import regex as re
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
@@ -25,12 +25,12 @@ logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
class NemotronHConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a
|
||||
r"""This is the configuration class to store the configuration of a
|
||||
[`NemotronHModel`]. It is used to instantiate a NemotronH model according
|
||||
to the specified arguments, defining the model architecture. Instantiating
|
||||
a configuration with the defaults will yield a similar configuration to
|
||||
that of the NemotronH-v0.1 model.
|
||||
|
||||
Args:
|
||||
vocab_size (`int`, *optional*, defaults to 131072):
|
||||
Vocabulary size of the NemotronH model. Defines the number of
|
||||
@@ -139,6 +139,7 @@ class NemotronHConfig(PretrainedConfig):
|
||||
Size of chunks for Mamba processing.
|
||||
rescale_prenorm_residual (`bool`, *optional*, defaults to `True`):
|
||||
Whether to rescale the pre-normalization residual connections.
|
||||
|
||||
"""
|
||||
|
||||
model_type = "nemotron_h"
|
||||
|
||||
@@ -6,8 +6,7 @@ from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
class OlmoHybridConfig(PretrainedConfig):
|
||||
r"""
|
||||
Configuration class for [`OlmoHybridModel`]. It is used to
|
||||
r"""Configuration class for [`OlmoHybridModel`]. It is used to
|
||||
instantiate an OLMo Hybrid model according to the specified
|
||||
arguments, defining the model architecture. Instantiating a
|
||||
configuration with the defaults will yield a similar
|
||||
@@ -19,7 +18,7 @@ class OlmoHybridConfig(PretrainedConfig):
|
||||
can be used to control the model outputs. Read the
|
||||
documentation from [`PreTrainedConfig`] for more information.
|
||||
|
||||
Args:
|
||||
Args:
|
||||
vocab_size (`int`, *optional*, defaults to 100352):
|
||||
Vocabulary size of the OlmoHybrid model. Defines
|
||||
the number of different tokens that can be
|
||||
@@ -159,6 +158,7 @@ class OlmoHybridConfig(PretrainedConfig):
|
||||
>>> model = OlmoHybridModel(configuration)
|
||||
>>> configuration = model.config
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
model_type = "olmo_hybrid"
|
||||
|
||||
@@ -14,6 +14,7 @@ class AIMv2Config(PretrainedConfig):
|
||||
"""This is the configuration class to store the configuration of an [`AIMv2Model`].
|
||||
Instantiating a configuration with the defaults will yield a similar configuration
|
||||
to that of the [apple/aimv2-large-patch14-224](https://huggingface.co/apple/aimv2-large-patch14-224).
|
||||
|
||||
Args:
|
||||
hidden_size: Dimension of the hidden representations.
|
||||
intermediate_size: Dimension of the SwiGLU representations.
|
||||
@@ -29,6 +30,7 @@ class AIMv2Config(PretrainedConfig):
|
||||
qkv_bias: Whether to add a bias to the queries, keys and values.
|
||||
use_bias: Whether to add a bias in the feed-forward and projection layers.
|
||||
kwargs: Keyword arguments for the [`PretrainedConfig`].
|
||||
|
||||
"""
|
||||
|
||||
model_type: str = "aimv2"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# 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.
|
||||
"""Qwen3.5 model configuration"""
|
||||
"""Qwen3.5 model configuration."""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# 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.
|
||||
"""Qwen3.5-MoE model configuration"""
|
||||
"""Qwen3.5-MoE model configuration."""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# 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.
|
||||
"""Qwen3-Next model configuration"""
|
||||
"""Qwen3-Next model configuration."""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
from transformers.utils import logging
|
||||
@@ -23,8 +23,7 @@ logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
class Qwen3NextConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a [`Qwen3NextModel`]. It is used to instantiate a
|
||||
r"""This is the configuration class to store the configuration of a [`Qwen3NextModel`]. It is used to instantiate a
|
||||
Qwen3-Next model according to the specified arguments, defining the model architecture.
|
||||
Instantiating a configuration with the defaults will yield a similar configuration to that of
|
||||
Qwen3-Next-80B-A3B-Instruct [Qwen/Qwen3-Next-80B-A3B-Instruct](https://huggingface.co/Qwen/Qwen3-Next-80B-A3B-Instruct).
|
||||
@@ -157,6 +156,7 @@ class Qwen3NextConfig(PretrainedConfig):
|
||||
>>> # Accessing the model configuration
|
||||
>>> configuration = model.config
|
||||
```
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
model_type = "qwen3_next"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Radio vision model configuration"""
|
||||
"""Radio vision model configuration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -21,8 +21,7 @@ OPENAI_CLIP_STD = (0.26862954, 0.26130258, 0.27577711)
|
||||
|
||||
|
||||
class RadioConfig(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a Radio
|
||||
r"""This is the configuration class to store the configuration of a Radio
|
||||
vision model. It is used to instantiate a Radio model according to the
|
||||
specified arguments, defining the model architecture.
|
||||
|
||||
@@ -55,6 +54,7 @@ class RadioConfig(PretrainedConfig):
|
||||
dedicated video patch embedder (3*T*P*P -> hidden) separate from the
|
||||
image embedder (3*P*P -> hidden). When False, a single embedder with
|
||||
input size 3*T*P*P is used for both (images are duplicated T times).
|
||||
|
||||
"""
|
||||
|
||||
model_type = "radio"
|
||||
|
||||
@@ -14,8 +14,7 @@ def register_speculator(name):
|
||||
|
||||
@register_speculator("eagle3")
|
||||
def update_eagle3(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
"""
|
||||
Apply Eagle-3 specific configuration transformations to the `dict` used to
|
||||
"""Apply Eagle-3 specific configuration transformations to the `dict` used to
|
||||
construct the Transformers PreTrainedConfig.
|
||||
|
||||
Eagle-3 specific fields:
|
||||
@@ -28,7 +27,6 @@ def update_eagle3(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
provide intermediate hidden states that help the drafter make better
|
||||
predictions. This is the standard field used in Eagle3 checkpoints.
|
||||
"""
|
||||
|
||||
pre_trained_config["draft_vocab_size"] = config_dict.get("draft_vocab_size")
|
||||
if config_dict.get("target_hidden_size") is not None:
|
||||
pre_trained_config["target_hidden_size"] = config_dict["target_hidden_size"]
|
||||
@@ -54,8 +52,7 @@ def update_eagle3(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
|
||||
@register_speculator("peagle")
|
||||
def update_peagle(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
"""
|
||||
Apply PEagle (Parallel Eagle) specific configuration transformations to
|
||||
"""Apply PEagle (Parallel Eagle) specific configuration transformations to
|
||||
the `dict` used to construct the Transformers PreTrainedConfig.
|
||||
|
||||
PEagle specific fields:
|
||||
@@ -92,8 +89,7 @@ def update_peagle(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
|
||||
@register_speculator("dflash")
|
||||
def update_dflash(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
"""
|
||||
Apply DFlash specific configuration transformations to the `dict` used to
|
||||
"""Apply DFlash specific configuration transformations to the `dict` used to
|
||||
construct the Transformers PreTrainedConfig.
|
||||
|
||||
DFlash specific fields:
|
||||
@@ -132,8 +128,7 @@ def update_dflash(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
|
||||
@register_speculator("dflash2")
|
||||
def update_dflash2(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
"""
|
||||
Apply DFlash2 specific configuration transformations to the `dict` used
|
||||
"""Apply DFlash2 specific configuration transformations to the `dict` used
|
||||
to construct the Transformers PreTrainedConfig.
|
||||
|
||||
DFlash2 extends DFlash with a grouped convolution layer and a
|
||||
@@ -156,8 +151,7 @@ def update_dflash2(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
|
||||
@register_speculator("dspark")
|
||||
def update_dspark(config_dict: dict, pre_trained_config: dict) -> None:
|
||||
"""
|
||||
Apply DSpark specific configuration transformations to the `dict` used to
|
||||
"""Apply DSpark specific configuration transformations to the `dict` used to
|
||||
construct the Transformers PreTrainedConfig.
|
||||
|
||||
DSpark extends DFlash with a Markov logit-bias head, reusing the same
|
||||
|
||||
@@ -47,9 +47,7 @@ class SpeculatorsConfig(PretrainedConfig):
|
||||
def extract_transformers_pre_trained_config(
|
||||
cls, config_dict: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Extract standard Transformers PreTrainedConfig config from speculators config.
|
||||
"""
|
||||
"""Extract the Transformers `PreTrainedConfig` from a speculators config."""
|
||||
speculators_model_type = config_dict.get("speculators_model_type")
|
||||
if speculators_model_type not in SUPPORTED_SPECULATORS_TYPES:
|
||||
raise ValueError(
|
||||
@@ -99,8 +97,7 @@ class SpeculatorsConfig(PretrainedConfig):
|
||||
def build_vllm_speculative_config(
|
||||
cls, config_dict: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Build vLLM-compatible speculative configuration from speculators format.
|
||||
"""Build vLLM-compatible speculative configuration from speculators format.
|
||||
|
||||
This method extracts and transforms speculative configuration from the
|
||||
speculators format into the structure expected by vLLM.
|
||||
@@ -110,6 +107,7 @@ class SpeculatorsConfig(PretrainedConfig):
|
||||
|
||||
Returns:
|
||||
Dictionary with vLLM-compatible speculative configuration
|
||||
|
||||
"""
|
||||
# Extract speculators configuration
|
||||
spec_config = config_dict["speculators_config"]
|
||||
|
||||
@@ -8,8 +8,7 @@ import transformers
|
||||
|
||||
|
||||
class UltravoxConfig(transformers.PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a
|
||||
r"""This is the configuration class to store the configuration of a
|
||||
[`UltravoxForConditionalGeneration`]. It is used to instantiate an
|
||||
Ultravox model according to the specified arguments, defining the model
|
||||
architecture.
|
||||
@@ -41,6 +40,7 @@ class UltravoxConfig(transformers.PretrainedConfig):
|
||||
Whether to apply layer normalization at the middle of the
|
||||
projector or at the end. Versions v0.4.1 and below
|
||||
use `False`, but v0.5 and above use `True`.
|
||||
|
||||
"""
|
||||
|
||||
model_type = "ultravox"
|
||||
|
||||
@@ -29,8 +29,7 @@ def try_get_class_from_dynamic_module(
|
||||
warn_on_fail: bool = True,
|
||||
**kwargs,
|
||||
) -> type | None:
|
||||
"""
|
||||
As `transformers.dynamic_module_utils.get_class_from_dynamic_module`,
|
||||
"""As `transformers.dynamic_module_utils.get_class_from_dynamic_module`,
|
||||
but ignoring any errors.
|
||||
"""
|
||||
try:
|
||||
|
||||
@@ -37,7 +37,8 @@ def _transformers_v4_compatibility_import():
|
||||
subset of `ProcessorChatTemplateKwargs` as defined in Transformers v4.
|
||||
In Transformers v5 these were merged into `ProcessorChatTemplateKwargs` and
|
||||
`ChatTemplateLoadKwargs` was removed. For backward compatibility, we add an alias
|
||||
for `ChatTemplateLoadKwargs` if it doesn't exist."""
|
||||
for `ChatTemplateLoadKwargs` if it doesn't exist.
|
||||
"""
|
||||
old_import = getattr(processing_utils, "ChatTemplateLoadKwargs", None)
|
||||
new_import = getattr(processing_utils, "ProcessorChatTemplateKwargs", None)
|
||||
if old_import is None and new_import is not None:
|
||||
@@ -52,7 +53,8 @@ def _transformers_v4_compatibility_init() -> Any:
|
||||
processor instance before calling the original `ProcessorMixin.__init__`.
|
||||
|
||||
This can be removed if `Molmo2ForConditionalGeneration` is upstreamed to
|
||||
Transformers."""
|
||||
Transformers.
|
||||
"""
|
||||
if hasattr(ProcessorMixin.__init__, "_vllm_patched"):
|
||||
return
|
||||
|
||||
@@ -80,9 +82,7 @@ _V = TypeVar("_V", bound=BaseVideoProcessor, default=BaseVideoProcessor)
|
||||
|
||||
|
||||
class HashableDict(dict):
|
||||
"""
|
||||
A dictionary that can be hashed by lru_cache.
|
||||
"""
|
||||
"""A dictionary that can be hashed by lru_cache."""
|
||||
|
||||
# NOTE: pythonic dict is not hashable,
|
||||
# we override on it directly for simplicity
|
||||
@@ -91,9 +91,7 @@ class HashableDict(dict):
|
||||
|
||||
|
||||
class HashableList(list):
|
||||
"""
|
||||
A list that can be hashed by lru_cache.
|
||||
"""
|
||||
"""A list that can be hashed by lru_cache."""
|
||||
|
||||
def __hash__(self) -> int: # type: ignore[override]
|
||||
return hash(tuple(self))
|
||||
@@ -399,7 +397,8 @@ def get_feature_extractor(
|
||||
**kwargs: Any,
|
||||
):
|
||||
"""Load an audio feature extractor for the given model name
|
||||
via HuggingFace."""
|
||||
via HuggingFace.
|
||||
"""
|
||||
try:
|
||||
processor_name = convert_model_repo_to_path(processor_name)
|
||||
feature_extractor = AutoFeatureExtractor.from_pretrained(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Multi-modal processors may be defined in this directory for the following
|
||||
"""Multi-modal processors may be defined in this directory for the following
|
||||
reasons:
|
||||
|
||||
- There is no processing file defined by HF Hub or Transformers library.
|
||||
|
||||
@@ -18,8 +18,7 @@ class BagelProcessorKwargs(ProcessingKwargs, total=False): # type: ignore[call-
|
||||
|
||||
|
||||
class BagelProcessor(ProcessorMixin):
|
||||
"""
|
||||
Constructs a BAGEL processor which wraps a
|
||||
"""Constructs a BAGEL processor which wraps a
|
||||
SigLIP image processor and a Qwen2 tokenizer.
|
||||
"""
|
||||
|
||||
@@ -36,9 +35,7 @@ class BagelProcessor(ProcessorMixin):
|
||||
images: ImageInput = None,
|
||||
**kwargs: Unpack[BagelProcessorKwargs],
|
||||
):
|
||||
"""
|
||||
Main method to prepare for the model one or several sequences(s) and image(s).
|
||||
"""
|
||||
"""Prepare one or more sequences and images for the model."""
|
||||
output_kwargs = self._merge_kwargs(
|
||||
BagelProcessorKwargs,
|
||||
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
|
||||
@@ -62,15 +59,11 @@ class BagelProcessor(ProcessorMixin):
|
||||
return BatchFeature(data={**pixel_values, **text_inputs})
|
||||
|
||||
def batch_decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to Qwen2TokenizerFast's batch_decode.
|
||||
"""
|
||||
"""Forward all arguments to `Qwen2TokenizerFast.batch_decode`."""
|
||||
return self.tokenizer.batch_decode(*args, **kwargs)
|
||||
|
||||
def decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to Qwen2TokenizerFast's decode.
|
||||
"""
|
||||
"""This method forwards all its arguments to Qwen2TokenizerFast's decode."""
|
||||
return self.tokenizer.decode(*args, **kwargs)
|
||||
|
||||
@property
|
||||
|
||||
@@ -228,7 +228,7 @@ class FilterbankFeatures(nn.Module):
|
||||
return self.fb
|
||||
|
||||
def splice_frames(self, x, frame_splicing):
|
||||
"""Stacks frames together across feature dim
|
||||
"""Stacks frames together across feature dim.
|
||||
|
||||
input is batch_size, feature_dim, num_frames
|
||||
output is batch_size, feature_dim*frame_splicing, num_frames
|
||||
@@ -537,7 +537,8 @@ class CohereASRFeatureExtractor(SequenceFeatureExtractor):
|
||||
|
||||
class CohereASRProcessor(ProcessorMixin):
|
||||
"""HF-compatible processor combining CohereASRFeatureExtractor and a
|
||||
tokenizer."""
|
||||
tokenizer.
|
||||
"""
|
||||
|
||||
feature_extractor_class = "CohereASRFeatureExtractor"
|
||||
tokenizer_class = "AutoTokenizer"
|
||||
|
||||
@@ -70,8 +70,7 @@ class Cosmos3EdgeImageProcessor(Siglip2ImageProcessor):
|
||||
resample: PILImageResampling | InterpolationMode | int | None = None,
|
||||
**kwargs,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Rescales the image so that the following conditions are met:
|
||||
"""Rescales the image so that the following conditions are met:
|
||||
|
||||
1. Both dimensions (height and width) are divisible by 'factor'.
|
||||
2. The total number of pixels is within the range ['min_pixels', 'max_pixels'].
|
||||
@@ -322,6 +321,7 @@ class Cosmos3EdgeProcessor(Qwen3VLProcessor):
|
||||
normalize, and patch video inputs.
|
||||
chat_template: An optional Jinja template used to render chat messages
|
||||
into a tokenizable string.
|
||||
|
||||
"""
|
||||
|
||||
attributes = ["image_processor", "tokenizer", "video_processor"]
|
||||
|
||||
@@ -234,9 +234,7 @@ class DeepseekOCRProcessor(ProcessorMixin):
|
||||
images: list[Image.Image],
|
||||
crop_mode: bool = CROP_MODE,
|
||||
):
|
||||
"""
|
||||
|
||||
Args:
|
||||
"""Args:
|
||||
prompt (str): the formatted prompt;
|
||||
images (List[ImageType]): the list of images;
|
||||
crop_mode (bool): if True, then crop the image;
|
||||
@@ -248,8 +246,8 @@ class DeepseekOCRProcessor(ProcessorMixin):
|
||||
- pixel_values (torch.FloatTensor): [n_patches, 3, H, W]
|
||||
- image_id (int): the id of the image token
|
||||
- num_image_tokens (List[int]): the number of image tokens
|
||||
"""
|
||||
|
||||
"""
|
||||
if prompt is None or images is None:
|
||||
raise ValueError("prompt and images must be used at the same time.")
|
||||
|
||||
@@ -309,7 +307,6 @@ class DeepseekOCRProcessor(ProcessorMixin):
|
||||
cropping: bool = True,
|
||||
):
|
||||
"""Tokenize text with <image> tags."""
|
||||
|
||||
num_image_tags = conversation.count(self.image_token)
|
||||
if num_image_tags != len(images):
|
||||
raise ValueError(
|
||||
|
||||
@@ -186,9 +186,7 @@ class DeepseekVLV2Processor(ProcessorMixin):
|
||||
inference_mode: bool = True,
|
||||
**kwargs: Any,
|
||||
):
|
||||
"""
|
||||
|
||||
Args:
|
||||
"""Args:
|
||||
prompt (str): the formatted prompt;
|
||||
images (list[ImageType]): the list of images;
|
||||
inference_mode (bool): if True, then remove the last eos token;
|
||||
@@ -201,8 +199,8 @@ class DeepseekVLV2Processor(ProcessorMixin):
|
||||
- pixel_values (torch.FloatTensor): [n_patches, 3, H, W]
|
||||
- image_id (int): the id of the image token
|
||||
- num_image_tokens (list[int]): the number of image tokens
|
||||
"""
|
||||
|
||||
"""
|
||||
if prompt is None or images is None:
|
||||
raise ValueError("prompt and images must be used at the same time.")
|
||||
|
||||
@@ -276,9 +274,7 @@ class DeepseekVLV2Processor(ProcessorMixin):
|
||||
inference_mode: bool = True,
|
||||
**kwargs: Any,
|
||||
):
|
||||
"""
|
||||
|
||||
Args:
|
||||
"""Args:
|
||||
text (str): the formatted prompt;
|
||||
images (list[ImageType]): the list of images;
|
||||
inference_mode (bool): if True, then remove the last eos token;
|
||||
@@ -290,8 +286,8 @@ class DeepseekVLV2Processor(ProcessorMixin):
|
||||
- images (torch.FloatTensor): [n_images, 3, H, W]
|
||||
- image_id (int): the id of the image token
|
||||
- num_image_tokens (list[int]): the number of image tokens
|
||||
"""
|
||||
|
||||
"""
|
||||
prepare = self.process_one(
|
||||
prompt=text,
|
||||
images=images,
|
||||
|
||||
@@ -68,8 +68,7 @@ class KaldifeatFbank:
|
||||
|
||||
|
||||
class FireRedASR2FeatureExtractor(SequenceFeatureExtractor):
|
||||
r"""
|
||||
Constructs a FireRedASR2 feature extractor.
|
||||
r"""Constructs a FireRedASR2 feature extractor.
|
||||
|
||||
This feature extractor inherits from [`~feature_extraction_sequence_
|
||||
utils.SequenceFeatureExtractor`] which contains most of the main
|
||||
@@ -99,6 +98,7 @@ class FireRedASR2FeatureExtractor(SequenceFeatureExtractor):
|
||||
Dithering has similar effect as `spectrogram(mel_floor=...)`. It reduces
|
||||
the high log_mel_fbank values for signals with hard-zero sections,
|
||||
when VAD cutoff is present in the signal.
|
||||
|
||||
"""
|
||||
|
||||
model_input_names = ["input_features"]
|
||||
@@ -230,9 +230,8 @@ class FireRedASR2FeatureExtractor(SequenceFeatureExtractor):
|
||||
|
||||
|
||||
class FireRedASR2Processor(ProcessorMixin):
|
||||
r"""
|
||||
Constructs a FireRedASR2 processor which wraps a FireRedASR2 feature extractor and
|
||||
a FireRedASR2 tokenizer into a single processor.
|
||||
r"""Constructs a FireRedASR2 processor which wraps a FireRedASR2 feature extractor
|
||||
and a FireRedASR2 tokenizer into a single processor.
|
||||
|
||||
[`FireRedASR2Processor`] offers all the functionalities of
|
||||
[`FireRedASR2FeatureExtractor`] and [`Qwen2Tokenizer`]. See the
|
||||
@@ -246,6 +245,7 @@ class FireRedASR2Processor(ProcessorMixin):
|
||||
tokenizer (`Qwen2Tokenizer`):
|
||||
An instance of [`Qwen2Tokenizer`]. The tokenizer is a required
|
||||
input.
|
||||
|
||||
"""
|
||||
|
||||
feature_extractor_class = "FireRedASR2FeatureExtractor"
|
||||
@@ -271,8 +271,7 @@ class FireRedASR2Processor(ProcessorMixin):
|
||||
)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
"""
|
||||
Forwards the `audio` argument to FireRedASR2FeatureExtractor's
|
||||
"""Forwards the `audio` argument to FireRedASR2FeatureExtractor's
|
||||
[`~FireRedASR2FeatureExtractor.__call__`] and the `text` argument to
|
||||
[`~Qwen2Tokenizer.__call__`]. Please refer to the docstring of the
|
||||
above two methods for more information.
|
||||
|
||||
@@ -21,10 +21,7 @@ logger = init_logger(__name__)
|
||||
|
||||
|
||||
def apply_cmvn(inputs, cmvn): # noqa
|
||||
"""
|
||||
Apply CMVN with mvn data
|
||||
"""
|
||||
|
||||
"""Apply CMVN with mvn data."""
|
||||
device = inputs.device
|
||||
# dtype = inputs.dtype
|
||||
frame, dim = inputs.shape
|
||||
@@ -219,8 +216,7 @@ class WavFrontend(nn.Module):
|
||||
|
||||
|
||||
class FunASRFeatureExtractor(SequenceFeatureExtractor):
|
||||
r"""
|
||||
Constructs a FunASR feature extractor.
|
||||
r"""Constructs a FunASR feature extractor.
|
||||
|
||||
This feature extractor inherits from [`~feature_extraction_sequence_
|
||||
utils.SequenceFeatureExtractor`] which contains most of the main
|
||||
@@ -255,6 +251,7 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
|
||||
Dithering has similar effect as `spectrogram(mel_floor=...)`. It reduces
|
||||
the high log_mel_fbank values for signals with hard-zero sections,
|
||||
when VAD cutoff is present in the signal.
|
||||
|
||||
"""
|
||||
|
||||
model_input_names = ["input_features"]
|
||||
@@ -369,8 +366,7 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
|
||||
|
||||
|
||||
class FunASRProcessor(ProcessorMixin):
|
||||
r"""
|
||||
Constructs a FunASR processor which wraps a FunASR feature extractor and
|
||||
r"""Constructs a FunASR processor which wraps a FunASR feature extractor and
|
||||
a FunASR tokenizer into a single processor.
|
||||
|
||||
[`FunASRProcessor`] offers all the functionalities of
|
||||
@@ -385,6 +381,7 @@ class FunASRProcessor(ProcessorMixin):
|
||||
tokenizer (`Qwen2Tokenizer`):
|
||||
An instance of [`Qwen2Tokenizer`]. The tokenizer is a required
|
||||
input.
|
||||
|
||||
"""
|
||||
|
||||
feature_extractor_class = "FunASRFeatureExtractor"
|
||||
@@ -410,8 +407,7 @@ class FunASRProcessor(ProcessorMixin):
|
||||
)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
"""
|
||||
Forwards the `audio` argument to FunASRFeatureExtractor's
|
||||
"""Forwards the `audio` argument to FunASRFeatureExtractor's
|
||||
[`~FunASRFeatureExtractor.__call__`] and the `text` argument to
|
||||
[`~Qwen2Tokenizer.__call__`]. Please refer to the docstring of the
|
||||
above two methods for more information.
|
||||
|
||||
@@ -10,8 +10,7 @@ from transformers.processing_utils import ProcessorMixin
|
||||
|
||||
|
||||
class GLM4VImageProcessorFast(BaseImageProcessorFast):
|
||||
"""
|
||||
Port of https://huggingface.co/zai-org/glm-4v-9b/blob/main/tokenization_chatglm.py#L177
|
||||
"""Port of https://huggingface.co/zai-org/glm-4v-9b/blob/main/tokenization_chatglm.py#L177
|
||||
to HF Transformers.
|
||||
"""
|
||||
|
||||
|
||||
@@ -261,7 +261,8 @@ def _resize_or_pad(
|
||||
allow_upscale: bool = False,
|
||||
) -> torch.Tensor:
|
||||
"""Resize onto the aligned canvas, or keep the aspect ratio and
|
||||
zero-pad the right/bottom sides (``resize_mode="pad"``)."""
|
||||
zero-pad the right/bottom sides (``resize_mode="pad"``).
|
||||
"""
|
||||
height, width = stacked_images.shape[-2:]
|
||||
|
||||
if resize_mode == "resize":
|
||||
@@ -307,7 +308,8 @@ def _pixel_budget(
|
||||
) -> tuple[int, int]:
|
||||
"""(min_pixels, max_pixels) from the token bounds of
|
||||
``processor_config.json``; one vision token covers
|
||||
``temporal_patch_size * (patch_size * merge_size) ** 2`` pixels."""
|
||||
``temporal_patch_size * (patch_size * merge_size) ** 2`` pixels.
|
||||
"""
|
||||
if min_image_tokens is None or max_image_tokens is None:
|
||||
raise ValueError(
|
||||
"min_image_tokens and max_image_tokens must be provided by "
|
||||
|
||||
@@ -358,8 +358,7 @@ class InternVLVideoProcessor(BaseVideoProcessor):
|
||||
|
||||
|
||||
class InternVLProcessor(ProcessorMixin):
|
||||
"""
|
||||
This model doesn't define its own HF processor,
|
||||
"""This model doesn't define its own HF processor,
|
||||
so we implement our own one here.
|
||||
|
||||
The code to insert image tokens is based on:
|
||||
|
||||
@@ -91,6 +91,7 @@ def get_image_size_for_max_num_patches(
|
||||
`tuple[int, int]`: Height and width (in pixels) that are multiples of
|
||||
`patch_size * pixel_shuffle_scale` and respect both the maximum and
|
||||
optional minimum patch-count constraints.
|
||||
|
||||
"""
|
||||
|
||||
def get_scaled_image_size(scale, original_size, patch_size, pixel_shuffle_scale):
|
||||
@@ -177,9 +178,11 @@ def prepare_image_tensor(
|
||||
The tensor is converted to floating point if needed.
|
||||
scale (`float`, *optional*, defaults to `VISION_SCALE`):
|
||||
Scalar multiplier applied before normalization.
|
||||
|
||||
Returns:
|
||||
`torch.Tensor`: Normalized tensor with the same shape as the input and
|
||||
dtype `torch.float32`.
|
||||
|
||||
"""
|
||||
if not torch.is_floating_point(image):
|
||||
image = image.float()
|
||||
@@ -209,6 +212,7 @@ def patchify_vision(image: torch.Tensor, patch_size: int) -> torch.Tensor:
|
||||
|
||||
Raises:
|
||||
ValueError: If `height` or `width` is not divisible by `patch_size`.
|
||||
|
||||
"""
|
||||
num_images, height, width, channels = image.shape
|
||||
if height % patch_size or width % patch_size:
|
||||
@@ -265,6 +269,7 @@ def process_vision_for_patches(
|
||||
/ patch_size, channels * patch_size**2)` and `dims_virtual` encodes
|
||||
effective `(images, height, width)` dimensions after optional pixel
|
||||
shuffling.
|
||||
|
||||
"""
|
||||
# Add batch dim if single image
|
||||
if images.dim() == 3:
|
||||
|
||||
@@ -28,8 +28,7 @@ class KimiK25Processor(ProcessorMixin):
|
||||
return_tensors: str | TensorType | None = None,
|
||||
**kwargs,
|
||||
) -> BatchFeature:
|
||||
"""
|
||||
Args:
|
||||
"""Args:
|
||||
text: The text to be field to the model.
|
||||
vision_chunks: List of `VisionChunk` items to be processed.
|
||||
For image: `VisionChunkImage` with
|
||||
@@ -44,6 +43,7 @@ class KimiK25Processor(ProcessorMixin):
|
||||
Returned when `vision_chunks` is not `None`.
|
||||
- **grid_thws** -- list of image 3D grid in LLM.
|
||||
Returned when `vision_chunks` is not `None`.
|
||||
|
||||
"""
|
||||
if vision_chunks is not None:
|
||||
mm_inputs = self.image_processor.preprocess(
|
||||
|
||||
@@ -1071,6 +1071,8 @@ class MiMoOmniProcessor(ProcessorMixin):
|
||||
tuples (pre-decoded).
|
||||
audio: list of ``str`` (path/url/base64), ``bytes``,
|
||||
``(waveform_1D, sample_rate)`` tuples, or ``np.ndarray``.
|
||||
video_audio: audio track extracted from ``videos``, in the same
|
||||
formats accepted by ``audio``.
|
||||
return_tensors: Passed to :class:`BatchFeature`.
|
||||
|
||||
Returns:
|
||||
@@ -1079,6 +1081,7 @@ class MiMoOmniProcessor(ProcessorMixin):
|
||||
- ``pixel_values`` + ``image_grid_thw``
|
||||
- ``pixel_values_videos`` + ``video_grid_thw`` + ``second_per_grid_ts``
|
||||
- ``audio_features``
|
||||
|
||||
"""
|
||||
if isinstance(text, list):
|
||||
text = text[0] if len(text) == 1 else "\n".join(text)
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
# 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.
|
||||
"""
|
||||
Processor class for MiniCPMO.
|
||||
"""
|
||||
"""Processor class for MiniCPMO."""
|
||||
|
||||
import math
|
||||
from typing import Literal, TypeAlias
|
||||
@@ -35,8 +33,7 @@ MiniCPMOBatchFeature: TypeAlias = BatchFeature
|
||||
|
||||
|
||||
class MiniCPMOProcessor(ProcessorMixin):
|
||||
r"""
|
||||
Constructs a MiniCPMV processor which wraps a MiniCPMV image
|
||||
r"""Constructs a MiniCPMV processor which wraps a MiniCPMV image
|
||||
processor and a MiniCPMV tokenizer into a single processor.
|
||||
|
||||
[`MiniCPMVProcessor`] offers all the functionalities of
|
||||
@@ -49,6 +46,7 @@ class MiniCPMOProcessor(ProcessorMixin):
|
||||
The image processor is a required input.
|
||||
tokenizer ([`LlamaTokenizerWrapper`], *optional*):
|
||||
The tokenizer is a required input.
|
||||
|
||||
"""
|
||||
|
||||
attributes = ["image_processor", "feature_extractor", "tokenizer"]
|
||||
@@ -253,8 +251,7 @@ class MiniCPMOProcessor(ProcessorMixin):
|
||||
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode
|
||||
# with CLIP->Llama
|
||||
def batch_decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to LlamaTokenizerFast's
|
||||
"""This method forwards all its arguments to LlamaTokenizerFast's
|
||||
[`~PythonBackend.batch_decode`]. Please refer to the
|
||||
docstring of this method for more information.
|
||||
"""
|
||||
@@ -274,8 +271,7 @@ class MiniCPMOProcessor(ProcessorMixin):
|
||||
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.decode
|
||||
# with CLIP->Llama
|
||||
def decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to LlamaTokenizerFast's
|
||||
"""This method forwards all its arguments to LlamaTokenizerFast's
|
||||
[`~PythonBackend.decode`]. Please refer to the docstring
|
||||
of this method for more information.
|
||||
"""
|
||||
@@ -551,15 +547,11 @@ class MelSpectrogramFeatures(torch.nn.Module):
|
||||
)
|
||||
|
||||
def __call__(self, audio: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
audio: Tensor([num_channels, num_samples])
|
||||
"""
|
||||
"""audio: Tensor([num_channels, num_samples])."""
|
||||
return super().__call__(audio)
|
||||
|
||||
def forward(self, audio: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
audio: Tensor([num_channels, num_samples])
|
||||
"""
|
||||
"""audio: Tensor([num_channels, num_samples])."""
|
||||
mel: torch.Tensor = self.mel_spec(audio)
|
||||
features = torch.log(torch.clip(mel, min=1e-5))
|
||||
return features
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
# 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.
|
||||
"""
|
||||
Processor class for MiniCPMV.
|
||||
"""
|
||||
"""Processor class for MiniCPMV."""
|
||||
|
||||
from typing import TypeAlias
|
||||
|
||||
@@ -36,8 +34,7 @@ MiniCPMVBatchFeature: TypeAlias = BatchFeature
|
||||
|
||||
|
||||
class MiniCPMVProcessor(ProcessorMixin):
|
||||
r"""
|
||||
Constructs a MiniCPMV processor which wraps a MiniCPMV image
|
||||
r"""Constructs a MiniCPMV processor which wraps a MiniCPMV image
|
||||
processor and a MiniCPMV tokenizer into a single processor.
|
||||
|
||||
[`MiniCPMVProcessor`] offers all the functionalities of
|
||||
@@ -50,6 +47,7 @@ class MiniCPMVProcessor(ProcessorMixin):
|
||||
The image processor is a required input.
|
||||
tokenizer ([`LlamaTokenizerWrapper`], *optional*):
|
||||
The tokenizer is a required input.
|
||||
|
||||
"""
|
||||
|
||||
attributes = ["image_processor", "tokenizer"]
|
||||
@@ -93,8 +91,7 @@ class MiniCPMVProcessor(ProcessorMixin):
|
||||
# Copied from transformers.models.clip.processing_clip.CLIPProcessor
|
||||
# .batch_decode with CLIP->Llama
|
||||
def batch_decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to LlamaTokenizerFast's
|
||||
"""This method forwards all its arguments to LlamaTokenizerFast's
|
||||
[`~PythonBackend.batch_decode`]. Please refer to the
|
||||
docstring of this method for more information.
|
||||
"""
|
||||
@@ -126,8 +123,7 @@ class MiniCPMVProcessor(ProcessorMixin):
|
||||
# Copied from transformers.models.clip.processing_clip.CLIPProcessor
|
||||
# .decode with CLIP->Llama
|
||||
def decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to LlamaTokenizerFast's
|
||||
"""This method forwards all its arguments to LlamaTokenizerFast's
|
||||
[`~PythonBackend.decode`]. Please refer to the docstring
|
||||
of this method for more information.
|
||||
"""
|
||||
|
||||
@@ -67,8 +67,7 @@ def select_tiling(
|
||||
|
||||
|
||||
class Moondream3Processor(ProcessorMixin):
|
||||
"""
|
||||
Constructs a Moondream3 processor which handles image preprocessing
|
||||
"""Constructs a Moondream3 processor which handles image preprocessing
|
||||
and tokenization for the Moondream3 multimodal model.
|
||||
|
||||
Args:
|
||||
@@ -78,6 +77,7 @@ class Moondream3Processor(ProcessorMixin):
|
||||
max_crops: Maximum number of crops per image.
|
||||
overlap_margin: Margin for overlapping crops in patches.
|
||||
patch_size: Size of each patch.
|
||||
|
||||
"""
|
||||
|
||||
attributes = ["tokenizer"]
|
||||
@@ -189,8 +189,7 @@ class Moondream3Processor(ProcessorMixin):
|
||||
pretrained_model_name_or_path,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Load the processor, using a separate tokenizer repo.
|
||||
"""Load the processor, using a separate tokenizer repo.
|
||||
|
||||
The moondream3 model uses a custom tokenizer from 'moondream/starmie-v1'
|
||||
instead of having tokenizer files in the model repo.
|
||||
@@ -294,8 +293,7 @@ class Moondream3Processor(ProcessorMixin):
|
||||
| list[PreTokenizedInput] = None,
|
||||
**kwargs: Unpack[Moondream3ProcessorKwargs],
|
||||
) -> BatchFeature:
|
||||
"""
|
||||
Process images and text for Moondream3 model.
|
||||
"""Process images and text for Moondream3 model.
|
||||
|
||||
Args:
|
||||
images: Input images (PIL Image, numpy array, or list thereof).
|
||||
@@ -304,6 +302,7 @@ class Moondream3Processor(ProcessorMixin):
|
||||
|
||||
Returns:
|
||||
BatchFeature with processed inputs.
|
||||
|
||||
"""
|
||||
output_kwargs = self._merge_kwargs(
|
||||
Moondream3ProcessorKwargs,
|
||||
@@ -428,8 +427,7 @@ class Moondream3Processor(ProcessorMixin):
|
||||
convert_to_rgb: bool = True,
|
||||
return_tensors: str = "pt",
|
||||
) -> tuple[torch.Tensor, tuple[int, int]]:
|
||||
"""
|
||||
Preprocess an image using overlap-and-resize cropping strategy.
|
||||
"""Preprocess an image using overlap-and-resize cropping strategy.
|
||||
|
||||
Args:
|
||||
image: Input PIL image, numpy array, or torch tensor.
|
||||
@@ -442,6 +440,7 @@ class Moondream3Processor(ProcessorMixin):
|
||||
|
||||
Returns:
|
||||
Tuple of (pixel_values tensor, tiling tuple).
|
||||
|
||||
"""
|
||||
image = self._to_pil_image(image)
|
||||
if convert_to_rgb:
|
||||
|
||||
@@ -292,8 +292,7 @@ class DynamicResolutionImageTiler:
|
||||
self,
|
||||
target_num_tokens_post_shuffle: int,
|
||||
) -> tuple[int, int]:
|
||||
"""
|
||||
TODO: optimize this so it squeezes closer to target number of tokens.
|
||||
"""TODO: optimize this so it squeezes closer to target number of tokens.
|
||||
Calculate image dimensions that produce approximately `target` tokens after
|
||||
pixel_shuffle.
|
||||
|
||||
@@ -318,6 +317,7 @@ class DynamicResolutionImageTiler:
|
||||
... height // PATCH_SIZE
|
||||
... ) // 2**2 == 8100 # tokens post-shuffle
|
||||
>>> assert tiler._get_num_embeddings(width=width, height=height) == 8100
|
||||
|
||||
"""
|
||||
side_pixels = (
|
||||
math.isqrt(target_num_tokens_post_shuffle)
|
||||
@@ -386,6 +386,7 @@ class DynamicResolutionImageTiler:
|
||||
num_tokens_available: Number of tokens available for this media
|
||||
Returns:
|
||||
DynamicResolutionParams for the media
|
||||
|
||||
"""
|
||||
current_num_tokens_available = num_tokens_available
|
||||
assert isinstance(media, Image.Image), (
|
||||
@@ -473,6 +474,7 @@ class DynamicResolutionImageTiler:
|
||||
num_tokens_available: Total number of tokens available across all media
|
||||
Returns:
|
||||
List of ImageTilingParams for each media item
|
||||
|
||||
"""
|
||||
num_tokens_available = (
|
||||
num_tokens_available
|
||||
@@ -571,8 +573,7 @@ class DynamicResolutionImageTiler:
|
||||
|
||||
|
||||
class BaseNanoNemotronVLProcessor(ABC):
|
||||
"""
|
||||
This model doesn't define its own HF processor,
|
||||
"""This model doesn't define its own HF processor,
|
||||
so we implement our own one here.
|
||||
|
||||
The code to insert image tokens is based on:
|
||||
@@ -761,8 +762,7 @@ class BaseNanoNemotronVLProcessor(ABC):
|
||||
|
||||
|
||||
class NanoNemotronVLProcessor(BaseNanoNemotronVLProcessor):
|
||||
"""
|
||||
HF Processor with extended video processing logic.
|
||||
"""HF Processor with extended video processing logic.
|
||||
Code for video processing is adapted from video example:
|
||||
https://huggingface.co/OpenGVLab/InternVL3-1B#inference-with-transformers
|
||||
"""
|
||||
@@ -1125,8 +1125,7 @@ class NanoNemotronVLProcessor(BaseNanoNemotronVLProcessor):
|
||||
img_context_token_ids: list[int],
|
||||
video_temporal_patch_size: int = 1,
|
||||
) -> PromptUpdateDetails:
|
||||
"""
|
||||
Build prompt replacement for a video.
|
||||
"""Build prompt replacement for a video.
|
||||
The replacement returned is not actually used to replace the placeholder
|
||||
tokens - it's just used to make sure we allocate the correct number
|
||||
of tokens.
|
||||
|
||||
@@ -191,8 +191,7 @@ class LlamaNemotronNanoVLImageProcessor(InternVLImageProcessor):
|
||||
|
||||
|
||||
class LlamaNemotronNanoVLProcessor(InternVLProcessor):
|
||||
"""
|
||||
This model doesn't define its own HF processor,
|
||||
"""This model doesn't define its own HF processor,
|
||||
so we implement our own one here.
|
||||
|
||||
The image processor is given by:
|
||||
@@ -287,8 +286,7 @@ class LlamaNemotronVLEmbedImageProcessor(InternVLImageProcessor):
|
||||
|
||||
|
||||
class LlamaNemotronVLEmbedProcessor(InternVLProcessor):
|
||||
"""
|
||||
Processor for LlamaNemotronVL embedding model.
|
||||
"""Processor for LlamaNemotronVL embedding model.
|
||||
|
||||
Inherits from NemotronVLProcessor and specializes it for embedding tasks:
|
||||
- Uses SigLIP transform with normalization instead of base transform
|
||||
|
||||
@@ -50,10 +50,10 @@ class OvisProcessorKwargs(ProcessingKwargs, total=False): # type: ignore[call-a
|
||||
|
||||
|
||||
class OvisProcessor(ProcessorMixin):
|
||||
r"""
|
||||
Constructs an Ovis processor which wraps an Ovis image processor and a Qwen2 tokenizer into a single processor.
|
||||
r"""Constructs an Ovis processor which wraps an Ovis image processor and a Qwen2 tokenizer into a single processor.
|
||||
[`OvisProcessor`] offers all the functionalities of [`Qwen2VLImageProcessor`] and [`Qwen2TokenizerFast`]. See the
|
||||
[`~OvisProcessor.__call__`] and [`~OvisProcessor.decode`] for more information.
|
||||
|
||||
Args:
|
||||
image_processor ([`Qwen2VLImageProcessor`], *optional*):
|
||||
The image processor is a required input.
|
||||
@@ -61,6 +61,7 @@ class OvisProcessor(ProcessorMixin):
|
||||
The tokenizer is a required input.
|
||||
chat_template (`str`, *optional*): A Jinja template which will be used to convert lists of messages
|
||||
in a chat into a tokenizable string.
|
||||
|
||||
"""
|
||||
|
||||
attributes = ["image_processor", "tokenizer"]
|
||||
@@ -107,12 +108,12 @@ class OvisProcessor(ProcessorMixin):
|
||||
| list[PreTokenizedInput] = None,
|
||||
**kwargs: Unpack[OvisProcessorKwargs],
|
||||
) -> BatchFeature:
|
||||
"""
|
||||
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
|
||||
"""Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
|
||||
and `kwargs` arguments to Qwen2TokenizerFast's [`~Qwen2TokenizerFast.__call__`] if `text` is not `None` to encode
|
||||
the text. To prepare the vision inputs, this method forwards the `vision_infos` and `kwrags` arguments to
|
||||
Qwen2VLImageProcessor's [`~Qwen2VLImageProcessor.__call__`] if `vision_infos` is not `None`.
|
||||
Args:
|
||||
|
||||
Args:
|
||||
images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `list[PIL.Image.Image]`, `list[np.ndarray]`, `list[torch.Tensor]`):
|
||||
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
|
||||
tensor. Both channels-first and channels-last formats are supported.
|
||||
@@ -129,7 +130,8 @@ class OvisProcessor(ProcessorMixin):
|
||||
- `'pt'`: Return PyTorch `torch.Tensor` objects.
|
||||
- `'np'`: Return NumPy `np.ndarray` objects.
|
||||
- `'jax'`: Return JAX `jnp.ndarray` objects.
|
||||
Returns:
|
||||
|
||||
Returns:
|
||||
[`BatchFeature`]: A [`BatchFeature`] with the following fields:
|
||||
- **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
|
||||
- **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
|
||||
@@ -140,8 +142,8 @@ class OvisProcessor(ProcessorMixin):
|
||||
- **image_grid_thw** -- List of image 3D grid in LLM. Returned when `images` is not `None`.
|
||||
- **video_grid_thw** -- List of video 3D grid in LLM. Returned when `videos` is not `None`.
|
||||
- **second_per_grid_ts** -- List of video seconds per time grid. Returned when `videos` is not `None`.
|
||||
"""
|
||||
|
||||
"""
|
||||
max_partition = kwargs.pop("max_partition", 9)
|
||||
covering_threshold = kwargs.pop("covering_threshold", 0.9)
|
||||
|
||||
@@ -416,28 +418,28 @@ class OvisProcessor(ProcessorMixin):
|
||||
return torch.tensor(pixel_values), image_placeholders, torch.tensor(grid)
|
||||
|
||||
def batch_decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to Qwen2TokenizerFast's [`~PythonBackend.batch_decode`]. Please
|
||||
"""This method forwards all its arguments to Qwen2TokenizerFast's [`~PythonBackend.batch_decode`]. Please
|
||||
refer to the docstring of this method for more information.
|
||||
"""
|
||||
return self.tokenizer.batch_decode(*args, **kwargs)
|
||||
|
||||
def decode(self, *args, **kwargs):
|
||||
"""
|
||||
This method forwards all its arguments to Qwen2TokenizerFast's [`~PythonBackend.decode`]. Please refer to
|
||||
"""This method forwards all its arguments to Qwen2TokenizerFast's [`~PythonBackend.decode`]. Please refer to
|
||||
the docstring of this method for more information.
|
||||
"""
|
||||
return self.tokenizer.decode(*args, **kwargs)
|
||||
|
||||
def post_process_image_text_to_text(self, generated_outputs):
|
||||
"""
|
||||
Post-process the output of the model to decode the text.
|
||||
"""Post-process the output of the model to decode the text.
|
||||
|
||||
Args:
|
||||
generated_outputs (`torch.Tensor` or `np.ndarray`):
|
||||
The output of the model `generate` function. The output is expected to be a tensor of shape `(batch_size, sequence_length)`
|
||||
or `(sequence_length,)`.
|
||||
|
||||
Returns:
|
||||
`list[str]`: The decoded text.
|
||||
|
||||
"""
|
||||
return self.tokenizer.batch_decode(
|
||||
generated_outputs,
|
||||
|
||||
@@ -33,13 +33,13 @@ class Ovis2_5ProcessorKwargs(ProcessingKwargs, total=False): # type: ignore[cal
|
||||
|
||||
|
||||
class Ovis2_5Processor(ProcessorMixin):
|
||||
r"""
|
||||
Constructs an Ovis processor which wraps an Ovis image processor
|
||||
r"""Constructs an Ovis processor which wraps an Ovis image processor
|
||||
and a Qwen2 tokenizer into a single processor.
|
||||
[`OvisProcessor`] offers all the functionalities of
|
||||
[`Qwen2VLImageProcessor`] and [`Qwen2TokenizerFast`].
|
||||
See the [`~OvisProcessor.__call__`] and [`~OvisProcessor.decode`]
|
||||
for more information.
|
||||
|
||||
Args:
|
||||
image_processor ([`Qwen2VLImageProcessor`], *optional*):
|
||||
The image processor is a required input.
|
||||
@@ -48,6 +48,7 @@ class Ovis2_5Processor(ProcessorMixin):
|
||||
chat_template (`str`, *optional*): A Jinja template which will
|
||||
be used to convert lists of messages in a chat into
|
||||
a tokenizable string.
|
||||
|
||||
"""
|
||||
|
||||
attributes = ["image_processor", "tokenizer"]
|
||||
@@ -110,43 +111,39 @@ class Ovis2_5Processor(ProcessorMixin):
|
||||
| list[PreTokenizedInput] = None,
|
||||
**kwargs: Unpack[Ovis2_5ProcessorKwargs],
|
||||
) -> BatchFeature:
|
||||
"""
|
||||
Main method to prepare for the model one or several sequences(s)
|
||||
"""Main method to prepare for the model one or several sequences(s)
|
||||
and image(s). This method forwards the `text`and `kwargs` arguments
|
||||
to Qwen2TokenizerFast's [`~Qwen2TokenizerFast.__call__`] if `text`
|
||||
is not `None` to encode the text. To prepare the vision inputs,
|
||||
this method forwards the `vision_infos` and `kwrags` arguments to
|
||||
Qwen2VLImageProcessor's [`~Qwen2VLImageProcessor.__call__`]
|
||||
if `vision_infos` is not `None`.
|
||||
Args:
|
||||
images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`,
|
||||
`list[PIL.Image.Image]`, `list[np.ndarray]`,
|
||||
`list[torch.Tensor]`):
|
||||
The image or batch of images to be prepared.
|
||||
Each image can be a PIL image, NumPy array or PyTorch
|
||||
tensor. Both channels-first and channels-last formats
|
||||
are supported.
|
||||
text (`str`, `list[str]`, `list[list[str]]`):
|
||||
The sequence or batch of sequences to be encoded.
|
||||
Each sequence can be a string or a list of strings
|
||||
(pretokenized string). If the sequences are provided as
|
||||
list of strings (pretokenized), you must set
|
||||
`is_split_into_words=True` (to lift the ambiguity with
|
||||
a batch of sequences).
|
||||
videos (`np.ndarray`, `torch.Tensor`, `list[np.ndarray]`,
|
||||
`list[torch.Tensor]`):
|
||||
The image or batch of videos to be prepared. Each video
|
||||
can be a 4D NumPy array or PyTorch tensor, or a nested
|
||||
list of 3D frames. Both channels-first and channels-last
|
||||
formats are supported.
|
||||
return_tensors (`str` or [`~utils.TensorType`], *optional*):
|
||||
If set, will return tensors of a particular framework.
|
||||
Acceptable values are:
|
||||
- `'tf'`: Return TensorFlow `tf.constant` objects.
|
||||
- `'pt'`: Return PyTorch `torch.Tensor` objects.
|
||||
- `'np'`: Return NumPy `np.ndarray` objects.
|
||||
- `'jax'`: Return JAX `jnp.ndarray` objects.
|
||||
Returns:
|
||||
|
||||
Args:
|
||||
images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, or a list):
|
||||
The image or batch of images to be prepared. Each image can
|
||||
be a PIL image, NumPy array or PyTorch tensor. Both
|
||||
channels-first and channels-last formats are supported.
|
||||
videos (`np.ndarray`, `torch.Tensor`, or a list of either):
|
||||
The video or batch of videos to be prepared. Each video can
|
||||
be a 4D NumPy array or PyTorch tensor, or a nested list of
|
||||
3D frames. Both channels-first and channels-last formats are
|
||||
supported.
|
||||
text (`str`, `list[str]`, `list[list[str]]`):
|
||||
The sequence or batch of sequences to be encoded. Each
|
||||
sequence can be a string or a list of strings (pretokenized
|
||||
string). If the sequences are provided as list of strings
|
||||
(pretokenized), you must set `is_split_into_words=True` (to
|
||||
lift the ambiguity with a batch of sequences).
|
||||
return_tensors (`str` or [`~utils.TensorType`], *optional*):
|
||||
If set, will return tensors of a particular framework.
|
||||
Acceptable values are:
|
||||
- `'tf'`: Return TensorFlow `tf.constant` objects.
|
||||
- `'pt'`: Return PyTorch `torch.Tensor` objects.
|
||||
- `'np'`: Return NumPy `np.ndarray` objects.
|
||||
- `'jax'`: Return JAX `jnp.ndarray` objects.
|
||||
|
||||
Returns:
|
||||
[`BatchFeature`]: A [`BatchFeature`] with the following fields:
|
||||
- **input_ids** -- list of token ids to be fed to a model.
|
||||
Returned when `text` is not `None`.
|
||||
@@ -164,6 +161,7 @@ class Ovis2_5Processor(ProcessorMixin):
|
||||
when `videos` is not `None`.
|
||||
- **second_per_grid_ts** -- list of video seconds per time grid.
|
||||
Returned when `videos` is not `None`.
|
||||
|
||||
"""
|
||||
output_kwargs = self._merge_kwargs(
|
||||
Ovis2_5ProcessorKwargs,
|
||||
|
||||
@@ -11,8 +11,7 @@ from vllm.tokenizers.mistral import MistralTokenizer
|
||||
|
||||
|
||||
class MistralCommonImageProcessor(ImageProcessingMixin):
|
||||
"""
|
||||
Provide a HF-compatible interface for
|
||||
"""Provide a HF-compatible interface for
|
||||
`mistral_common.tokens.tokenizers.multimodal.ImageEncoder`.
|
||||
"""
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ from vllm.tokenizers.mistral import MistralTokenizer
|
||||
|
||||
|
||||
class MistralCommonFeatureExtractor(SequenceFeatureExtractor):
|
||||
"""
|
||||
Provide a HF-compatible interface for
|
||||
"""Provide a HF-compatible interface for
|
||||
`mistral_common.tokens.tokenizers.multimodal.AudioEncoder`.
|
||||
"""
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ def resolve_revision(
|
||||
Returns:
|
||||
The resolved revision, or `revision` unchanged if it cannot be resolved
|
||||
(local path, ModelScope, or any Hub error).
|
||||
|
||||
"""
|
||||
if Path(repo_id).exists() or envs.VLLM_USE_MODELSCOPE:
|
||||
return revision
|
||||
@@ -106,6 +107,7 @@ def with_retry(
|
||||
retry_delay: Seconds to wait after the first failure, doubled each time.
|
||||
fatal_errors: Exceptions that are a definitive answer rather than a
|
||||
transient failure. These are raised immediately, without logging.
|
||||
|
||||
"""
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
@@ -353,8 +355,7 @@ def get_hf_file_bytes(
|
||||
def try_get_local_file(
|
||||
model: str | Path, file_name: str, revision: str | None = "main"
|
||||
) -> Path | Any | None:
|
||||
"""
|
||||
Try to get a local file from the HuggingFace repository.
|
||||
"""Try to get a local file from the HuggingFace repository.
|
||||
|
||||
The possible return values are:
|
||||
|
||||
@@ -385,20 +386,19 @@ def try_get_local_file(
|
||||
def get_hf_file_to_dict(
|
||||
file_name: str, model: str | Path, revision: str | None = "main"
|
||||
):
|
||||
"""
|
||||
Downloads a file from the Hugging Face Hub and returns
|
||||
"""Downloads a file from the Hugging Face Hub and returns
|
||||
its contents as a dictionary.
|
||||
|
||||
Parameters:
|
||||
- file_name (str): The name of the file to download.
|
||||
- model (str): The name of the model on the Hugging Face Hub.
|
||||
- revision (str): The specific version of the model.
|
||||
Args:
|
||||
file_name (str): The name of the file to download.
|
||||
model (str): The name of the model on the Hugging Face Hub.
|
||||
revision (str): The specific version of the model.
|
||||
|
||||
Returns:
|
||||
- config_dict (dict): A dictionary containing
|
||||
the contents of the downloaded file.
|
||||
"""
|
||||
|
||||
"""
|
||||
file_path = try_get_local_file(model=model, file_name=file_name, revision=revision)
|
||||
|
||||
if file_path is None:
|
||||
|
||||
@@ -25,14 +25,14 @@ except ImportError:
|
||||
|
||||
|
||||
def list_safetensors(path: str = "") -> list[str]:
|
||||
"""
|
||||
List full file names from object path and filter by allow pattern.
|
||||
"""List full file names from object path and filter by allow pattern.
|
||||
|
||||
Args:
|
||||
path: The object storage path to list from.
|
||||
|
||||
Returns:
|
||||
list[str]: List of full object storage paths allowed by the pattern
|
||||
|
||||
"""
|
||||
return runai_list_safetensors(path)
|
||||
|
||||
@@ -42,8 +42,7 @@ def is_runai_obj_uri(model_or_path: str) -> bool:
|
||||
|
||||
|
||||
class ObjectStorageModel:
|
||||
"""
|
||||
A class representing an ObjectStorage model mirrored into a
|
||||
"""A class representing an ObjectStorage model mirrored into a
|
||||
temporary directory.
|
||||
|
||||
Attributes:
|
||||
@@ -51,6 +50,7 @@ class ObjectStorageModel:
|
||||
|
||||
Methods:
|
||||
pull_files(): Pull model from object storage to the temporary directory.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, url: str) -> None:
|
||||
@@ -86,8 +86,7 @@ class ObjectStorageModel:
|
||||
allow_pattern: list[str] | None = None,
|
||||
ignore_pattern: list[str] | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Pull files from object storage into the temporary directory.
|
||||
"""Pull files from object storage into the temporary directory.
|
||||
|
||||
Args:
|
||||
model_path: The object storage path of the model.
|
||||
|
||||
@@ -36,8 +36,7 @@ def glob(
|
||||
path: str = "",
|
||||
allow_pattern: list[str] | None = None,
|
||||
) -> list[str]:
|
||||
"""
|
||||
List full file names from S3 path and filter by allow pattern.
|
||||
"""List full file names from S3 path and filter by allow pattern.
|
||||
|
||||
Args:
|
||||
s3: S3 client to use.
|
||||
@@ -46,6 +45,7 @@ def glob(
|
||||
|
||||
Returns:
|
||||
list[str]: List of full S3 paths allowed by the pattern
|
||||
|
||||
"""
|
||||
if s3 is None:
|
||||
s3 = boto3.client("s3")
|
||||
@@ -61,8 +61,7 @@ def list_files(
|
||||
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.
|
||||
"""List files from S3 path and filter by pattern.
|
||||
|
||||
Args:
|
||||
s3: S3 client to use.
|
||||
@@ -77,6 +76,7 @@ def list_files(
|
||||
and the prefix as a dir like string
|
||||
- The third element is a list of files allowed or
|
||||
disallowed by pattern
|
||||
|
||||
"""
|
||||
parts = path.removeprefix("s3://").split("/")
|
||||
prefix = "/".join(parts[1:])
|
||||
|
||||
@@ -80,16 +80,15 @@ def _maybe_space_split_dict(path: str | PathLike) -> dict[str, str]:
|
||||
|
||||
@cache
|
||||
def maybe_model_redirect(model: str) -> str:
|
||||
"""
|
||||
Use model_redirect to redirect the model name to a local folder.
|
||||
"""Use model_redirect to redirect the model name to a local folder.
|
||||
|
||||
Args:
|
||||
model: hf model name
|
||||
|
||||
Returns:
|
||||
maybe redirect to a local folder
|
||||
"""
|
||||
|
||||
"""
|
||||
model_redirect_path = envs.VLLM_MODEL_REDIRECT_PATH
|
||||
|
||||
if not model_redirect_path:
|
||||
@@ -117,7 +116,8 @@ def parse_safetensors_file_metadata(path: str | PathLike) -> dict[str, Any]:
|
||||
|
||||
def convert_model_repo_to_path(model_repo: str) -> str:
|
||||
"""When VLLM_USE_MODELSCOPE is True convert a model
|
||||
repository string to a Path str."""
|
||||
repository string to a Path str.
|
||||
"""
|
||||
if not envs.VLLM_USE_MODELSCOPE or Path(model_repo).exists():
|
||||
return model_repo
|
||||
from modelscope.utils.file_utils import get_model_cache_root
|
||||
|
||||
Reference in New Issue
Block a user