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
@@ -79,6 +79,7 @@ class SchedulerInterface(ABC):
|
||||
Returns:
|
||||
A SchedulerOutput object containing information about the scheduled
|
||||
requests.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -105,6 +106,7 @@ class SchedulerInterface(ABC):
|
||||
Returns:
|
||||
A dict of client index to EngineCoreOutputs object containing the
|
||||
outputs for each request originating from that client.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -115,6 +117,7 @@ class SchedulerInterface(ABC):
|
||||
|
||||
Args:
|
||||
draft_token_ids: The input draft token ids for each request.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -129,6 +132,7 @@ class SchedulerInterface(ABC):
|
||||
draft_token_ids: The input draft token ids for each request.
|
||||
scheduler_output: Update the given scheduler_output
|
||||
with the corresponding draft token ids.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -138,6 +142,7 @@ class SchedulerInterface(ABC):
|
||||
|
||||
Args:
|
||||
request: The new request being added.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -162,6 +167,7 @@ class SchedulerInterface(ABC):
|
||||
Returns:
|
||||
List of requests that were aborted. Will not include any that were
|
||||
already finished.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -172,7 +178,8 @@ class SchedulerInterface(ABC):
|
||||
|
||||
def has_unfinished_requests(self) -> bool:
|
||||
"""Returns True if there are unfinished requests in the scheduler's
|
||||
internal queue."""
|
||||
internal queue.
|
||||
"""
|
||||
return self.get_num_unfinished_requests() > 0
|
||||
|
||||
@abstractmethod
|
||||
@@ -192,7 +199,8 @@ class SchedulerInterface(ABC):
|
||||
|
||||
def has_requests(self) -> bool:
|
||||
"""Returns True if there are unfinished requests, or finished requests
|
||||
not yet returned in SchedulerOutputs."""
|
||||
not yet returned in SchedulerOutputs.
|
||||
"""
|
||||
return self.has_unfinished_requests() or self.has_finished_requests()
|
||||
|
||||
@property
|
||||
@@ -218,6 +226,8 @@ class SchedulerInterface(ABC):
|
||||
preempted and moved to the waiting queue. Otherwise, this method
|
||||
will only reset the KV prefix cache when there is no running request
|
||||
taking KV cache.
|
||||
reset_connector: If True, also reset any KV connector state.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ class RequestQueue(ABC):
|
||||
@abstractmethod
|
||||
def prepend_requests(self, requests: "RequestQueue") -> None:
|
||||
"""Prepend all requests from another queue to the front of this
|
||||
queue."""
|
||||
queue.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
@@ -129,8 +130,7 @@ class FCFSRequestQueue(deque[Request], RequestQueue):
|
||||
|
||||
|
||||
class PriorityRequestQueue(RequestQueue):
|
||||
"""
|
||||
A priority queue that supports heap operations.
|
||||
"""A priority queue that supports heap operations.
|
||||
|
||||
Respects the ordering defined in the Request class, where
|
||||
requests with a smaller value of `priority` are processed first.
|
||||
@@ -161,14 +161,16 @@ class PriorityRequestQueue(RequestQueue):
|
||||
"""Add a request to the queue according to priority policy.
|
||||
|
||||
Note: In a priority queue, there is no concept of prepending to the
|
||||
front. Requests are ordered by (priority, arrival_time)."""
|
||||
front. Requests are ordered by (priority, arrival_time).
|
||||
"""
|
||||
self.add_request(request)
|
||||
|
||||
def prepend_requests(self, requests: RequestQueue) -> None:
|
||||
"""Add all requests from another queue according to priority policy.
|
||||
|
||||
Note: In a priority queue, there is no concept of prepending to the
|
||||
front. Requests are ordered by (priority, arrival_time)."""
|
||||
front. Requests are ordered by (priority, arrival_time).
|
||||
"""
|
||||
for request in requests:
|
||||
self.add_request(request)
|
||||
|
||||
|
||||
@@ -1558,12 +1558,10 @@ class Scheduler(SchedulerInterface):
|
||||
def _update_request_as_session(
|
||||
self, session: Request, update: StreamingUpdate
|
||||
) -> None:
|
||||
"""
|
||||
Updates the waiting session with the next streaming update.
|
||||
"""Updates the waiting session with the next streaming update.
|
||||
|
||||
Discards the last sampled output token from the prior input chunk.
|
||||
"""
|
||||
|
||||
# Current streaming input behaviour: Keep only computed output tokens
|
||||
# (discard final sampled output token).
|
||||
num_computed_tokens = session.num_computed_tokens
|
||||
@@ -1665,8 +1663,7 @@ class Scheduler(SchedulerInterface):
|
||||
encoder_compute_budget: int,
|
||||
shift_computed_tokens: int = 0,
|
||||
) -> tuple[list[int], int, int, list[int]]:
|
||||
"""
|
||||
Determine which encoder inputs need to be scheduled in the current step,
|
||||
"""Determine which encoder inputs need to be scheduled in the current step,
|
||||
and update `num_new_tokens` and encoder token budget accordingly.
|
||||
|
||||
An encoder input will be scheduled if:
|
||||
@@ -2507,6 +2504,7 @@ class Scheduler(SchedulerInterface):
|
||||
Returns:
|
||||
List of requests that were aborted. Will not include any that were
|
||||
already finished.
|
||||
|
||||
"""
|
||||
assert RequestStatus.is_finished(finished_status)
|
||||
if isinstance(request_ids, str):
|
||||
@@ -2841,8 +2839,7 @@ class Scheduler(SchedulerInterface):
|
||||
def _connector_finished(
|
||||
self, request: Request
|
||||
) -> tuple[bool, dict[str, Any] | None]:
|
||||
"""
|
||||
Invoke the KV connector request_finished() method if applicable.
|
||||
"""Invoke the KV connector request_finished() method if applicable.
|
||||
|
||||
Returns optional kv transfer parameters to be included with the
|
||||
request outputs.
|
||||
@@ -2910,14 +2907,12 @@ class Scheduler(SchedulerInterface):
|
||||
|
||||
def _inflight_prefill_reserved_blocks(self) -> int:
|
||||
"""Num blocks in-flight prefills still need to finish (their reservation)."""
|
||||
|
||||
return sum(
|
||||
self._request_remaining_blocks(req) for req in self._inflight_prefills
|
||||
)
|
||||
|
||||
def _update_waiting_for_remote_kv(self, request: Request) -> None:
|
||||
"""
|
||||
KV Connector: update request state after async recv is finished.
|
||||
"""KV Connector: update request state after async recv is finished.
|
||||
|
||||
When the kv transfer is ready, we cache the blocks
|
||||
and the request state will be moved back to WAITING from
|
||||
@@ -2959,9 +2954,7 @@ class Scheduler(SchedulerInterface):
|
||||
self.finished_recving_kv_req_ids.remove(request.request_id)
|
||||
|
||||
def _try_promote_blocked_waiting_request(self, request: Request) -> bool:
|
||||
"""
|
||||
Try to promote a blocked waiting request back to schedulable states.
|
||||
"""
|
||||
"""Try to promote a blocked waiting request back to schedulable states."""
|
||||
if request.status == RequestStatus.WAITING_FOR_REMOTE_KVS:
|
||||
# finished_recving_kv_req_ids is populated during
|
||||
# update_from_output(), based on worker-side connector signals
|
||||
@@ -2995,8 +2988,7 @@ class Scheduler(SchedulerInterface):
|
||||
)
|
||||
|
||||
def _update_from_kv_xfer_finished(self, kv_connector_output: KVConnectorOutput):
|
||||
"""
|
||||
KV Connector: update the scheduler state based on the output.
|
||||
"""KV Connector: update the scheduler state based on the output.
|
||||
|
||||
The Worker side connectors add finished_recving and
|
||||
finished_sending reqs to the output.
|
||||
@@ -3004,7 +2996,6 @@ class Scheduler(SchedulerInterface):
|
||||
# if finished_recving: add to state so we can
|
||||
schedule the request during the next step.
|
||||
"""
|
||||
|
||||
if self.connector is not None:
|
||||
self.connector.update_connector_output(kv_connector_output)
|
||||
|
||||
@@ -3030,8 +3021,7 @@ class Scheduler(SchedulerInterface):
|
||||
num_scheduled_tokens: dict[str, int],
|
||||
evict_blocks: bool = True,
|
||||
) -> tuple[set[str], int, set[int]]:
|
||||
"""
|
||||
Identify and update requests affected by invalid KV cache blocks.
|
||||
"""Identify and update requests affected by invalid KV cache blocks.
|
||||
|
||||
This method scans the given requests, detects those with invalid blocks
|
||||
and adjusts their `num_computed_tokens` to the longest valid prefix.
|
||||
@@ -3053,6 +3043,7 @@ class Scheduler(SchedulerInterface):
|
||||
be recomputed across all affected requests.
|
||||
- blocks_to_evict (set[int]): Block IDs to evict from cache,
|
||||
including invalid blocks and downstream dependent blocks.
|
||||
|
||||
"""
|
||||
affected_req_ids: set[str] = set()
|
||||
total_affected_tokens = 0
|
||||
@@ -3145,11 +3136,11 @@ class Scheduler(SchedulerInterface):
|
||||
def _handle_invalid_blocks(
|
||||
self, invalid_block_ids: set[int], num_scheduled_tokens: dict[str, int]
|
||||
) -> set[str]:
|
||||
"""
|
||||
Handle requests affected by invalid KV cache blocks.
|
||||
"""Handle requests affected by invalid KV cache blocks.
|
||||
|
||||
Returns:
|
||||
Set of affected request IDs to skip in update_from_output main loop.
|
||||
|
||||
"""
|
||||
if len(self.kv_cache_config.kv_cache_groups) > 1:
|
||||
# Block IDs are only unique within a group, so a flat set of
|
||||
|
||||
@@ -30,11 +30,14 @@ def check_sequence_repetition(
|
||||
params: RepetitionDetectionParams,
|
||||
) -> bool:
|
||||
"""Check if a sequence of token IDs has a repetition pattern.
|
||||
|
||||
Args:
|
||||
token_ids: List of token IDs
|
||||
params: Repetition detection parameters.
|
||||
|
||||
Returns:
|
||||
True if a repetition pattern is found, False otherwise.
|
||||
|
||||
"""
|
||||
max_pattern_size = params.max_pattern_size
|
||||
min_pattern_size = params.min_pattern_size
|
||||
@@ -77,6 +80,7 @@ def remove_all(lst: list, items_to_remove: set) -> list:
|
||||
Note:
|
||||
For single item removal, this modifies the original list in-place
|
||||
and returns it. For multiple items, it creates and returns a new list.
|
||||
|
||||
"""
|
||||
if not items_to_remove:
|
||||
return lst
|
||||
|
||||
Reference in New Issue
Block a user