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
@@ -9,8 +9,7 @@ from vllm.platforms import current_platform
|
||||
|
||||
@torch.compile(backend=current_platform.simple_compile_backend)
|
||||
def batched_count_greater_than(x: torch.Tensor, values: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
Counts elements in each row of x that are greater than the corresponding
|
||||
"""Counts elements in each row of x that are greater than the corresponding
|
||||
value in values. Use torch.compile to generate an optimized kernel for
|
||||
this function. otherwise, it will create additional copies of the input
|
||||
tensors and cause memory issues.
|
||||
@@ -21,6 +20,7 @@ def batched_count_greater_than(x: torch.Tensor, values: torch.Tensor) -> torch.T
|
||||
|
||||
Returns:
|
||||
torch.Tensor: A 1D tensor of shape (batch_size,) with the counts.
|
||||
|
||||
"""
|
||||
torch._check(x.shape[0] >= 1)
|
||||
torch._check(x.shape[0] == values.shape[0])
|
||||
|
||||
@@ -15,9 +15,7 @@ def apply_all_penalties(
|
||||
repetition_penalties: torch.Tensor,
|
||||
output_token_ids: list[list[int]],
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Applies presence, frequency and repetition penalties to the logits.
|
||||
"""
|
||||
"""Applies presence, frequency and repetition penalties to the logits."""
|
||||
_, vocab_size = logits.shape
|
||||
output_tokens_t = _convert_to_tensors(output_token_ids, vocab_size, logits.device)
|
||||
|
||||
@@ -41,9 +39,7 @@ def apply_all_penalties(
|
||||
def _convert_to_tensors(
|
||||
output_token_ids: list[list[int]], vocab_size: int, device: torch.device
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Convert the different list data structures to tensors.
|
||||
"""
|
||||
"""Convert the different list data structures to tensors."""
|
||||
output_tokens_tensor = make_tensor_with_pad(
|
||||
output_token_ids,
|
||||
# Use the value of vocab_size as a pad since we don't have a
|
||||
|
||||
@@ -91,8 +91,7 @@ def flashinfer_sampler_supported() -> bool:
|
||||
|
||||
|
||||
class TopKTopPSampler(nn.Module):
|
||||
"""
|
||||
Module that performs optional top-k and top-p filtering followed by
|
||||
"""Module that performs optional top-k and top-p filtering followed by
|
||||
weighted random sampling of logits.
|
||||
|
||||
Implementations may update the logits tensor in-place.
|
||||
@@ -154,8 +153,7 @@ class TopKTopPSampler(nn.Module):
|
||||
k: torch.Tensor | None,
|
||||
p: torch.Tensor | None,
|
||||
) -> tuple[torch.Tensor, torch.Tensor | None]:
|
||||
"""
|
||||
PyTorch-native implementation of top-k and top-p sampling.
|
||||
"""PyTorch-native implementation of top-k and top-p sampling.
|
||||
|
||||
The logits tensor may be updated in-place.
|
||||
"""
|
||||
@@ -207,8 +205,7 @@ class TopKTopPSampler(nn.Module):
|
||||
k: torch.Tensor | None,
|
||||
p: torch.Tensor | None,
|
||||
) -> tuple[torch.Tensor, torch.Tensor | None]:
|
||||
"""
|
||||
PyTorch-native implementation of top-k and top-p sampling for CPU.
|
||||
"""PyTorch-native implementation of top-k and top-p sampling for CPU.
|
||||
|
||||
The logits tensor may be updated in-place.
|
||||
"""
|
||||
@@ -423,8 +420,7 @@ def apply_top_k_top_p_pytorch(
|
||||
|
||||
|
||||
def apply_top_k_only(logits: torch.Tensor, k: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
Apply top-k mask to the logits.
|
||||
"""Apply top-k mask to the logits.
|
||||
|
||||
This implementation doesn't involve sorting the entire vocab.
|
||||
Note however that it involves a GPU->CPU sync which can be detrimental for
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Combined Top-K and Top-P Triton kernels.
|
||||
"""Combined Top-K and Top-P Triton kernels.
|
||||
|
||||
Based on the paper "Qrita: High-performance Top-k and Top-p Algorithm for GPUs
|
||||
using Pivot-based Truncation and Selection" By Park et al.
|
||||
@@ -1617,8 +1616,7 @@ def apply_top_k_top_p_triton(
|
||||
p: torch.Tensor | None,
|
||||
mask_value: float = float("-inf"),
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Apply combined top-k and top-p masking using Triton.
|
||||
"""Apply combined top-k and top-p masking using Triton.
|
||||
|
||||
Top-k is applied first (by logit value), then top-p is applied
|
||||
to the remaining k values (by probability).
|
||||
@@ -1634,6 +1632,7 @@ def apply_top_k_top_p_triton(
|
||||
|
||||
Returns:
|
||||
The masked logits tensor. It may or may not be modified in-place.
|
||||
|
||||
"""
|
||||
assert logits.ndim == 2
|
||||
assert logits.dtype == torch.float32
|
||||
|
||||
Reference in New Issue
Block a user