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
+51 -56
View File
@@ -112,8 +112,7 @@ class StreamingTranscriptionPostProcessor:
def _require_is_multimodal(is_multimodal: Tensor | None) -> Tensor:
"""
A helper function to be used in the context of
"""A helper function to be used in the context of
[vllm.model_executor.models.interfaces.SupportsMultiModal.embed_input_ids][]
to provide a better error message.
"""
@@ -225,20 +224,18 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
@classmethod
def get_placeholder_str(cls, modality: str, i: int) -> str | None:
"""
Get the placeholder text for the `i`th `modality` item in the prompt.
"""
"""Get the placeholder text for the `i`th `modality` item in the prompt."""
...
def embed_multimodal(self, **kwargs: object) -> MultiModalEmbeddings:
"""
Returns multimodal embeddings generated from multimodal kwargs
"""Returns multimodal embeddings generated from multimodal kwargs
to be merged with text embeddings.
Note:
The returned multimodal embeddings must be in the same order as
the appearances of their corresponding multimodal data item in the
input prompt.
"""
...
@@ -254,14 +251,14 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
)
def get_language_model(self) -> "VllmModel":
"""
Returns the underlying language model used for text generation.
"""Returns the underlying language model used for text generation.
This is typically the `torch.nn.Module` instance responsible for
processing the merged multimodal embeddings and producing hidden states
Returns:
torch.nn.Module: The core language model component.
"""
# Cached
assert isinstance(self, nn.Module)
@@ -302,8 +299,7 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
*,
targets: type[nn.Module] | tuple[type[nn.Module], ...] | None = None,
):
"""
Mark each child module that was assigned to this model during this context
"""Mark each child module that was assigned to this model during this context
as a language model component.
Language model components are automatically skipped in `--mm-encoder-only`
@@ -338,8 +334,7 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
*,
targets: type[nn.Module] | tuple[type[nn.Module], ...] | None = None,
):
"""
Mark each child module that was assigned to this model during this context
"""Mark each child module that was assigned to this model during this context
as a tower model component.
Tower model components are automatically skipped when `--limit-mm-per-prompt`
@@ -397,8 +392,7 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
language_targets: type[nn.Module] | tuple[type[nn.Module], ...],
tower_targets: dict[str, type[nn.Module] | tuple[type[nn.Module], ...]],
):
"""
Composite wrapper over `_mark_language_model` and
"""Composite wrapper over `_mark_language_model` and
`_mark_tower_model` by modality.
"""
with ExitStack() as stack:
@@ -438,8 +432,7 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
mm_kwargs: "MultiModalKwargsItem | None",
num_mm_embeds: int,
) -> tuple[int, int | None]:
"""
Return ``(tower_tokens, connector_tokens)`` for multimodal LoRA mappings.
"""Return ``(tower_tokens, connector_tokens)`` for multimodal LoRA mappings.
MM LoRA uses these counts to build adapter mappings for the tower and
connector forwards. Models with multiple modalities can override this
@@ -497,8 +490,7 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
*,
is_multimodal: Tensor | None = None,
) -> Tensor:
"""
Apply token embeddings to `input_ids`.
"""Apply token embeddings to `input_ids`.
If `multimodal_embeddings` is passed, scatter them into
`input_ids` according to the mask `is_multimodal`.
@@ -551,8 +543,7 @@ class SupportsMultiModalPruning(Protocol):
mrope_positions: torch.LongTensor,
num_computed_tokens: int,
) -> tuple[Sequence[torch.Tensor], Tensor, int]:
"""
Update part of input mrope positions (starting with
"""Update part of input mrope positions (starting with
num_computed_tokens index). Original mrope_positions are computed
for unpruned sequence and becomes incorrect once pruning occurs,
so once we prune media tokens we should reflect this in the
@@ -571,6 +562,7 @@ class SupportsMultiModalPruning(Protocol):
Returns:
Tuple of (multimodal_embeddings, mrope_positions,
mrope_position_delta).
"""
...
@@ -650,16 +642,12 @@ class SupportsScoreTemplate(Protocol):
@classmethod
def get_score_template(cls, query: str, document: str) -> str | None:
"""
Generate a full prompt by populating the score template with query and document content.
""" # noqa: E501
"""Generate a full prompt by populating the score template with query and document content.""" # noqa: E501
...
@classmethod
def post_process_tokens(cls, prompt: "TokensPrompt") -> None:
"""
Perform architecture-specific manipulations on the input tokens.
"""
"""Perform architecture-specific manipulations on the input tokens."""
...
@@ -790,8 +778,7 @@ class SupportsPP(Protocol):
*,
intermediate_tensors: "IntermediateTensors | None",
) -> "Tensor | IntermediateTensors | tuple[Tensor, list[Tensor]]":
"""
Accept [`IntermediateTensors`][vllm.sequence.IntermediateTensors] when
"""Accept [`IntermediateTensors`][vllm.sequence.IntermediateTensors] when
PP rank > 0.
Return [`IntermediateTensors`][vllm.sequence.IntermediateTensors] only
@@ -905,7 +892,8 @@ def has_inner_state(
@runtime_checkable
class IsAttentionFree(Protocol):
"""The interface required for all models like Mamba that lack attention,
but do have state whose size is constant wrt the number of tokens."""
but do have state whose size is constant wrt the number of tokens.
"""
is_attention_free: ClassVar[Literal[True]] = True
"""
@@ -933,7 +921,8 @@ def is_attention_free(
class IsHybrid(Protocol):
"""The interface required for all models like Jamba that have both
attention and mamba blocks, indicates that
hf_config has 'layers_block_type'"""
hf_config has 'layers_block_type'
"""
is_hybrid: ClassVar[Literal[True]] = True
"""
@@ -953,6 +942,7 @@ class IsHybrid(Protocol):
Returns:
Shapes for each state cache used by the model.
"""
...
@@ -966,6 +956,7 @@ class IsHybrid(Protocol):
(state, block_ids, cur_block_idx, num_accepted_tokens) and returns
a MambaCopySpec describing the memory-copy parameters for prefix
caching in align mode.
"""
...
@@ -994,9 +985,7 @@ def is_hybrid(
@runtime_checkable
class MixtureOfExperts(Protocol):
"""
Check if the model is a mixture of experts (MoE) model.
"""
"""Check if the model is a mixture of experts (MoE) model."""
expert_weights: MutableSequence[Sequence[Tensor]]
"""
@@ -1039,8 +1028,7 @@ class MixtureOfExperts(Protocol):
logical_to_physical_map: Tensor,
logical_replica_count: Tensor,
) -> None:
"""
Register the EPLB state in the MoE model.
"""Register the EPLB state in the MoE model.
Since these are views of the actual EPLB state, any changes made by
the EPLB algorithm are automatically reflected in the model's behavior
@@ -1054,6 +1042,7 @@ class MixtureOfExperts(Protocol):
expert_load_view: A view of the expert load metrics tensor.
logical_to_physical_map: Mapping from logical to physical experts.
logical_replica_count: Count of replicas for each logical expert.
"""
self.expert_weights = []
for layer_idx, layer in enumerate(self.moe_layers):
@@ -1086,8 +1075,8 @@ def get_mixture_of_experts_model(model: object) -> MixtureOfExperts | None:
Returns:
The MixtureOfExperts instance contained within the model, or None.
"""
"""
if is_mixture_of_experts(model):
return model
@@ -1349,7 +1338,8 @@ class SupportsTranscription(Protocol):
) -> "PromptType":
"""Get the prompt for the ASR model.
The model has control over the construction, as long as it
returns a valid PromptType."""
returns a valid PromptType.
"""
...
@classmethod
@@ -1359,8 +1349,7 @@ class SupportsTranscription(Protocol):
@classmethod
def validate_language(cls, language: str | None) -> str | None:
"""
Ensure the language specified in the transcription request
"""Ensure the language specified in the transcription request
is a valid ISO 639-1 language code. If the request language is
valid, but not natively supported by the model, trigger a
warning (but not an exception).
@@ -1396,8 +1385,7 @@ class SupportsTranscription(Protocol):
stt_config: "SpeechToTextConfig",
model_config: "ModelConfig",
) -> int | None:
"""
Map from audio duration to number of audio tokens produced by the ASR
"""Map from audio duration to number of audio tokens produced by the ASR
model, without running a forward pass.
This is used for estimating the amount of processing for this audio.
"""
@@ -1405,8 +1393,7 @@ class SupportsTranscription(Protocol):
@classmethod
def post_process_output(cls, text: str) -> str:
"""
Post-process the raw model output text.
"""Post-process the raw model output text.
Some ASR models output structured formats (e.g., language tags,
special tokens) that need to be stripped before returning to the user.
@@ -1416,6 +1403,7 @@ class SupportsTranscription(Protocol):
Returns:
Cleaned transcription text.
"""
return text
@@ -1432,8 +1420,7 @@ class SupportsTranscription(Protocol):
def get_streaming_post_processor_cls(
cls,
) -> type[StreamingTranscriptionPostProcessor]:
"""
Return a stateful post-processor class for streaming output deltas.
"""Return a stateful post-processor class for streaming output deltas.
Each instance receives the next decoded text delta and whether the
request output is final. It returns the cleaned delta that should be
@@ -1644,7 +1631,8 @@ class EagleModelMixin:
@runtime_checkable
class SupportsEagle(SupportsEagleBase, Protocol):
"""The interface required for models that support
EAGLE-1 and EAGLE-2 speculative decoding."""
EAGLE-1 and EAGLE-2 speculative decoding.
"""
supports_eagle: ClassVar[Literal[True]] = True
"""
@@ -1674,7 +1662,8 @@ def supports_eagle(
@runtime_checkable
class SupportsEagle3(SupportsEagleBase, Protocol):
"""The interface required for models that support
EAGLE-3 speculative decoding."""
EAGLE-3 speculative decoding.
"""
supports_eagle3: ClassVar[Literal[True]] = True
"""
@@ -1687,12 +1676,12 @@ class SupportsEagle3(SupportsEagleBase, Protocol):
"""
def set_aux_hidden_state_layers(self, layers: tuple[int, ...]) -> None:
"""
Set which layers should output auxiliary hidden states for EAGLE-3.
"""Set which layers should output auxiliary hidden states for EAGLE-3.
Args:
layers: Tuple of layer indices that should output auxiliary
hidden states.
"""
parent_ref = self
if hasattr(self, "get_language_model"):
@@ -1710,14 +1699,14 @@ class SupportsEagle3(SupportsEagleBase, Protocol):
holder._set_aux_hidden_state_layers(layers)
def get_eagle3_default_aux_hidden_state_layers(self) -> tuple[int, ...]:
"""
Get the default layer indices that should output auxiliary hidden states
"""Get the default layer indices that should output auxiliary hidden states
for EAGLE-3 for this model. Models can override this method to provide
different default layers based on their architecture, but it is encouraged
to instead include the layer specification in the model's config if possible.
Returns:
Tuple of layer indices for auxiliary hidden state outputs.
"""
parent_ref = self
if hasattr(self, "get_language_model"):
@@ -1765,8 +1754,7 @@ class SupportsMRoPE(Protocol):
input_tokens: list[int],
mm_features: list["MultiModalFeatureSpec"],
) -> tuple[torch.Tensor, int]:
"""
Get M-RoPE input positions and delta value for this specific model.
"""Get M-RoPE input positions and delta value for this specific model.
This method should be implemented by each model that supports M-RoPE
to provide model-specific logic for computing input positions.
@@ -1779,6 +1767,7 @@ class SupportsMRoPE(Protocol):
llm_positions: Tensor of shape `[num_dims, num_tokens]`, one row
per M-RoPE position channel (e.g. T/H/W).
mrope_position_delta: Delta for position calculations.
"""
...
@@ -1886,8 +1875,7 @@ class SupportsEncoderCudaGraph(Protocol):
clone: bool = False,
batch_mm_kwargs: dict[str, Any] | None = None,
) -> None:
"""
Post-process encoder output, directly call scatter_output_slices by default.
"""Post-process encoder output, directly call scatter_output_slices by default.
By default, delegates directly to scatter_output_slices.
Override this for models that require additional processing on the raw
@@ -1913,10 +1901,17 @@ class SupportsEncoderCudaGraph(Protocol):
"""Create dummy inputs and buffers for CUDA graph capture.
Args:
token_budget: Token budget the capture is sized for.
max_batch_size: Maximum number of items in a captured batch.
max_frames_per_batch: Maximum number of frames in a captured batch.
device: Device the dummy inputs and buffers are created on.
dtype: Dtype of the dummy inputs and buffers.
path: Configured encoder path.
axis_keys: The resolved capture-axis keys (one per axis of
``EncoderCudaGraphConfig.capture_axes``) this capture is for.
None or empty when no capture axes are configured; models
without capture axes ignore it.
"""
...