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:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
+19 -29
View File
@@ -70,6 +70,7 @@ def overlay_modality_mm_kwargs(
Returns:
A new dict with the modality-scoped keys overlaid when present.
"""
merged = dict(kwargs)
if modality is None:
@@ -128,8 +129,7 @@ _P = TypeVar("_P", bound=ProcessorMixin, default=ProcessorMixin)
@dataclass(frozen=True)
class InputProcessingContext:
"""
Contains information about the model which may be used to
"""Contains information about the model which may be used to
modify the inputs.
"""
@@ -162,13 +162,13 @@ class InputProcessingContext:
typ: type[Any] | tuple[type[Any], ...] | None = None,
/,
) -> Any:
"""
Get the HuggingFace configuration
"""Get the HuggingFace configuration
(`transformers.PretrainedConfig`) of the model,
additionally checking its type.
Raises:
TypeError: If the configuration is not of the specified type.
"""
if typ is None:
from transformers.configuration_utils import PretrainedConfig
@@ -186,17 +186,15 @@ class InputProcessingContext:
return hf_config
def get_hf_image_processor_config(self) -> dict[str, Any]:
"""
Get the HuggingFace image processor configuration of the model.
"""
"""Get the HuggingFace image processor configuration of the model."""
return self.model_config.hf_image_processor_config
def get_mm_config(self):
"""
Get the multimodal config of the model.
"""Get the multimodal config of the model.
Raises:
RuntimeError: If the model is not a multimodal model.
"""
mm_config = self.model_config.multimodal_config
if mm_config is None:
@@ -221,13 +219,13 @@ class InputProcessingContext:
/,
**kwargs: object,
) -> Any:
"""
Get the HuggingFace processor
"""Get the HuggingFace processor
(`transformers.ProcessorMixin`) of the model,
additionally checking its type.
Raises:
TypeError: If the processor is not of the specified type.
"""
if typ is None:
from transformers.processing_utils import ProcessorMixin
@@ -254,8 +252,7 @@ class InputProcessingContext:
/,
**kwargs: object,
) -> _T:
"""
Initialize a HuggingFace-like processor class, merging the
"""Initialize a HuggingFace-like processor class, merging the
keyword arguments with those in the model's configuration.
"""
merged_kwargs = self.get_merged_mm_kwargs(kwargs)
@@ -317,8 +314,7 @@ class InputProcessingContext:
data: Mapping[str, object],
kwargs: Mapping[str, object] = {},
) -> BatchFeature:
"""
Call `hf_processor` on the prompt `data`
"""Call `hf_processor` on the prompt `data`
(text, image, audio...) with configurable options `kwargs`.
"""
assert callable(hf_processor)
@@ -385,8 +381,7 @@ class BaseProcessingInfo:
return self.ctx.get_hf_config()
def get_hf_processor(self, **kwargs: object) -> ProcessorMixin:
"""
Subclasses can override this method to handle
"""Subclasses can override this method to handle
specific kwargs from model config or user inputs.
"""
return self.ctx.get_hf_processor(**kwargs)
@@ -409,8 +404,7 @@ class BaseProcessingInfo:
return self.get_default_tok_params()
def _get_expected_hidden_size(self) -> int | None:
"""
Get expected hidden size for embedding validation if `mm_embeds` are enabled.
"""Get expected hidden size for embedding validation if `mm_embeds` are enabled.
This validates hidden dimensions to prevent a vulnerability where embeddings
with correct `ndim` but wrong `shape` could cause crashes at inference time.
@@ -430,8 +424,7 @@ class BaseProcessingInfo:
return mm_config is not None and mm_config.allow_missing_mm_embeddings
def get_data_parser(self) -> MultiModalDataParser:
"""
Constructs a parser to preprocess multi-modal data items
"""Constructs a parser to preprocess multi-modal data items
before passing them to
[`_get_hf_mm_data`][vllm.multimodal.processing.BaseMultiModalProcessor._get_hf_mm_data].
@@ -453,8 +446,7 @@ class BaseProcessingInfo:
return False
def get_supported_mm_limits(self) -> Mapping[str, int | None]:
"""
Return the maximum supported number of items for each modality.
"""Return the maximum supported number of items for each modality.
A value of `None` means unlimited number of items.
@@ -486,8 +478,7 @@ class BaseProcessingInfo:
return allowed_limits
def validate_num_items(self, modality: str, num_items: int) -> None:
"""
Raise `ValueError` if the number of input items for the given modality
"""Raise `ValueError` if the number of input items for the given modality
is invalid.
"""
supported_limit = self.supported_mm_limits.get(modality, 0)
@@ -512,8 +503,7 @@ class BaseProcessingInfo:
*,
validate: bool = True,
) -> MultiModalDataItems:
"""
Normalize [`MultiModalDataDict`][vllm.inputs.MultiModalDataDict]
"""Normalize [`MultiModalDataDict`][vllm.inputs.MultiModalDataDict]
to [`MultiModalDataItems`][vllm.multimodal.parse.MultiModalDataItems]
before passing them to
[`_get_hf_mm_data`][vllm.multimodal.processing.BaseMultiModalProcessor._get_hf_mm_data].
@@ -546,8 +536,7 @@ class BaseProcessingInfo:
seq_len: int,
mm_counts: Mapping[str, int],
) -> Mapping[str, int] | None:
"""
Return the maximum number of tokens per item of for each modality.
"""Return the maximum number of tokens per item of for each modality.
When `None` (the default) is returned, vLLM will generate dummy inputs
(images/videos) at maximum possible sizes and process them to determine
@@ -564,5 +553,6 @@ class BaseProcessingInfo:
length and the maximum number of items of each modality allowed,
and agree with dummy inputs (images/videos) at maximum possible
sizes.
"""
return None
+6 -9
View File
@@ -26,8 +26,7 @@ logger = init_logger(__name__)
class BaseDummyInputsBuilder(ABC, Generic[_I]):
"""
Abstract base class that constructs the dummy data to profile
"""Abstract base class that constructs the dummy data to profile
multi-modal models.
"""
@@ -38,9 +37,7 @@ class BaseDummyInputsBuilder(ABC, Generic[_I]):
@abstractmethod
def get_dummy_text(self, mm_counts: Mapping[str, int]) -> str:
"""
Build the text input corresponding to `mm_counts`.
"""
"""Build the text input corresponding to `mm_counts`."""
raise NotImplementedError
@abstractmethod
@@ -50,8 +47,7 @@ class BaseDummyInputsBuilder(ABC, Generic[_I]):
mm_counts: Mapping[str, int],
mm_options: Mapping[str, BaseDummyOptions],
) -> MultiModalDataDict:
"""
Build the multimodal input which, after processing, results in
"""Build the multimodal input which, after processing, results in
the maximum possible number of placeholder tokens.
Args:
@@ -61,6 +57,7 @@ class BaseDummyInputsBuilder(ABC, Generic[_I]):
If None, use model defaults for backward compatibility.
If provided, models can use these to customize dummy
data generation.
"""
raise NotImplementedError
@@ -70,14 +67,14 @@ class BaseDummyInputsBuilder(ABC, Generic[_I]):
mm_counts: Mapping[str, int],
mm_options: Mapping[str, BaseDummyOptions],
) -> ProcessorInputs:
"""
Build the input which, after processing, results in
"""Build the input which, after processing, results in
the maximum possible number of placeholder tokens.
Args:
seq_len: Sequence length
mm_counts: Count of items per modality
mm_options: Configurable options per modality (optional)
"""
dummy_text = self.get_dummy_text(mm_counts)
dummy_mm_data = self.get_dummy_mm_data(seq_len, mm_counts, mm_options)
+1 -2
View File
@@ -18,8 +18,7 @@ _HF_MODALITY_PROCESSOR_KWARGS = {
@dataclass
class ProcessorInputs:
"""
Represents the keyword arguments to
"""Represents the keyword arguments to
[`vllm.multimodal.processing.BaseMultiModalProcessor.apply`][].
"""
+29 -56
View File
@@ -104,8 +104,7 @@ class PromptIndex:
class PromptIndexTargets:
@staticmethod
def start() -> PromptIndex:
"""
Resolves to the start of the prompt (before the first token).
"""Resolves to the start of the prompt (before the first token).
This results in a match even if the prompt is empty.
"""
@@ -116,9 +115,7 @@ class PromptIndexTargets:
@staticmethod
def prefix(seq: list[int]) -> PromptIndex:
"""
Resolves to a location in the prompt after the given prefix.
"""
"""Resolves to a location in the prompt after the given prefix."""
def get_match_index(
prompt: list[int],
@@ -146,8 +143,7 @@ class PromptIndexTargets:
@staticmethod
def end() -> PromptIndex:
"""
Resolves to the end of the prompt (after the last token).
"""Resolves to the end of the prompt (after the last token).
This results in a match even if the prompt is empty.
"""
@@ -247,8 +243,7 @@ class UpdateMode(str, Enum):
@dataclass
class PromptUpdate(ABC):
"""
Defines how to update a prompt with placeholder tokens.
"""Defines how to update a prompt with placeholder tokens.
Note:
The target and content are token sequences. When converting text
@@ -256,6 +251,7 @@ class PromptUpdate(ABC):
`add_special_tokens=False` to match how the prompt itself is
tokenized. Otherwise, the updated prompt may contain duplicated
special tokens or fail to match the target.
"""
modality: str
@@ -294,8 +290,7 @@ class PromptUpdate(ABC):
return content
def resolve(self, item_idx: int) -> "ResolvedPromptUpdate":
"""
Given the index of the processed item within
"""Given the index of the processed item within
[`modality`][vllm.multimodal.processing.PromptUpdate.modality],
output a copy of this object with its lazy attributes resolved.
"""
@@ -310,11 +305,9 @@ class PromptUpdate(ABC):
@dataclass
class PromptInsertion(PromptUpdate):
"""
Defines how to insert placeholder tokens into a prompt.
"""Defines how to insert placeholder tokens into a prompt.
Example:
For each image, insert a number of `<image>` feature placeholders
equal to the feature size of the vision encoder after the `<s>` token:
@@ -355,6 +348,7 @@ class PromptInsertion(PromptUpdate):
insertion=[image_token_id] * image_feature_size,
)
```
"""
insertion: PromptUpdateContent = field(repr=False)
@@ -379,11 +373,9 @@ class PromptInsertion(PromptUpdate):
@dataclass
class PromptReplacement(PromptUpdate):
"""
Defines how to replace portions of an input prompt with placeholder tokens.
"""Defines how to replace portions of an input prompt with placeholder tokens.
Example:
For each image, replace one `<image>` input placeholder in the prompt
with a number of `<image>` feature placeholders
equal to the feature size of the vision encoder:
@@ -412,6 +404,7 @@ class PromptReplacement(PromptUpdate):
),
)
```
"""
replacement: PromptUpdateContent = field(repr=False)
@@ -447,8 +440,7 @@ _M = TypeVar("_M", bound=_HasModalityAttr | _HasModalityProp)
def full_groupby_modality(values: Iterable[_M]) -> ItemsView[str, list[_M]]:
"""
Convenience function to apply
"""Convenience function to apply
[`full_groupby`][vllm.utils.collection_utils.full_groupby]
based on modality.
"""
@@ -462,8 +454,7 @@ class PromptTargetMatch(NamedTuple):
@dataclass(frozen=True)
class ResolvedPromptUpdate:
"""
A [`PromptUpdate`][vllm.multimodal.processing.PromptUpdate] with its
"""A [`PromptUpdate`][vllm.multimodal.processing.PromptUpdate] with its
lazy attributes resolved.
"""
@@ -522,8 +513,7 @@ def iter_token_matches(
*,
start_idx: int = 0,
) -> Generator[_TokenMatch]:
"""
Yield each occurrence of `match_ids` in `token_ids`.
"""Yield each occurrence of `match_ids` in `token_ids`.
Note that empty matches are ignored.
"""
@@ -562,8 +552,7 @@ def replace_token_matches(
match_ids: list[int],
new_ids: list[int],
) -> list[int]:
"""
Replace each occurrence of `match_ids` in `token_ids`
"""Replace each occurrence of `match_ids` in `token_ids`
with `new_ids`.
Note that empty matches are ignored.
@@ -846,8 +835,7 @@ def apply_token_matches(
prompt: list[int],
mm_prompt_updates: "MultiModalPromptUpdates",
) -> tuple[list[int], "MultiModalPromptUpdatesApplyResult"]:
"""
Apply the updates in `mm_prompt_updates` to `prompt`.
"""Apply the updates in `mm_prompt_updates` to `prompt`.
Matches are exclusive even when multiple modalities share
the same placeholder tokens. In that case, the modality that
@@ -914,8 +902,7 @@ def _iter_placeholders(
prompt: list[int],
mm_prompt_updates: "MultiModalPromptUpdates",
) -> Iterable[PlaceholderFeaturesInfo]:
"""
Yield each set of placeholder tokens found in `prompt`.
"""Yield each set of placeholder tokens found in `prompt`.
Matches are exclusive even when multiple modalities share
the same placeholder tokens. In that case, the modality that
@@ -1028,8 +1015,7 @@ class MultiModalProcessingInfo(NamedTuple):
class BaseMultiModalProcessor(ABC, Generic[_I]):
"""
Abstract base class to process multi-modal inputs to be used in vLLM.
"""Abstract base class to process multi-modal inputs to be used in vLLM.
Not to be confused with `transformers.ProcessorMixin`.
"""
@@ -1097,8 +1083,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
hf_processor_mm_kwargs: Mapping[str, object],
out_mm_kwargs: MultiModalKwargsItems,
) -> Sequence[PromptUpdate]:
"""
Given the original multi-modal items for this modality
"""Given the original multi-modal items for this modality
and HF-processed data, output the updates to perform.
The information returned by this method is used to update token inputs
@@ -1167,8 +1152,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
return processor_data, passthrough_data
def _get_hf_processor_text(self, mm_counts: Mapping[str, int]) -> str | None:
"""
Get the text to pass to the HF processor alongside the multi-modal
"""Get the text to pass to the HF processor alongside the multi-modal
data.
By default, no text is passed. If the HF processor requires that
@@ -1183,8 +1167,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
mm_data: Mapping[str, object],
hf_processor_mm_kwargs: Mapping[str, object],
) -> tuple[Mapping[str, object], Mapping[str, object]]:
"""
Pre-process the multi-modal data and HF processor keyword arguments
"""Pre-process the multi-modal data and HF processor keyword arguments
before they are passed to the HF processor.
By default, both are returned as-is. If the HF processor expects the
@@ -1201,8 +1184,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
hf_processor_mm_kwargs: Mapping[str, object],
processed_data: BatchFeature,
) -> BatchFeature:
"""
Post-process the output of the HF processor.
"""Post-process the output of the HF processor.
By default, the output is returned as-is. If you need to modify the
output of the HF processor before it is converted into multi-modal
@@ -1215,9 +1197,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
) -> BatchFeature:
"""
Apply the HF processor on the multi-modal data.
"""
"""Apply the HF processor on the multi-modal data."""
valid_mm_items = mm_items.select(
{k for k, c in mm_items.get_all_counts().items() if c > 0}
)
@@ -1250,8 +1230,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
)
def _postprocess_prompt(self, prompt: list[int]) -> list[int]:
"""
Post-process the prompt token IDs before locating or applying
"""Post-process the prompt token IDs before locating or applying
multi-modal prompt updates.
By default, the prompt is returned as-is. If the HF processor (or
@@ -1303,8 +1282,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
cached_update: ResolvedPromptUpdate,
new_item_idx: int,
) -> ResolvedPromptUpdate:
"""
Override this if other attributes of `ResolvedPromptUpdate`
"""Override this if other attributes of `ResolvedPromptUpdate`
also need to be recomputed after retrieving from the cache.
"""
return replace(cached_update, item_idx=new_item_idx)
@@ -1404,8 +1382,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
inputs: ProcessorInputs,
timing_ctx: TimingContext,
) -> MultiModalProcessingInfo:
"""
Apply the HF processor on the full prompt text,
"""Apply the HF processor on the full prompt text,
caching the results and reusing cached results.
"""
cache = self.cache
@@ -1522,8 +1499,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
*,
encode_segments_separately: bool = False,
) -> tuple[list[int], MultiModalPromptUpdatesApplyResult]:
"""
Apply multi-modal prompt updates in text space, then encode the
"""Apply multi-modal prompt updates in text space, then encode the
result.
A non-special-token target may be tokenized differently inside the
@@ -1716,8 +1692,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
inputs: ProcessorInputs,
timing_ctx: TimingContext,
) -> MultiModalInput:
"""
Process multi-modal inputs to be used in vLLM.
"""Process multi-modal inputs to be used in vLLM.
The main steps are:
@@ -1763,8 +1738,7 @@ class EncDecMultiModalProcessor(BaseMultiModalProcessor[_I]):
prompt: list[int],
mm_items: MultiModalDataItems,
) -> list[int]:
"""
Create input prompt for the encoder. HF processor will be applied on
"""Create input prompt for the encoder. HF processor will be applied on
this prompt during profiling and generation.
"""
raise NotImplementedError
@@ -1805,8 +1779,7 @@ class EncDecMultiModalProcessor(BaseMultiModalProcessor[_I]):
inputs: ProcessorInputs,
timing_ctx: TimingContext,
) -> MultiModalEncDecInput:
"""
Process multi-modal inputs to be used in vLLM.
"""Process multi-modal inputs to be used in vLLM.
The main processing steps are modified to fit encoder-decoder model:
1. Create encoder prompt from input prompt text.
2. Apply the HF processor on encoder prompt.