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
@@ -72,7 +72,7 @@ temp_dir = tempfile.gettempdir()
def enable_xet_high_performance():
"""automatically activates xet high performance mode"""
"""Automatically activates xet high performance mode"""
if "HF_XET_HIGH_PERFORMANCE" not in os.environ:
huggingface_hub.constants.HF_XET_HIGH_PERFORMANCE = True
@@ -103,8 +103,7 @@ def get_lock(model_name_or_path: str | Path, cache_dir: str | None = None):
def atomic_writer(
filepath: str | Path, mode: str = "w", encoding: str | None = None
) -> Generator[IO]:
"""
Context manager that provides an atomic file writing routine.
"""Context manager that provides an atomic file writing routine.
The context manager writes to a temporary file and, if successful,
atomically replaces the original file.
@@ -116,6 +115,7 @@ def atomic_writer(
Yields:
file object: A handle to the temporary file.
"""
# Create a temporary file in the same directory as the target file
# to ensure it's on the same filesystem for an atomic replace.
@@ -144,7 +144,8 @@ def atomic_writer(
def _natural_sort_key(filepath: str) -> list:
"""Natural sort key for filenames with numeric components, such as
model-00001-of-00005.safetensors -> ['model-', 1, '-of-', 5, '.safetensors']"""
model-00001-of-00005.safetensors -> ['model-', 1, '-of-', 5, '.safetensors']
"""
return [
int(s) if s.isdigit() else s
for s in re.split(r"(\d+)", os.path.basename(filepath))
@@ -161,7 +162,8 @@ def maybe_download_from_modelscope(
"""Download model from ModelScope hub if VLLM_USE_MODELSCOPE is True.
Returns the path to the downloaded model, or None if the model is not
downloaded from ModelScope."""
downloaded from ModelScope.
"""
if envs.VLLM_USE_MODELSCOPE:
# download model from ModelScope hub,
# lazy import so that modelscope is not required for normal use.
@@ -482,6 +484,7 @@ def download_weights_from_hf(
Returns:
str: The path to the downloaded model weights.
"""
assert len(allow_patterns) > 0
local_only = huggingface_hub.constants.HF_HUB_OFFLINE
@@ -580,6 +583,7 @@ def download_safetensors_index_file_from_hf(
subfolder (Optional[str]): The subfolder within the model repository
to download weights from.
revision (Optional[str]): The revision of the model.
"""
# Use file lock to prevent multiple processes from
# downloading the same model weights at the same time.
@@ -637,8 +641,7 @@ def filter_duplicate_safetensors_files(
def filter_files_not_needed_for_inference(hf_weights_files: list[str]) -> list[str]:
"""
Exclude files that are not needed for inference.
"""Exclude files that are not needed for inference.
See https://github.com/huggingface/transformers/blob/v4.34.0/src/transformers/trainer.py#L227-L233
"""
@@ -1145,7 +1148,8 @@ def instanttensor_weights_iterator(
use_tqdm_on_load: bool,
) -> Generator[tuple[str, torch.Tensor], None, None]:
"""Iterate over the weights in the model safetensor files
using instanttensor library."""
using instanttensor library.
"""
try:
import instanttensor
except ImportError as e:
@@ -1407,6 +1411,7 @@ def maybe_remap_kv_scale_name(name: str, params_dict: dict) -> str | None:
str: The remapped parameter name if successful, or the original name
if no remapping is needed.
None: If the remapped name is not found in params_dict.
"""
# Already in vLLM's expected form (e.g. weights pre-renamed by a
# `WeightsMapper` from the quant config). Skip the regex remap, which
@@ -1506,8 +1511,7 @@ def maybe_remap_moe_expert_param_name(
name: str,
params_dict: dict[str, torch.nn.Parameter],
) -> str:
"""
Remap MoE expert parameter names to account for routed_experts hierarchy.
"""Remap MoE expert parameter names to account for routed_experts hierarchy.
This handles the transition from the old FusedMoE structure where weights
were directly in the experts module, to the new MoERunner → RoutedExperts
@@ -1529,6 +1533,7 @@ def maybe_remap_moe_expert_param_name(
Returns:
Remapped parameter name if routed_experts hierarchy exists,
otherwise the original name
"""
# Only remap if this looks like an expert parameter
if ".experts." not in name:
@@ -1582,8 +1587,7 @@ def remap_moe_expert_weights(
weights: Iterable[tuple[str, torch.Tensor]],
params_dict: dict[str, torch.nn.Parameter],
) -> Generator[tuple[str, torch.Tensor], None, None]:
"""
Wrapper generator that remaps MoE expert parameter names for backward compatibility.
"""Remap MoE expert parameter names for backward compatibility.
This allows models with custom weight loading to automatically handle both old
and new checkpoint formats without needing model-specific remapping code.
@@ -1601,6 +1605,7 @@ def remap_moe_expert_weights(
Yields:
(remapped_name, tensor) tuples
"""
for name, weight in weights:
remapped_name = maybe_remap_moe_expert_param_name(name, params_dict)