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
+14 -12
View File
@@ -54,7 +54,8 @@ def create_logits_tensor(
token_idx_to_override: int | None = None,
) -> torch.Tensor:
"""Helper function to create logits tensor that
will produce desired token ids on argmax"""
will produce desired token ids on argmax
"""
token_ids = [tokens[:-1] for tokens in output_token_ids]
num_total_tokens = sum(len(tokens) for tokens in token_ids)
logits = torch.full((num_total_tokens, vocab_size), -100.0, device=DEVICE_TYPE)
@@ -131,7 +132,7 @@ def create_sampling_metadata(
########################### Tests for Greedy Sampling ###################
def test_perfect_match(rejection_sampler):
"""Test when output tokens perfectly match speculated tokens"""
"""Test when output tokens perfectly match speculated tokens."""
spec_tokens = [[1, 2, 3]]
output_tokens = [[1, 2, 3, 4]] # 4 is the bonus token
@@ -152,7 +153,7 @@ def test_perfect_match(rejection_sampler):
def test_early_mismatch(rejection_sampler):
"""Test when there's an early mismatch in tokens"""
"""Test when there's an early mismatch in tokens."""
spec_tokens = [[1, 2, 3]]
output_tokens = [[1, 5, 3, 4]] # Mismatch at position 1
@@ -177,7 +178,7 @@ def test_early_mismatch(rejection_sampler):
def test_multiple_sequences(rejection_sampler):
"""Test handling multiple sequences of speculated tokens"""
"""Test handling multiple sequences of speculated tokens."""
spec_tokens = [[1, 2], [3]]
output_tokens = [[1, 2, 5], [3, 4]] # Two sequences with bonus tokens 5 and 4
@@ -202,7 +203,7 @@ def test_multiple_sequences(rejection_sampler):
def test_single_token_sequence(rejection_sampler):
"""Test handling sequences with single token"""
"""Test handling sequences with single token."""
spec_tokens = [[1]]
output_tokens = [[1, 2]] # Single token with bonus token 2
@@ -223,7 +224,7 @@ def test_single_token_sequence(rejection_sampler):
def test_empty_sequence(rejection_sampler):
"""Test handling empty sequence of speculated tokens"""
"""Test handling empty sequence of speculated tokens."""
spec_tokens: list[list[int]] = [[]]
output_tokens = [[5]] # Just the bonus token
@@ -244,7 +245,7 @@ def test_empty_sequence(rejection_sampler):
def test_multiple_mismatches(rejection_sampler):
"""Test handling multiple sequences with mismatches"""
"""Test handling multiple sequences with mismatches."""
spec_tokens = [[1, 2, 3], [4, 5, 6]]
output_tokens = [[1, 2, 7, 6], [4, 8, 6, 9]] # Mismatches in both sequences
@@ -286,7 +287,7 @@ def test_multiple_mismatches(rejection_sampler):
],
)
def test_parametrized_cases(rejection_sampler, spec_tokens, output_tokens, expected):
"""Parametrized test for various matching scenarios"""
"""Parametrized test for various matching scenarios."""
metadata = create_sampling_metadata(all_greedy=True)
logits = create_logits_tensor(output_tokens)
bonus_token_tensor = torch.tensor(
@@ -486,6 +487,7 @@ def estimate_rejection_sampling_pdf(
Returns:
Estimated probability distribution of the output tokens.
"""
mock_sampler = Mock(spec=Sampler)
mock_sampler.logprobs_mode = "raw_logprobs"
@@ -656,7 +658,7 @@ def _test_masked_logits(
@pytest.mark.parametrize("top_k", [1, 5, 99])
def test_top_k(rejection_sampler, top_k):
"""Test rejection sampling with top-k sampling"""
"""Test rejection sampling with top-k sampling."""
vocab_size = 100
batch_size = 100
num_draft_tokens = 3
@@ -699,7 +701,7 @@ def test_top_k(rejection_sampler, top_k):
@pytest.mark.parametrize("top_p", [0.5, 0.9, 0.99])
def test_top_p(rejection_sampler, top_p):
"""Test rejection sampling with top-p sampling"""
"""Test rejection sampling with top-p sampling."""
vocab_size = 100
batch_size = 100
num_draft_tokens = 3
@@ -746,7 +748,7 @@ def test_top_p(rejection_sampler, top_p):
########################### Tests for Logit Processors ###################
def test_frequency_penalties(rejection_sampler):
"""Test rejection sampling with frequency penalties"""
"""Test rejection sampling with frequency penalties."""
spec_tokens = [[1, 1, 1], [], [1, 1, 1]]
output_tokens = [[1, 1, 1, 1], [7], [1, 1, 1, 1]] # 1, 7 and 1 are the bonus tokens
@@ -829,7 +831,7 @@ def test_bad_words(rejection_sampler):
def test_allowed_token_ids(rejection_sampler):
"""Test rejection sampling with allowed token ids"""
"""Test rejection sampling with allowed token ids."""
spec_tokens = [[1, 2, 10], [10, 5, 3], [7, 10, 12]]
output_tokens = [[1, 2, 10, 5], [10, 5, 10, 5], [7, 10, 12, 5]]
# Not allowed tokens: