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
@@ -33,7 +33,6 @@ def should_do_global_cleanup_after_test(request) -> bool:
|
||||
This can provide a ~10x speedup for non-GPU unit tests since they don't need
|
||||
to initialize torch.
|
||||
"""
|
||||
|
||||
return not request.node.get_closest_marker("skip_global_cleanup")
|
||||
|
||||
|
||||
@@ -367,8 +366,7 @@ def qwen36_moe_3d_lora_files():
|
||||
|
||||
@pytest.fixture
|
||||
def reset_default_device():
|
||||
"""
|
||||
Some tests, such as `test_punica_ops.py`, explicitly set the
|
||||
"""Some tests, such as `test_punica_ops.py`, explicitly set the
|
||||
default device, which can affect subsequent tests. Adding this fixture
|
||||
helps avoid this problem.
|
||||
"""
|
||||
|
||||
@@ -55,8 +55,7 @@ async def requests_processing_time(llm, lora_requests: list[LoRARequest]) -> flo
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_lora(chatglm3_lora_files):
|
||||
"""
|
||||
The add_lora function is used to preload some LoRA adapters into the
|
||||
"""The add_lora function is used to preload some LoRA adapters into the
|
||||
engine in anticipation of future requests using these adapters. To test
|
||||
this functionality, we use the async engine to process some requests - We
|
||||
do it twice, once with add_lora() preloading and once without.
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Tests for applying default registered multimodal loras.
|
||||
"""
|
||||
"""Tests for applying default registered multimodal loras."""
|
||||
|
||||
import os
|
||||
import unittest.mock as mock
|
||||
@@ -134,7 +132,8 @@ def test_default_mm_lora_fails_with_overridden_lora_request(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
"""Ensure that if the lora_request conflicts with default_mm_loras,
|
||||
we use the lora_request."""
|
||||
we use the lora_request.
|
||||
"""
|
||||
run_test(
|
||||
vllm_runner,
|
||||
audio_assets,
|
||||
|
||||
@@ -41,8 +41,7 @@ def CEILDIV(x, y):
|
||||
|
||||
|
||||
def assign_loras_to_tokens(num_tokens: int, num_sequences: int, max_loras: int):
|
||||
"""
|
||||
Split `num_tokens` into `num_sequences` sequences.
|
||||
"""Split `num_tokens` into `num_sequences` sequences.
|
||||
Each sequence randomly selects 1 LoRA index from [0, max_loras),
|
||||
and all tokens in that sequence are assigned this LoRA index.
|
||||
|
||||
@@ -54,6 +53,7 @@ def assign_loras_to_tokens(num_tokens: int, num_sequences: int, max_loras: int):
|
||||
Returns:
|
||||
torch.Tensor: 1D tensor of shape [num_tokens], where each value
|
||||
is the LoRA index assigned to that token.
|
||||
|
||||
"""
|
||||
assert num_sequences > 0 and max_loras > 0
|
||||
assert num_tokens >= num_sequences, "num_tokens must be >= num_sequences"
|
||||
@@ -81,9 +81,8 @@ def assign_loras_to_tokens(num_tokens: int, num_sequences: int, max_loras: int):
|
||||
|
||||
|
||||
def assign_experts_to_tokens(num_tokens: int, num_experts: int, top_k_num: int):
|
||||
"""
|
||||
For each token, randomly select `top_k_num` distinct experts out of `num_experts`,
|
||||
and assign normalized random weights that sum to 1.
|
||||
"""For each token, randomly select `top_k_num` distinct experts out of
|
||||
`num_experts`, and assign normalized random weights that sum to 1.
|
||||
|
||||
Args:
|
||||
num_tokens (int): Total number of tokens.
|
||||
@@ -95,6 +94,7 @@ def assign_experts_to_tokens(num_tokens: int, num_experts: int, top_k_num: int):
|
||||
expert index for each token.
|
||||
expert_weights (torch.Tensor): shape [num_tokens, top_k_num],
|
||||
normalized weights (sum = 1 per row).
|
||||
|
||||
"""
|
||||
assert top_k_num <= num_experts, "top_k_num must be <= num_experts"
|
||||
|
||||
@@ -379,8 +379,7 @@ def use_fused_moe_lora_kernel_naive(
|
||||
offset=0,
|
||||
add_inputs=True,
|
||||
):
|
||||
"""
|
||||
Test helper for naive_block_assignment path.
|
||||
"""Test helper for naive_block_assignment path.
|
||||
Skips moe_lora_align_block_size and uses flattened topk_ids as expert_ids.
|
||||
"""
|
||||
config = {
|
||||
@@ -472,8 +471,7 @@ def test_fused_moe_lora_kernel_naive_block_assignment(
|
||||
device,
|
||||
seed,
|
||||
):
|
||||
"""
|
||||
Test the naive_block_assignment path of the fused_moe_lora kernel.
|
||||
"""Test the naive_block_assignment path of the fused_moe_lora kernel.
|
||||
This path is triggered when batch_size * top_k is much smaller than
|
||||
num_experts * max_loras, and skips the moe_lora_align_block_size kernel.
|
||||
"""
|
||||
@@ -1125,7 +1123,8 @@ def test_fused_moe_lora_kernel_one_shot_early_exit(trigger, device):
|
||||
@pytest.mark.parametrize("device", DEVICES)
|
||||
def test_fused_moe_lora_kernel_zero_grid_no_crash(device):
|
||||
"""num_active_loras=0 (or num_slices=0) would otherwise launch a grid
|
||||
with a zero dimension. one-shot wrapper must short-circuit before launch."""
|
||||
with a zero dimension. one-shot wrapper must short-circuit before launch.
|
||||
"""
|
||||
torch.set_default_device(device)
|
||||
set_random_seed(0)
|
||||
num_tokens, top_k, E, max_loras, R, K, N = 8, 2, 8, 4, 16, 1024, 1024
|
||||
@@ -1187,7 +1186,8 @@ def test_fused_moe_lora_kernel_zero_grid_no_crash(device):
|
||||
def test_fused_moe_lora_kernel_rejects_bad_block_size_m(device):
|
||||
"""one-shot must surface a clear assertion when shrink_block_size_m is not
|
||||
a power of 2 / less than 16, instead of the cryptic Triton compile
|
||||
failure (`arange's range must be a power of 2`)."""
|
||||
failure (`arange's range must be a power of 2`).
|
||||
"""
|
||||
torch.set_default_device(device)
|
||||
set_random_seed(0)
|
||||
num_tokens, top_k, E, max_loras, R, K, N = 32, 2, 8, 4, 16, 1024, 1024
|
||||
|
||||
@@ -126,8 +126,7 @@ def clean_cache_reset_device(reset_default_device):
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def skip_cuda_with_stage_false(request):
|
||||
"""
|
||||
On cuda-like platforms, we use the same kernels for prefill and decode
|
||||
"""On cuda-like platforms, we use the same kernels for prefill and decode
|
||||
stage, and 'stage' is generally ignored, so we only need to test once.
|
||||
"""
|
||||
if current_platform.is_cuda_alike() or current_platform.is_xpu():
|
||||
@@ -153,8 +152,8 @@ def get_random_id_to_index(
|
||||
num_slots: The number of slots in the mapping. Must be larger
|
||||
than num_loras.
|
||||
log: Whether to log the output.
|
||||
"""
|
||||
|
||||
"""
|
||||
if num_loras > num_slots:
|
||||
raise ValueError(
|
||||
f"num_loras is higher than num_slots: {num_loras} > {num_slots}. "
|
||||
@@ -190,8 +189,8 @@ def populate_loras(
|
||||
repeats: must only be set for column parallel packed
|
||||
layers. Indicates the number of loras to compose
|
||||
together to create a single lora layer.
|
||||
"""
|
||||
|
||||
"""
|
||||
# Dictionary that maps the lora ID to the
|
||||
# corresponding lora weights.
|
||||
lora_dict: dict[int, LoRALayerWeights] = dict()
|
||||
@@ -246,8 +245,8 @@ def create_random_inputs(
|
||||
input_range: the range of values to include in the input.
|
||||
input_range[0] <= possible input values < input_range[1]
|
||||
input_type: the type of values in the input.
|
||||
"""
|
||||
|
||||
"""
|
||||
low, high = input_range
|
||||
|
||||
inputs: list[torch.Tensor] = []
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Script to test add_lora, remove_lora, pin_lora, list_loras functions.
|
||||
"""
|
||||
"""Script to test add_lora, remove_lora, pin_lora, list_loras functions."""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def do_sample(
|
||||
|
||||
@pytest.mark.parametrize("tp_size", [4])
|
||||
def test_mixtral_lora(mixtral_lora_files, tp_size):
|
||||
"""Original test, the LoRA model has the common target modules, not all"""
|
||||
"""Original test, the LoRA model has the common target modules, not all."""
|
||||
if (
|
||||
torch.accelerator.device_count() < tp_size
|
||||
and tp_size > 1
|
||||
|
||||
@@ -249,7 +249,8 @@ def _build_and_run_align(
|
||||
)
|
||||
def test_moe_lora_align_block_size_mixed_base_and_lora(max_loras):
|
||||
"""Regression test for issue #32235: real LoRA slot must not be skipped
|
||||
when ``active_lora_ids`` has -1 at position 0."""
|
||||
when ``active_lora_ids`` has -1 at position 0.
|
||||
"""
|
||||
out = _build_and_run_align(
|
||||
num_lora_tokens=8, num_base_tokens=8, max_loras=max_loras
|
||||
)
|
||||
@@ -288,7 +289,8 @@ def test_moe_lora_align_block_size_disabled_adapter_untouched():
|
||||
kernels. Pins the invariant protected by the ``adapter_enabled`` guard
|
||||
in ``lora_count_and_sort_expert_tokens_kernel``: without it the sort
|
||||
kernel reads uninitialized ``token_mask`` values for disabled slots and
|
||||
pollutes ``sorted_token_ids`` / ``cumsum_buffer``."""
|
||||
pollutes ``sorted_token_ids`` / ``cumsum_buffer``.
|
||||
"""
|
||||
max_loras = 1
|
||||
out = _build_and_run_align(
|
||||
num_lora_tokens=16,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
End-to-end correctness test for 2D MoE LoRA expert-parallel
|
||||
"""End-to-end correctness test for 2D MoE LoRA expert-parallel
|
||||
load-time slicing
|
||||
"""
|
||||
|
||||
@@ -20,7 +19,8 @@ NON_EXPERT_MODULES = ("q_proj", "k_proj", "v_proj", "o_proj", "gate")
|
||||
|
||||
def _expected_lora_modules() -> set[str]:
|
||||
"""Replicate the set ``WorkerLoRAManager._load_adapter`` would build
|
||||
from this model's ``packed_modules_mapping``."""
|
||||
from this model's ``packed_modules_mapping``.
|
||||
"""
|
||||
expected: set[str] = set(NON_EXPERT_MODULES)
|
||||
for expert in range(GLOBAL_NUM_EXPERTS):
|
||||
for proj in EXPERT_PROJECTIONS:
|
||||
@@ -43,7 +43,8 @@ def _load(lora_dir, peft_helper, *, moe_ep_spec, lora_id):
|
||||
def test_moe_lora_ep2_real_qwen3moe(qwen3moe_lora_files, ep_rank):
|
||||
"""ep_size=2 against the real Qwen3-MoE adapter: each rank's loaded
|
||||
LoRA has the right size, the right expert membership, and the
|
||||
right tensor values."""
|
||||
right tensor values.
|
||||
"""
|
||||
peft_helper = PEFTHelper.from_local_dir(
|
||||
qwen3moe_lora_files, max_position_embeddings=4096
|
||||
)
|
||||
|
||||
@@ -45,7 +45,8 @@ def _bgmv_shrink(
|
||||
inputs, lora_weight, output, seq_len_tensor, lora_indices, scaling=1.0
|
||||
):
|
||||
"""Memory-efficient shrink reference: per-LoRA matmul loop.
|
||||
output[mask] = scaling * inputs[mask] @ weight.T"""
|
||||
output[mask] = scaling * inputs[mask] @ weight.T
|
||||
"""
|
||||
exploded = torch.repeat_interleave(lora_indices, seq_len_tensor)
|
||||
for lid in exploded.unique():
|
||||
if lid < 0:
|
||||
@@ -66,7 +67,8 @@ def _bgmv_expand(
|
||||
add_inputs=False,
|
||||
):
|
||||
"""Memory-efficient expand reference: per-LoRA matmul loop.
|
||||
output[mask, offset:offset+n] (+)= inputs[mask] @ weight.T"""
|
||||
output[mask, offset:offset+n] (+)= inputs[mask] @ weight.T
|
||||
"""
|
||||
exploded = torch.repeat_interleave(lora_indices, seq_len_tensor)
|
||||
for lid in exploded.unique():
|
||||
if lid < 0:
|
||||
@@ -160,8 +162,7 @@ def check_lora_shrink_kernel(
|
||||
seq_length: int,
|
||||
scaling: float,
|
||||
):
|
||||
"""
|
||||
Compare outputs of torch_ops.sgmv_shrink and triton_ops.lora_shrink
|
||||
"""Compare outputs of torch_ops.sgmv_shrink and triton_ops.lora_shrink
|
||||
kernels.
|
||||
"""
|
||||
data: PunicaTensors = generate_data_for_nslices(
|
||||
@@ -234,8 +235,7 @@ def check_lora_expand_kernel(
|
||||
seq_length: int,
|
||||
add_inputs: bool,
|
||||
):
|
||||
"""
|
||||
Compare outputs of torch_ops.sgmv_expand and triton_ops.lora_expand
|
||||
"""Compare outputs of torch_ops.sgmv_expand and triton_ops.lora_expand
|
||||
kernels.
|
||||
"""
|
||||
data: PunicaTensors = generate_data_for_nslices(
|
||||
@@ -438,9 +438,7 @@ def test_kernels(
|
||||
seed: int,
|
||||
op_type: str,
|
||||
):
|
||||
"""
|
||||
Tests LoRA kernels.
|
||||
"""
|
||||
"""Tests LoRA kernels."""
|
||||
torch.set_default_device(device)
|
||||
torch.accelerator.set_device_index(device)
|
||||
set_random_seed(seed)
|
||||
@@ -491,9 +489,7 @@ def test_kernels_hidden_size(
|
||||
seed: int,
|
||||
op_type: str,
|
||||
):
|
||||
"""
|
||||
Tests SGMV and LoRA kernels.
|
||||
"""
|
||||
"""Tests SGMV and LoRA kernels."""
|
||||
torch.set_default_device(device)
|
||||
torch.accelerator.set_device_index(device)
|
||||
set_random_seed(seed)
|
||||
@@ -526,8 +522,7 @@ def test_kernels_hidden_size(
|
||||
|
||||
@pytest.mark.parametrize("device", DEVICES)
|
||||
def test_add_lora_fused_moe_early_exit(device):
|
||||
"""
|
||||
Ensures add_lora_fused_moe does not invoke the LoRA kernel or
|
||||
"""Ensures add_lora_fused_moe does not invoke the LoRA kernel or
|
||||
modify the output tensor when no_lora_flag_cpu is True
|
||||
"""
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -877,7 +877,8 @@ def test_lora_shrink_fp8(
|
||||
quant_mode: str,
|
||||
):
|
||||
"""Test FP8 shrink kernel with per-tensor, per-channel, and block-wise
|
||||
quantization, comparing against the bf16 baseline."""
|
||||
quantization, comparing against the bf16 baseline.
|
||||
"""
|
||||
torch.set_default_device(device)
|
||||
set_random_seed(seed)
|
||||
|
||||
@@ -932,7 +933,8 @@ def test_lora_expand_fp8(
|
||||
quant_mode: str,
|
||||
):
|
||||
"""Test FP8 expand kernel with per-tensor, per-channel, and block-wise
|
||||
quantization, comparing against the bf16 baseline."""
|
||||
quantization, comparing against the bf16 baseline.
|
||||
"""
|
||||
torch.set_default_device(device)
|
||||
set_random_seed(seed)
|
||||
|
||||
|
||||
@@ -86,9 +86,7 @@ def check_bgmv_shrink(
|
||||
device: str,
|
||||
scaling: float,
|
||||
):
|
||||
"""
|
||||
Compare vllm.bgmv_shrink against a reference implementation.
|
||||
"""
|
||||
"""Compare vllm.bgmv_shrink against a reference implementation."""
|
||||
seq_length = 1
|
||||
data: PunicaTensors = generate_data(
|
||||
batches,
|
||||
@@ -130,9 +128,7 @@ def check_bgmv_expand(
|
||||
device: str,
|
||||
add_inputs: bool,
|
||||
):
|
||||
"""
|
||||
Compare vllm.bgmv_expand against a reference implementation.
|
||||
"""
|
||||
"""Compare vllm.bgmv_expand against a reference implementation."""
|
||||
seq_length = 1
|
||||
data: PunicaTensors = generate_data(
|
||||
batches,
|
||||
@@ -172,9 +168,7 @@ def check_bgmv_expand_slice(
|
||||
device: str,
|
||||
add_inputs: bool,
|
||||
):
|
||||
"""
|
||||
Compare vllm.bgmv_expand_slice against a reference implementation.
|
||||
"""
|
||||
"""Compare vllm.bgmv_expand_slice against a reference implementation."""
|
||||
seq_length = 1
|
||||
data: PunicaTensors = generate_data_for_expand_nslices(
|
||||
batches,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Tests for Qwen3 unembed LoRA support.
|
||||
"""Tests for Qwen3 unembed LoRA support.
|
||||
|
||||
This test creates synthetic LoRA weights that include lm_head (output embedding)
|
||||
to verify that Qwen3 properly supports LoRA on the unembed/lm_head layer.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
This script contains:
|
||||
"""This script contains:
|
||||
1. test multi loras service with tp >= 2
|
||||
2. test multi loras request
|
||||
"""
|
||||
@@ -125,8 +124,7 @@ def test_multi_loras_with_tp_sync():
|
||||
return output_text
|
||||
|
||||
def reload_lora(name: str):
|
||||
"""
|
||||
reload a lora to simulate the case:
|
||||
"""Reload a lora to simulate the case:
|
||||
setting `VLLM_ALLOW_RUNTIME_LORA_UPDATING=true`
|
||||
for dynamic lora loading and unloading
|
||||
"""
|
||||
@@ -205,8 +203,7 @@ def test_multiple_lora_requests():
|
||||
def test_load_inplace_offline_reload(
|
||||
qwen3_meowing_lora_files: str, qwen3_woofing_lora_files: str
|
||||
) -> None:
|
||||
"""
|
||||
Test that load_inplace=True allows reloading LoRA adapters with the same ID
|
||||
"""Test that load_inplace=True allows reloading LoRA adapters with the same ID
|
||||
in offline mode (using LLM class directly).
|
||||
"""
|
||||
llm = LLM(
|
||||
@@ -255,8 +252,7 @@ def test_load_inplace_offline_reload(
|
||||
def test_load_inplace_false_no_reload(
|
||||
qwen3_meowing_lora_files: str, qwen3_woofing_lora_files: str
|
||||
) -> None:
|
||||
"""
|
||||
Test that load_inplace=False prevents reloading when an adapter
|
||||
"""Test that load_inplace=False prevents reloading when an adapter
|
||||
with the same ID already exists.
|
||||
"""
|
||||
llm = LLM(
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestConfig:
|
||||
|
||||
|
||||
class Qwen2VLTester:
|
||||
"""Test helper for Qwen2 VL models with LoRA"""
|
||||
"""Test helper for Qwen2 VL models with LoRA."""
|
||||
|
||||
PROMPT_TEMPLATE = (
|
||||
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>"
|
||||
@@ -199,7 +199,7 @@ def _enable_deterministic_lora_shrink(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_qwen2vl_lora(qwen2vl_lora_files):
|
||||
"""Test Qwen 2.0 VL model with LoRA"""
|
||||
"""Test Qwen 2.0 VL model with LoRA."""
|
||||
config = TestConfig(model_path=QWEN2VL_MODEL_PATH, lora_path=qwen2vl_lora_files)
|
||||
with Qwen2VLTester(config) as tester:
|
||||
# Test with different LoRA IDs
|
||||
@@ -230,7 +230,7 @@ def test_qwen2vl_lora_beam_search(qwen2vl_lora_files):
|
||||
current_platform.is_cuda_alike(), reason="Skipping to avoid redundant model tests"
|
||||
)
|
||||
def test_qwen25vl_lora(qwen25vl_lora_files):
|
||||
"""Test Qwen 2.5 VL model with LoRA"""
|
||||
"""Test Qwen 2.5 VL model with LoRA."""
|
||||
config = TestConfig(model_path=QWEN25VL_MODEL_PATH, lora_path=qwen25vl_lora_files)
|
||||
with Qwen2VLTester(config) as tester:
|
||||
# Test with different LoRA IDs
|
||||
@@ -292,8 +292,7 @@ def test_qwen2vl_multiple_lora_types(
|
||||
qwen2vl_vision_tower_lora_files,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
"""
|
||||
Test multiple LoRA adapter types (language, vision tower + connector,
|
||||
"""Test multiple LoRA adapter types (language, vision tower + connector,
|
||||
vision tower only) using the same LLM instance to verify mm_encoder_cache
|
||||
behavior with different LoRA requests.
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Integration tests for Whisper models with LoRA adapters.
|
||||
"""Integration tests for Whisper models with LoRA adapters.
|
||||
|
||||
These tests verify that Whisper models can correctly load and use LoRA adapters
|
||||
for speech-to-text transcription tasks.
|
||||
|
||||
+1
-2
@@ -116,8 +116,7 @@ class PunicaTensors:
|
||||
token_lora_mapping: torch.Tensor
|
||||
|
||||
def meta(self) -> tuple[int, int]:
|
||||
"""
|
||||
Infer max_seq_length and token_nums from the tensors
|
||||
"""Infer max_seq_length and token_nums from the tensors
|
||||
and return them.
|
||||
"""
|
||||
max_seq_length = self.seq_len_tensor.max()
|
||||
|
||||
Reference in New Issue
Block a user