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
+16 -14
View File
@@ -98,7 +98,7 @@ class LogitsProcsRequestParams:
self.params = _sampling_params_from_logitproc(logitproc_type)
def __str__(self):
"""For debugging"""
"""For debugging."""
summ = ", ".join(f"{k}={v}" for k, v in vars(self).items())
return f"MyClass({summ})"
@@ -117,7 +117,7 @@ def _generate_fake_sampling_metadata(
vocab_size: int,
device: torch.device,
) -> SamplingMetadata:
"""Generate fake sampling metadata with fake logitsprocs"""
"""Generate fake sampling metadata with fake logitsprocs."""
output_token_ids: list[list[int]] = []
prompt_token_ids: list[list[int]] = []
for _ in range(batch_size):
@@ -176,7 +176,7 @@ def _generate_fake_sampling_metadata(
def _generate_test_fakes(batch_size: int, device: str) -> LogitsprocsTestFakes:
"""Generate fake logits and sampling metadata"""
"""Generate fake logits and sampling metadata."""
fake_logits = create_fake_logits(batch_size, VOCAB_SIZE)
# Create one dominant token per batch, to support min-p test
for i in range(batch_size):
@@ -192,7 +192,7 @@ def _generate_test_fakes(batch_size: int, device: str) -> LogitsprocsTestFakes:
def _sampling_params_from_logitproc(logitproc_type: LogitprocType) -> SamplingParams:
"""Customize request SamplingParams for a specified logitproc"""
"""Customize request SamplingParams for a specified logitproc."""
# SamplingParams for req with no logitproc
kwargs = {"min_p": 0.0, "logit_bias": None, "min_tokens": 0}
if fxn := logitsprocs_test_mapping[logitproc_type].gen_request_fxn:
@@ -220,6 +220,7 @@ def _generate_mixed_logitsprocs_batch_params(
Returns:
List of per-request params which configure the engine for that request's
enabled logitproc
"""
batch_size = len(logitsprocs_types) * reqs_per_logitproc
# Generate multiple repeats of key params for each logitproc;
@@ -251,7 +252,7 @@ def _raise_error_invalid(
def _logit_bias_params(kwargs: dict) -> None:
"""Logit bias config"""
"""Logit bias config."""
kwargs["logit_bias"] = {
random.randint(0, VOCAB_SIZE - 1): random.choice([-0.1, 0.2])
}
@@ -265,7 +266,7 @@ def _logit_bias_validate(
request_params: LogitsProcsRequestParams,
step_idx: int,
) -> None:
"""Validate logit bias logitproc applied correctly"""
"""Validate logit bias logitproc applied correctly."""
logit_bias = request_params.params.logit_bias
logits_old = test_fakes.logits[persistent_batch[batch_index].workload_index].cpu()
logits_new = logits_new[batch_index].cpu()
@@ -301,7 +302,7 @@ def _logit_bias_validate(
def _min_p_params(kwargs: dict) -> None:
"""Min-p logitproc config"""
"""Min-p logitproc config."""
kwargs["min_p"] = 0.1
@@ -313,7 +314,7 @@ def _min_p_validate(
request_params: LogitsProcsRequestParams,
step_idx: int,
) -> None:
"""Validate min-p logitproc applied correctly"""
"""Validate min-p logitproc applied correctly."""
for token_id in range(VOCAB_SIZE):
logits_for_token = logits_new[batch_index][token_id]
if token_id == 0:
@@ -347,7 +348,7 @@ def _min_p_validate(
def _min_tokens_params(kwargs: dict) -> None:
"""Min-tokens logitproc config"""
"""Min-tokens logitproc config."""
kwargs["min_tokens"] = MIN_TOKENS_LEN_THRESHOLD
kwargs["stop_token_ids"] = [
np.random.randint(0, VOCAB_SIZE - 1)
@@ -363,7 +364,7 @@ def _min_tokens_validate(
request_params: LogitsProcsRequestParams,
step_idx: int,
) -> None:
"""Validate min-tokens logitsproc applied correctly"""
"""Validate min-tokens logitsproc applied correctly."""
ref_num_out_tokens = len(request_params.out_tokens)
min_reached = ref_num_out_tokens >= MIN_TOKENS_LEN_THRESHOLD
ref_all_stop_token_ids = request_params.params.all_stop_token_ids
@@ -560,7 +561,7 @@ def test_min_tokens_restores_all_masked_structured_output_stop_token_spec_decode
def _thinking_budget_params(kwargs: dict) -> None:
"""Set SamplingParams kwargs for thinking token budget tests"""
"""Set SamplingParams kwargs for thinking token budget tests."""
kwargs["thinking_token_budget"] = THINKING_TOKEN_BUDGET
@@ -661,7 +662,7 @@ def _none_validate(
request_params: LogitsProcsRequestParams,
step_idx: int,
) -> None:
"""Validate that no logits processors are applied"""
"""Validate that no logits processors are applied."""
logits = test_fakes.logits[persistent_batch[batch_index].workload_index].cpu()
ref_logits = logits_new[batch_index]
if not torch.all(ref_logits == logits):
@@ -706,7 +707,7 @@ logitsprocs_test_mapping = {
def _get_test_cases() -> list[list[str]]:
"""Each test case is a set of logitsprocs"""
"""Each test case is a set of logitsprocs."""
logitsprocs_types = list(logitsprocs_test_mapping.keys())
# Isolate thinking-budget handling from other processors to avoid cross-talk.
@@ -1343,7 +1344,8 @@ def test_thinking_budget_invalid_budget_rejected(invalid_budget):
def test_thinking_budget_long_thinking_section_end_marker_found_at_correct_index():
"""Test thinking budget enforced for a long thinking run,
then a natural end marker."""
then a natural end marker.
"""
h = ThinkingBudgetStateHolder(
MockReasoningConfig(), 8, 0, torch.device("cpu"), False
)
@@ -86,8 +86,8 @@ def _run_test(kwargs: dict, logitproc_loaded: bool) -> None:
Args:
kwargs: `LLM` constructor kwargs
logitproc_loaded: server has loaded dummy logitproc if True
"""
"""
# Create a vLLM instance and load custom logitproc
llm_logitproc = LLM(
model=MODEL_NAME,
@@ -131,7 +131,7 @@ def _run_test(kwargs: dict, logitproc_loaded: bool) -> None:
@create_new_process_for_each_test()
@pytest.mark.parametrize("logitproc_source", list(CustomLogitprocSource))
def test_custom_logitsprocs(monkeypatch, logitproc_source: CustomLogitprocSource):
"""Test offline Python interface for passing custom logitsprocs
"""Test offline Python interface for passing custom logitsprocs.
Construct an `LLM` instance which loads a custom logitproc that has a
well-defined behavior (mask out all tokens except one `target_token`)
@@ -158,8 +158,8 @@ def test_custom_logitsprocs(monkeypatch, logitproc_source: CustomLogitprocSource
logitproc_source: what source (entrypoint, fully-qualified class name
(FQCN), class object, or None) the user pulls the
logitproc from
"""
"""
# Test that logitproc info is passed to workers
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "1")
set_random_seed(40)
@@ -192,7 +192,7 @@ def test_custom_logitsprocs(monkeypatch, logitproc_source: CustomLogitprocSource
@create_new_process_for_each_test()
def test_custom_logitsprocs_req(monkeypatch):
"""Test passing request-level logits processor to offline Python interface
"""Test passing request-level logits processor to offline Python interface.
Wrap a request-level logits processor to create a batch level logits
processor that has a well-defined behavior (mask out all tokens except one
@@ -213,8 +213,8 @@ def test_custom_logitsprocs_req(monkeypatch):
Args:
monkeypatch: for setting env vars
"""
"""
# Test that logitproc info is passed to workers
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "1")
set_random_seed(40)
@@ -258,6 +258,7 @@ def test_rejects_custom_logitsprocs(
logitproc_source: what source (entrypoint, fully-qualified class name
(FQCN), or class object) the user pulls the
logitproc from
"""
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0")
set_random_seed(40)
@@ -77,7 +77,6 @@ def server(default_server_args, request, monkeypatch):
(2) No --logits-processors cli arg; inject a dummy logits processor
entrypoint
"""
# Test that logitproc info is passed to workers
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "1")
@@ -118,7 +117,7 @@ api_keyword_args = {
[MODEL_NAME],
)
def test_custom_logitsprocs(server, model_name: str):
"""Test custom logitsprocs when starting OpenAI server from CLI
"""Test custom logitsprocs when starting OpenAI server from CLI.
Launch vLLM OpenAI-compatible server, configured to load a custom logitproc
that has a well-defined behavior (mask out all tokens except one
@@ -130,7 +129,6 @@ def test_custom_logitsprocs(server, model_name: str):
Validate that requests which activate the custom logitproc, repeat the same
token
"""
import asyncio
async def _async_main(srv, mn):
@@ -180,8 +178,7 @@ def test_custom_logitsprocs(server, model_name: str):
async def test_invalid_custom_logitsproc_arg(
client: openai.AsyncOpenAI, model_name: str
):
"""Test that request with invalid custom logitsproc is rejected"""
"""Test that request with invalid custom logitsproc is rejected."""
prompt = "Hello, my name is"
# Pass invalid (non-int) target_token value to dummy logits processor
request_keyword_args: dict[str, Any] = {
+11 -8
View File
@@ -37,7 +37,7 @@ DUMMY_LOGITPROC_FQCN = f"{DUMMY_LOGITPROC_MODULE}:DummyLogitsProcessor"
class CustomLogitprocSource(Enum):
"""How to source a logitproc for testing purposes"""
"""How to source a logitproc for testing purposes."""
LOGITPROC_SOURCE_NONE = auto() # No custom logitproc
LOGITPROC_SOURCE_ENTRYPOINT = auto() # Via entrypoint
@@ -55,7 +55,7 @@ prompts = [
class DummyLogitsProcessor(LogitsProcessor):
"""Fake logit processor to support unit testing and examples"""
"""Fake logit processor to support unit testing and examples."""
@classmethod
def validate_params(cls, params: SamplingParams):
@@ -73,7 +73,7 @@ class DummyLogitsProcessor(LogitsProcessor):
self.req_info: dict[int, int] = {}
def is_argmax_invariant(self) -> bool:
"""Never impacts greedy sampling"""
"""Never impacts greedy sampling."""
return False
def update_state(self, batch_update: BatchUpdate | None):
@@ -115,7 +115,7 @@ class DummyLogitsProcessor(LogitsProcessor):
class EntryPoint:
"""Dummy entrypoint class for logitsprocs testing"""
"""Dummy entrypoint class for logitsprocs testing."""
def __init__(self):
self.name = DUMMY_LOGITPROC_ENTRYPOINT
@@ -126,7 +126,7 @@ class EntryPoint:
class EntryPoints(list):
"""Dummy EntryPoints class for logitsprocs testing"""
"""Dummy EntryPoints class for logitsprocs testing."""
def __init__(self, group: str):
# Emulate list-like functionality
@@ -138,10 +138,11 @@ class EntryPoints(list):
class DummyPerReqLogitsProcessor:
"""The request-level logits processor masks out all logits except the
token id identified by `target_token`"""
token id identified by `target_token`
"""
def __init__(self, target_token: int) -> None:
"""Specify `target_token`"""
"""Specify `target_token`."""
self.target_token = target_token
def __call__(
@@ -157,7 +158,8 @@ class DummyPerReqLogitsProcessor:
class WrappedPerReqLogitsProcessor(AdapterLogitsProcessor):
"""Example of wrapping a fake request-level logit processor to create a
batch-level logits processor"""
batch-level logits processor
"""
def is_argmax_invariant(self) -> bool:
return False
@@ -178,6 +180,7 @@ class WrappedPerReqLogitsProcessor(AdapterLogitsProcessor):
Returns:
`Callable` request logits processor, or None
"""
target_token: Any | None = params.extra_args and params.extra_args.get(
"target_token"