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
+1 -3
View File
@@ -16,9 +16,7 @@ logger = logging.getLogger(__name__)
def vllm_version_matches_substr(substr: str) -> bool:
"""
Check to see if the vLLM version matches a substring.
"""
"""Check to see if the vLLM version matches a substring."""
from importlib.metadata import PackageNotFoundError, version
try:
+4 -11
View File
@@ -181,9 +181,7 @@ class CpuPlatform(Platform):
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
"""Set the device for the current platform."""
torch.cpu.set_device(device)
@classmethod
@@ -508,8 +506,7 @@ class CpuPlatform(Platform):
@classmethod
def discover_numa_topology(cls) -> list[list[int]]:
"""
Discover NUMA topology and keep the last physical core of each numa
"""Discover NUMA topology and keep the last physical core of each numa
into one core group list for nixl start_kv_load()
"""
SYS_NODE = "/sys/devices/system/node"
@@ -570,9 +567,7 @@ class CpuPlatform(Platform):
@classmethod
def get_device_communicator_cls(cls) -> str:
"""
Get device specific communicator class for distributed communication.
"""
"""Get device specific communicator class for distributed communication."""
return "vllm.distributed.device_communicators.cpu_communicator.CpuCommunicator" # noqa
@classmethod
@@ -636,9 +631,7 @@ class CpuPlatform(Platform):
kv_cache: torch.Tensor,
indices: torch.Tensor,
) -> None:
"""
Rewrite the kv cache shape for the current platform.
"""
"""Rewrite the kv cache shape for the current platform."""
# Import lazily: cpu_attn pulls in _custom_ops, which needs a fully
# initialized vllm.platforms (avoid circular import while CpuPlatform loads).
from vllm._custom_ops import cpu_attn_reshape_and_cache
+4 -7
View File
@@ -62,7 +62,8 @@ def _cuda_device_count_stateless(cuda_visible_devices: str | None = None) -> int
CUDA_VISIBLE_DEVICES has already been set to the desired value.
# This can be removed and simply replaced with torch.cuda.get_device_count
# after https://github.com/pytorch/pytorch/pull/122815 is released."""
# after https://github.com/pytorch/pytorch/pull/122815 is released.
"""
# Note: cuda_visible_devices is not used, but we keep it as an argument for
# LRU Cache purposes.
@@ -265,9 +266,7 @@ class CudaPlatformBase(Platform):
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
"""Set the device for the current platform."""
torch.cuda.set_device(device)
# With this trick we can force the device to be set eagerly
# see https://github.com/pytorch/pytorch/issues/155668
@@ -838,9 +837,7 @@ class NvmlCudaPlatform(CudaPlatformBase):
@classmethod
@with_nvml_context
def is_fully_connected(cls, physical_device_ids: list[int]) -> bool:
"""
query if the set of gpus are fully connected by nvlink (1 hop)
"""
"""Query if the set of gpus are fully connected by nvlink (1 hop)."""
handles = [pynvml.nvmlDeviceGetHandleByIndex(i) for i in physical_device_ids]
for i, handle in enumerate(handles):
for j, peer_handle in enumerate(handles):
+55 -131
View File
@@ -42,7 +42,8 @@ def set_assigned_physical_gpu_ids(ids: list[int]) -> None:
Idempotent: a second call with the same value is a no-op.
Raises RuntimeError if called again with a different value.
This is expected to run during single-threaded worker initialization."""
This is expected to run during single-threaded worker initialization.
"""
global _assigned_physical_gpu_ids
if _assigned_physical_gpu_ids is not None:
if _assigned_physical_gpu_ids != ids:
@@ -122,8 +123,7 @@ class DeviceCapability(NamedTuple):
return f"{self.major}.{self.minor}"
def to_int(self) -> int:
"""
Express device capability as an integer `<major><minor>`.
"""Express device capability as an integer `<major><minor>`.
It is assumed that the minor version is always a single digit.
"""
@@ -175,7 +175,7 @@ class Platform:
@property
def pass_key(self) -> str:
"""Inductor config key for the PassManager custom pass"""
"""Inductor config key for the PassManager custom pass."""
return "post_grad_custom_post_pass"
@property
@@ -238,23 +238,19 @@ class Platform:
@classmethod
def get_pass_manager_cls(cls) -> str:
"""
Get the pass manager class for this platform.
"""Get the pass manager class for this platform.
It will be registered as a custom pass under the current_platform.pass_key.
"""
return "vllm.compilation.passes.pass_manager.PostGradPassManager"
@classmethod
def get_compile_backend(cls) -> str:
"""
Get the custom compile backend for current platform.
"""
"""Get the custom compile backend for current platform."""
return cls.simple_compile_backend
@classmethod
def import_ir_kernels(cls) -> None:
"""
The default implementation imports ``vllm.kernels``, which registers
"""The default implementation imports ``vllm.kernels``, which registers
the built-in IR op implementations. Out-of-tree (OOT) platforms should
override this method to import their own kernel modules.
"""
@@ -392,8 +388,7 @@ class Platform:
dtype: torch.dtype,
backend: "AttentionBackendEnum | None" = None,
) -> "AttentionBackendEnum":
"""
Get the vision attention backend class of a device.
"""Get the vision attention backend class of a device.
NOTE: ViT Attention should be checked and override in the platform-specific
implementation. we should not override this in any other places, like
@@ -426,6 +421,7 @@ class Platform:
Args:
device_id: Device index in the visible device namespace, matching
the argument accepted by torch.cuda.
"""
return None
@@ -435,8 +431,7 @@ class Platform:
capability: tuple[int, int] | int,
device_id: int = 0,
) -> bool:
"""
Test whether this platform is compatible with a device capability.
"""Test whether this platform is compatible with a device capability.
The `capability` argument can either be:
@@ -459,8 +454,7 @@ class Platform:
capability: tuple[int, int] | int,
device_id: int = 0,
) -> bool:
"""
Test whether this platform has exactly the specified device capability.
"""Test whether this platform has exactly the specified device capability.
The `capability` argument can either be:
@@ -483,8 +477,7 @@ class Platform:
capability: int,
device_id: int = 0,
) -> bool:
"""
Returns True if the device capability is any <major>.x.
"""Returns True if the device capability is any <major>.x.
Mirrors CUDA 13 'family' architecture semantics (e.g. 10.x, 11.x, 12.x).
"""
current_capability = cls.get_device_capability(device_id=device_id)
@@ -532,9 +525,7 @@ class Platform:
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
"""Set the device for the current platform."""
raise NotImplementedError
@classmethod
@@ -546,8 +537,7 @@ class Platform:
def pre_register_and_update(
cls, parser: FlexibleArgumentParser | None = None
) -> None:
"""
Do some pre-registration or update action for the current platform.
"""Do some pre-registration or update action for the current platform.
This function is called before global VllmConfig is initialized or cli
arguments are parsed. It's used for out-of-tree platforms to register or
@@ -560,8 +550,7 @@ class Platform:
@classmethod
def apply_config_platform_defaults(cls, vllm_config: "VllmConfig") -> None:
"""
Apply the platform-specific default values to the config.
"""Apply the platform-specific default values to the config.
This function is called during the initialization of global VllmConfig, after
parsing cli arguments.
@@ -574,8 +563,7 @@ class Platform:
@classmethod
def check_and_update_config(cls, vllm_config: "VllmConfig") -> None:
"""
Check and update the configuration for the current platform.
"""Check and update the configuration for the current platform.
It can raise an exception if the configuration is not compatible with
the current platform, or it can update the configuration to make it
@@ -607,8 +595,7 @@ class Platform:
@classmethod
def update_block_size_for_backend(cls, vllm_config: "VllmConfig") -> None:
"""
Ensure block_size is compatible with the attention backend.
"""Ensure block_size is compatible with the attention backend.
For hybrid models, also aligns block_size with mamba page sizes.
"""
from vllm.config.cache import CacheConfig
@@ -780,8 +767,7 @@ class Platform:
vllm_config: "VllmConfig",
backend_cls: "type[AttentionBackend]",
) -> None:
"""
For hybrid attention/mamba models, ensure that the attention page
"""For hybrid attention/mamba models, ensure that the attention page
size is >= the mamba page size, and pad the mamba page size to match.
"""
from math import lcm
@@ -963,15 +949,12 @@ class Platform:
@classmethod
def register_custom_kv_cache_specs(cls, vllm_config: "VllmConfig") -> None:
"""
Register custom KVCacheSpec class on current platform.
"""
"""Register custom KVCacheSpec class on current platform."""
pass
@classmethod
def verify_model_arch(cls, model_arch: str) -> None:
"""
Verify whether the current platform supports the specified model
"""Verify whether the current platform supports the specified model
architecture.
- This will raise an Error or Warning based on the model support on
@@ -982,9 +965,7 @@ class Platform:
@classmethod
def verify_quantization(cls, quant: str) -> None:
"""
Verify whether the quantization is supported by the current platform.
"""
"""Verify whether the quantization is supported by the current platform."""
if cls.supported_quantization and quant not in cls.supported_quantization:
raise ValueError(
f"{quant} quantization is currently not supported in {cls.device_name}."
@@ -992,8 +973,7 @@ class Platform:
@classmethod
def get_cpu_architecture(cls) -> CpuArchEnum:
"""
Determine the CPU architecture of the current system.
"""Determine the CPU architecture of the current system.
Returns CpuArchEnum indicating the architecture type.
"""
machine = platform.machine().lower()
@@ -1031,50 +1011,37 @@ class Platform:
def get_current_memory_usage(
cls, device: torch.types.Device | None = None
) -> float:
"""
Return the memory usage in bytes.
"""
"""Return the memory usage in bytes."""
raise NotImplementedError
@classmethod
def get_punica_wrapper(cls) -> str:
"""
Return the punica wrapper for current platform.
"""
"""Return the punica wrapper for current platform."""
raise NotImplementedError
@classmethod
def get_infinity_values(cls, dtype: torch.dtype) -> tuple[float, float]:
"""
Return the platform specific values for (-inf, inf)
"""
"""Return the platform specific values for (-inf, inf)."""
return float("-inf"), float("inf")
@classmethod
def can_update_inplace(cls) -> bool:
"""
Checks if the platform allows inplace memory updates
"""
"""Checks if the platform allows inplace memory updates."""
return True
@classmethod
def get_lora_vocab_padding_size(cls) -> int:
"""
Returns how much padding the LoRA logits need for kernels
"""
"""Returns how much padding the LoRA logits need for kernels."""
return 256
@classmethod
def get_device_communicator_cls(cls) -> str:
"""
Get device specific communicator class for distributed communication.
"""
"""Get device specific communicator class for distributed communication."""
return "vllm.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase" # noqa
@classmethod
def is_integrated_gpu(cls, device_id: int = 0) -> bool:
"""
Returns whether the GPU is an integrated (UMA) device that shares
"""Returns whether the GPU is an integrated (UMA) device that shares
system memory with the CPU.
On UMA systems (e.g. NVIDIA GH200, DGX Spark, Jetson Orin),
@@ -1085,22 +1052,17 @@ class Platform:
@classmethod
def supports_mx(cls) -> bool:
"""
Returns whether the current platform supports MX types.
"""
"""Returns whether the current platform supports MX types."""
return False
@classmethod
def supports_fp8(cls) -> bool:
"""
Returns whether the current platform supports FP8 types.
"""
"""Returns whether the current platform supports FP8 types."""
return False
@classmethod
def is_fp8_fnuz(cls) -> bool:
"""
Returns whether the preferred FP8 type is FNUZ on the current platform.
"""Returns whether the preferred FP8 type is FNUZ on the current platform.
There are two representations of FP8, OCP FP8 and FNUZ FP8.
The OCP specification can be found at https://tinyurl.com/b7jvwpft.
@@ -1113,8 +1075,7 @@ class Platform:
@classmethod
def fp8_dtype(cls) -> torch.dtype:
"""
Returns the preferred FP8 type on the current platform.
"""Returns the preferred FP8 type on the current platform.
See the documentation for is_fp8_fnuz for details.
"""
@@ -1122,22 +1083,17 @@ class Platform:
@classmethod
def use_all_gather(cls) -> bool:
"""
Whether to use allgather in LogitsProcessor to gather the logits.
"""
"""Whether to use allgather in LogitsProcessor to gather the logits."""
return True
@classmethod
def use_custom_allreduce(cls) -> bool:
"""
Returns if custom allreduce is supported on the current platform
"""
"""Returns if custom allreduce is supported on the current platform."""
return False
@classmethod
def opaque_attention_op(cls) -> bool:
"""
Returns True if we register attention as one giant opaque custom op
"""Returns True if we register attention as one giant opaque custom op
on the current platform
"""
return False
@@ -1148,7 +1104,7 @@ class Platform:
processed_inputs: "EngineInput",
params: "SamplingParams | PoolingParams",
) -> None:
"""Raises if this request is unsupported on this platform"""
"""Raises if this request is unsupported on this platform."""
def __getattr__(self, key: str):
# Pickle checks dunder methods like __getstate__. If we return None
@@ -1172,9 +1128,7 @@ class Platform:
return None
def get_global_graph_pool(self) -> Any:
"""
Return the global graph pool for this platform.
"""
"""Return the global graph pool for this platform."""
cls = self.__class__
if cls._global_graph_pool is None:
cls._global_graph_pool = self.graph_pool_handle()
@@ -1182,9 +1136,7 @@ class Platform:
@classmethod
def get_static_graph_wrapper_cls(cls) -> str:
"""
Get static graph wrapper class for static graph.
"""
"""Get static graph wrapper class for static graph."""
return "vllm.compilation.base_static_graph.AbstractStaticGraphWrapper"
@classmethod
@@ -1196,36 +1148,27 @@ class Platform:
group_size: int,
timeout: timedelta,
) -> "ProcessGroup":
"""
Init platform-specific torch distributed process group.
"""
"""Init platform-specific torch distributed process group."""
raise NotImplementedError
@classmethod
def check_if_supports_dtype(cls, dtype: torch.dtype):
"""
Check if the dtype is supported by the current platform.
"""
"""Check if the dtype is supported by the current platform."""
raise NotImplementedError
@classmethod
def support_hybrid_kv_cache(cls) -> bool:
"""
Returns if the hybrid kv cache is supported by the current platform.
"""
"""Returns if the hybrid kv cache is supported by the current platform."""
return False
@classmethod
def support_static_graph_mode(cls) -> bool:
"""
Returns if the graph mode is supported by the current platform.
"""
"""Returns if the graph mode is supported by the current platform."""
return False
@classmethod
def check_runner_kv_caches_multi_layer(cls) -> None:
"""
Check whether the platform's ModelRunner can handle multiple attention
"""Check whether the platform's ModelRunner can handle multiple attention
layers that share the same layer index (e.g. cross attention and self
attention in the same decoder block of an encoder-decoder model such as
BART).
@@ -1241,15 +1184,12 @@ class Platform:
@classmethod
def support_deep_gemm(cls) -> bool:
"""
Returns if DeepGEMM is supported by the current platform.
"""
"""Returns if DeepGEMM is supported by the current platform."""
return False
@classmethod
def use_custom_op_collectives(cls) -> bool:
"""
Whether this platform should use torch.ops.vllm.* custom ops for collectives.
"""Whether this platform should use torch.ops.vllm.* custom ops for collectives.
Returns False by default - platforms must explicitly opt-in.
"""
@@ -1257,16 +1197,12 @@ class Platform:
@classmethod
def use_sync_weight_loader(cls) -> bool:
"""
Returns if the current platform needs to sync weight loader.
"""
"""Returns if the current platform needs to sync weight loader."""
return False
@classmethod
def make_synced_weight_loader(cls, original_weight_loader):
"""
Wrap the original weight loader to make it synced.
"""
"""Wrap the original weight loader to make it synced."""
if not cls.use_sync_weight_loader():
return original_weight_loader
@@ -1280,37 +1216,29 @@ class Platform:
@classmethod
def get_nixl_supported_devices(cls) -> dict[str, tuple[str, ...]]:
"""
Returns a mapping from device_type to a tuple of supported
"""Returns a mapping from device_type to a tuple of supported
kv_buffer_device for nixl.
"""
return {}
@classmethod
def get_nixl_memory_type(cls) -> str | None:
"""
Returns the nixl memory type for the current platform.
"""
"""Returns the nixl memory type for the current platform."""
return None
@classmethod
def check_max_model_len(cls, max_model_len: int) -> int:
"""
Check max_model_len for the current platform.
"""
"""Check max_model_len for the current platform."""
return max_model_len
@classmethod
def set_additional_forward_context(cls, *args, **kwargs) -> dict[str, Any]:
"""
Set some additional forward context for the current platform if needs.
"""
"""Set some additional forward context for the current platform if needs."""
return {}
@classmethod
def num_compute_units(cls, device_id: int = 0) -> int:
"""
Get the number of compute units for the current platform.
"""Get the number of compute units for the current platform.
(NVIDIA SM / AMD CU / Intel EU)
"""
raise NotImplementedError(
@@ -1329,16 +1257,12 @@ class Platform:
@classmethod
def is_arch_support_pdl(cls) -> bool:
"""
Does the current platform support PDL (Programmatic Dependent Launch)?
"""
"""Does the current platform support PDL (Programmatic Dependent Launch)?"""
return False
@classmethod
def validate_environ(cls, hard_fail: bool) -> None:
"""
Validate environment variables for the current platform.
"""
"""Validate environment variables for the current platform."""
from vllm import envs
for env in os.environ:
+9 -12
View File
@@ -91,7 +91,8 @@ def _rocm_device_count_stateless(cuda_visible_devices: str | None = None) -> int
CUDA_VISIBLE_DEVICES has already been set to the desired value.
# This can be removed and simply replaced with torch.cuda.get_device_count
# after https://github.com/pytorch/pytorch/pull/122815 is released."""
# after https://github.com/pytorch/pytorch/pull/122815 is released.
"""
# Note: cuda_visible_devices is not used, but we keep it as an argument for
# LRU Cache purposes.
@@ -126,7 +127,8 @@ def _get_wsl_kernel_version() -> tuple[int, ...] | None:
def _sync_hip_cuda_env_vars():
"""Ensure HIP_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES are consistent.
Treats empty string as unset. Raises on genuine conflicts."""
Treats empty string as unset. Raises on genuine conflicts.
"""
hip_val = os.environ.get("HIP_VISIBLE_DEVICES") or None
cuda_val = os.environ.get("CUDA_VISIBLE_DEVICES") or None
@@ -187,8 +189,7 @@ def _query_total_memory_from_amdsmi(physical_device_id: int) -> int:
def _get_gcn_arch() -> str:
"""
Get GCN arch via amdsmi (no CUDA init), fallback to torch.cuda.
"""Get GCN arch via amdsmi (no CUDA init), fallback to torch.cuda.
Called once at module level; result stored in _GCN_ARCH.
"""
try:
@@ -223,8 +224,7 @@ _ON_RDNA4 = any(arch in _GCN_ARCH for arch in ["gfx1200", "gfx1201"])
def _capability_from_gcn_arch(gcn_arch: str) -> tuple[int, int] | None:
"""
Parse (major, minor) from a GCN arch string, mirroring how
"""Parse (major, minor) from a GCN arch string, mirroring how
HIP derives hipDeviceProp_t.major / .minor.
Format: gfx<MAJOR><MINOR><STEPPING>
@@ -238,6 +238,7 @@ def _capability_from_gcn_arch(gcn_arch: str) -> tuple[int, int] | None:
Returns None only when the string is not gfx-prefixed at all
(i.e. not a ROCm arch string). Raises on any string that looks
like a GCN arch but does not match a known layout.
"""
m = re.match(r"gfx(\d+)", gcn_arch)
if not m:
@@ -778,9 +779,7 @@ class RocmPlatform(Platform):
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
"""Set the device for the current platform."""
torch.cuda.set_device(device)
@classmethod
@@ -805,9 +804,7 @@ class RocmPlatform(Platform):
@classmethod
@with_amdsmi_context
def is_fully_connected(cls, physical_device_ids: list[int]) -> bool:
"""
Query if the set of gpus are fully connected by xgmi (1 hop)
"""
"""Query if the set of gpus are fully connected by xgmi (1 hop)."""
handles = [amdsmi_get_processor_handles()[i] for i in physical_device_ids]
for i, handle in enumerate(handles):
for j, peer_handle in enumerate(handles):
+3 -5
View File
@@ -31,8 +31,7 @@ logger = init_logger(__name__)
def get_mem_info_wrapper(
device: int | str | torch.device | None = None,
) -> tuple[int, int]:
"""
Get memory info for a device, compatible with torch.accelerator.get_memory_info API.
"""Get memory info for a device, matching `torch.accelerator.get_memory_info`.
Args:
device: Device specification. Can be:
@@ -43,6 +42,7 @@ def get_mem_info_wrapper(
Returns:
Tuple[int, int]: (free_memory, total_memory) in bytes
"""
# Handle None - use current device
if device is None:
@@ -237,9 +237,7 @@ class XPUPlatform(Platform):
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
"""Set the device for the current platform."""
torch.xpu.set_device(device)
@classmethod