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
@@ -36,7 +36,7 @@ FailureCallback = Callable[[], None]
|
||||
|
||||
|
||||
class Executor(ABC):
|
||||
"""Abstract base class for vLLM executors."
|
||||
"""Abstract base class for vLLM executors.
|
||||
|
||||
An executor is responsible for executing the model on one device,
|
||||
or it can be a distributed executor that can execute the model on multiple devices.
|
||||
@@ -139,8 +139,7 @@ class Executor(ABC):
|
||||
)
|
||||
|
||||
def register_failure_callback(self, callback: FailureCallback): # noqa: B027
|
||||
"""
|
||||
Register a function to be called if the executor enters a permanent
|
||||
"""Register a function to be called if the executor enters a permanent
|
||||
failed state.
|
||||
"""
|
||||
pass
|
||||
@@ -168,8 +167,29 @@ class Executor(ABC):
|
||||
kwargs: dict | None = None,
|
||||
non_block: Literal[False] = False,
|
||||
) -> list[_R]:
|
||||
"""
|
||||
Execute an RPC call on all workers.
|
||||
pass
|
||||
|
||||
@overload
|
||||
def collective_rpc(
|
||||
self,
|
||||
method: str | Callable[[WorkerBase], _R],
|
||||
timeout: float | None = None,
|
||||
args: tuple = (),
|
||||
kwargs: dict | None = None,
|
||||
non_block: Literal[True] = True,
|
||||
) -> Future[list[_R]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def collective_rpc(
|
||||
self,
|
||||
method: str | Callable[[WorkerBase], _R],
|
||||
timeout: float | None = None,
|
||||
args: tuple = (),
|
||||
kwargs: dict | None = None,
|
||||
non_block: bool = False,
|
||||
) -> list[_R] | Future[list[_R]]:
|
||||
"""Execute an RPC call on all workers.
|
||||
|
||||
Args:
|
||||
method: Name of the worker method to execute, or a callable that
|
||||
@@ -191,24 +211,8 @@ class Executor(ABC):
|
||||
Note:
|
||||
It is recommended to use this API to only pass control messages,
|
||||
and set up data-plane communication to pass data.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
@overload
|
||||
def collective_rpc(
|
||||
self,
|
||||
method: str | Callable[[WorkerBase], _R],
|
||||
timeout: float | None = None,
|
||||
args: tuple = (),
|
||||
kwargs: dict | None = None,
|
||||
non_block: Literal[True] = True,
|
||||
) -> Future[list[_R]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def collective_rpc(
|
||||
self, method, timeout=None, args=(), kwargs=None, non_block: bool = False
|
||||
):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_kv_connector_handshake_metadata(
|
||||
@@ -280,7 +284,8 @@ class Executor(ABC):
|
||||
@abstractmethod
|
||||
def check_health(self) -> None:
|
||||
"""Checks if the executor is healthy. If not, it should raise an
|
||||
exception."""
|
||||
exception.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def shutdown(self) -> None:
|
||||
@@ -288,7 +293,7 @@ class Executor(ABC):
|
||||
self.collective_rpc("shutdown")
|
||||
|
||||
def init_kv_output_aggregator(self, connector: "KVConnectorBase") -> None:
|
||||
"""Init KVOutputAggregator"""
|
||||
"""Init KVOutputAggregator."""
|
||||
self.kv_output_aggregator = KVOutputAggregator.from_connector(
|
||||
connector, self.parallel_config.world_size
|
||||
)
|
||||
@@ -381,9 +386,7 @@ class Executor(ABC):
|
||||
|
||||
@classmethod
|
||||
def supports_async_scheduling(cls) -> bool:
|
||||
"""
|
||||
Whether the executor supports async scheduling.
|
||||
"""
|
||||
"""Whether the executor supports async scheduling."""
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -384,7 +384,8 @@ class MultiprocExecutor(Executor):
|
||||
ec_output_aggregator: ECOutputAggregator | None = None,
|
||||
) -> Any:
|
||||
"""Returns single result if unique_reply_rank and/or an output
|
||||
aggregator is provided, otherwise list."""
|
||||
aggregator is provided, otherwise list.
|
||||
"""
|
||||
assert self.rpc_broadcast_mq is not None, (
|
||||
"collective_rpc should not be called on follower node"
|
||||
)
|
||||
@@ -451,7 +452,8 @@ class MultiprocExecutor(Executor):
|
||||
def _ensure_worker_termination(worker_procs: list[BaseProcess]):
|
||||
"""Ensure that all worker processes are terminated. Assumes workers have
|
||||
received termination requests. Waits for processing, then sends
|
||||
termination and kill signals if needed."""
|
||||
termination and kill signals if needed.
|
||||
"""
|
||||
|
||||
def wait_for_termination(procs, timeout):
|
||||
if not time:
|
||||
@@ -500,7 +502,7 @@ class MultiprocExecutor(Executor):
|
||||
p.kill()
|
||||
|
||||
def shutdown(self):
|
||||
"""Properly shut down the executor and its workers"""
|
||||
"""Properly shut down the executor and its workers."""
|
||||
if not getattr(self, "shutting_down", False):
|
||||
worker_count = len(getattr(self, "workers", None) or [])
|
||||
logger.debug(
|
||||
@@ -852,8 +854,8 @@ class WorkerProc:
|
||||
@staticmethod
|
||||
def worker_main(*args, **kwargs):
|
||||
"""Worker initialization and execution loops.
|
||||
This runs a background process"""
|
||||
|
||||
This runs a background process
|
||||
"""
|
||||
# Signal handler used for graceful termination.
|
||||
# SystemExit exception is only raised once to allow this and worker
|
||||
# processes to terminate without error
|
||||
@@ -1010,7 +1012,6 @@ class WorkerProc:
|
||||
|
||||
def async_output_busy_loop(self):
|
||||
"""Entrypoint for the thread which handles outputs asynchronously."""
|
||||
|
||||
# set device to the worker device for the thread.
|
||||
# a thread will not inherit the context of the main thread.
|
||||
# when calling any cuda runtime functions, it will implicitly
|
||||
@@ -1027,7 +1028,7 @@ class WorkerProc:
|
||||
self.enqueue_output(output)
|
||||
|
||||
def worker_busy_loop(self):
|
||||
"""Main busy loop for Multiprocessing Workers"""
|
||||
"""Main busy loop for Multiprocessing Workers."""
|
||||
assert self.rpc_broadcast_mq is not None
|
||||
while True:
|
||||
self._execute_worker_rpc(self.rpc_broadcast_mq.dequeue(indefinite=True))
|
||||
@@ -1098,8 +1099,8 @@ class WorkerProc:
|
||||
def set_multiprocessing_worker_envs(local_world_size: int = 1):
|
||||
"""Set up environment variables that should be used when there are workers
|
||||
in a multiprocessing environment. This should be called by the parent
|
||||
process before worker processes are created"""
|
||||
|
||||
process before worker processes are created
|
||||
"""
|
||||
_maybe_force_spawn()
|
||||
|
||||
if current_platform.is_cpu() or "OMP_NUM_THREADS" in os.environ:
|
||||
|
||||
@@ -52,8 +52,7 @@ COMPLETED_NONE_FUTURE.set_result(None)
|
||||
|
||||
@dataclass
|
||||
class RayWorkerMetaData:
|
||||
"""
|
||||
Metadata for a Ray worker.
|
||||
"""Metadata for a Ray worker.
|
||||
The order of ray worker creation can be random,
|
||||
and we need to reset the rank after creating all workers.
|
||||
"""
|
||||
@@ -65,7 +64,7 @@ class RayWorkerMetaData:
|
||||
|
||||
|
||||
class RayDistributedExecutor(Executor):
|
||||
"""Ray-based distributed executor"""
|
||||
"""Ray-based distributed executor."""
|
||||
|
||||
uses_ray: bool = True
|
||||
supports_pp: bool = True
|
||||
@@ -249,8 +248,7 @@ class RayDistributedExecutor(Executor):
|
||||
ip_counts[ip] = ip_counts.get(ip, 0) + 1
|
||||
|
||||
def sort_by_driver_then_worker_ip(item: RayWorkerMetaData):
|
||||
"""
|
||||
Sort the workers based on 3 properties:
|
||||
"""Sort the workers based on 3 properties:
|
||||
1. If the worker is on the same node as the driver (vllm engine),
|
||||
it should be placed first.
|
||||
2. Then, if the worker is on a node with fewer workers, it should
|
||||
@@ -439,6 +437,7 @@ class RayDistributedExecutor(Executor):
|
||||
|
||||
Returns:
|
||||
The model runner output.
|
||||
|
||||
"""
|
||||
scheduler_output = self.scheduler_output
|
||||
if scheduler_output is None:
|
||||
|
||||
@@ -72,7 +72,7 @@ class RayWorkerHandle:
|
||||
"""run() ObjectRef used as a sentinel for health monitoring"""
|
||||
|
||||
def run(self):
|
||||
"""Start the worker's busy loop"""
|
||||
"""Start the worker's busy loop."""
|
||||
self.run_ref = self.actor.run.remote()
|
||||
|
||||
|
||||
@@ -190,8 +190,7 @@ class RayWorkerProc(WorkerProc):
|
||||
def _init_message_queues(
|
||||
self, input_shm_handle: Handle, vllm_config: VllmConfig
|
||||
) -> None:
|
||||
"""
|
||||
Workers on the same node as the executor use shared memory for
|
||||
"""Workers on the same node as the executor use shared memory for
|
||||
both the broadcast (input) MQ and the response MQ. Workers on
|
||||
different nodes use TCP (n_local_reader=0).
|
||||
"""
|
||||
|
||||
@@ -55,7 +55,8 @@ try:
|
||||
|
||||
class RayWorkerWrapper(WorkerWrapperBase):
|
||||
"""Ray wrapper for vllm.worker.Worker, allowing Worker to be
|
||||
lazily initialized after Ray sets CUDA_VISIBLE_DEVICES."""
|
||||
lazily initialized after Ray sets CUDA_VISIBLE_DEVICES.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -68,8 +69,7 @@ try:
|
||||
rpc_rank: int
|
||||
|
||||
def adjust_rank(self, rank_mapping: dict[int, int]) -> None:
|
||||
"""
|
||||
Adjust the rpc_rank based on the given mapping.
|
||||
"""Adjust the rpc_rank based on the given mapping.
|
||||
It is only used during the initialization of the executor,
|
||||
to adjust the rpc_rank of workers after we create all workers.
|
||||
"""
|
||||
@@ -363,8 +363,7 @@ def get_bundles_for_indices(
|
||||
bundle_indices: list[int],
|
||||
world_size: int,
|
||||
) -> list[tuple[int, str, str]]:
|
||||
"""
|
||||
Return GPU bundle indices paired with node IDs and node IPs for
|
||||
"""Return GPU bundle indices paired with node IDs and node IPs for
|
||||
explicit bundle indices specified via VLLM_RAY_BUNDLE_INDICES.
|
||||
"""
|
||||
assert len(bundle_indices) == world_size, (
|
||||
@@ -391,8 +390,7 @@ def get_bundles_for_indices(
|
||||
def get_bundles_sorted_by_node(
|
||||
placement_group: "PlacementGroup",
|
||||
) -> list[tuple[int, str, str]]:
|
||||
"""
|
||||
Return GPU bundle indices paired with node IDs and node IPs,
|
||||
"""Return GPU bundle indices paired with node IDs and node IPs,
|
||||
sorted driver-first.
|
||||
|
||||
This utility has to be invoked from the driver node.
|
||||
@@ -533,6 +531,7 @@ def initialize_ray_cluster(
|
||||
on the current (driver) node and pin the first PG bundle to it.
|
||||
Set to False for executors like RayExecutorV2 where all GPU work
|
||||
is delegated to remote Ray actors.
|
||||
|
||||
"""
|
||||
assert_ray_available()
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
Reference in New Issue
Block a user