diff --git a/benchmarks/benchmark_hidden_state_extraction.py b/benchmarks/benchmark_hidden_state_extraction.py index 1f5da88c2c..878be2c293 100644 --- a/benchmarks/benchmark_hidden_state_extraction.py +++ b/benchmarks/benchmark_hidden_state_extraction.py @@ -136,8 +136,7 @@ async def _client_loop( client_id: int, ): """A single async client: pulls prompts, submits to engine, consumes - hidden states as soon as each request finishes. - """ + hidden states as soon as each request finishes.""" loop = asyncio.get_event_loop() while True: item = await prompt_queue.get() diff --git a/benchmarks/fused_kernels/merge_attn_states_benchmarks.py b/benchmarks/fused_kernels/merge_attn_states_benchmarks.py index a4b4533fa3..61dfd7ea12 100644 --- a/benchmarks/fused_kernels/merge_attn_states_benchmarks.py +++ b/benchmarks/fused_kernels/merge_attn_states_benchmarks.py @@ -84,8 +84,7 @@ def make_inputs( def build_configs(head_configs, num_tokens_list, input_dtypes, tp_sizes): """Build (num_tokens, num_heads, head_size, dtype_str) config tuples, - applying TP division to num_heads and skipping invalid combos. - """ + applying TP division to num_heads and skipping invalid combos.""" configs = [] for (_, nh, hs), nt, dtype, tp in itertools.product( head_configs, num_tokens_list, input_dtypes, tp_sizes diff --git a/benchmarks/kernels/benchmark_moe_defaults.py b/benchmarks/kernels/benchmark_moe_defaults.py index f21fbaa703..00c6606db0 100644 --- a/benchmarks/kernels/benchmark_moe_defaults.py +++ b/benchmarks/kernels/benchmark_moe_defaults.py @@ -32,8 +32,7 @@ FP8_DTYPE = current_platform.fp8_dtype() def old_default_config(M, E, N, K, topk, dtype=None, block_shape=None): """The original defaults before https://github.com/vllm-project/vllm/pull/34846, - for comparison. - """ + for comparison.""" if dtype == "fp8_w8a8" and block_shape is not None: return { "BLOCK_SIZE_M": 64, diff --git a/benchmarks/kernels/benchmark_vocab_parallel_embedding.py b/benchmarks/kernels/benchmark_vocab_parallel_embedding.py index 2922c449ea..4925e6c024 100644 --- a/benchmarks/kernels/benchmark_vocab_parallel_embedding.py +++ b/benchmarks/kernels/benchmark_vocab_parallel_embedding.py @@ -97,8 +97,7 @@ def graph_replay(fn): def calculate_diff(vocab_size, hidden_size, tp_size, num_tokens): """The fused kernel must be bit-exact with the path it replaces, on every - rank of the shard. - """ + rank of the shard.""" dtype = torch.bfloat16 for tp_rank in range(tp_size): input_ids, weight, shard_indices = make_inputs( diff --git a/docs/mkdocs/gen_files/generate_examples.py b/docs/mkdocs/gen_files/generate_examples.py index c051653cf9..a514dcf879 100644 --- a/docs/mkdocs/gen_files/generate_examples.py +++ b/docs/mkdocs/gen_files/generate_examples.py @@ -75,8 +75,7 @@ class Example: If path is a file, it returns the path itself. If path is a directory, it searches for Markdown files (*.md) in the directory and returns the first one - found. If no Markdown files are found, it returns None. - """ + found. If no Markdown files are found, it returns None.""" # Single file example if self.path.is_file(): return self.path @@ -91,8 +90,7 @@ class Example: """Determine other files in the directory excluding the main file. If path is a file, it returns an empty list. Otherwise, it returns every file - in the directory except the main file in a list. - """ + in the directory except the main file in a list.""" # Single file example if self.path.is_file(): return [] diff --git a/examples/features/logits_processor/custom_req.py b/examples/features/logits_processor/custom_req.py index 36b83ec958..eb57029efa 100644 --- a/examples/features/logits_processor/custom_req.py +++ b/examples/features/logits_processor/custom_req.py @@ -55,8 +55,7 @@ logger = init_logger(__name__) 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`.""" @@ -75,8 +74,7 @@ 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""" @classmethod def validate_params(cls, params: SamplingParams): diff --git a/examples/features/logits_processor/custom_req_init.py b/examples/features/logits_processor/custom_req_init.py index 4f29bd2714..38554f06d8 100644 --- a/examples/features/logits_processor/custom_req_init.py +++ b/examples/features/logits_processor/custom_req_init.py @@ -56,8 +56,7 @@ logger = init_logger(__name__) 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`.""" @@ -76,8 +75,7 @@ class DummyPerReqLogitsProcessor: class WrappedPerReqLogitsProcessor(AdapterLogitsProcessor): """Example of overriding the wrapper class `__init__()` in order to utilize - info about the device type - """ + info about the device type""" @classmethod def validate_params(cls, params: SamplingParams): diff --git a/examples/rl/rlhf_sharded_rdt_small_ep.py b/examples/rl/rlhf_sharded_rdt_small_ep.py index ed31a32ad8..213eae55ef 100644 --- a/examples/rl/rlhf_sharded_rdt_small_ep.py +++ b/examples/rl/rlhf_sharded_rdt_small_ep.py @@ -101,8 +101,7 @@ PROMPTS = ["The capital of France is", "The future of AI is"] class FSDPTrainWorker: """One FSDP2 rank per GPU. Identical to the 8-GPU example's worker: the sharded-RDT engine owns the NIXL serve surface, so this stays a plain Ray - actor with no producer mixin. - """ + actor with no producer mixin.""" def __init__(self, model_name, rank, world_size, master_addr, master_port): self.rank = rank diff --git a/pyproject.toml b/pyproject.toml index 83949db8fe..b5c03b22b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,9 @@ ignore = [ # don't enforce that everything has a docstring "D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107", # unwanted pydocstyle rules - "D205", "D301", "D400", "D401", "D404", "D415", + "D205", "D209", "D301", "D400", "D401", "D404", "D415", + # incompatible pydocstyle pairs; pin the half `ruff` already picks + "D203", "D213", # star imports "F405", "F403", # lambda expression assignment diff --git a/setup.py b/setup.py index 48cbdcf763..b24bcc1a2c 100644 --- a/setup.py +++ b/setup.py @@ -724,8 +724,7 @@ class precompiled_wheel_utils: wheels: list[dict], repo_url: str, arch: str ) -> None: """Warn if installed torch differs from the custom ROCm build on - wheels.vllm.ai and suggest the correct install command. - """ + wheels.vllm.ai and suggest the correct install command.""" try: installed = torch.__version__ except Exception: diff --git a/tests/basic_correctness/test_mem.py b/tests/basic_correctness/test_mem.py index f04bb397f0..6b4895c643 100644 --- a/tests/basic_correctness/test_mem.py +++ b/tests/basic_correctness/test_mem.py @@ -112,8 +112,7 @@ def test_basic_cumem(): @create_new_process_for_each_test("fork" if current_platform.is_cuda() else "spawn") def test_discard_tags(): """Test that discard(tags) selectively frees GPU memory for specific - tags while keeping other tags mapped and usable. - """ + tags while keeping other tags mapped and usable.""" allocator = get_mem_allocator_instance() with allocator.use_memory_pool("weights"): diff --git a/tests/benchmarks/test_bfcl_dataset.py b/tests/benchmarks/test_bfcl_dataset.py index 982b93ad8e..d191922319 100644 --- a/tests/benchmarks/test_bfcl_dataset.py +++ b/tests/benchmarks/test_bfcl_dataset.py @@ -13,8 +13,7 @@ from vllm.benchmarks.datasets import BFCLDataset, get_samples def _patch_hf_api(side_effect): """Return a patch context that swaps `hf_api()` to a stub whose - `.hf_hub_download` attribute uses `side_effect`. - """ + `.hf_hub_download` attribute uses `side_effect`.""" fake_api = MagicMock() fake_api.hf_hub_download.side_effect = side_effect return patch("vllm.benchmarks.datasets.datasets.hf_api", return_value=fake_api) @@ -116,8 +115,7 @@ def test_bfcl_dataset_translates_schema_and_attaches_tools( ) -> None: """BFCLDataset should translate schemas to OpenAI tool format, set `messages` directly on SampleRequest, and attach tools/tool_choice via - request_overrides. - """ + request_overrides.""" paths = _write_fake_files(tmp_path) def fake_download(_repo, filename, **_kwargs): @@ -168,8 +166,7 @@ def test_bfcl_dataset_missing_category_raises_clear_error( hf_tokenizer: PreTrainedTokenizerBase, ) -> None: """A typo'd category should produce an actionable ValueError, not an - opaque huggingface_hub exception. - """ + opaque huggingface_hub exception.""" from huggingface_hub.errors import EntryNotFoundError args = _args_for_bfcl(categories=["simpl"]) # typo @@ -187,8 +184,7 @@ def test_bfcl_dataset_missing_category_raises_clear_error( @pytest.mark.benchmark def test_chat_backend_uses_messages_field_when_set() -> None: """When RequestFuncInput.chat_messages is set, the chat backend must use - it verbatim and skip default content construction from `prompt`. - """ + it verbatim and skip default content construction from `prompt`.""" import asyncio from vllm.benchmarks.lib.endpoint_request_func import ( @@ -248,8 +244,7 @@ def test_chat_backend_uses_messages_field_when_set() -> None: def test_bfcl_prompt_len_includes_tools(tmp_path: Path) -> None: """prompt_len must reflect tokens from both messages *and* tool schemas, so percentile buckets and input-distribution summaries aren't biased - low for tool-heavy traffic. - """ + low for tool-heavy traffic.""" paths = _write_fake_files(tmp_path) def fake_download(_repo, filename, **_kwargs): @@ -296,8 +291,7 @@ def test_bfcl_prompt_len_falls_back_when_tokenizer_rejects_tools( tmp_path: Path, ) -> None: """Older tokenizers don't accept tools=; fallback must still produce a - non-zero prompt_len without crashing. - """ + non-zero prompt_len without crashing.""" paths = _write_fake_files(tmp_path) def fake_download(_repo, filename, **_kwargs): diff --git a/tests/benchmarks/test_custom_dataset_chat_template_kwargs.py b/tests/benchmarks/test_custom_dataset_chat_template_kwargs.py index 28ecb6e443..149ea6625a 100644 --- a/tests/benchmarks/test_custom_dataset_chat_template_kwargs.py +++ b/tests/benchmarks/test_custom_dataset_chat_template_kwargs.py @@ -12,8 +12,7 @@ from vllm.benchmarks.datasets import get_samples class _RecordingTokenizer: """Minimal tokenizer stub that records the kwargs forwarded to apply_chat_template, so we can assert chat_template_kwargs propagation - without loading a real model/template. - """ + without loading a real model/template.""" def __init__(self) -> None: self.captured_kwargs: dict | None = None diff --git a/tests/benchmarks/test_sampling_params.py b/tests/benchmarks/test_sampling_params.py index 13dcf8ad20..3bc34a84b3 100644 --- a/tests/benchmarks/test_sampling_params.py +++ b/tests/benchmarks/test_sampling_params.py @@ -10,8 +10,7 @@ from vllm.tokenizers import TokenizerLike class _FakeTokenizer(TokenizerLike): """Minimal tokenizer implementing the TokenizerLike protocol - for testing get_sampling_params. - """ + for testing get_sampling_params.""" def __init__(self, vocab_size: int = 1000, num_special_tokens: int = 0) -> None: self._vocab_size = vocab_size @@ -172,8 +171,7 @@ class TestGetSamplingParams: def test_output_low_clamped_to_one(self): """Even with a high ratio that would push output_low to 0, - the function clamps it to 1. - """ + the function clamps it to 1.""" rng = np.random.default_rng(0) # output_len=1, ratio=0.99 → floor(1*0.01)=0, should clamp to 1 _, output_lens, _ = get_sampling_params( @@ -235,8 +233,7 @@ class TestGetSamplingParams: def test_input_len_zero_with_special_tokens(self): """input_len < num_special_tokens → real_input_len = 0, which is fine - (range [0, 0]). - """ + (range [0, 0]).""" rng = np.random.default_rng(0) input_lens, _, _ = get_sampling_params( rng, 5, 0.0, 5, 50, self._tok(num_special=10) diff --git a/tests/benchmarks/test_skip_tokenizer_init.py b/tests/benchmarks/test_skip_tokenizer_init.py index 1eb9a2536e..741db2e0d6 100644 --- a/tests/benchmarks/test_skip_tokenizer_init.py +++ b/tests/benchmarks/test_skip_tokenizer_init.py @@ -52,8 +52,7 @@ def _write_dataset(path: Path) -> None: def _args(dataset_path: str) -> argparse.Namespace: """Reproduce the argparse.Namespace that serve.py builds from the - failing command, including skip_tokenizer_init=True. - """ + failing command, including skip_tokenizer_init=True.""" return argparse.Namespace( # dataset dataset_name="custom", diff --git a/tests/compile/passes/test_fusion.py b/tests/compile/passes/test_fusion.py index 0945bd622a..843052f4af 100644 --- a/tests/compile/passes/test_fusion.py +++ b/tests/compile/passes/test_fusion.py @@ -732,8 +732,7 @@ def test_aiter_fusion_rmsnorm_gated_quant_no_gdn_layers( monkeypatch: pytest.MonkeyPatch, ): """Verify that without GDN layers in static_forward_context, - the gated pattern is not registered and no matches occur. - """ + the gated pattern is not registered and no matches occur.""" group_shape = GroupShape(1, 128) vllm_config = VllmConfig( model_config=ModelConfig(dtype=dtype), diff --git a/tests/compile/passes/test_split_coalescing.py b/tests/compile/passes/test_split_coalescing.py index 52e531e127..ab7a0be1a2 100644 --- a/tests/compile/passes/test_split_coalescing.py +++ b/tests/compile/passes/test_split_coalescing.py @@ -15,8 +15,7 @@ DEVICE_TYPE = current_platform.device_type class SplitCoalescingModel(torch.nn.Module): """Model with 3 separate split_with_sizes calls on the same input, - simulating the B200+FP8 graph where CSE fails to merge them. - """ + simulating the B200+FP8 graph where CSE fails to merge them.""" def __init__(self, q_size: int, kv_size: int) -> None: super().__init__() diff --git a/tests/compile/test_codegen.py b/tests/compile/test_codegen.py index a0086cb702..21db287a24 100644 --- a/tests/compile/test_codegen.py +++ b/tests/compile/test_codegen.py @@ -77,8 +77,7 @@ def test_non_primitive_kwargs_lifted_to_consts( into the namespace, so ``device`` is unbound. The fix collects such objects into ``__vllm_consts__`` and references them by index. The unqualified ``device(type=...)`` form must never appear in the - generated source. - """ + generated source.""" split_gm = _trace_and_split(model_fn, (x,), split_ops) code, submod_names, consts = generate_execution_code(split_gm) @@ -99,8 +98,7 @@ def test_dtype_singleton_deduped(x: torch.Tensor) -> None: """``torch.float16`` is a process-wide singleton, so two ops referring to it in the traced graph share a single consts slot via ``id()``-based dedup. Distinct expressions (``x.to(...)`` vs ``(x*2).to(...)``) ensure - the tracer can't CSE the two ops into a single node. - """ + the tracer can't CSE the two ops into a single node.""" def model_fn(x: torch.Tensor) -> torch.Tensor: return x.to(dtype=torch.float16) + (x * 2).to(dtype=torch.float16) @@ -149,8 +147,7 @@ def test_distinct_dtypes_get_distinct_slots(x: torch.Tensor) -> None: def test_consts_ordering_deterministic(x: torch.Tensor) -> None: """Two independent traces of the same model must produce equal consts lists *in the same order*. Cache artifacts identify const slots by - index, so a non-deterministic order would invalidate cached code. - """ + index, so a non-deterministic order would invalidate cached code.""" def model_fn(x: torch.Tensor) -> torch.Tensor: # Multiple distinct non-primitives encountered in a fixed graph order. @@ -188,8 +185,7 @@ def test_consts_shared_across_split_submods(x: torch.Tensor) -> None: The function below splits into three inlined submods, two of which independently reference ``torch.float16``. The shared ``const_index`` threaded through recursive ``generate_execution_code_with_name`` calls - must collapse the dtype to a single slot used from both submods. - """ + must collapse the dtype to a single slot used from both submods.""" def model_fn(x: torch.Tensor) -> torch.Tensor: a = x.to(dtype=torch.float16) # submod_0: _to_copy(fp16) @@ -234,8 +230,7 @@ def test_non_graphmodule_submod_uses_indexed_callable(x: torch.Tensor) -> None: """When a child of split_gm is *not* a ``torch.fx.GraphModule`` — as happens in production once ``PiecewiseBackend`` replaces submods — codegen emits ``__vllm_submods__[idx](...)`` instead of inlining, and - the runtime callable is bound from ``submod_callables``. - """ + the runtime callable is bound from ``submod_callables``.""" def model_fn(x: torch.Tensor) -> torch.Tensor: return x.relu().sigmoid() @@ -285,8 +280,7 @@ def test_non_graphmodule_submod_uses_indexed_callable(x: torch.Tensor) -> None: def test_getitem_in_stitching_graph(x: torch.Tensor) -> None: """``operator.getitem`` on submod tuple returns is the ``call_function`` special case at codegen.py — emitted as ``name = source[index]`` - rather than a function call. - """ + rather than a function call.""" def model_fn(x: torch.Tensor) -> torch.Tensor: return x.relu().sigmoid() @@ -304,8 +298,7 @@ def test_getitem_in_stitching_graph(x: torch.Tensor) -> None: def test_del_emitted_for_intermediate_values(x: torch.Tensor) -> None: """The codegen schedules ``del`` after a value's last use to free memory early. Multi-submod splits naturally have intermediates whose - last use is not the output node. - """ + last use is not the output node.""" def model_fn(x: torch.Tensor) -> torch.Tensor: return x.relu().sigmoid().tanh() @@ -325,8 +318,7 @@ def test_with_submod_false_rejects_call_module() -> None: """``generate_execution_code_with_name(with_submod=False)`` is the recursive entry for inlining a GraphModule into its parent. It must refuse a graph that itself contains ``call_module`` nodes — the parent - is responsible for handling those. - """ + is responsible for handling those.""" g = fx.Graph() x_node = g.placeholder("x") root = torch.nn.Module() @@ -343,8 +335,7 @@ def test_node_ref_recurses_through_containers() -> None: """``_node_ref`` is the recursive walker that lifts non-primitives nested inside list/tuple/dict args. Real aten ops rarely produce such structures, but the path is needed for DTensor placement lists and - other future cases — unit-test the walker directly. - """ + other future cases — unit-test the walker directly.""" consts: list = [] const_index: dict[int, int] = {} cpu = torch.device("cpu") @@ -368,8 +359,7 @@ def test_node_ref_recurses_through_containers() -> None: def test_legacy_code_without_consts() -> None: """``compile_execution_fn(consts=None)`` must still load code that has no ``__vllm_consts__`` reference, so older serialized cache artifacts - keep working. - """ + keep working.""" # Pre-consts codegen: no __vllm_consts__ reference, only torch/operator. legacy_code = ( "import torch\n" diff --git a/tests/compile/test_compile_ranges.py b/tests/compile/test_compile_ranges.py index b3e2ec4731..4dfea42a6b 100644 --- a/tests/compile/test_compile_ranges.py +++ b/tests/compile/test_compile_ranges.py @@ -129,8 +129,7 @@ def test_compile_config_get_compile_ranges(): class PostGradStaticShapeChecker(InductorPass): """Asserts that compile_sizes entries produce graphs with fully concrete - (non-symbolic) shapes, and compile_ranges entries have symbolic shapes. - """ + (non-symbolic) shapes, and compile_ranges entries have symbolic shapes.""" def __init__(self): self.num_static_calls = 0 @@ -171,8 +170,7 @@ class PostGradStaticShapeChecker(InductorPass): def test_compile_sizes_produce_static_shapes(disable_vllm_compile_cache): """Verify that compile_sizes entries are compiled with fully concrete - shapes (no SymInts), while compile_ranges entries retain dynamic shapes. - """ + shapes (no SymInts), while compile_ranges entries retain dynamic shapes.""" checker = PostGradStaticShapeChecker() torch.set_default_device("cuda") vllm_config = VllmConfig( diff --git a/tests/compile/test_config.py b/tests/compile/test_config.py index fc32956218..5c9132ccbf 100644 --- a/tests/compile/test_config.py +++ b/tests/compile/test_config.py @@ -1229,8 +1229,7 @@ def test_compile_sizes_padding_validation(): def test_inductor_asserts_default_disabled(monkeypatch): """Test that inductor runtime asserts are disabled by default - (INFO logging level) on torch < 2.12. - """ + (INFO logging level) on torch < 2.12.""" monkeypatch.setenv("VLLM_LOGGING_LEVEL", "INFO") import importlib @@ -1248,8 +1247,7 @@ def test_inductor_asserts_default_disabled(monkeypatch): def test_inductor_asserts_enabled_in_debug(monkeypatch): """Test that VLLM_LOGGING_LEVEL=DEBUG enables inductor runtime asserts - on torch < 2.12. - """ + on torch < 2.12.""" monkeypatch.setenv("VLLM_LOGGING_LEVEL", "DEBUG") import importlib @@ -1285,8 +1283,7 @@ def test_get_inductor_factors_includes_configs(): def test_inductor_asserts_user_override(monkeypatch): """Test that explicit inductor_compile_config overrides the - debug-logging default. - """ + debug-logging default.""" monkeypatch.setenv("VLLM_LOGGING_LEVEL", "INFO") import importlib diff --git a/tests/compile/test_inductor_fallback_allow_list_patch.py b/tests/compile/test_inductor_fallback_allow_list_patch.py index c5705da211..29fe9962e3 100644 --- a/tests/compile/test_inductor_fallback_allow_list_patch.py +++ b/tests/compile/test_inductor_fallback_allow_list_patch.py @@ -236,8 +236,7 @@ class TestInductorFallbackFastPath: def test_inner_set_membership_still_works_for_standard_ops(self): """The patch must not break Inductor's existing fallback decisions - for non-vllm ops such as ``torchvision::roi_align``. - """ + for non-vllm ops such as ``torchvision::roi_align``.""" import torch._inductor.lowering as _lowering allow_list = _lowering.FALLBACK_ALLOW_LIST diff --git a/tests/config/test_model_arch_config.py b/tests/config/test_model_arch_config.py index f71d4875d7..b68820c0d5 100644 --- a/tests/config/test_model_arch_config.py +++ b/tests/config/test_model_arch_config.py @@ -372,8 +372,7 @@ class _HeterogeneousConfig(PretrainedConfig): """A heterogeneous config with no convertor of its own. Mirrors the parts vLLM uses: per-layer configs are shallow copies with the - varying attributes applied and heterogeneity stripped, so they do not recurse. - """ + varying attributes applied and heterogeneity stripped, so they do not recurse.""" is_heterogeneous = True @@ -472,8 +471,7 @@ def test_deepseek_v4_convertor_splits_vision_architecture(): """The vision checkpoint shares model_type/architectures with the text-only DeepSeek-V4; the convertor routes it to the VL wrapper class by rewriting hf_config.architectures (model-class resolution reads the - raw attribute). - """ + raw attribute).""" from vllm.transformers_utils.configs.deepseek_v4 import DeepseekV4Config from vllm.transformers_utils.model_arch_config_convertor import ( DeepseekV4ModelArchConfigConvertor, diff --git a/tests/config/test_multimodal_config.py b/tests/config/test_multimodal_config.py index abf834608a..84cf092c21 100644 --- a/tests/config/test_multimodal_config.py +++ b/tests/config/test_multimodal_config.py @@ -42,8 +42,7 @@ def test_mm_encoder_attn_backend_hash_updates(): def test_language_model_only_does_not_affect_mm_hash(): """language_model_only does not affect the ViT computation graph, - so it should not change the multimodal config hash. - """ + so it should not change the multimodal config hash.""" base_hash = MultiModalConfig().compute_hash() lm_only_hash = MultiModalConfig(language_model_only=True).compute_hash() assert base_hash == lm_only_hash @@ -51,8 +50,7 @@ def test_language_model_only_does_not_affect_mm_hash(): def test_language_model_only_affects_model_hash(): """language_model_only affects the LM computation graph, - so it should change the model config hash. - """ + so it should change the model config hash.""" model = "llava-hf/llava-1.5-7b-hf" base_hash = ModelConfig(model).compute_hash() lm_only_hash = ModelConfig(model, language_model_only=True).compute_hash() @@ -388,8 +386,7 @@ def _resolve_mm_video_decode_device( torchcodec_available: bool = True, ) -> dict: """Run processor-device then video-decode-device resolution and report - the resulting video media IO kwargs. - """ + the resulting video media IO kwargs.""" mm_config = MultiModalConfig( mm_processor_kwargs={} if device is None else {"device": device}, mm_tensor_ipc=mm_tensor_ipc, # type: ignore[arg-type] @@ -419,8 +416,7 @@ def _resolve_mm_video_decode_device( def test_auto_video_decode_uses_nvdec_on_encoder_instance(): """The processor runs on the accelerator there, so decoded frames should - stay on-device too. - """ + stay on-device too.""" assert _resolve_mm_video_decode_device(ec_role="ec_producer") == { "backend": "torchcodec", "device": "cuda", @@ -432,8 +428,7 @@ def test_auto_video_decode_stays_on_cpu_off_encoder_instance( ec_role: ECRole | None, ): """The processor stays on CPU off encode-only instances, so video - decoding should too. - """ + decoding should too.""" assert _resolve_mm_video_decode_device(ec_role=ec_role) == {} diff --git a/tests/config/test_speculative_draft_hf_overrides.py b/tests/config/test_speculative_draft_hf_overrides.py index 10f8c994f4..8505172da3 100644 --- a/tests/config/test_speculative_draft_hf_overrides.py +++ b/tests/config/test_speculative_draft_hf_overrides.py @@ -34,8 +34,7 @@ def _make_hf_config(**kwargs) -> PretrainedConfig: @pytest.mark.cpu_test def test_dict_overrides_are_not_forwarded_to_draft(): """Dict overrides are target-specific key patches; the draft must get - only the architecture-mapping override. - """ + only the architecture-mapping override.""" composed = SpeculativeConfig.compose_draft_hf_overrides( {"max_position_embeddings": 1234} ) @@ -51,8 +50,7 @@ def test_none_overrides_fall_back_to_arch_mapping(): @pytest.mark.cpu_test def test_callable_overrides_reach_the_draft_config(): """A callable override (config-to-config transform) composes with the - architecture-mapping override and is applied to the draft config. - """ + architecture-mapping override and is applied to the draft config.""" def shrink(hf_config: PretrainedConfig) -> PretrainedConfig: hf_config.num_hidden_layers = 1 @@ -69,8 +67,7 @@ def test_callable_overrides_reach_the_draft_config(): @pytest.mark.cpu_test def test_arch_mapping_applies_before_callable_override(): """The static arch-mapping override runs first, so the user callable - observes (and may adjust) the post-mapping config. - """ + observes (and may adjust) the post-mapping config.""" seen_architectures: list[str] = [] def record(hf_config: PretrainedConfig) -> PretrainedConfig: @@ -131,8 +128,7 @@ def test_composed_override_is_picklable(): the composed override must be picklable. A nested local closure is not (it raised ``Can't get local object`` on DFlashDraftModel); a ``functools.partial`` over a module-referenceable static method is. - Guard against regressing to a closure. - """ + Guard against regressing to a closure.""" composed = SpeculativeConfig.compose_draft_hf_overrides(_module_level_shrink) assert isinstance(composed, functools.partial) diff --git a/tests/config/test_speculative_draft_max_position_embeddings.py b/tests/config/test_speculative_draft_max_position_embeddings.py index 711aaf9b03..117ae5a66d 100644 --- a/tests/config/test_speculative_draft_max_position_embeddings.py +++ b/tests/config/test_speculative_draft_max_position_embeddings.py @@ -99,8 +99,7 @@ def test_independent_draft_model_keeps_its_own_limit( vllm_caplog: pytest.LogCaptureFixture, ): """An independent AR draft may genuinely have a smaller context than the - target; its max_position_embeddings must not be resized. - """ + target; its max_position_embeddings must not be resized.""" target_model_config = ModelConfig( AR_MODEL, hf_overrides={"max_position_embeddings": 8192} ) diff --git a/tests/distributed/conftest.py b/tests/distributed/conftest.py index 876ee9dcf5..85a9d73aa5 100644 --- a/tests/distributed/conftest.py +++ b/tests/distributed/conftest.py @@ -179,8 +179,7 @@ class MockSubscriber: @pytest.fixture def enable_ray_v2_backend(): """Set env vars for the Ray V2 executor backend and shut down Ray - between tests. - """ + between tests.""" import ray saved = { diff --git a/tests/distributed/test_eplb_quant_scale_consistency.py b/tests/distributed/test_eplb_quant_scale_consistency.py index 49dc8afbf3..3b50b315f0 100644 --- a/tests/distributed/test_eplb_quant_scale_consistency.py +++ b/tests/distributed/test_eplb_quant_scale_consistency.py @@ -124,8 +124,7 @@ def _build_processed_layer( backend: str, raw: dict[str, torch.Tensor], device: torch.device ) -> tuple[CompressedTensorsW4A4Nvfp4MoEMethod, _RoutedExpertsStub]: """Create the method + layer, load ``raw`` and run the real - process_weights_after_loading (which builds the flashinfer kernel). - """ + process_weights_after_loading (which builds the flashinfer kernel).""" moe_config = _make_moe_config(backend) method = CompressedTensorsW4A4Nvfp4MoEMethod(moe_config, "layer.0", use_a16=False) layer = _RoutedExpertsStub(moe_config).to(device) @@ -158,8 +157,7 @@ def _assert_tensors_equal( def _simulate_eplb_rearrangement(layer: torch.nn.Module, perm: torch.Tensor) -> None: """Permute experts of every registered Parameter in place, the way - EPLB's in-place rearrangement moves expert slices along dim 0. - """ + EPLB's in-place rearrangement moves expert slices along dim 0.""" with torch.no_grad(): for _, param in layer.named_parameters(): param.copy_(param[perm]) @@ -167,8 +165,7 @@ def _simulate_eplb_rearrangement(layer: torch.nn.Module, perm: torch.Tensor) -> def _ensure_world1_distributed() -> None: """The enable_eplb config makes weight processing all-reduce activation - scale amaxes over the EP group, so a (single-rank) EP group must exist. - """ + scale amaxes over the EP group, so a (single-rank) EP group must exist.""" from vllm.distributed.parallel_state import ( ensure_model_parallel_initialized, init_distributed_environment, @@ -256,8 +253,7 @@ def test_nvfp4_eplb_rearrangement_matches_reload(backend: str) -> None: def test_fp8_per_tensor_alphas_registered_and_aliased() -> None: """CPU-only: the fp8 per-tensor oracle must register the fused (w_scale * a_scale) products as layer Parameters aliased by the quant - config, so EPLB rearrangement keeps kernels consistent. - """ + config, so EPLB rearrangement keeps kernels consistent.""" from vllm.model_executor.layers.fused_moe.oracle.fp8 import ( Fp8MoeBackend, make_fp8_moe_quant_config, diff --git a/tests/distributed/test_mnnvl_alltoall.py b/tests/distributed/test_mnnvl_alltoall.py index 0258c781c7..1cd6752460 100644 --- a/tests/distributed/test_mnnvl_alltoall.py +++ b/tests/distributed/test_mnnvl_alltoall.py @@ -160,8 +160,7 @@ def _make_forward_context(rank, world_size, num_tokens_per_rank): class _AttnMeta: """Minimal placeholder so set_forward_context's ``attn_metadata is not None`` guard (forward_context.py:334) - is satisfied. The real DPMetadata is built from num_tokens_across_dp. - """ + is satisfied. The real DPMetadata is built from num_tokens_across_dp.""" dp_metadata = None @@ -460,8 +459,7 @@ def _one_sided_workspace_grow_worker(rank, world_size): def test_one_sided_manager_workspace_grow(world_size): """A later initialize() with a larger per-token payload must grow the workspace and rebuild MoeAlltoAll; a later initialize() with a smaller - payload must no-op. - """ + payload must no-op.""" _spawn_workers( _one_sided_workspace_grow_worker, world_size, diff --git a/tests/distributed/test_mq_connect_ip.py b/tests/distributed/test_mq_connect_ip.py index 701dc8f248..05617bbb60 100644 --- a/tests/distributed/test_mq_connect_ip.py +++ b/tests/distributed/test_mq_connect_ip.py @@ -21,8 +21,7 @@ from vllm.utils.network_utils import get_ip def test_mq_bind_with_local_ip(): """MessageQueue with remote readers should successfully bind - when connect_ip is the local node's IP. - """ + when connect_ip is the local node's IP.""" # n_reader=2, n_local_reader=1 means 1 remote reader, # which triggers the remote ZMQ socket bind. mq = MessageQueue( @@ -44,8 +43,7 @@ def test_mq_bind_with_local_ip(): def test_mq_bind_with_non_local_ip_fails(): """MessageQueue should fail to bind when connect_ip is a non-local IP address (simulating the bug where master_addr - from a different node was used). - """ + from a different node was used).""" # Use a non-local IP that we definitely can't bind to. # 198.51.100.1 is from TEST-NET-2 (RFC 5737), never locally assigned. non_local_ip = "198.51.100.1" @@ -59,8 +57,7 @@ def test_mq_bind_with_non_local_ip_fails(): def test_mq_bind_defaults_to_local_ip(): """When connect_ip is None, MessageQueue should auto-detect - the local IP and bind successfully. - """ + the local IP and bind successfully.""" mq = MessageQueue( n_reader=2, n_local_reader=1, diff --git a/tests/distributed/test_pynccl.py b/tests/distributed/test_pynccl.py index 0eda9a14e0..91dccd5798 100644 --- a/tests/distributed/test_pynccl.py +++ b/tests/distributed/test_pynccl.py @@ -495,8 +495,7 @@ def test_pynccl_suspend_resume_idempotent(): def test_pynccl_suspend_noop_without_symbol(): """RCCL / NCCL < 2.29.7 lack ncclCommSuspend; suspend() must no-op, not - crash, and resume() must then no-op too since nothing was suspended. - """ + crash, and resume() must then no-op too since nothing was suspended.""" from unittest.mock import Mock comm = object.__new__(PyNcclCommunicator) diff --git a/tests/distributed/test_ray_v2_executor_e2e.py b/tests/distributed/test_ray_v2_executor_e2e.py index 27de410e38..335324c371 100644 --- a/tests/distributed/test_ray_v2_executor_e2e.py +++ b/tests/distributed/test_ray_v2_executor_e2e.py @@ -23,8 +23,7 @@ def _ray_init(): Without this, workers cannot unpickle actor classes defined in the ``tests`` package, causing FunctionActorManager to fall back to - TemporaryActor which drops async method signatures. - """ + TemporaryActor which drops async method signatures.""" project_root = str(pathlib.Path(__file__).resolve().parents[2]) ray.init( ignore_reinit_error=True, diff --git a/tests/distributed/test_sharded_rdt_plan.py b/tests/distributed/test_sharded_rdt_plan.py index 5cf0a82203..7923c413fc 100644 --- a/tests/distributed/test_sharded_rdt_plan.py +++ b/tests/distributed/test_sharded_rdt_plan.py @@ -53,8 +53,7 @@ META = torch.device("meta") class _FakeLayer: """Stand-in for a leaf module. The planner only stores it and keys on - ``id()``; nothing in the plan path touches its attributes. - """ + ``id()``; nothing in the plan path touches its attributes.""" def __init__(self, tag: str) -> None: self.tag = tag @@ -65,8 +64,7 @@ class _FakeLayer: def _module(layer, copies): """What the bake records for one leaf module: a scatter list whose entries - all carry that module as their ``layer``. - """ + all carry that module as their ``layer``.""" for c in copies: c.layer = layer return copies @@ -83,8 +81,7 @@ def _copy( dtype=torch.bfloat16, ): """A `_Scatter` as the bake would record it: source key, owning layer, and - the meta destination region. - """ + the meta destination region.""" stride = ( (1,) if len(shape) == 1 @@ -143,8 +140,7 @@ def _planner(baked, *, name_meta, live=None, held_by=None, group_lens=None): def _one_module_per_layer(n_layers, *, dtype="bfloat16", numel=4): """`(baked, name_meta, names, group_lens)` for a pre / N-layer / post model - where every gather group is one fully-baked leaf module. - """ + where every gather group is one fully-baked leaf module.""" names = ["embed.weight"] names += [f"model.layers.{i}.w" for i in range(n_layers)] names += ["norm.weight"] @@ -165,8 +161,7 @@ def _one_module_per_layer(n_layers, *, dtype="bfloat16", numel=4): class TestFakeOpChains: """Every allowlisted op must append itself to the chain and hand back a child whose shape/dtype PyTorch itself computed. The chain is the wire - format the producer replays, so its exact contents are load-bearing. - """ + format the producer replays, so its exact contents are load-bearing.""" def _fake(self, shape=(4, 6), dtype=torch.bfloat16, sink=None): return FakeRDTTensor( @@ -227,8 +222,7 @@ class TestFakeOpChains: @pytest.mark.parametrize("op,n", [("chunk", 2), ("unbind", 4)]) def test_multi_return_op_emits_one_child_per_output(self, op, n): """chunk/unbind hand back a tuple; each child carries the base op plus a - trailing __getitem__(i) so the producer can index the replayed result. - """ + trailing __getitem__(i) so the producer can index the replayed result.""" parts = getattr(self._fake(), op)(*((n,) if op == "chunk" else ()), 0) assert isinstance(parts, tuple) assert len(parts) == n @@ -244,8 +238,7 @@ class TestFakeOpChains: class TestFakeUnsupportedOps: """Anything that needs real data must fail loudly at bake time rather than - silently transferring the wrong bytes. - """ + silently transferring the wrong bytes.""" def _fake(self): return FakeRDTTensor( @@ -285,8 +278,7 @@ class TestFakeUnsupportedOps: class TestBakeRecording: """During the dry run the fake's ``copy_`` is the data sink: it records the - source chain plus the meta destination's strided region and moves nothing. - """ + source chain plus the meta destination's strided region and moves nothing.""" def _recorder_and_fake(self, shape=(4, 6)): rec = BakeSink() @@ -322,8 +314,7 @@ class TestBakeRecording: def test_unattributed_copy_is_live_but_unrecorded(self): """A copy_ with no loader stamp cannot be attributed to a param, so its - module must fall back to the plain load — but the name still moved data. - """ + module must fall back to the plain load — but the name still moved data.""" rec, fake = self._recorder_and_fake() rec.current = None torch.empty((4, 6), dtype=torch.bfloat16, device=META).copy_(fake) @@ -363,8 +354,7 @@ class TestBakeRecording: producer packs what the replay yields, so the record must carry the POST-chain dtype: taking it from the source name's metadata instead sizes the slice with the wrong itemsize and shifts every later slice in the - chunk, carving the packed blob differently on the two sides. - """ + chunk, carving the packed blob differently on the two sides.""" rec, fake = self._recorder_and_fake(shape=(4,)) layer = _FakeLayer("reinterpreted") rec.current = (layer, "weight") @@ -384,8 +374,7 @@ class TestBakeRecording: the producer packs what the chain yields, and nothing downstream can catch a mismatch — the consumer's buffer view is exactly prod(dest.shape) elements, so it reshapes cleanly over bytes laid out at other offsets. - So the bake refuses rather than recording a slice it cannot carve. - """ + So the bake refuses rather than recording a slice it cannot carve.""" rec, fake = self._recorder_and_fake(shape=(1, 6)) rec.current = (_FakeLayer("broadcast"), "weight") param = torch.empty((4, 6), dtype=torch.bfloat16, device=META) @@ -401,8 +390,7 @@ class TestBakeRecording: class TestConsumerIdentity: """Every worker in the fleet needs a DISTINCT id in 0..C-1: it selects the worker's producer block and keys the producer's per-consumer serve ring, so - a collision silently serves two workers out of one ring. - """ + a collision silently serves two workers out of one ring.""" def _engine(self, *, dp_index, rank, world_size): eng = object.__new__(ShardedRDTWeightTransferEngine) @@ -439,8 +427,7 @@ class TestConsumerIdentity: def test_independent_engines_offset_into_distinct_ranges(self): """A fleet of separate engines restarts _global_worker_index at 0 in each, so without the replica offset every engine would claim 0..w-1. - The driver sets replica_rank on the payload; these are the ids it buys. - """ + The driver sets replica_rank on the payload; these are the ids it buys.""" ids = [ self._ids(num_consumers=8, workers=range(4), replica_rank=r, num_replicas=2) for r in (0, 1) @@ -466,8 +453,7 @@ def _router( group_lens=None, ): """A router over ``n`` single-name groups unless told otherwise, so a test - can state expectations in group indices. - """ + can state expectations in group indices.""" if names is None: n = len(name_owner_class or []) or (len(group_lens or []) or 1) names = [f"g{i}" for i in range(n)] @@ -496,8 +482,7 @@ class TestRdtRouter: def test_every_producer_nic_carries_traffic(self): """16 producers / 8 consumers: the block rule spreads each consumer's pulls over its block, alternating by group, so no producer sits idle. - Plain `consumer_id % len(owners)` would idle half of them. - """ + Plain `consumer_id % len(owners)` would idle half of them.""" r = _router(16, 8, group_lens=[1] * 95) names = [f"g{i}" for i in range(95)] for c in range(8): @@ -515,8 +500,7 @@ class TestRdtRouter: def test_pipeline_stages_route_to_the_owning_stage(self): """2 stages x 8 ranks: groups 0-2 on stage 0, 3-5 on stage 1. Two owner - sets, one per stage; each consumer reaches both. - """ + sets, one per stage; each consumer reaches both.""" r = _router( 16, 8, @@ -532,8 +516,7 @@ class TestRdtRouter: def test_expert_names_route_to_the_holding_ranks(self): """A name held by only some ranks routes to those; a replicated name - keeps the full set. - """ + keeps the full set.""" r = RdtRouter( 8, 4, @@ -552,8 +535,7 @@ class TestRdtRouter: def test_consumers_spread_over_an_owner_set(self): """Several ranks hold a name (its TP peers); the block rule must spread - consumers across them, not funnel through one. - """ + consumers across them, not funnel through one.""" r = _router( 4, 4, owner_sets=[[0, 1]], name_owner_class=[0] * 6, group_lens=[1] * 6 ) @@ -562,8 +544,7 @@ class TestRdtRouter: def test_a_group_frees_at_every_owner_of_any_of_its_names(self): """The free barrier is per group, so its fan-out is the UNION over the - group's names: a rank holding none of them is not signalled. - """ + group's names: a rank holding none of them is not signalled.""" r = RdtRouter(4, 2, [[0, 1], [2, 3]], [0, 1, 0], ["a", "b", "c"], [2, 1]) assert r.group_owners(0) == [0, 1, 2, 3] assert r.group_owners(1) == [0, 1] @@ -633,8 +614,7 @@ class TestReplicaOverlay: def test_adding_a_deployment_does_not_move_the_first_one(self): """The strongest form: an existing consumer's routes are byte-identical - before and after another deployment is provisioned. - """ + before and after another deployment is provisioned.""" one, names = self._fleet(16, 8, 1) two, _ = self._fleet(16, 8, 2) for consumer_id in range(8): @@ -644,8 +624,7 @@ class TestReplicaOverlay: def test_one_deployment_is_the_historical_carve(self): """Default (no width) and width == the whole fleet must agree with the - plain block rule, so a single-deployment fleet is untouched. - """ + plain block rule, so a single-deployment fleet is untouched.""" plain = _router(16, 8, group_lens=[1] * 6) explicit, names = self._fleet(16, 8, 1) for consumer_id in range(8): @@ -659,8 +638,7 @@ class TestReplicaOverlay: def test_the_overlay_holds_for_partially_owned_names(self): """Pipeline stages and experts too: two owner sets, one narrow. The narrow one already forced agreement (one owner, no block to carve); the - wide one is what the carve decides. - """ + wide one is what the carve decides.""" r, names = self._fleet( 8, 4, @@ -676,16 +654,14 @@ class TestReplicaOverlay: def test_a_width_that_does_not_divide_the_fleet_raises(self): """A uniform fleet is asserted upstream in ``get_world_size``; if it ever is not, the overlay would map two workers of one deployment onto the same - block index, so refuse rather than serve the wrong bytes. - """ + block index, so refuse rather than serve the wrong bytes.""" with pytest.raises(ValueError, match="does not divide"): RdtRouter(4, 6, None, None, ["a"], [1], workers_per_replica=4) def test_pulls_still_carry_the_global_consumer_id(self): """The carve uses the index WITHIN a deployment, but the wire must keep the fleet-global id: it is what lets the producer tell the sharers of a - slot apart, and count their arrivals separately. - """ + slot apart, and count their arrivals separately.""" class _Method: def __init__(self): @@ -728,8 +704,7 @@ def _producer_pack_offsets(slices): class TestPackedLayout: def test_consumer_layout_matches_the_producer_rule(self): """Mixed dtypes, sizes that do not land on 16B — i.e. the Kimi-style - group (fp8 weights + fp32 scales + bf16 norms) that exposes alignment. - """ + group (fp8 weights + fp32 scales + bf16 norms) that exposes alignment.""" specs = [ ("w.fp8", "float8_e4m3fn", [17]), ("w.scale", "float32", [3]), @@ -804,8 +779,7 @@ class TestPackedLayout: class TestChunkModuleScatters: """The chunk cut: one chunk per distinct owner class present in the copies, ascending by class index. Derived purely from the bake plus the ownership - table, so vLLM's expert placement needs no cases. - """ + table, so vLLM's expert placement needs no cases.""" def test_unstamped_copies_form_one_chunk(self): layer = _FakeLayer("l") @@ -819,8 +793,7 @@ class TestChunkModuleScatters: """Classes are numbered by first appearance in metadata order, so the replicated class (0) leads and the rest follow — the ordering the old "-1 first, then ascending stamp" rule produced, now falling out of the - table instead of a special case. - """ + table instead of a special case.""" layer = _FakeLayer("moe") names = ["norm", "e5", "e0", "e2"] copies = [_copy(n, shape=(4,)) for n in names] @@ -840,8 +813,7 @@ class TestChunkModuleScatters: def test_copy_order_within_a_chunk_is_bake_order(self): """Scatter order within a chunk must follow the bake, not the stamp - sort: the packed layout and the producer's replay agree on keys order. - """ + sort: the packed layout and the producer's replay agree on keys order.""" layer = _FakeLayer("moe") names = ["e3", "e1", "e2"] # one stamp, deliberately unsorted names copies = [_copy(n, shape=(4,)) for n in names] @@ -855,8 +827,7 @@ class TestChunkModuleScatters: def test_stamps_interleave_across_modules_without_reordering_within(self): """Two modules' copies bucket by stamp; within each bucket the order is - module-then-bake order. - """ + module-then-bake order.""" a, b = _FakeLayer("a"), _FakeLayer("b") mods = [ _module(a, [_copy("a0", shape=(4,)), _copy("a1", shape=(4,))]), @@ -876,8 +847,7 @@ class TestChunkModuleScatters: def test_scatters_carry_their_own_dtype(self): """Dtype rides the record from the bake, where it is the fake's dtype AFTER its op chain — not a plan-time lookup of the source name, which - would be wrong for any chain that reinterprets dtype. - """ + would be wrong for any chain that reinterprets dtype.""" layer = _FakeLayer("l") eng = _planner({}, name_meta={"w": ("float32", [10])}) ((_er, scatters),) = eng._chunk_module_scatters( @@ -916,8 +886,7 @@ class TestBuildCallPlan: def test_materialize_fires_on_a_modules_first_chunk_only(self): """Empty HF params are allocated once per module, by construction — - including a FusedMoE-like module whose copies span owner-class chunks. - """ + including a FusedMoE-like module whose copies span owner-class chunks.""" layer = _FakeLayer("spanning") names = [f"w{i}" for i in range(4)] copies = [_copy(n, shape=(4,)) for n in names] @@ -952,8 +921,7 @@ class TestBuildCallPlan: def test_free_signal_waits_for_a_groups_last_chunk_when_it_is_split(self): """The load-bearing case: with the group cut across owner-class chunks the signal must hang off the LAST one. Signaling earlier lets the producers - drop the gather buffers while a later chunk's RDMA is still reading. - """ + drop the gather buffers while a later chunk's RDMA is still reading.""" layer = _FakeLayer("l") names = [f"w{i}" for i in range(4)] copies = [_copy(n, shape=(4,)) for n in names] @@ -969,8 +937,7 @@ class TestBuildCallPlan: def test_free_signal_timing_across_two_split_groups(self): """Two groups x 2 owner-class chunks each: signals land on each group's - last chunk only. - """ + last chunk only.""" names_a = [f"model.layers.0.w{i}" for i in range(4)] names_b = [f"model.layers.1.w{i}" for i in range(4)] baked, name_meta, stamps = {}, {}, {} @@ -988,8 +955,7 @@ class TestBuildCallPlan: def test_a_group_with_nothing_local_is_signaled_at_sync_start(self): """The owners still published it, so this consumer must signal it — immediately, before the pipeline (signal-before-publish is tolerated), - never hung off another group's chunk. - """ + never hung off another group's chunk.""" baked, name_meta, names, group_lens = _one_module_per_layer(2) del baked["model.layers.1.w"] # nothing baked, and not live => no pull eng = _planner( @@ -1010,8 +976,7 @@ class TestBuildCallPlan: def test_modules_are_deduped_within_a_group(self): """Several names of one fused module map to the same scatter list; the - plan must not chunk it twice. - """ + plan must not chunk it twice.""" layer = _FakeLayer("fused") names = ["qkv.q", "qkv.k", "qkv.v"] copies = [_copy(n, shape=(4,)) for n in names] @@ -1027,8 +992,7 @@ class TestBuildCallPlan: def test_plan_is_a_pure_function_of_its_inputs(self): """Called twice with the same arguments it must produce the same plan — - that is what lets the engine build it once and reuse it every sync. - """ + that is what lets the engine build it once and reuse it every sync.""" baked, name_meta, names, group_lens = _one_module_per_layer(2) eng = _planner(baked, name_meta=name_meta) a = eng._build_call_plan(names, group_lens) @@ -1048,8 +1012,7 @@ class TestBuildCallPlan: class TestUnbakedNamesGuard: """A live name with no baked plan has no way to load — there is no fallback, and its pull would target groups the pipeline already freed — so the plan - build fails at init, naming the names. - """ + build fails at init, naming the names.""" def test_a_live_unbaked_name_fails_the_plan_build(self): baked, name_meta, names, group_lens = _one_module_per_layer(2) @@ -1060,8 +1023,7 @@ class TestUnbakedNamesGuard: def test_never_copied_names_are_dropped_entirely(self): """Experts owned by another EP rank no-op in their loader: not an error, - and not a chunk — their group is pre-freed if nothing else fills it. - """ + and not a chunk — their group is pre-freed if nothing else fills it.""" baked, name_meta, names, group_lens = _one_module_per_layer(2) del baked["norm.weight"] eng = _planner(baked, name_meta=name_meta, live=set(names) - {"norm.weight"}) @@ -1073,15 +1035,13 @@ class TestUnbakedNamesGuard: class TestCallPlanRouting: """Under partial ownership each chunk must be pulled from a producer that actually holds every name in it. Consumers bind EVERY producer (signals fan - out to all owners), so local index == trainer rank. - """ + out to all owners), so local index == trainer rank.""" def _routed_planner( self, held_by_group, num_consumers, consumer_id, *, held_by=None ): """``held_by_group[g]`` = the ranks holding group g's names, so a test - can still speak in groups; ``held_by`` overrides individual names. - """ + can still speak in groups; ``held_by`` overrides individual names.""" baked, name_meta, names, group_lens = _one_module_per_layer( len(held_by_group) - 2 ) @@ -1108,16 +1068,14 @@ class TestCallPlanRouting: def test_two_stage_ownership_splits_chunks_between_owners(self): """Two PP stages, 4 groups: stage 0 holds the first half, stage 1 the - second. Every chunk goes to a holder of its names. - """ + second. Every chunk goes to a holder of its names.""" eng, names, group_lens = self._routed_planner([[0], [0], [1], [1]], 1, 0) plan = eng._build_call_plan(names, group_lens) assert [c.owner for c in plan.chunks] == [0, 0, 1, 1] def test_a_multi_owner_group_still_resolves_to_one_producer(self): """Every chunk is served by exactly ONE producer: splitting a pull only - multiplies produce calls, since the consumer's NIC bounds it. - """ + multiplies produce calls, since the consumer's NIC bounds it.""" eng, names, group_lens = self._routed_planner([[0, 1]] * 4, 1, 0) plan = eng._build_call_plan(names, group_lens) assert all(0 <= c.owner < 2 for c in plan.chunks) @@ -1125,8 +1083,7 @@ class TestCallPlanRouting: def test_an_expert_name_routes_to_the_rank_holding_it(self): """PP ∩ EP: stage 0 = ranks 0-1, stage 1 = ranks 2-3, and one expert name inside a stage-1 group is held by rank 3 alone. The name's own owner - set is what routes it. - """ + set is what routes it.""" eng, names, group_lens = self._routed_planner( [[0, 1], [0, 1], [2, 3], [2, 3]], 1, @@ -1141,8 +1098,7 @@ class TestCallPlanRouting: def test_an_unheld_name_is_rejected_at_init(self): """A name no rank holds can never be served. The trainer raises when it transposes the holdings; the router's validate() is the consumer-side - backstop, and either way it fails at init rather than at first pull. - """ + backstop, and either way it fails at init rather than at first pull.""" with pytest.raises(ValueError, match="empty"): RdtRouter(2, 1, [[]], [0], ["w"], [1]).validate() @@ -1151,16 +1107,14 @@ class TestSignalCompleteness: """Every gather group is signaled exactly once — after its last chunk when the worker pulls from it, at sync start otherwise — for ANY expert placement. A group signaled twice over-credits the barrier; a group never - signaled parks a producer credit and hangs end_sync. - """ + signaled parks a producer credit and hangs end_sync.""" def _moe_planner(self, worker_experts, *, ep_size=4, n_experts=8, n_layers=2): """Pre / n_layers MoE layers / post. Each layer: one norm (its own module, stamp -1) + n_experts expert names stamped ``e // n_local``. The worker's bake covers only ``worker_experts`` (its placement); foreign expert names never copied => dropped entirely, as in the real - bake. - """ + bake.""" n_local = n_experts // ep_size names = ["embed.weight"] group_lens = [1] @@ -1220,8 +1174,7 @@ class TestSignalCompleteness: def test_placement_changes_only_the_chunk_count_never_the_signals(self): """Linear experts 0-3 hit 2 owner classes; round_robin 0,2,4,6 - hits all 4. More chunks per group, identical signal set. - """ + hits all 4. More chunks per group, identical signal set.""" plans = {} for label, experts in (("linear", [0, 1, 2, 3]), ("round_robin", [0, 2, 4, 6])): eng, names, group_lens = self._moe_planner(worker_experts=experts) @@ -1235,8 +1188,7 @@ class TestSignalCompleteness: def test_the_fused_module_materializes_first_and_quants_last_across_chunks(self): """The FusedMoE shape: one module's copies span every owner-class chunk of - its group; materialize on its first, quant on its last. - """ + its group; materialize on its first, quant on its last.""" eng, names, group_lens = self._moe_planner( worker_experts=[0, 2, 4, 6], n_layers=1 ) @@ -1294,8 +1246,7 @@ class TestLayerwiseGroups: def test_flattening_a_partition_returns_the_input_order(self): """Un-indexed names group by POSITION, not by name class — so one that looks like a pre-block name still lands after the layers it follows. - Group index therefore means the same thing on every rank. - """ + Group index therefore means the same thing on every rank.""" names = [ "embed.weight", "model.layers.0.a", @@ -1313,8 +1264,7 @@ class TestLayerwiseGroups: def test_stacks_keep_prefix_appearance_order_and_sort_within(self): """Two stacks stay in the order they appear — the vision tower before the - text stack — while each sorts by index internally. - """ + text stack — while each sorts by index internally.""" names = [ "visual.blocks.1.w", "visual.blocks.0.w", @@ -1331,8 +1281,7 @@ class TestLayerwiseGroups: def test_the_post_block_lands_last_however_early_it_arrives(self): """Megatron-Bridge streams the last pipeline stage's output block before its layers. Sweeping un-indexed names after the first layer into a - trailing group is what lets the gather loop walk groups ascending. - """ + trailing group is what lets the gather loop walk groups ascending.""" names = ["model.layers.0.w", "model.norm.weight", "model.layers.1.w"] assert layerwise_groups(names) == [ ["model.layers.0.w"], @@ -1342,8 +1291,7 @@ class TestLayerwiseGroups: def test_names_sharing_a_layer_coalesce_when_the_source_interleaves(self): """A raw-checkpoint source may yield in shard-packing order. Coalescing on - the key keeps that from shattering one layer into many groups. - """ + the key keeps that from shattering one layer into many groups.""" names = [ "model.layers.0.a", "model.layers.1.a", @@ -1385,15 +1333,13 @@ class TestLayerwiseGroups: def test_every_supported_naming_convention_partitions_per_layer(self, prefix): """One decoder layer per group under any prefix, with no per-architecture table. A literal `model.layers.` match silently yields one whole-model - group for most of these. - """ + group for most of these.""" names = [f"{prefix}{i}.self_attn.q_proj.weight" for i in range(3)] assert layerwise_groups(names) == [[n] for n in names] def test_a_moe_layer_stays_whole(self): """The OUTERMOST index wins, so per-expert names group by layer. Splitting - on the expert would cut FusedMoE — one leaf module — across groups. - """ + on the expert would cut FusedMoE — one leaf module — across groups.""" names = [ "model.layers.0.mlp.experts.0.w1.weight", "model.layers.0.mlp.experts.1.w1.weight", @@ -1410,8 +1356,7 @@ class TestLayerwiseGroups: def test_a_vlm_partitions_the_vision_tower_and_the_text_stack(self): """Qwen-VL layout. Today's literal `model.layers.` match puts every one of these in ONE group — the whole model — because the text stack ships as - `model.language_model.layers.`. - """ + `model.language_model.layers.`.""" names = [ "visual.patch_embed.proj.weight", "visual.blocks.0.attn.qkv.weight", @@ -1430,8 +1375,7 @@ class TestLayerwiseGroups: def test_two_stacks_sharing_an_index_do_not_merge(self): """The key carries the prefix, so vision block 0 and text layer 0 are - different groups even though both are index 0. - """ + different groups even though both are index 0.""" names = [ "visual.blocks.0.attn.qkv.weight", "model.language_model.layers.0.self_attn.q_proj.weight", @@ -1468,23 +1412,20 @@ class TestOpAllowlistAgreement: def test_every_bake_recordable_op_is_replayable(self): """Anything the bake can record must be serveable, or the failure lands a - whole sync later than the mistake. - """ + whole sync later than the mistake.""" assert not set(SUPPORTED_OPS.values()) - set(ALLOWED_OPS) def test_the_producer_allows_nothing_the_consumer_cannot_emit(self): """The allowlist is also a guard against a misbehaving or spoofed consumer invoking arbitrary methods on trainer tensors, so it must not be wider than the ops the bake can actually produce. ``to`` in particular - would let a replay change dtype or device. - """ + would let a replay change dtype or device.""" assert not set(ALLOWED_OPS) - set(SUPPORTED_OPS.values()) assert "to" not in ALLOWED_OPS def test_transpose_via_t_is_serveable(self): """The specific regression: a chain recorded from ``.t()`` must pass the - producer's guard. - """ + producer's guard.""" fake = FakeRDTTensor( name="w", shape=torch.Size((4, 6)), @@ -1529,8 +1470,7 @@ BAKE_MODELS = [ class TestRequiresTheRayExecutor: """The engine's data plane is Ray's, so a non-Ray executor cannot work. The check is at construction because the alternative is an opaque failure during - the first handshake, long after the misconfiguration. - """ + the first handshake, long after the misconfiguration.""" def _construct(self, backend): cfg = SimpleNamespace( @@ -1557,8 +1497,7 @@ class TestRequiresTheRayExecutor: def test_a_custom_executor_class_is_left_alone(self): """A `type[Executor]` override is deliberate and unjudgeable here, so it - must not be rejected for merely not being the string "ray". - """ + must not be rejected for merely not being the string "ray".""" class _CustomExecutor: pass diff --git a/tests/distributed/test_sharded_rdt_producer.py b/tests/distributed/test_sharded_rdt_producer.py index 7036d10289..8147841d9a 100644 --- a/tests/distributed/test_sharded_rdt_producer.py +++ b/tests/distributed/test_sharded_rdt_producer.py @@ -236,8 +236,7 @@ class TestPublishAndRebuild: def test_views_of_one_storage_do_not_overlap(self, server_factory): """One IPC export per storage, one as_strided view per name — the whole point of the storage/view split. Overlapping views would serve the same - bytes for two different weights. - """ + bytes for two different weights.""" server = server_factory() server.begin_sync(1) _publish(server, GI_A, GROUP_A, nbytes=64) @@ -260,8 +259,7 @@ class TestPublishAndRebuild: def test_the_default_lookahead_is_one(self): """1 is the sweet spot: group N+1 is gathered AND pullable while N is being pulled, with resident memory at its floor of 2 groups — the bound - the larger-model runs size against. - """ + the larger-model runs size against.""" assert DEFAULT_GATHER_LOOKAHEAD == 1 @@ -276,8 +274,7 @@ class TestFreeBarrier: def test_group_is_held_until_the_last_live_consumer_signals(self, server_factory): """Every live consumer signals every owner; releasing on the first - signal would drop storage other consumers are still reading. - """ + signal would drop storage other consumers are still reading.""" server = server_factory() server.begin_sync(3) _publish(server, GI_A, GROUP_A) @@ -304,8 +301,7 @@ class TestFreeBarrier: ): """A consumer with nothing to pull from a group signals it at sync start, which can precede the publish. The publish must then release the - group rather than wait for a signal that will never come again. - """ + group rather than wait for a signal that will never come again.""" server = server_factory() server.begin_sync(1) server.free_group(GI_A) @@ -328,8 +324,7 @@ class TestFreeBarrier: the server says the group is gone — and it hears that ONLY through ``wait_freed`` / ``end_sync``, never a publish return (a freed notice riding an unharvested async publish while the engine blocks in - ``wait_freed`` would wedge the loop). - """ + ``wait_freed`` would wedge the loop).""" server = server_factory() server.begin_sync(1) _publish(server, GI_A, GROUP_A) @@ -358,8 +353,7 @@ class TestFreeBarrier: class _CountingSource: """`iter_groups` yielding one CPU-tensor group per call, built lazily so a - group's tensors exist only once the engine's credit gate lets it gather. - """ + group's tensors exist only once the engine's credit gate lets it gather.""" def __init__(self, groups): self._groups = groups @@ -372,8 +366,7 @@ class _CountingSource: class _ResidencyDict(dict): """The engine's `_inflight`, instrumented: `max_len` is the high-water mark of groups whose CUDA-IPC export refs were alive at once — the trainer's - resident-memory bound in groups. - """ + resident-memory bound in groups.""" def __init__(self): super().__init__() @@ -387,8 +380,7 @@ class _ResidencyDict(dict): def _loop_engine(server, n_groups, *, lookahead): """A real engine wired straight to a real (non-Ray) server, with only the state `_run_gather_loop` reads. The `_rpc` seam dispatches inline; - `_publish_async` sees no `.remote` and runs inline too. - """ + `_publish_async` sees no `.remote` and runs inline too.""" groups = [(f"model.layers.{gi}.w",) for gi in range(n_groups)] e = ShardedRDTTrainerWeightTransferEngine.__new__( ShardedRDTTrainerWeightTransferEngine @@ -411,16 +403,14 @@ class TestGatherCredit: serveable immediately, and the ENGINE's loop stops gathering while more than `gather_lookahead` groups are unfreed. So at most `lookahead + 1` groups are resident — two at the default — while group N+1 is pulled the instant N's - pulls finish. - """ + pulls finish.""" @pytest.fixture def gather_engine(self, monkeypatch): """Neutralize the two CUDA touches in the export path so the REAL gather loop runs on CPU: `.cuda()` becomes identity, and the storage export ships the `(nbytes, ..., device, ...)` tuple the fixture's - stubbed `rebuild_cuda_tensor` expects. - """ + stubbed `rebuild_cuda_tensor` expects.""" monkeypatch.setattr(torch.Tensor, "cuda", lambda self: self) monkeypatch.setattr( trainer_mod, @@ -432,8 +422,7 @@ class TestGatherCredit: def test_publish_never_blocks(self, server_factory): """Publishing must not park on a credit: the whole point is that a gathered group becomes serveable immediately. Three publishes with no - frees, inline on this thread — a block here hangs the test. - """ + frees, inline on this thread — a block here hangs the test.""" server = server_factory(gather_lookahead=1) server.begin_sync(1) for gi in range(3): @@ -447,8 +436,7 @@ class TestGatherCredit: than 2 groups of gathered weights, no matter how the consumer paces — and the pipeline still overlaps, because the consumer here refuses to free group N until N+1 is already published (pullable). A gate an - off-by-one too tight deadlocks this test; too loose fails max_len. - """ + off-by-one too tight deadlocks this test; too loose fails max_len.""" server = server_factory(gather_lookahead=1) n_groups = 8 engine = gather_engine(server, n_groups, lookahead=1) @@ -490,8 +478,7 @@ class TestGatherCredit: ): """0 is the serialized baseline: the loop waits for group N to be freed before gathering N+1, so exactly ONE group is ever resident and nothing - overlaps. A floor of 1 on the bound would silently pipeline instead. - """ + overlaps. A floor of 1 on the bound would silently pipeline instead.""" server = server_factory(gather_lookahead=0) engine = gather_engine(server, 4, lookahead=0) @@ -517,8 +504,7 @@ class TestGatherCredit: self, server_factory, gather_engine ): """Lookahead + 1, not a hardcoded 2: at lookahead=2 a free-nothing - consumer sees exactly 3 groups gathered before the loop parks. - """ + consumer sees exactly 3 groups gathered before the loop parks.""" server = server_factory(gather_lookahead=2) engine = gather_engine(server, 8, lookahead=2) @@ -554,8 +540,7 @@ class TestGatherCredit: def test_a_gather_error_releases_a_blocked_wait_freed(self, server_factory): """Otherwise a trainer-side failure on another rank deadlocks this one inside its credit gate. It must RAISE, not return empty — an empty - return would spin the engine straight back into the wait. - """ + return would spin the engine straight back into the wait.""" server = server_factory() server.begin_sync(1) _publish(server, GI_A, GROUP_A) @@ -636,8 +621,7 @@ class TestBeginSync: def test_the_target_is_floored_at_one(self, server_factory): """A bare/zero call must not make every group free instantly (or divide - the barrier by zero). - """ + the barrier by zero).""" server = server_factory() server.begin_sync(0) assert server._live_count == 1 @@ -645,8 +629,7 @@ class TestBeginSync: def test_a_degraded_sync_lowers_the_target(self, server_factory): """FT degraded sync: the live count is the WHOLE degraded-sync mechanism on this side — the group releases after the live consumers - alone. - """ + alone.""" server = server_factory() server.begin_sync(2) # 4 provisioned, 2 alive _publish(server, GI_A, GROUP_A) @@ -670,8 +653,7 @@ class TestBeginSync: def test_a_straggler_signal_cannot_credit_the_next_sync(self, server_factory): """begin_sync resets the counts, so a signal that leaked past the sync boundary would over-credit — the reason the consumer drains its fired - signals before finishing. Pin the reset side of that contract. - """ + signals before finishing. Pin the reset side of that contract.""" server = server_factory() server.begin_sync(2) _publish(server, GI_A, GROUP_A) @@ -693,8 +675,7 @@ class TestBeginSync: self, server_factory ): """The packed layout repeats every sync — that is what makes caching the - destination views worth ~5ms per 384-spec group. - """ + destination views worth ~5ms per 384-spec group.""" server = server_factory() server._pack_dsts[("sentinel",)] = (0, []) server.begin_sync(1) @@ -705,8 +686,7 @@ class TestServedNamesGuard: """A producer serves only the names it holds: its stage's groups, and within them its own EP coordinate's experts plus the replicated names. Without this guard a misrouted pull would block forever in the cache wait - for a name this rank never publishes. - """ + for a name this rank never publishes.""" def test_a_pull_for_an_unserved_name_fails_loudly(self, server_factory): server = server_factory(served_names=list(GROUP_A)) @@ -722,8 +702,7 @@ class TestServedNamesGuard: def test_served_names_none_accepts_anything(self, server_factory): """Gather-to-all: every producer holds every group, so there is nothing - to guard. The call proceeds to the cache wait (not exercised here). - """ + to guard. The call proceeds to the cache wait (not exercised here).""" server = server_factory(served_names=None) assert server._served_names is None @@ -770,8 +749,7 @@ class TestStallWatchdog: def test_end_sync_fails_when_a_consumer_never_signals(self, server_factory): """The exact mid-sync death signature: the group is published, one of - the two live consumers that owed a signal is gone. - """ + the two live consumers that owed a signal is gone.""" server = server_factory(stall_timeout_s=0.3) server.begin_sync(2) _publish(server, GI_A, GROUP_A) @@ -785,8 +763,7 @@ class TestStallWatchdog: """The watchdog fires on the existing `set_gather_error` channel, so one stall unwinds the whole rank through one path rather than each waiter timing out separately — here both a consumer parked in the serve cache - wait and the engine parked in its credit gate. - """ + wait and the engine parked in its credit gate.""" server = server_factory(gather_lookahead=1, stall_timeout_s=0.3) server.begin_sync(1) _publish(server, GI_A, GROUP_A) @@ -819,8 +796,7 @@ class TestStallWatchdog: """A consumer that is slow but signaling must never trip it: the stamp is global to the producer, so a steady trickle of signals holds the whole rank open. Nine sequential publishes with a 0.3s timeout each take - longer in total than the timeout, and none may fire. - """ + longer in total than the timeout, and none may fire.""" server = server_factory(gather_lookahead=1, stall_timeout_s=0.3) server.begin_sync(1) for gi in range(9): @@ -833,8 +809,7 @@ class TestStallWatchdog: def test_begin_sync_resets_the_progress_stamp(self, server_factory): """Syncs are minutes apart. Without the reset the first publish of sync N+1 - would measure its stall from somewhere inside sync N and fire immediately. - """ + would measure its stall from somewhere inside sync N and fire immediately.""" server = server_factory(gather_lookahead=1, stall_timeout_s=0.3) server.begin_sync(1) _publish(server, GI_A, GROUP_A) @@ -856,8 +831,7 @@ class TestConcurrentPublishAndFree: self, server_factory ): """Every group published must end up freed and out of the cache, with - end_sync returning cleanly — the property whose violation is a hang. - """ + end_sync returning cleanly — the property whose violation is a hang.""" server = server_factory(gather_lookahead=2) server.begin_sync(1) groups = [(gi, (f"model.layers.{gi}.w",)) for gi in range(12)] @@ -892,8 +866,7 @@ class TestConcurrentPublishAndFree: ): """All live consumers signaling at once: the release must happen on the last signal and only once, or the engine drops IPC refs twice (or - never). - """ + never).""" server = server_factory() server.begin_sync(8) _publish(server, GI_A, GROUP_A) @@ -920,8 +893,7 @@ class TestFakeServerAgreesWithTheRealOne: """`test_sharded_rdt_trainer.py`'s `_FakeProducerServer` is a second, independent model of this protocol that the engine-side tests assert on. Pin the two against each other so the fake cannot silently drift from the - semantics the real server enforces. - """ + semantics the real server enforces.""" @staticmethod def _fake(): @@ -952,8 +924,7 @@ class TestExportRing: """The packed export path. Its one hard invariant is that the trainer packs a group exactly the way ``publish_group`` rebuilds it — a layout disagreement would serve the wrong bytes with nothing downstream to catch - it. - """ + it.""" @staticmethod def _engine(): @@ -1045,8 +1016,7 @@ class TestExportRingSlotSafety: ): """Free the later group of each pair first and hold the earlier one live until the NEXT group is gathered -- the window a modular slot counter got - wrong (at lookahead=1 there are 2 slots, so group 2 took group 0's). - """ + wrong (at lookahead=1 there are 2 slots, so group 2 took group 0's).""" server = server_factory(gather_lookahead=1) n_groups = 8 engine = gather_engine(server, n_groups, lookahead=1) @@ -1170,8 +1140,7 @@ class TestSharedServeSlots: def test_one_deployment_never_shares(self, sharing_server): """With the width equal to the live count every group is a singleton, so - each call packs for itself out of its own ring. - """ + each call packs for itself out of its own ring.""" server = sharing_server(workers_per_replica=2) server.begin_sync(2, [0, 1]) _publish(server, GI_A, GROUP_A) @@ -1251,8 +1220,7 @@ class TestSharedServeSlots: def test_a_seqless_call_is_refused(self, sharing_server): """The slot comes from ``seq``, so a caller that sends none cannot be - served safely. - """ + served safely.""" server = sharing_server(workers_per_replica=2) server.begin_sync(1, [0]) _publish(server, GI_A, GROUP_A) @@ -1262,8 +1230,7 @@ class TestSharedServeSlots: def test_a_failed_pack_reaches_every_sharer(self, sharing_server): """Only the packer touches the buffer, so its failure has to be - republished: a waiter must raise rather than read a half-written slot. - """ + republished: a waiter must raise rather than read a half-written slot.""" server = sharing_server(workers_per_replica=2) server.begin_sync(4, [0, 1, 2, 3]) _publish(server, GI_A, GROUP_A) @@ -1287,8 +1254,7 @@ class TestSharedServeSlots: def test_a_degraded_sync_narrows_the_rendezvous(self, sharing_server): """A dead deployment must not be waited for: a survivor left alone in - its group packs for itself instead of blocking on the corpse. - """ + its group packs for itself instead of blocking on the corpse.""" server = sharing_server(workers_per_replica=2, stall_timeout_s=30.0) server.begin_sync(3, [0, 1, 3]) # consumer 2 died _publish(server, GI_A, GROUP_A) @@ -1302,8 +1268,7 @@ class TestSharedServeSlots: def test_a_sharer_that_never_arrives_trips_the_watchdog(self, sharing_server): """A consumer that dies INSIDE the sync window has no detector, exactly - as for the free barrier; the rendezvous waits on the same channel. - """ + as for the free barrier; the rendezvous waits on the same channel.""" server = sharing_server(workers_per_replica=2, stall_timeout_s=0.3) server.begin_sync(4, [0, 1, 2, 3]) _publish(server, GI_A, GROUP_A) @@ -1315,8 +1280,7 @@ class TestSharedServeSlots: class TestSharedReservation: """``reserve_serve_buffer`` under sharing: one ring per GROUP, and the - init-time check that the group's members pull the same chunks. - """ + init-time check that the group's members pull the same chunks.""" def test_matching_plans_reserve_one_ring_between_them(self, sharing_server): server = sharing_server(workers_per_replica=2) @@ -1338,8 +1302,7 @@ class TestSharedReservation: def test_mismatched_plans_fail_at_reservation(self, sharing_server): """Sharing rests on the sharers pulling the same chunks. Checked here, where it names both consumers, rather than at serve time, where it is a - rendezvous nobody completes. - """ + rendezvous nobody completes.""" server = sharing_server(workers_per_replica=2) server.reserve_serve_buffer(0, 1024, "plan-a") @@ -1348,8 +1311,7 @@ class TestSharedReservation: def test_different_groups_may_differ(self, sharing_server): """Only the members of ONE group have to agree; worker 0 and worker 1 of - the same deployment hold different slices and never share a slot. - """ + the same deployment hold different slices and never share a slot.""" server = sharing_server(workers_per_replica=2) server.reserve_serve_buffer(0, 1024, "plan-a") server.reserve_serve_buffer(1, 1024, "plan-b") @@ -1358,8 +1320,7 @@ class TestSharedReservation: def test_a_missing_digest_skips_the_check(self, sharing_server): """The digest is optional on the wire, so an engine that does not send - one still reserves. - """ + one still reserves.""" server = sharing_server(workers_per_replica=2) server.reserve_serve_buffer(0, 1024, None) server.reserve_serve_buffer(2, 1024, None) diff --git a/tests/distributed/test_sharded_rdt_trainer.py b/tests/distributed/test_sharded_rdt_trainer.py index df9628cc85..9339e503c4 100644 --- a/tests/distributed/test_sharded_rdt_trainer.py +++ b/tests/distributed/test_sharded_rdt_trainer.py @@ -34,8 +34,7 @@ from vllm.distributed.weight_transfer.sharded_rdt_trainer import ( class _ListSource(WeightSource): """A WeightSource over an explicit ordered (name, cpu-tensor) list, so the - sharded-RDT group/order logic can be tested without a real model. - """ + sharded-RDT group/order logic can be tested without a real model.""" def __init__(self, pairs): self._pairs = list(pairs) @@ -55,8 +54,7 @@ class _FakeProducerServer: per-group barrier: publish/free are keyed by GROUP INDEX, signals count to the ``begin_sync`` live total, publish_group returns nothing, and freed groups flow back only through wait_freed / end_sync (see - test_sharded_rdt_producer.TestFakeServerAgreesWithTheRealOne). - """ + test_sharded_rdt_producer.TestFakeServerAgreesWithTheRealOne).""" def __init__(self, auto_free=True): self.order: list[str] = [] @@ -100,8 +98,7 @@ class _FakeProducerServer: must already have a banked credit when the gate asks (auto_free, or a test's own free_group) — anything else is the deadlock the real watchdog would kill, so fail loudly. Not appended to ``order``: it is - pacing, not a lifecycle milestone. - """ + pacing, not a lifecycle milestone.""" assert self._pending_freed, ( "wait_freed with nothing freed: the gather loop would deadlock" ) @@ -124,8 +121,7 @@ def _rdt_engine_with_fake_server( ): """Build a ShardedRDTTrainerWeightTransferEngine wired to an in-process fake server (no Ray, no CUDA IPC): bypass trainer_init's spawn, set the - group-major metadata, and route _rpc to the fake. - """ + group-major metadata, and route _rpc to the fake.""" import vllm.distributed.weight_transfer.sharded_rdt_trainer as mod # reduce_tensor needs CUDA; the fake server never rebuilds, so stub it. @@ -325,8 +321,7 @@ def test_sharded_rdt_send_weights_surfaces_update_error(monkeypatch): class _OwnedSource(_ListSource): """A source holding only some groups' names, like a pipeline-parallel rank. - Takes group indices for convenience and declares the names inside them. - """ + Takes group indices for convenience and declares the names inside them.""" def __init__(self, pairs, owned_group_idx): super().__init__(pairs) @@ -392,8 +387,7 @@ def test_sharded_rdt_owned_group_order_mismatch_raises(monkeypatch): ) def test_sharded_rdt_begin_sync_carries_the_live_count(monkeypatch): """The free barrier's target is one integer per sync: the live consumer - count, defaulting to the whole provisioned fleet. - """ + count, defaulting to the whole provisioned fleet.""" server = _FakeProducerServer(auto_free=True) engine = _rdt_engine_with_fake_server( _rdt_source_two_layers(), @@ -411,8 +405,7 @@ def test_sharded_rdt_begin_sync_carries_the_live_count(monkeypatch): class TestLiveCountPlumbing: """``send_weights(live_consumer_ids)`` -> the barrier target. The provisioned geometry is frozen; a degraded sync only lowers the target and - narrows each slot-sharing group's rendezvous. - """ + narrows each slot-sharing group's rendezvous.""" @staticmethod def _engine(num_consumers, world=2, rank=0): @@ -445,8 +438,7 @@ class TestLiveCountPlumbing: def test_which_consumers_died_does_not_matter_only_how_many(self): """The whole point of the barrier: no routed per-producer targets, so - the identity of the dead consumer is irrelevant to the producers. - """ + the identity of the dead consumer is irrelevant to the producers.""" counts = [] for live in ([0, 1, 2, 3], [4, 5, 6, 7], [0, 2, 4, 6]): engine, got = self._engine(num_consumers=8) @@ -457,8 +449,7 @@ class TestLiveCountPlumbing: def test_the_live_ids_travel_with_the_count(self): """The count sizes the free barrier, the ids size the slot-sharing rendezvous, so a producer that shares slots can tell WHICH consumers it - is still waiting for. They must describe the same set. - """ + is still waiting for. They must describe the same set.""" engine, got = self._engine(num_consumers=8) engine.send_weights([6, 0, 2, 2]) ((count, ids),) = got @@ -526,8 +517,7 @@ def test_sharded_rdt_rejects_a_rank_holding_nothing(monkeypatch): def test_sharded_rdt_rejects_a_name_no_rank_holds(monkeypatch): """Every name must be held somewhere or it can never be served — caught - when the holdings are transposed, naming the orphan. - """ + when the holdings are transposed, naming the orphan.""" with pytest.raises(ValueError, match="no trainer rank holds"): _rdt_engine_with_fake_server( _OwnedSource(_rdt_source_two_layers()._pairs, [0, 1]), @@ -541,8 +531,7 @@ def test_sharded_rdt_rejects_a_name_no_rank_holds(monkeypatch): def test_sharded_rdt_rejects_metadata_disagreement_across_ranks(monkeypatch): """Only the sender's metadata reaches the consumers, so a rank describing - just its own share must fail loudly rather than silently drop the rest. - """ + just its own share must fail loudly rather than silently drop the rest.""" engine = _rdt_engine_with_fake_server( _OwnedSource(_rdt_source_two_layers()._pairs, [1, 2]), is_sender=False, @@ -565,8 +554,7 @@ def _serve_ring_server(src_name, src): """A producer server with one cached tensor and a pre-seeded serve ring, so a pull needs no Ray and no NIXL registration. Returns (server, serve) where ``serve(chain)`` packs one spec into the SAME ring slot every time — which is - what puts the destination-view cache, and only it, under test. - """ + what puts the destination-view cache, and only it, under test.""" from vllm.distributed.weight_transfer.sharded_rdt_trainer import ( _RDTProducerServer, ) diff --git a/tests/distributed/test_shm_broadcast.py b/tests/distributed/test_shm_broadcast.py index 2274f15d97..7debed4cbb 100644 --- a/tests/distributed/test_shm_broadcast.py +++ b/tests/distributed/test_shm_broadcast.py @@ -419,8 +419,7 @@ def test_tensor_broadcast(): def _dumps_oob(obj) -> tuple[bytes, list]: """Pickle `obj` the same way `MessageQueue.enqueue` does: tensor - dispatch table + out-of-band buffers >= 1MiB. - """ + dispatch table + out-of-band buffers >= 1MiB.""" buffers = [] def callback(buf: pickle.PickleBuffer) -> bool: @@ -491,8 +490,7 @@ def test_tensor_pickle_roundtrip(case: str): @pytest.mark.parametrize("case", ["cuda", "requires_grad", "conj"]) def test_reduce_tensor_fallback(case: str): """Tensors the zero-copy reducer can't safely alias must fall back to - torch's default reduction. - """ + torch's default reduction.""" if case == "cuda": if not torch.cuda.is_available(): pytest.skip("requires CUDA") @@ -755,8 +753,7 @@ def test_remote_subscribe_addr_unique_concurrent_writers( Pre-fix, the writer probed a port with get_open_port() and bound it afterwards; pinning the probe to one free port makes every writer bind the same port and fail deterministically on that code path, - while the late-binding implementation never consults the probe. - """ + while the late-binding implementation never consults the probe.""" from vllm.distributed.device_communicators import shm_broadcast colliding_port = get_open_port() diff --git a/tests/distributed/test_utils.py b/tests/distributed/test_utils.py index fad1d2a006..031937d7f5 100644 --- a/tests/distributed/test_utils.py +++ b/tests/distributed/test_utils.py @@ -31,8 +31,7 @@ class _CUDADeviceCountStatelessTestActor: def test_cuda_device_count_stateless(): """Test that cuda_device_count_stateless changes return value if - CUDA_VISIBLE_DEVICES is changed. - """ + CUDA_VISIBLE_DEVICES is changed.""" if current_platform.is_rocm(): pytest.skip("Skip for ROCm because Ray uses HIP_VISIBLE_DEVICES.") actor = _CUDADeviceCountStatelessTestActor.options( # type: ignore diff --git a/tests/distributed/test_weight_transfer.py b/tests/distributed/test_weight_transfer.py index ced71ead76..1353def738 100644 --- a/tests/distributed/test_weight_transfer.py +++ b/tests/distributed/test_weight_transfer.py @@ -1166,8 +1166,7 @@ class RecordingClient: def _module_with(*pairs): """A tiny nn.Module exposing the given (name, tensor) pairs as parameters, - so trainer tests can build a ModuleSource without a real model. - """ + so trainer tests can build a ModuleSource without a real model.""" module = torch.nn.Module() for name, tensor in pairs: module.register_parameter(name, torch.nn.Parameter(tensor, requires_grad=False)) @@ -1288,8 +1287,7 @@ class TestModuleSource: def test_metadata_agrees_with_iteration(self): """The two channels must line up element-for-element: engines declare - the round from `metadata()` and then send what iteration yields. - """ + the round from `metadata()` and then send what iteration yields.""" source = ModuleSource( _module_with(("w", torch.zeros(2, 3)), ("b", torch.zeros(3))) ) @@ -1303,13 +1301,11 @@ class TestModuleSource: class TestWeightSourceGroupContract: """`groups()` / `iter_groups()` on the WeightSource ABC. Groups are what backends gather and free by, so the default must agree with - `layerwise_groups` over `metadata()`, restricted to what this rank holds. - """ + `layerwise_groups` over `metadata()`, restricted to what this rank holds.""" class _Source(WeightSource): """Minimal source over an ordered (name, tensor) list, optionally holding - only some names (in which case it iterates only their groups). - """ + only some names (in which case it iterates only their groups).""" def __init__(self, names, held=None, reverse=False): self._pairs = [(n, torch.full((2,), float(i))) for i, n in enumerate(names)] @@ -1364,8 +1360,7 @@ class TestWeightSourceGroupContract: def test_groups_order_follows_metadata_not_the_declaration(self): """The declaration is a SET of names; the groups it selects still come out in metadata order, so each pairs with the right ``iter_groups()`` - batch however the source listed them. - """ + batch however the source listed them.""" names = ["embed.w", "model.layers.0.a", "model.layers.1.a", "norm.w"] source = self._source( names, held=["model.layers.1.a", "model.layers.0.a", "model.layers.1.a"] @@ -1399,16 +1394,14 @@ class TestWeightSourceGroupContract: def test_out_of_order_iteration_raises(self): """Materializing is usually a collective, so a rank that iterates out of - order deadlocks its peers -- fail loudly instead. - """ + order deadlocks its peers -- fail loudly instead.""" source = self._source(["model.layers.0.a", "model.layers.0.b"], reverse=True) with pytest.raises(RuntimeError, match="iteration order must match"): list(source.iter_groups()) def test_a_source_may_override_iter_groups(self): """The extension point: materialize a whole group in one step instead of - one generator resume per tensor. - """ + one generator resume per tensor.""" calls = [] class _Batched(TestWeightSourceGroupContract._Source): @@ -1429,8 +1422,7 @@ class TestDeferredProcessingContract: caller that takes over the update tail (running its own `finalize_layerwise_reload` instead of going through `finish_weight_update`) reads the flag and calls the method. Both must be answerable on any engine, or - that caller ends up reaching through a getattr. - """ + that caller ends up reaching through a getattr.""" def _engines(self): return { @@ -1444,8 +1436,7 @@ class TestDeferredProcessingContract: def test_every_engine_can_be_drained(self): """The default is a no-op, so a caller never has to check whether the - method exists before calling it. - """ + method exists before calling it.""" for name, cls in self._engines().items(): assert callable(cls.drain_pending), name @@ -1539,8 +1530,7 @@ class TestTrainerEngineBase: ) def test_ipc_trainer_send_weights_drives_client_in_order(): """send_weights issues start -> update -> finish and ships per-round metadata; - the packed wire param rides the init info, not the per-round update_info. - """ + the packed wire param rides the init info, not the per-round update_info.""" client = RecordingClient() engine = IPCTrainerWeightTransferEngine( client=client, @@ -1559,8 +1549,7 @@ def test_ipc_trainer_send_weights_drives_client_in_order(): def test_ipc_trainer_init_ships_packed_to_worker(): """trainer_init drives the inference-side init handshake and propagates the - must-agree `packed` flag to the worker. - """ + must-agree `packed` flag to the worker.""" if torch.accelerator.device_count() < 1: pytest.skip("Need at least 1 GPU (CUDA IPC handles).") @@ -1581,8 +1570,7 @@ def test_ipc_trainer_init_ships_packed_to_worker(): def test_nccl_trainer_init_ships_worker_init_info(monkeypatch): """The sender's trainer_init drives the inference-side init handshake with the worker-shaped init info (rank_offset=1) while opening its own endpoint, - and propagates the must-agree wire params to the worker. - """ + and propagates the must-agree wire params to the worker.""" import vllm.distributed.weight_transfer.nccl_engine as nccl_engine_mod # Bypass the real NCCL rendezvous. @@ -1623,8 +1611,7 @@ def test_nccl_trainer_init_ships_worker_init_info(monkeypatch): def test_nccl_worker_learns_wire_params_from_init_handshake(monkeypatch): """The worker engine reads packed + buffer geometry from the trainer-supplied init info at the handshake, not from the config or the - per-round update info. - """ + per-round update info.""" import vllm.distributed.weight_transfer.nccl_engine as nccl_engine_mod monkeypatch.setattr( @@ -1657,8 +1644,7 @@ def test_nccl_worker_learns_wire_params_from_init_handshake(monkeypatch): def test_nccl_trainer_init_non_sender_skips_rendezvous_and_client(): """Non-sender trainer ranks build an engine without opening an endpoint or - touching the client; they only join the collectives in send_weights. - """ + touching the client; they only join the collectives in send_weights.""" client = RecordingClient() engine = WeightTransferTrainerFactory.trainer_init( init_info=NCCLTrainerInitInfo( @@ -1688,8 +1674,7 @@ def test_nccl_trainer_init_non_sender_skips_rendezvous_and_client(): def test_nccl_trainer_send_weights_drives_client_in_order(): """send_weights issues start -> update -> finish and ships per-round metadata; the packed wire params ride the init handshake, not the - per-round update_info. - """ + per-round update_info.""" client = RecordingClient() engine = NCCLTrainerWeightTransferEngine( client=client, @@ -1710,8 +1695,7 @@ def test_nccl_trainer_send_weights_drives_client_in_order(): class _ScriptedSource(WeightSource): """Declares `meta` but yields whatever `pairs` says — used to drive the - metadata/iteration agreement checks. - """ + metadata/iteration agreement checks.""" def __init__(self, meta, pairs): self._meta = meta @@ -1747,8 +1731,7 @@ def test_nccl_trainer_init_requires_source(): def test_nccl_trainer_send_weights_rejects_reordered_source(monkeypatch): """The worker sizes its buffers (and cuts packed chunks) from metadata(), so - iteration disagreeing with it must raise rather than corrupt the stream. - """ + iteration disagreeing with it must raise rather than corrupt the stream.""" meta = [ ParamMeta("w", torch.float32, (4,)), ParamMeta("b", torch.float32, (2,)), @@ -1762,8 +1745,7 @@ def test_nccl_trainer_send_weights_rejects_reordered_source(monkeypatch): def test_nccl_trainer_send_weights_rejects_dtype_disagreement(monkeypatch): """A source that declares one wire dtype and materializes another would make - the two sides disagree on every byte offset. - """ + the two sides disagree on every byte offset.""" meta = [ParamMeta("w", torch.float32, (4,))] engine = _mock_group_engine( _ScriptedSource(meta, [("w", torch.zeros(4, dtype=torch.bfloat16))]), @@ -1790,8 +1772,7 @@ def test_nccl_trainer_send_weights_rejects_truncated_source(monkeypatch): def test_nccl_trainer_send_weights_broadcasts_contiguous(monkeypatch): """NCCL sends numel elements from data_ptr(), so a non-contiguous view must - be linearized first or the worker receives unrelated memory. - """ + be linearized first or the worker receives unrelated memory.""" base = torch.arange(6, dtype=torch.float32).reshape(2, 3) view = base.t() # non-contiguous meta = [ParamMeta("w", torch.float32, tuple(view.shape))] @@ -1861,8 +1842,7 @@ def _sparse_patch(device: str = "cpu") -> SparseWeightPatch: def test_sparse_nccl_trainer_init_ships_worker_init_info(monkeypatch): """The sender's trainer_init drives the init handshake with the worker-shaped init info; sparse ships no packed wire params, so the worker - keeps its unpacked defaults. Sparse takes no `source`. - """ + keeps its unpacked defaults. Sparse takes no `source`.""" import vllm.distributed.weight_transfer.sparse_nccl_engine as sparse_mod monkeypatch.setattr(sparse_mod, "open_trainer_endpoint", lambda info: MagicMock()) @@ -1915,8 +1895,7 @@ def test_sparse_nccl_trainer_send_weights_drives_client_in_order(monkeypatch): def test_sparse_nccl_trainer_send_weights_empty_round_is_noop(): """A round with no patches must not touch the client (an empty sparse - update info is invalid by construction). - """ + update info is invalid by construction).""" client = RecordingClient() engine = SparseNCCLTrainerWeightTransferEngine(client=client) engine.model_update_group = MagicMock() @@ -1952,8 +1931,7 @@ def test_sparse_nccl_trainer_rejects_source(): def test_sparse_nccl_trainer_validates_patch_before_any_rpc(): """Malformed patches must fail on the trainer, before start_weight_update: the worker's own checks only run once the broadcasts are already in flight, - where a size mismatch wedges both sides instead of raising. - """ + where a size mismatch wedges both sides instead of raising.""" client = RecordingClient() engine = SparseNCCLTrainerWeightTransferEngine(client=client) engine.model_update_group = MagicMock() diff --git a/tests/distributed/test_weight_transfer_nccl_uid.py b/tests/distributed/test_weight_transfer_nccl_uid.py index 5820137604..18a6442a2a 100644 --- a/tests/distributed/test_weight_transfer_nccl_uid.py +++ b/tests/distributed/test_weight_transfer_nccl_uid.py @@ -403,8 +403,7 @@ def trainer_broadcast_tensor_torch_free( def _run_uid_transfer(trainer_task) -> None: """Mint a unique id, run the worker and the given trainer peer concurrently, and assert the tensor round-trips. Both ranks must enter init together -- - there is no store barrier on the UID path. - """ + there is no store barrier on the UID path.""" from vllm.distributed.device_communicators.pynccl_wrapper import NCCLLibrary _init_ray_for_weight_transfer() @@ -451,8 +450,7 @@ def _run_uid_transfer(trainer_task) -> None: ) def test_nccl_weight_transfer_between_processes_uid(): """Weight transfer over a pre-shared ncclUniqueId (no TCPStore), with both - ranks on vLLM's ``PyNcclCommunicator``. - """ + ranks on vLLM's ``PyNcclCommunicator``.""" _run_uid_transfer(trainer_broadcast_tensor_uid) @@ -462,7 +460,6 @@ def test_nccl_weight_transfer_between_processes_uid(): ) def test_nccl_weight_transfer_torch_free_trainer(): """UID weight transfer against a foreign peer that uses no torch and no vLLM - communicator, only a cupy buffer and raw ``ncclBroadcast``. - """ + communicator, only a cupy buffer and raw ``ncclBroadcast``.""" pytest.importorskip("cupy") _run_uid_transfer(trainer_broadcast_tensor_torch_free) diff --git a/tests/engine/test_arg_utils.py b/tests/engine/test_arg_utils.py index 9adfedc9f4..68fe250677 100644 --- a/tests/engine/test_arg_utils.py +++ b/tests/engine/test_arg_utils.py @@ -570,8 +570,7 @@ def test_attention_config(): def test_multi_node_world_size_includes_pcp(monkeypatch): """PCP expands the process world size, so the --nnodes divisibility check must include it. Without this, TP=1/PCP=2 over 2 nodes computes a world - size of 1 and the launch is rejected before the engine starts. - """ + size of 1 and the launch is rejected before the engine starts.""" import vllm.config.vllm # PCP requires the V2 model runner, which is gated on Triton. @@ -797,8 +796,7 @@ def test_expand_json_human_readable_numbers(input_json, expected_json): ) def test_cloud_storage_uri_skips_get_model_path(uri, monkeypatch): """Cloud storage URIs should not be passed to get_model_path() - when HF_HUB_OFFLINE=1, as they are not valid HF repo IDs. - """ + when HF_HUB_OFFLINE=1, as they are not valid HF repo IDs.""" import huggingface_hub monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True) @@ -810,8 +808,7 @@ def test_cloud_storage_uri_skips_get_model_path(uri, monkeypatch): def test_cloud_storage_tokenizer_skips_get_model_path(monkeypatch): """Cloud storage tokenizer URI should not be passed to - get_model_path() when HF_HUB_OFFLINE=1. - """ + get_model_path() when HF_HUB_OFFLINE=1.""" import huggingface_hub monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True) @@ -973,8 +970,7 @@ class TestDpDeviceIdSharding: def test_dp_supervisor_device_ids_stay_env_relative(self): """Regression test: the DP supervisor must pass env-relative indices, not physical IDs, because each child re-resolves --device-ids - against its inherited device-control env var. - """ + against its inherited device-control env var.""" import argparse from vllm.entrypoints.launchers.dp_supervisor import _build_device_ids @@ -1001,8 +997,7 @@ class TestDpDeviceIdSharding: def test_dp_rank_shards_user_assigned_gpu_ids(self): """get_physical_gpu_ids_for_local_dp_rank slices the user-provided - --device-ids list instead of recomputing from the env var. - """ + --device-ids list instead of recomputing from the env var.""" from vllm.platforms import current_platform from vllm.v1.engine.utils import get_physical_gpu_ids_for_local_dp_rank diff --git a/tests/entrypoints/anthropic/test_anthropic_messages_conversion.py b/tests/entrypoints/anthropic/test_anthropic_messages_conversion.py index 63e44eaceb..226908d673 100644 --- a/tests/entrypoints/anthropic/test_anthropic_messages_conversion.py +++ b/tests/entrypoints/anthropic/test_anthropic_messages_conversion.py @@ -241,8 +241,7 @@ class TestToolResultContent: self, tool_result_content ) -> AnthropicMessagesRequest: """Build a request with assistant tool_use followed by user - tool_result. - """ + tool_result.""" return _make_request( [ { @@ -327,8 +326,7 @@ class TestToolResultContent: def test_tool_result_with_text_and_image(self): """Mixed text+image tool_result: text in tool msg, image in user - msg. - """ + msg.""" request = self._make_tool_result_request( [ {"type": "text", "text": "Here is the screenshot"}, @@ -425,8 +423,7 @@ class TestToolResultContent: class TestAttributionHeaderStripping: def test_billing_header_stripped_from_system(self): """Claude Code's x-anthropic-billing-header block should be - stripped to preserve prefix caching. - """ + stripped to preserve prefix caching.""" request = _make_request( [{"role": "user", "content": "Hello"}], system=[ @@ -1150,8 +1147,7 @@ class TestMessageStreamConverterToolUseContentBuffering: async def test_buffered_content_flushed_on_done_without_usage_chunk(self): """Content buffered during tool_use must be emitted even if the stream jumps straight from finish_reason to [DONE], skipping the - empty-choices usage chunk. - """ + empty-choices usage chunk.""" async def sse_input(): yield _make_stream_chunk( @@ -1255,8 +1251,7 @@ class TestStreamingCacheUsageSemantics: async def test_streaming_cache_fields_absent_then_populated(self): """First chunk lacks prompt_tokens_details (vLLM contract); message_start omits cache fields. The final chunk carries - prompt_tokens_details, so message_delta carries resolved values. - """ + prompt_tokens_details, so message_delta carries resolved values.""" async def sse_input(): yield _make_stream_chunk( @@ -1301,8 +1296,7 @@ class TestStreamingCacheUsageSemantics: @pytest.mark.asyncio async def test_streaming_no_cache_hit(self): """When the final chunk reports cached_tokens=0, message_delta carries - cache fields = 0 (cache miss); message_start still omits them. - """ + cache fields = 0 (cache miss); message_start still omits them.""" async def sse_input(): yield _make_stream_chunk( @@ -1343,8 +1337,7 @@ class TestStreamingCacheUsageSemantics: @pytest.mark.asyncio async def test_streaming_no_prompt_tokens_details_at_all(self): """If --enable-prompt-tokens-details is off, no chunk carries cache - info; both message_start and message_delta omit cache fields. - """ + info; both message_start and message_delta omit cache fields.""" async def sse_input(): yield _make_stream_chunk( @@ -1465,8 +1458,7 @@ class TestMessagesFullConverter: class TestCacheSalt: def test_cache_salt_passed_through(self): """cache_salt on the Anthropic request reaches the converted - ChatCompletionRequest so prefix-cache isolation works via /v1/messages. - """ + ChatCompletionRequest so prefix-cache isolation works via /v1/messages.""" request = _make_request( [{"role": "user", "content": "Hello"}], cache_salt="tenant-abc-secret-salt", @@ -1671,8 +1663,7 @@ class TestClientErrorResponses: @staticmethod def _conversion_error() -> ValidationError: """A real pydantic ValidationError like the one ChatCompletionRequest - construction raises when Anthropic input violates the OpenAI schema. - """ + construction raises when Anthropic input violates the OpenAI schema.""" class _StubRequest(BaseModel): stop: Annotated[list[str], Field(max_length=4)] | None = None @@ -1683,8 +1674,7 @@ class TestClientErrorResponses: def test_validation_error_returns_bad_request(self): """A pydantic ValidationError during Anthropic->OpenAI conversion is - surfaced as a 400 BadRequestError, not a 500. - """ + surfaced as a 400 BadRequestError, not a 500.""" handler = MagicMock(spec=AnthropicServingMessages) handler.create_messages.side_effect = self._conversion_error() diff --git a/tests/entrypoints/cohere/test_serving_streaming.py b/tests/entrypoints/cohere/test_serving_streaming.py index 8723c6ecc7..8c2e8623ad 100644 --- a/tests/entrypoints/cohere/test_serving_streaming.py +++ b/tests/entrypoints/cohere/test_serving_streaming.py @@ -87,8 +87,7 @@ def _make_chunk( citations: list[Any] | None = None, ) -> str: """Build the ``data: {...}\\n\\n`` SSE frame the production code - consumes. - """ + consumes.""" delta: dict[str, Any] = {} if role is not None: delta["role"] = role @@ -136,8 +135,7 @@ async def _stream_from(items: list[str]) -> AsyncGenerator[str, None]: async def _drain(serving: CohereServingChatV2, items: list[str]) -> list[str]: """Drive ``_chat_completion_stream_to_v2`` over ``items`` and collect - the emitted SSE frames. - """ + the emitted SSE frames.""" request = CohereChatV2Request( model="m", messages=[{"role": "user", "content": "hi"}], stream=True ) diff --git a/tests/entrypoints/launchers/api_server/test_api_server_process_manager.py b/tests/entrypoints/launchers/api_server/test_api_server_process_manager.py index 7f2f771107..668f115448 100644 --- a/tests/entrypoints/launchers/api_server/test_api_server_process_manager.py +++ b/tests/entrypoints/launchers/api_server/test_api_server_process_manager.py @@ -50,8 +50,7 @@ def update_admission_stats_worker(listen_address, sock, args, client_config): # importable by `multiprocessing.spawn` (no closures, no nesting). def defer_addresses_stub_worker(listen_address, sock, args, client_config): """Bind ROUTER/PULL with a kernel-assigned port, report the actual - endpoints back via the pipe, then exit. - """ + endpoints back via the pipe, then exit.""" ctx = zmq.Context() try: in_sock = make_zmq_socket( @@ -358,8 +357,7 @@ def test_external_process_monitoring(api_server_args): def test_gather_actual_addresses_end_to_end(): """Each child binds ROUTER/PULL with a kernel-picked port and reports the bound endpoints back via its per-child pipe; the manager surfaces - them via :py:meth:`gather_actual_addresses`. - """ + them via :py:meth:`gather_actual_addresses`.""" host = "127.0.0.1" num_servers = 4 @@ -409,8 +407,7 @@ def test_gather_actual_addresses_end_to_end(): @pytest.mark.timeout(30) def test_gather_actual_addresses_child_crash_before_report(): """A child that exits before sending its endpoints must surface a - clear ``RuntimeError`` rather than hang or return ``None`` slots. - """ + clear ``RuntimeError`` rather than hang or return ``None`` slots.""" host = "127.0.0.1" num_servers = 2 placeholder_inputs = [ @@ -447,8 +444,7 @@ def test_gather_actual_addresses_child_crash_before_report(): def test_rust_frontend_launch_log_redacts_credentials(monkeypatch, caplog): """The Rust frontend command carries every non-default arg as JSON. - Credentials must not reach the log line. - """ + Credentials must not reach the log line.""" import subprocess as subprocess_mod from vllm.entrypoints.launchers.cli_args import make_arg_parser diff --git a/tests/entrypoints/launchers/test_cli_args.py b/tests/entrypoints/launchers/test_cli_args.py index cf2f678e40..0bcca8cb41 100644 --- a/tests/entrypoints/launchers/test_cli_args.py +++ b/tests/entrypoints/launchers/test_cli_args.py @@ -186,8 +186,7 @@ def test_enable_auto_choice_fails_with_enable_reasoning(serve_parser): def test_passes_with_reasoning_parser(serve_parser): """Ensure validation passes if reasoning is enabled - with a reasoning parser - """ + with a reasoning parser""" args = serve_parser.parse_args( args=[ "--reasoning-parser", @@ -382,8 +381,7 @@ def test_default_chat_template_kwargs_invalid_json(serve_parser): ) def test_served_model_name_parsing(tmp_path, vllm_parser, args, raises): """Ensure that users don't misuse --served-model-name and end up with the default - model tag instead of the one they intended to serve. - """ + model tag instead of the one they intended to serve.""" # Call the serve subparser args.insert(0, "serve") # Create a dummy config file if the test case includes it diff --git a/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_audio_embeds.py b/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_audio_embeds.py index b12bf3a60b..aac68334bf 100644 --- a/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_audio_embeds.py +++ b/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_audio_embeds.py @@ -2,8 +2,7 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """E2E test for mixing `prompt_embeds` with `audio_embeds` in a single -Chat Completions request. -""" +Chat Completions request.""" import json diff --git a/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_image_embeds.py b/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_image_embeds.py index b72d940714..c6ce165cf3 100644 --- a/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_image_embeds.py +++ b/tests/entrypoints/multimodal/openai/chat_completion/test_chat_completion_with_mixed_image_embeds.py @@ -68,8 +68,7 @@ async def client(server): def image_url() -> str: """Stable real image as a data URL, kept identical across both the text and prompt_embeds requests so any output difference must come from - how the text content is delivered. - """ + how the text content is delivered.""" return encode_image_url(ImageAsset("stop_sign").pil_image) diff --git a/tests/entrypoints/multimodal/openai/chat_completion/test_vision.py b/tests/entrypoints/multimodal/openai/chat_completion/test_vision.py index 6d1c2f24e9..56a7cf6a13 100644 --- a/tests/entrypoints/multimodal/openai/chat_completion/test_vision.py +++ b/tests/entrypoints/multimodal/openai/chat_completion/test_vision.py @@ -145,8 +145,7 @@ def describe_image_messages( ) -> list[dict]: """Build the system + user messages used by the completions-with-image family of tests. *extra_image_fields* is merged into the top-level - image content block (for uuid / bad-key tests). - """ + image content block (for uuid / bad-key tests).""" image_block: dict = { "type": "image_url", "image_url": {"url": image_url}, @@ -176,8 +175,7 @@ async def complete_and_check( temperature: float = 0.0, ) -> str: """Run a chat completion and assert the output is non-empty. - Returns the content string. - """ + Returns the content string.""" chat_completion = await client.chat.completions.create( model=model_name, messages=messages, diff --git a/tests/entrypoints/openai/chat_completion/test_chat_error.py b/tests/entrypoints/openai/chat_completion/test_chat_error.py index e0f7128744..b83341cc50 100644 --- a/tests/entrypoints/openai/chat_completion/test_chat_error.py +++ b/tests/entrypoints/openai/chat_completion/test_chat_error.py @@ -465,8 +465,7 @@ def test_system_message_warns_on_video(video_content): def test_json_schema_response_format_missing_schema(): """When response_format type is 'json_schema' but the json_schema field is not provided, request construction should raise a validation error - so the API returns 400 instead of 500. - """ + so the API returns 400 instead of 500.""" with pytest.raises(Exception, match="json_schema.*must be provided"): ChatCompletionRequest( model=MODEL_NAME, @@ -520,8 +519,7 @@ def test_structured_outputs_structural_tag_invalid(structural_tag): @pytest.mark.parametrize("field_name", ["prompt_logprobs", "top_logprobs"]) def test_non_numeric_logprobs_rejected(field_name): """A non-numeric logprobs value must be a clean 400 validation error, not a - TypeError from the mode='before' comparison (which surfaces as HTTP 500). - """ + TypeError from the mode='before' comparison (which surfaces as HTTP 500).""" with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"): ChatCompletionRequest( model=MODEL_NAME, diff --git a/tests/entrypoints/openai/chat_completion/test_chat_logit_bias_validation.py b/tests/entrypoints/openai/chat_completion/test_chat_logit_bias_validation.py index f1801701e3..b415fa116d 100644 --- a/tests/entrypoints/openai/chat_completion/test_chat_logit_bias_validation.py +++ b/tests/entrypoints/openai/chat_completion/test_chat_logit_bias_validation.py @@ -81,8 +81,7 @@ async def test_chat_logit_bias_invalid(client): @pytest.mark.asyncio async def test_chat_logit_bias_non_integer_key(client): """Test that a non-integer logit_bias key is rejected with a clean, - informative error instead of a raw 'invalid literal for int()' message. - """ + informative error instead of a raw 'invalid literal for int()' message.""" with pytest.raises(openai.BadRequestError) as excinfo: await client.chat.completions.create( model=MODEL_NAME, @@ -102,8 +101,7 @@ async def test_chat_logit_bias_non_integer_key(client): @pytest.mark.asyncio async def test_chat_logit_bias_non_numeric_value(client): """Test that a non-numeric logit_bias value is rejected with a message - that names the specific offending token, not just a generic TypeError. - """ + that names the specific offending token, not just a generic TypeError.""" with pytest.raises(openai.BadRequestError) as excinfo: await client.chat.completions.create( model=MODEL_NAME, @@ -122,8 +120,7 @@ async def test_chat_logit_bias_non_numeric_value(client): @pytest.mark.asyncio async def test_chat_logit_bias_multiple_non_integer_keys(client): """Test that ALL invalid logit_bias keys are reported together, - not just the first one encountered. - """ + not just the first one encountered.""" with pytest.raises(openai.BadRequestError) as excinfo: await client.chat.completions.create( model=MODEL_NAME, diff --git a/tests/entrypoints/openai/chat_completion/test_extra_content_fields.py b/tests/entrypoints/openai/chat_completion/test_extra_content_fields.py index 9c0a4db68b..f4036c4374 100644 --- a/tests/entrypoints/openai/chat_completion/test_extra_content_fields.py +++ b/tests/entrypoints/openai/chat_completion/test_extra_content_fields.py @@ -54,8 +54,7 @@ def stop_sign_image_url(): async def test_translategemma_extra_lang_code_fields(client: openai.AsyncOpenAI): """En -> es translation through TranslateGemma's bundled chat template's ``text`` content branch, which depends on ``source_lang_code`` / - ``target_lang_code`` extra fields being preserved on the content part. - """ + ``target_lang_code`` extra fields being preserved on the content part.""" completion = await client.chat.completions.create( model=MODEL_NAME, messages=[ @@ -99,8 +98,7 @@ async def test_translategemma_image_extra_lang_code_fields( ``source_lang_code`` / ``target_lang_code`` extras must survive parsing and end up alongside the ``{"type": "image"}`` placeholder so the template's image branch (``content["type"] == 'image'``) renders the - right OCR-translation prompt. - """ + right OCR-translation prompt.""" completion = await client.chat.completions.create( model=MODEL_NAME, messages=[ diff --git a/tests/entrypoints/openai/chat_completion/test_logprob_token_ids.py b/tests/entrypoints/openai/chat_completion/test_logprob_token_ids.py index 62f915b054..1eea6db48a 100644 --- a/tests/entrypoints/openai/chat_completion/test_logprob_token_ids.py +++ b/tests/entrypoints/openai/chat_completion/test_logprob_token_ids.py @@ -191,8 +191,7 @@ async def test_logprob_token_ids_stream_with_no_top_k(server): async def test_logprob_token_ids_default_behavior_unchanged(server): """Without `logprob_token_ids`, the response carries the natural top-k most-likely tokens. This guards against the new field accidentally - changing the default-path output. - """ + changing the default-path output.""" async with server.get_async_client() as client: resp = await client.chat.completions.create( model=MODEL_NAME, diff --git a/tests/entrypoints/openai/chat_completion/test_serving_chat.py b/tests/entrypoints/openai/chat_completion/test_serving_chat.py index 73cffa76cf..2757320362 100644 --- a/tests/entrypoints/openai/chat_completion/test_serving_chat.py +++ b/tests/entrypoints/openai/chat_completion/test_serving_chat.py @@ -1406,8 +1406,7 @@ async def test_serving_chat_did_set_correct_cache_salt(model_type): @pytest.mark.asyncio async def test_serving_chat_data_parallel_rank_extraction(): """Test that data_parallel_rank is properly extracted from header and - passed to engine. - """ + passed to engine.""" mock_engine = MagicMock(spec=AsyncLLM) mock_engine.errored = False mock_engine.model_config = MockModelConfig() @@ -1729,8 +1728,7 @@ class TestServingChatWithHarmony: @pytest.mark.asyncio async def test_system_message_without_tools(self, serving_chat, stream): """Leading system message produces a developer message with - DeveloperContent (# Instructions header). - """ + DeveloperContent (# Instructions header).""" messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello"}, @@ -1752,8 +1750,7 @@ class TestServingChatWithHarmony: @pytest.mark.asyncio async def test_system_message_with_tools(self, serving_chat, stream, weather_tools): """Leading system message is folded into the developer message - alongside tool definitions. - """ + alongside tool definitions.""" messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What's the weather?"}, @@ -2168,8 +2165,7 @@ class TestServingChatWithHarmony: @pytest.mark.asyncio async def test_tool_choice_validation_without_parser(): """Test that tool_choice='required' or named tool without tool_parser - returns an appropriate error message. - """ + returns an appropriate error message.""" mock_engine = MagicMock(spec=AsyncLLM) mock_engine.errored = False mock_engine.model_config = MockModelConfig() diff --git a/tests/entrypoints/openai/chat_completion/test_thinking_token_budget.py b/tests/entrypoints/openai/chat_completion/test_thinking_token_budget.py index b7ed422223..ecff3f8ee6 100644 --- a/tests/entrypoints/openai/chat_completion/test_thinking_token_budget.py +++ b/tests/entrypoints/openai/chat_completion/test_thinking_token_budget.py @@ -151,8 +151,7 @@ async def client(request, server, server_with_auto_reasoning_config): @pytest.mark.parametrize("client", ["default", "auto_config"], indirect=True) async def test_thinking_token_budget_mixed_requests(client: openai.AsyncOpenAI): """Test that mixed requests (some with thinking_token_budget, some without) - complete successfully without errors. - """ + complete successfully without errors.""" response_with_budget = await client.chat.completions.create( model=MODEL_NAME, messages=MESSAGES, diff --git a/tests/entrypoints/openai/completion/test_completion_error.py b/tests/entrypoints/openai/completion/test_completion_error.py index 1fee99be57..46f4fe452c 100644 --- a/tests/entrypoints/openai/completion/test_completion_error.py +++ b/tests/entrypoints/openai/completion/test_completion_error.py @@ -521,8 +521,7 @@ async def test_completion_error_stream(): def test_json_schema_response_format_missing_schema(): """When response_format type is 'json_schema' but the json_schema field is not provided, request construction should raise a validation error - so the API returns 400 instead of 500. - """ + so the API returns 400 instead of 500.""" with pytest.raises(Exception, match="json_schema.*must be provided"): CompletionRequest( model=MODEL_NAME, @@ -585,8 +584,7 @@ def test_negative_prompt_token_ids_flat(): def test_logprobs_minus_one_allowed(): """logprobs=-1 means "return all logprobs". The sampling layer and the chat top_logprobs / prompt_logprobs validators all accept -1, so the completion - logprobs validator must accept it too instead of rejecting it as negative. - """ + logprobs validator must accept it too instead of rejecting it as negative.""" request = CompletionRequest( model=MODEL_NAME, prompt="Test prompt", @@ -746,8 +744,7 @@ class TestCompletionPromptListLimit: @pytest.mark.parametrize("field_name", ["prompt_logprobs", "logprobs"]) def test_non_numeric_logprobs_rejected(field_name): """A non-numeric logprobs value must be a clean 400 validation error, not a - TypeError from the mode='before' comparison (which surfaces as HTTP 500). - """ + TypeError from the mode='before' comparison (which surfaces as HTTP 500).""" with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"): CompletionRequest( model=MODEL_NAME, diff --git a/tests/entrypoints/openai/parser/test_harmony_render_parity.py b/tests/entrypoints/openai/parser/test_harmony_render_parity.py index ce6e4c80f8..5cb4461223 100644 --- a/tests/entrypoints/openai/parser/test_harmony_render_parity.py +++ b/tests/entrypoints/openai/parser/test_harmony_render_parity.py @@ -43,8 +43,7 @@ def _system(): class TestResponseInputToHarmonyRenderParity: """Each test drives the same conversation through both APIs and asserts - identical Harmony messages and rendered token sequences. - """ + identical Harmony messages and rendered token sequences.""" # ----------------------------------------------------------------------- # Single-message cases @@ -52,8 +51,7 @@ class TestResponseInputToHarmonyRenderParity: def test_developer_message(self): """Both APIs must render developer messages identically using - DeveloperContent (with the '# Instructions' header). - """ + DeveloperContent (with the '# Instructions' header).""" chat_msgs = parse_chat_input_to_harmony_message( {"role": "developer", "content": "Be concise."} ) @@ -248,8 +246,7 @@ class TestResponseInputToHarmonyRenderParity: def test_reasoning_combined_with_function_call(self): """Chat API packs reasoning + tool_calls into one dict; responses API represents them as two separate items. Both must produce the same two - Harmony messages in the same order: analysis then commentary. - """ + Harmony messages in the same order: analysis then commentary.""" chat_msgs = parse_chat_input_to_harmony_message( { "role": "assistant", @@ -532,8 +529,7 @@ class TestResponseInputToHarmonyRenderParity: def test_completed_turns_drop_reasoning(self): """Validates that reasoning from completed turns is dropped, while reasoning from the current in-progress tool-call turn is preserved - in both chat completions and responses previous_input_messages. - """ + in both chat completions and responses previous_input_messages.""" first_turn_reasoning = "FIRST_TURN_REASONING" second_turn_reasoning = "SECOND_TURN_REASONING" diff --git a/tests/entrypoints/openai/parser/test_harmony_utils.py b/tests/entrypoints/openai/parser/test_harmony_utils.py index 816e879342..4c1dfe52e0 100644 --- a/tests/entrypoints/openai/parser/test_harmony_utils.py +++ b/tests/entrypoints/openai/parser/test_harmony_utils.py @@ -323,8 +323,7 @@ class TestCommonParseInputToHarmonyMessage: def test_system_message(self, parse_function): """Test parsing system messages, which are parsed into developer messages - with DeveloperContent. - """ + with DeveloperContent.""" chat_msg = { "role": "system", "content": "You are a helpful assistant", diff --git a/tests/entrypoints/openai/responses/test_function_call_parsing.py b/tests/entrypoints/openai/responses/test_function_call_parsing.py index c83fe0f61c..5b70c7819a 100644 --- a/tests/entrypoints/openai/responses/test_function_call_parsing.py +++ b/tests/entrypoints/openai/responses/test_function_call_parsing.py @@ -12,8 +12,7 @@ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest def test_function_call_dict_converted_to_object(): """Test that function_call dictionaries are correctly parsed into - ResponseFunctionToolCall objects. - """ + ResponseFunctionToolCall objects.""" # Create a request with function_call as dict request_data = { "model": "gpt-oss", @@ -330,8 +329,7 @@ def test_validator_handles_empty_iterator(): def test_assistant_string_content_stays_easyinput(): """EasyInput assistant message with plain string content is not - coerced into a ResponseOutputMessage. - """ + coerced into a ResponseOutputMessage.""" request_data = { "model": "test-model", "input": [ @@ -353,8 +351,7 @@ def test_assistant_string_content_stays_easyinput(): def test_assistant_output_style_content_coerced(): """Assistant message whose content is output-message-shaped (list of - output_text items) should be coerced to ResponseOutputMessage. - """ + output_text items) should be coerced to ResponseOutputMessage.""" request_data = { "model": "test-model", "input": [ diff --git a/tests/entrypoints/openai/responses/test_response_input_to_harmony.py b/tests/entrypoints/openai/responses/test_response_input_to_harmony.py index 2485983bf3..e2be8477e4 100644 --- a/tests/entrypoints/openai/responses/test_response_input_to_harmony.py +++ b/tests/entrypoints/openai/responses/test_response_input_to_harmony.py @@ -67,8 +67,7 @@ class TestResponseInputToHarmonyMessage: def test_system_message(self): """System messages carry developer instructions and must be rendered - as developer messages with DeveloperContent. - """ + as developer messages with DeveloperContent.""" msg = response_input_to_harmony( {"type": "message", "role": "system", "content": "Be helpful."}, prev_responses=[], @@ -90,8 +89,7 @@ class TestResponseInputToHarmonyMessage: def test_developer_message_gets_instructions_prefix(self): """Developer messages must use DeveloperContent which adds the - '# Instructions' header the model was trained on. - """ + '# Instructions' header the model was trained on.""" msg = response_input_to_harmony( {"type": "message", "role": "developer", "content": "Be concise."}, prev_responses=[], @@ -121,8 +119,7 @@ class TestResponseInputToHarmonyMessage: def test_developer_message_array_content_concatenated(self): """Array content in developer messages is flattened and rendered - via DeveloperContent with the '# Instructions' header. - """ + via DeveloperContent with the '# Instructions' header.""" msg = response_input_to_harmony( { "type": "message", @@ -213,8 +210,7 @@ class TestResponseInputToHarmonyMessage: def test_function_call_output_uses_most_recent_matching_call(self): """When multiple prev_responses share a call_id, the last one wins - because the search is reversed. - """ + because the search is reversed.""" earlier = ResponseFunctionToolCall( id="fc_old", call_id="call_test", diff --git a/tests/entrypoints/openai/responses/test_responses_utils.py b/tests/entrypoints/openai/responses/test_responses_utils.py index 1e59c82244..967ddacda6 100644 --- a/tests/entrypoints/openai/responses/test_responses_utils.py +++ b/tests/entrypoints/openai/responses/test_responses_utils.py @@ -839,13 +839,11 @@ class TestConstructChatMessagesCombinePolicy: class TestConstructInputMessagesInstructionsLeak: """Regression tests for #37697: instructions from a prior response - should NOT leak through previous_response_id. - """ + should NOT leak through previous_response_id.""" def test_old_instructions_stripped_from_prev_msg(self): """System message in prev_msg must be dropped so the new request's - instructions are the only system message in the conversation. - """ + instructions are the only system message in the conversation.""" prev = [ {"role": "system", "content": "old instructions"}, {"role": "user", "content": "What is 2+2?"}, @@ -862,8 +860,7 @@ class TestConstructInputMessagesInstructionsLeak: def test_no_instructions_in_new_request(self): """If the new request has no instructions, old ones should still - be stripped -- they must not carry over. - """ + be stripped -- they must not carry over.""" prev = [ {"role": "system", "content": "old instructions"}, {"role": "user", "content": "Hi"}, diff --git a/tests/entrypoints/openai/responses/test_serving_responses.py b/tests/entrypoints/openai/responses/test_serving_responses.py index 1f9d95ea2e..a445774fcc 100644 --- a/tests/entrypoints/openai/responses/test_serving_responses.py +++ b/tests/entrypoints/openai/responses/test_serving_responses.py @@ -1163,8 +1163,7 @@ class TestHarmonyPreambleStreaming: def test_preamble_done_emits_text_done_events(self) -> None: """Completed preamble should emit text done + content_part done + - output_item done, same shape as final channel. - """ + output_item done, same shape as final channel.""" from vllm.entrypoints.openai.responses.streaming_events import ( emit_previous_item_done_events, ) @@ -1185,8 +1184,7 @@ class TestHarmonyPreambleStreaming: def test_commentary_with_recipient_no_preamble_done(self) -> None: """Commentary + recipient='functions.X' should route to function call - done, not preamble done. - """ + done, not preamble done.""" from vllm.entrypoints.openai.responses.streaming_events import ( emit_previous_item_done_events, ) @@ -1332,8 +1330,7 @@ def _mock_parser_with_reasoning(serving, delta_sequence: list[DeltaMessage]): class TestStreamingReasoningToContentTransition: """Tests for _process_simple_streaming_events reasoning-to-content transition, specifically the fix for mixed deltas that carry both - reasoning and content simultaneously. - """ + reasoning and content simultaneously.""" @pytest.mark.asyncio async def test_mixed_delta_reasoning_and_content_emits_reasoning_delta( @@ -1343,8 +1340,7 @@ class TestStreamingReasoningToContentTransition: and content set (e.g. reasoning end and content start in the same chunk), the trailing reasoning text must be emitted as a ResponseReasoningTextDeltaEvent and included in the - ResponseReasoningTextDoneEvent text. - """ + ResponseReasoningTextDoneEvent text.""" monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False) serving = _make_serving_instance_with_reasoning() @@ -1413,8 +1409,7 @@ class TestStreamingReasoningToContentTransition: self, monkeypatch ): """When the transition from reasoning to content is clean (no mixed - delta), no extra reasoning delta event should be emitted. - """ + delta), no extra reasoning delta event should be emitted.""" monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False) serving = _make_serving_instance_with_reasoning() @@ -1475,8 +1470,7 @@ class TestStreamingReasoningToContentTransition: async def test_reasoning_only_stream_no_content(self, monkeypatch): """When the stream has only reasoning deltas and no content, the reasoning done event should be emitted at finalization with the - full accumulated text, and no text delta events should appear. - """ + full accumulated text, and no text delta events should appear.""" monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False) serving = _make_serving_instance_with_reasoning() diff --git a/tests/entrypoints/openai/responses/test_simple.py b/tests/entrypoints/openai/responses/test_simple.py index 1880c06392..ba55a58e7d 100644 --- a/tests/entrypoints/openai/responses/test_simple.py +++ b/tests/entrypoints/openai/responses/test_simple.py @@ -143,8 +143,7 @@ async def test_streaming_output_consistency(client: OpenAI, model_name: str): @pytest.mark.parametrize("model_name", [MODEL_NAME]) async def test_streaming_logprobs(client: OpenAI, model_name: str): """Test that streaming with logprobs returns valid logprob data on - output_text.delta events and that top_logprobs has the requested count. - """ + output_text.delta events and that top_logprobs has the requested count.""" response = await client.responses.create( model=model_name, input="Say hello.", diff --git a/tests/entrypoints/openai/responses/test_streaming_events.py b/tests/entrypoints/openai/responses/test_streaming_events.py index 2e9b47133d..e1a8bf46f6 100644 --- a/tests/entrypoints/openai/responses/test_streaming_events.py +++ b/tests/entrypoints/openai/responses/test_streaming_events.py @@ -124,8 +124,7 @@ class TestProcessorCompoundDeltas: def test_split_name_and_args_same_index(self): """Regression: parsers like KimiK2 emit name and args as separate - DeltaToolCalls at the same index within one DeltaMessage. - """ + DeltaToolCalls at the same index within one DeltaMessage.""" tc_name = _make_tool_call(0, name="get_weather") tc_args = _make_tool_call(0, arguments='{"city":"SF"}') delta = DeltaMessage(tool_calls=[tc_name, tc_args]) @@ -141,8 +140,7 @@ class TestProcessorCompoundDeltas: def test_reasoning_to_content_transition(self): """Regression: the old special case in emit_delta handled this; - now split_delta handles it generically. - """ + now split_delta handles it generically.""" processor = SimpleStreamingEventProcessor() _run_through_processor(processor, DeltaMessage(reasoning="think")) assert processor.state.current_state == _StateType.REASONING diff --git a/tests/entrypoints/openai/test_render_token_offsets.py b/tests/entrypoints/openai/test_render_token_offsets.py index 6ef66ee37b..a2e66b7bd6 100644 --- a/tests/entrypoints/openai/test_render_token_offsets.py +++ b/tests/entrypoints/openai/test_render_token_offsets.py @@ -25,8 +25,7 @@ def _model_config() -> Mock: def test_completion_flag_forwarded_to_tok_params(): """build_tok_params must forward return_token_offsets, defaulting to False (zero behavioral change for existing callers) and coercing JSON - null to False via the bool() guard. - """ + null to False via the bool() guard.""" cfg = _model_config() default = CompletionRequest(model="m", prompt="hi") @@ -41,8 +40,7 @@ def test_completion_flag_forwarded_to_tok_params(): def test_chat_flag_forwarded_to_tok_params(): """Chat build_tok_params has its own (max_completion_tokens) branch, so - its return_token_offsets forwarding is verified independently. - """ + its return_token_offsets forwarding is verified independently.""" cfg = _model_config() messages = [{"role": "user", "content": "hi"}] @@ -66,8 +64,7 @@ def test_generate_request_token_offsets_default_none(): def test_generate_request_token_offsets_survive_json_round_trip(): """GenerateRequest crosses the disagg serialization boundary; the - tuple[int, int] offsets must survive model_dump and re-validate. - """ + tuple[int, int] offsets must survive model_dump and re-validate.""" req = GenerateRequest( token_ids=[10, 20], sampling_params=SamplingParams(), diff --git a/tests/entrypoints/pooling/embed/test_cohere_online.py b/tests/entrypoints/pooling/embed/test_cohere_online.py index 29276cb050..4964d99e0c 100644 --- a/tests/entrypoints/pooling/embed/test_cohere_online.py +++ b/tests/entrypoints/pooling/embed/test_cohere_online.py @@ -111,8 +111,7 @@ def test_basic_embed(server: RemoteOpenAIServer, model_name: str): def test_unsupported_input_type_rejected(server: RemoteOpenAIServer, model_name: str): """An input_type not defined in the model's prompt config should be - rejected with a 400 error. - """ + rejected with a 400 error.""" body = { "model": model_name, "input_type": "nonexistent_type", @@ -139,8 +138,7 @@ def test_omitted_input_type_accepted(server: RemoteOpenAIServer, model_name: str def test_v1_v2_parity(server: RemoteOpenAIServer, model_name: str): """v1 (OpenAI) and v2 (Cohere) endpoints should produce the same - float embeddings for a generic model. - """ + float embeddings for a generic model.""" texts = ["hello world"] v2 = _cohere_embed(server, model_name, texts=texts, embedding_types=["float"]) v1 = _openai_embed(server, model_name, texts) diff --git a/tests/entrypoints/pooling/embed/test_cohere_openai_parity.py b/tests/entrypoints/pooling/embed/test_cohere_openai_parity.py index 5608cbcb4e..3e168adbdb 100644 --- a/tests/entrypoints/pooling/embed/test_cohere_openai_parity.py +++ b/tests/entrypoints/pooling/embed/test_cohere_openai_parity.py @@ -76,8 +76,7 @@ def test_single_text_parity(server: RemoteOpenAIServer): def test_batch_parity(server: RemoteOpenAIServer): """A batch of texts should produce equivalent embeddings via both APIs, - in the same order. - """ + in the same order.""" texts = [ "machine learning", "deep learning", diff --git a/tests/entrypoints/pooling/embed/test_io_processor.py b/tests/entrypoints/pooling/embed/test_io_processor.py index b002aae8db..f06e43d143 100644 --- a/tests/entrypoints/pooling/embed/test_io_processor.py +++ b/tests/entrypoints/pooling/embed/test_io_processor.py @@ -241,8 +241,7 @@ class TestResolveTruncation: def test_truncate_none_with_max_tokens(self): """truncate=NONE should NOT set truncate_prompt_tokens; the - max_tokens limit is enforced separately via _check_max_tokens. - """ + max_tokens limit is enforced separately via _check_max_tokens.""" req = self._make_request(truncate="NONE", max_tokens=10) tokens, side = EmbedIOProcessor._resolve_cohere_truncation(req) assert tokens is None diff --git a/tests/entrypoints/pooling/embed/test_online_long_text.py b/tests/entrypoints/pooling/embed/test_online_long_text.py index aeb82336fa..ab3633cd3d 100644 --- a/tests/entrypoints/pooling/embed/test_online_long_text.py +++ b/tests/entrypoints/pooling/embed/test_online_long_text.py @@ -240,8 +240,7 @@ async def test_long_text_embedding_1500_chars( client_with_chunked_processing: openai.AsyncOpenAI, model_name: str ): """Test embedding processing for ~1500 character long text - (~1028 tokens, exceeding 512 token limit). - """ + (~1028 tokens, exceeding 512 token limit).""" # Verify text length # Verify text has sufficient word count (approximately 1500 words) word_count = len(LONG_TEXT_1500_WORDS.split()) @@ -289,8 +288,7 @@ async def test_long_text_embedding_2500_chars( client_with_chunked_processing: openai.AsyncOpenAI, model_name: str ): """Test embedding processing for ~2500 character long text - (~2048 tokens, requiring multiple chunks). - """ + (~2048 tokens, requiring multiple chunks).""" # Verify text length # Verify text has sufficient word count (approximately 2500 words) word_count = len(LONG_TEXT_2500_WORDS.split()) @@ -382,8 +380,7 @@ async def test_chunked_vs_normal_consistency( client_with_chunked_processing: openai.AsyncOpenAI, model_name: str ): """Test consistency between chunked and - normal processing (using short text). - """ + normal processing (using short text).""" # Use a short text within the 512 token limit short_text = ( "Artificial intelligence technology is changing our world, " diff --git a/tests/entrypoints/pooling/embed/test_protocol.py b/tests/entrypoints/pooling/embed/test_protocol.py index 24d4f9e6d7..91c853f910 100644 --- a/tests/entrypoints/pooling/embed/test_protocol.py +++ b/tests/entrypoints/pooling/embed/test_protocol.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Unit tests for Cohere embed protocol: build_typed_embeddings and its -underlying packing helpers, plus Cohere-specific serving helpers. -""" +underlying packing helpers, plus Cohere-specific serving helpers.""" import struct diff --git a/tests/entrypoints/scale_out/derender/test_derender.py b/tests/entrypoints/scale_out/derender/test_derender.py index db702b4b07..d7e0298ac3 100644 --- a/tests/entrypoints/scale_out/derender/test_derender.py +++ b/tests/entrypoints/scale_out/derender/test_derender.py @@ -454,8 +454,7 @@ async def test_derender_completion_empty_generate_responses(client): @pytest.mark.asyncio async def test_derender_completion_logprobs(client): """token_id:N placeholders in logprobs are resolved; CompletionLogProbs - flat-list structure is returned with non-empty tokens and text_offsets. - """ + flat-list structure is returned with non-empty tokens and text_offsets.""" gr1 = await _render_completion(client, "Hello world") ids1 = gr1["token_ids"][:3] token_id = ids1[0] diff --git a/tests/entrypoints/scale_out/derender/test_derender_parity.py b/tests/entrypoints/scale_out/derender/test_derender_parity.py index 6bcede3199..adece09c0a 100644 --- a/tests/entrypoints/scale_out/derender/test_derender_parity.py +++ b/tests/entrypoints/scale_out/derender/test_derender_parity.py @@ -121,8 +121,7 @@ async def _disagg( def _tool_sig(response_choice: dict) -> list[tuple[str, dict]]: """[(name, json normalized args)] so key ordering / whitespace don't - cause false negatives. - """ + cause false negatives.""" return [ (tc["function"]["name"], json.loads(tc["function"]["arguments"])) for tc in (response_choice["message"].get("tool_calls") or []) @@ -144,8 +143,7 @@ async def _run_parity_case( client: httpx.AsyncClient, messages: list[dict], **extra ) -> tuple[dict, dict]: """Run the coupled request then feed its generated tokens into the - disaggregated derender endpoint. Returns (coupled, disagg). - """ + disaggregated derender endpoint. Returns (coupled, disagg).""" coupled = await _coupled(client, messages, **extra) ch = coupled["choices"][0] chat_request = {"model": MODEL, "messages": messages, **extra} @@ -205,8 +203,7 @@ async def test_parity_tool_call(client): @pytest.mark.asyncio async def test_parity_reasoning_and_tool_call(client): """Combined reasoning + tool call parity means the highest drift risk - since it exercises both parser branches on the same output. - """ + since it exercises both parser branches on the same output.""" messages = [{"role": "user", "content": "What's the weather in Paris?"}] coupled, disagg = await _run_parity_case( client, diff --git a/tests/entrypoints/scale_out/render/test_render.py b/tests/entrypoints/scale_out/render/test_render.py index bb6a521ef1..e21343553d 100644 --- a/tests/entrypoints/scale_out/render/test_render.py +++ b/tests/entrypoints/scale_out/render/test_render.py @@ -455,8 +455,7 @@ async def test_chat_completion_render_with_sampling_params(client): @pytest.mark.asyncio async def test_completion_render_emits_token_offsets(client): """With return_token_offsets, /v1/completions/render returns per-token - (start, end) char offsets aligned with token_ids. - """ + (start, end) char offsets aligned with token_ids.""" prompt = "Hello, world." response = await client.post( "/v1/completions/render", @@ -481,8 +480,7 @@ async def test_completion_render_emits_token_offsets(client): @pytest.mark.asyncio async def test_completion_render_default_no_token_offsets(client): """Without the flag, token_offsets must be null (existing responses - unchanged). - """ + unchanged).""" response = await client.post( "/v1/completions/render", json={ @@ -499,8 +497,7 @@ async def test_completion_render_default_no_token_offsets(client): @pytest.mark.asyncio async def test_chat_render_emits_token_offsets(client): """With return_token_offsets, /v1/chat/completions/render returns - per-token offsets relative to the templated prompt string. - """ + per-token offsets relative to the templated prompt string.""" response = await client.post( "/v1/chat/completions/render", json={ @@ -674,8 +671,7 @@ async def test_chat_completion_render_assistant_tokens_mask_with_generation_tags client, ): """With a ``{% generation %}``-enabled template, the mask marks assistant - tokens and the masked tokens decode to the assistant content. - """ + tokens and the masked tokens decode to the assistant content.""" response = await client.post( "/v1/chat/completions/render", json={ diff --git a/tests/entrypoints/scale_out/token_in_token_out/test_protocol.py b/tests/entrypoints/scale_out/token_in_token_out/test_protocol.py index 1dcf93330e..e51530ce45 100644 --- a/tests/entrypoints/scale_out/token_in_token_out/test_protocol.py +++ b/tests/entrypoints/scale_out/token_in_token_out/test_protocol.py @@ -25,8 +25,7 @@ def _base_payload() -> dict: def test_omitted_max_tokens_is_not_provided(): """Body without ``max_tokens`` must surface as 'not provided' so the - server can apply its own default instead of the dataclass 16. - """ + server can apply its own default instead of the dataclass 16.""" req = GenerateRequest.model_validate(_base_payload()) # SamplingParams' dataclass default leaks through the parsed instance — # this is exactly the bug the server-side defaulting works around. @@ -36,8 +35,7 @@ def test_omitted_max_tokens_is_not_provided(): def test_explicit_max_tokens_is_provided(): """Even when the client picks the same value as the dataclass default, - it must register as explicitly set so the server won't override it. - """ + it must register as explicitly set so the server won't override it.""" payload = _base_payload() payload["sampling_params"] = {"max_tokens": 16} req = GenerateRequest.model_validate(payload) @@ -69,8 +67,7 @@ def test_json_roundtrip_preserves_provided_keys(): def test_internal_instance_construction_treats_all_as_provided(): """When internal callers build ``GenerateRequest`` from a pre-resolved ``SamplingParams`` instance, every field is considered explicitly set - so server-side defaulting can't clobber values resolved upstream. - """ + so server-side defaulting can't clobber values resolved upstream.""" sp = SamplingParams(max_tokens=500, temperature=0.0) req = GenerateRequest(token_ids=[1, 2, 3], sampling_params=sp) assert req.is_sampling_param_provided("max_tokens") diff --git a/tests/entrypoints/serve/exception_handling/test_error_sanitization.py b/tests/entrypoints/serve/exception_handling/test_error_sanitization.py index cb14260ab8..426d1ede74 100644 --- a/tests/entrypoints/serve/exception_handling/test_error_sanitization.py +++ b/tests/entrypoints/serve/exception_handling/test_error_sanitization.py @@ -22,8 +22,7 @@ def test_sanitize_message(): class TestSanitizeMessageFilePaths: """sanitize_message should also strip file paths and traceback - frames, not just memory addresses - see #31683. - """ + frames, not just memory addresses - see #31683.""" def test_strips_traceback_style_frame(self): msg = ( @@ -45,8 +44,7 @@ class TestSanitizeMessageFilePaths: def test_strips_single_parent_container_path(self): """Regression: /app/server.py and /workspace/server.py (common in - container deployments) were missed by the original {2,} quantifier. - """ + container deployments) were missed by the original {2,} quantifier.""" assert "/app/" not in sanitize_message("Error in /app/server.py") assert "/workspace/" not in sanitize_message("Error in /workspace/server.py") diff --git a/tests/entrypoints/serve/exception_handling/test_validation_exception_handler.py b/tests/entrypoints/serve/exception_handling/test_validation_exception_handler.py index bd4e87a155..942dd95c18 100644 --- a/tests/entrypoints/serve/exception_handling/test_validation_exception_handler.py +++ b/tests/entrypoints/serve/exception_handling/test_validation_exception_handler.py @@ -24,8 +24,7 @@ from vllm.entrypoints.serve.exception_handling.handlers.validation import ( def _fake_request(log_error_stack: bool = False) -> SimpleNamespace: """Minimal stand-in for a FastAPI Request - just enough for the - handler to read req.app.state.args.log_error_stack. - """ + handler to read req.app.state.args.log_error_stack.""" return SimpleNamespace( app=SimpleNamespace( state=SimpleNamespace(args=SimpleNamespace(log_error_stack=log_error_stack)) @@ -36,8 +35,7 @@ def _fake_request(log_error_stack: bool = False) -> SimpleNamespace: class TestValidationErrorParamFallback: """Ensure `param` falls back to the Pydantic error's `loc` when no - custom VLLMValidationError context is present. - """ + custom VLLMValidationError context is present.""" @pytest.mark.parametrize( ("error_type", "msg"), @@ -61,8 +59,7 @@ class TestValidationErrorParamFallback: async def test_param_fallback_does_not_crash_on_non_dict_error(self): """Schemathesis fuzzing found that errors[0] isn't always a dict. The fallback must not crash in that case - it should just leave - param as None instead of raising. - """ + param as None instead of raising.""" exc = RequestValidationError(["some unexpected non-dict error"]) response = await validation_exception_handler(_fake_request(), exc) @@ -100,8 +97,7 @@ class TestCleanLocForParam: def test_all_internal_falls_back_to_raw_join(self): """If every loc segment looks internal, fall back to the raw - dot-join rather than returning an empty string. - """ + dot-join rather than returning an empty string.""" loc = ("function-wrap[__log_extra_fields__()]",) assert clean_loc_for_param(loc) == "function-wrap[__log_extra_fields__()]" @@ -109,8 +105,7 @@ class TestCleanLocForParam: class TestValidationErrorDoesNotLeakServerPaths: """FastAPI sets endpoint_file/line/function/path on the exception during routing, not in the constructor - so we set them manually - here to reproduce the real leak. See #31683. - """ + here to reproduce the real leak. See #31683.""" @pytest.mark.asyncio async def test_handler_strips_endpoint_file_context(self): diff --git a/tests/entrypoints/serve/lora/test_lora_adapters.py b/tests/entrypoints/serve/lora/test_lora_adapters.py index 79356fc951..8a860dc625 100644 --- a/tests/entrypoints/serve/lora/test_lora_adapters.py +++ b/tests/entrypoints/serve/lora/test_lora_adapters.py @@ -245,8 +245,7 @@ async def test_multiple_lora_adapters( client: openai.AsyncOpenAI, tmp_path, qwen3_lora_files ): """Validate that many loras can be dynamically registered and inferenced - with concurrently - """ + with concurrently""" # This test file configures the server with --max-cpu-loras=2 and this test # will concurrently load 10 adapters, so it should flex the LRU cache diff --git a/tests/entrypoints/serve/middleware/test_authentication_middleware.py b/tests/entrypoints/serve/middleware/test_authentication_middleware.py index ee22407fdd..528261e644 100644 --- a/tests/entrypoints/serve/middleware/test_authentication_middleware.py +++ b/tests/entrypoints/serve/middleware/test_authentication_middleware.py @@ -72,8 +72,7 @@ class MockModelConfig: @pytest.fixture(params=get_args(SupportedTask)) def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]]: """For each supported task, build an app with only that task's routers, - extract all routes, and return the task name and routes. - """ + extract all routes, and return the task name and routes.""" task = request.param # Enable development mode to register all routes (including dev-only routes). monkeypatch.setenv("VLLM_SERVER_DEV_MODE", "1") @@ -99,8 +98,7 @@ def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]] def test_auto_discovered_protected_routes_require_auth(task_routes): """For every auto-discovered route that starts with a guarded prefix, - verify that authentication is enforced. - """ + verify that authentication is enforced.""" task, routes = task_routes app = _create_app_with_mock_routes(routes) client = TestClient(app) @@ -134,8 +132,7 @@ def test_auto_discovered_protected_routes_require_auth(task_routes): def test_auto_discovered_unprotected_routes_no_auth(task_routes): """For every auto-discovered route that does NOT start with a guarded - prefix, verify that no authentication is required. - """ + prefix, verify that no authentication is required.""" task, routes = task_routes app = _create_app_with_mock_routes(routes) client = TestClient(app) diff --git a/tests/entrypoints/serve/sagemaker/test_sagemaker_handler_overrides.py b/tests/entrypoints/serve/sagemaker/test_sagemaker_handler_overrides.py index b6137dae93..20b917400b 100644 --- a/tests/entrypoints/serve/sagemaker/test_sagemaker_handler_overrides.py +++ b/tests/entrypoints/serve/sagemaker/test_sagemaker_handler_overrides.py @@ -114,8 +114,7 @@ class TestHandlerOverrideIntegration: def test_customer_script_functions_auto_loaded(self, monkeypatch, tmp_path): """Test customer scenario: script functions automatically override - framework defaults. - """ + framework defaults.""" try: from model_hosting_container_standards.sagemaker.config import ( SageMakerEnvVars, @@ -176,8 +175,7 @@ async def custom_sagemaker_invocation_handler(request: Request): def test_customer_decorator_usage(self, monkeypatch, tmp_path): """Test customer scenario: using @custom_ping_handler and - @custom_invocation_handler decorators. - """ + @custom_invocation_handler decorators.""" try: from model_hosting_container_standards.sagemaker.config import ( SageMakerEnvVars, @@ -233,8 +231,7 @@ async def my_invoke(request: Request): def test_handler_priority_order(self, monkeypatch, tmp_path): """Test priority: @custom_ping_handler/@custom_invocation_handler - decorators vs script functions. - """ + decorators vs script functions.""" try: from model_hosting_container_standards.sagemaker.config import ( SageMakerEnvVars, @@ -307,8 +304,7 @@ async def custom_sagemaker_invocation_handler(request: Request): def test_environment_variable_script_loading(self, monkeypatch, tmp_path): """Test that environment variables correctly specify script location - and loading. - """ + and loading.""" try: from model_hosting_container_standards.sagemaker.config import ( SageMakerEnvVars, @@ -420,8 +416,7 @@ async def custom_sagemaker_invocation_handler(request: Request): def test_handler_env_var_override(self, monkeypatch, tmp_path): """Test CUSTOM_FASTAPI_PING_HANDLER and CUSTOM_FASTAPI_INVOCATION_HANDLER - environment variable overrides. - """ + environment variable overrides.""" try: from model_hosting_container_standards.common.fastapi.config import ( FastAPIEnvVars, @@ -515,8 +510,7 @@ async def custom_sagemaker_invocation_handler(request: Request): def test_env_var_priority_over_decorator_and_script(self, monkeypatch, tmp_path): """Test that environment variables have highest priority over decorators - and script functions for both ping and invocation handlers. - """ + and script functions for both ping and invocation handlers.""" try: from model_hosting_container_standards.common.fastapi.config import ( FastAPIEnvVars, diff --git a/tests/entrypoints/serve/tokenize/test_tokenize_then_chat_vlm.py b/tests/entrypoints/serve/tokenize/test_tokenize_then_chat_vlm.py index 49e181e36e..1d114bc8b8 100644 --- a/tests/entrypoints/serve/tokenize/test_tokenize_then_chat_vlm.py +++ b/tests/entrypoints/serve/tokenize/test_tokenize_then_chat_vlm.py @@ -51,8 +51,7 @@ async def test_tokenize_then_chat_completion_with_image( local_asset_server, ): """Tokenize a multimodal message, then send the same message to chat - completions. The chat completion must succeed (not 500). - """ + completions. The chat completion must succeed (not 500).""" image_url = local_asset_server.url_for("stop_sign.jpg") messages = [ { diff --git a/tests/entrypoints/serve/utils/test_api_utils.py b/tests/entrypoints/serve/utils/test_api_utils.py index 051978b60c..a41f39187f 100644 --- a/tests/entrypoints/serve/utils/test_api_utils.py +++ b/tests/entrypoints/serve/utils/test_api_utils.py @@ -36,13 +36,11 @@ def test_should_include_usage_force_enables_continuous_usage(stream_options, exp class TestGetMaxTokens: """Tests for get_max_tokens() to ensure generation_config's max_tokens acts as a default when from model author, and as a ceiling when - explicitly set by the user. - """ + explicitly set by the user.""" def test_default_sampling_params_used_when_no_request_max_tokens(self): """When user doesn't specify max_tokens, generation_config default - should apply. - """ + should apply.""" result = get_max_tokens( max_model_len=24000, max_tokens=None, @@ -53,8 +51,7 @@ class TestGetMaxTokens: def test_request_max_tokens_not_capped_by_default_sampling_params(self): """When user specifies max_tokens in request, model author's - generation_config max_tokens must NOT cap it (fixes #34005). - """ + generation_config max_tokens must NOT cap it (fixes #34005).""" result = get_max_tokens( max_model_len=24000, max_tokens=5000, @@ -97,8 +94,7 @@ class TestGetMaxTokens: def test_request_max_tokens_smaller_than_default(self): """When user explicitly requests fewer tokens than gen_config default, - that should be respected. - """ + that should be respected.""" result = get_max_tokens( max_model_len=24000, max_tokens=512, diff --git a/tests/entrypoints/serve/utils/test_request_logger.py b/tests/entrypoints/serve/utils/test_request_logger.py index 5df3c3cd84..717ff190b3 100644 --- a/tests/entrypoints/serve/utils/test_request_logger.py +++ b/tests/entrypoints/serve/utils/test_request_logger.py @@ -239,8 +239,7 @@ def test_request_logger_log_outputs_integration(): def test_streaming_complete_logs_full_text_content(): """Test that streaming complete logging includes - full accumulated text, not just token count. - """ + full accumulated text, not just token count.""" mock_logger = MagicMock() with patch("vllm.entrypoints.serve.utils.request_logger.logger", mock_logger): diff --git a/tests/entrypoints/serve/utils/test_sse_keep_alive.py b/tests/entrypoints/serve/utils/test_sse_keep_alive.py index 6c61080f8f..519b9bb4a1 100644 --- a/tests/entrypoints/serve/utils/test_sse_keep_alive.py +++ b/tests/entrypoints/serve/utils/test_sse_keep_alive.py @@ -17,8 +17,7 @@ from vllm.entrypoints.serve.utils.sse_keep_alive import ( def test_disabled_returns_same_generator(): """For 0, negative, and NaN intervals the exact same generator object must be returned (identity), proving no wrapper or per-chunk overhead when - disabled. - """ + disabled.""" async def gen(): yield "x" @@ -34,8 +33,7 @@ def test_disabled_returns_same_generator(): @pytest.mark.asyncio async def test_keep_alive_during_silent_start(): """A silent start (queue wait / prefill) emits keep-alive comments before - the first real chunk. - """ + the first real chunk.""" release = asyncio.Event() async def gen(): @@ -57,8 +55,7 @@ async def test_keep_alive_during_silent_start(): @pytest.mark.asyncio async def test_no_keep_alive_when_streaming_is_fast(): """If chunks arrive faster than the interval, no comment is emitted and all - data is forwarded. - """ + data is forwarded.""" async def gen(): for chunk in ["a", "b", "c"]: @@ -72,8 +69,7 @@ async def test_no_keep_alive_when_streaming_is_fast(): @pytest.mark.asyncio async def test_keep_alive_between_chunks_does_not_drop_data(): """Keep-alives interleaved with real chunks must never drop or reorder - data. - """ + data.""" release_b = asyncio.Event() release_c = asyncio.Event() @@ -139,8 +135,7 @@ async def test_upstream_cancelled_error_propagates(): @pytest.mark.asyncio async def test_aclose_closes_upstream(): """Closing a wrapper that is mid-stream must complete promptly and close - the upstream generator (regression for the earlier leaked-task hang). - """ + the upstream generator (regression for the earlier leaked-task hang).""" finalized = asyncio.Event() async def gen(): @@ -159,8 +154,7 @@ async def test_aclose_closes_upstream(): @pytest.mark.asyncio async def test_client_disconnect_cancels_upstream(): """Cancelling the consumer mid-stream must cancel the pending anext and - close the upstream generator so its cleanup runs. - """ + close the upstream generator so its cleanup runs.""" finalized = asyncio.Event() async def gen(): @@ -187,8 +181,7 @@ async def test_client_disconnect_cancels_upstream(): @pytest.mark.asyncio async def test_streaming_response_emits_comment(): """A keep-alive comment must reach the client through the real - StreamingResponse used by the routers. - """ + StreamingResponse used by the routers.""" release = asyncio.Event() async def gen(): @@ -227,8 +220,7 @@ async def test_streaming_response_emits_comment(): async def test_streaming_response_disconnect_closes_upstream(): """On the ASGI 2.3 disconnect path used by the pinned Uvicorn, Starlette cancels streaming and the wrapper's finally must close the upstream - generator. - """ + generator.""" finalized = asyncio.Event() async def gen(): diff --git a/tests/entrypoints/speech_to_text/realtime/test_realtime_validation.py b/tests/entrypoints/speech_to_text/realtime/test_realtime_validation.py index b9ea18bbae..7fb7a5522d 100644 --- a/tests/entrypoints/speech_to_text/realtime/test_realtime_validation.py +++ b/tests/entrypoints/speech_to_text/realtime/test_realtime_validation.py @@ -295,8 +295,7 @@ async def test_session_update_invalid_model_returns_error(model_name): @pytest.mark.parametrize("model_name", [MODEL_NAME]) async def test_commit_without_session_update_returns_error(model_name): """Test that committing before validating the model returns an error - and does not fall through to processing. - """ + and does not fall through to processing.""" server_args = ["--enforce-eager", "--max-model-len", "2048"] if model_name.startswith("mistralai"): diff --git a/tests/entrypoints/unit_tests/test_context.py b/tests/entrypoints/unit_tests/test_context.py index e09687425b..c92813ea66 100644 --- a/tests/entrypoints/unit_tests/test_context.py +++ b/tests/entrypoints/unit_tests/test_context.py @@ -51,8 +51,7 @@ async def generate_mock_outputs( num_turns, prompt_token_counts, output_token_counts, cached_token_counts=None ): """Generate a sequence of mock RequestOutput objects to simulate multiple - turns. - """ + turns.""" if cached_token_counts is None: cached_token_counts = [0] * num_turns @@ -271,8 +270,7 @@ def test_reasoning_tokens_counting(): def test_preamble_tokens_not_counted_as_reasoning(): """Preambles (commentary with no recipient) are visible user text, - not hidden reasoning. They must NOT inflate num_reasoning_tokens. - """ + not hidden reasoning. They must NOT inflate num_reasoning_tokens.""" context, parser = make_harmony_context() parser.enqueue_chunk_result(reasoning_token_count=0) @@ -289,8 +287,7 @@ def test_preamble_tokens_not_counted_as_reasoning(): def test_commentary_with_recipient_counted_as_reasoning(): """Commentary directed at a tool (recipient != None) is hidden from - the user, so it should still count as reasoning tokens. - """ + the user, so it should still count as reasoning tokens.""" context, parser = make_harmony_context() parser.enqueue_chunk_result(reasoning_token_count=3) @@ -349,8 +346,7 @@ async def test_single_turn_no_tool_output(): @pytest.mark.asyncio async def test_negative_tool_tokens_edge_case(): """Test edge case where calculation could result in negative tool - tokens. We should log an error and clamp the value to 0. - """ + tokens. We should log an error and clamp the value to 0.""" # Use patch to check if logger.error was called with patch("vllm.entrypoints.openai.responses.context.logger.error") as mock_log: context, _ = make_harmony_context(available_tools=["browser"]) @@ -690,8 +686,7 @@ def create_simple_context_output( finished=True, ): """Helper to create a RequestOutput with customizable text for - SimpleContext tests. - """ + SimpleContext tests.""" if token_ids is None: token_ids = [] return RequestOutput( @@ -875,8 +870,7 @@ def test_simple_context_final_output(): def test_simple_context_output_messages_empty_text_with_tokens(): """output_messages should be returned when tokens exist even if text is - empty (e.g. special tokens). - """ + empty (e.g. special tokens).""" context = SimpleContext() context.append_output( create_simple_context_output( @@ -894,8 +888,7 @@ def test_simple_context_output_messages_empty_text_with_tokens(): def test_simple_context_output_messages_no_mutation(): """Each call to output_messages returns a fresh list; callers can't - corrupt internal state. - """ + corrupt internal state.""" context = SimpleContext() context.append_output( create_simple_context_output( diff --git a/tests/entrypoints/weight_transfer/test_weight_transfer_llm.py b/tests/entrypoints/weight_transfer/test_weight_transfer_llm.py index 9b36ab398d..e5c3616d6e 100644 --- a/tests/entrypoints/weight_transfer/test_weight_transfer_llm.py +++ b/tests/entrypoints/weight_transfer/test_weight_transfer_llm.py @@ -121,8 +121,7 @@ def test_get_world_size_tp1(vllm_runner): @create_new_process_for_each_test() def test_init_weight_transfer_engine_calls_engine(vllm_runner): """Test that init_weight_transfer_engine calls the engine's - init_transfer_engine method. - """ + init_transfer_engine method.""" if torch.accelerator.device_count() < 1: pytest.skip("Need at least 1 GPU for this test") diff --git a/tests/fusion/test_quant_activation_contract.py b/tests/fusion/test_quant_activation_contract.py index 7e346cc767..15b9835d6c 100644 --- a/tests/fusion/test_quant_activation_contract.py +++ b/tests/fusion/test_quant_activation_contract.py @@ -86,8 +86,7 @@ def _all_kernel_classes() -> list[type]: def _probe(cls: type): """A bare kernel instance with a plausible config, so input_quant_key() - can be queried without the hardware-gated constructor. - """ + can be queried without the hardware-gated constructor.""" obj = cls.__new__(cls) # type: ignore[call-overload] if issubclass(cls, NvFp4LinearKernel): obj.config = NvFp4LinearLayerConfig() diff --git a/tests/kernels/attention/test_amx_mla.py b/tests/kernels/attention/test_amx_mla.py index 7dab61f1c4..f5fa2fad16 100644 --- a/tests/kernels/attention/test_amx_mla.py +++ b/tests/kernels/attention/test_amx_mla.py @@ -247,8 +247,7 @@ def test_extend_attention_cpu_matches_reference(prefix_lens, extend_lens): class _FakeLinear: """Minimal duck-typed stand-in for kv_b_proj: only .weight and - .quant_method are read by get_and_maybe_dequant_weights(). - """ + .quant_method are read by get_and_maybe_dequant_weights().""" def __init__(self, weight: torch.Tensor): self.weight = weight @@ -319,8 +318,7 @@ class _FakeAttnMetadata: def test_amx_mla_impl_forward_mqa_matches_reference(default_vllm_config): """forward_mqa receives already-absorbed Q (as MLAAttention.forward_impl would produce via layer.W_UK_T) and must reproduce plain per-head MLA - decode attention through W_UK/W_UV. - """ + decode attention through W_UK/W_UV.""" set_random_seed(1) num_heads, qk_nope_head_dim, v_head_dim, kv_lora_rank = 4, 32, 32, 64 impl, kv_b_weight = _make_amx_mla_impl( @@ -386,8 +384,7 @@ def test_amx_mla_impl_forward_mqa_matches_reference(default_vllm_config): def test_amx_mla_impl_forward_mha_matches_reference(default_vllm_config): """forward_mha receives raw unabsorbed Q and must attend correctly for a prefill batch with a mix of fresh and continued (cached-prefix) - sequences. - """ + sequences.""" set_random_seed(2) num_heads, qk_nope_head_dim, v_head_dim, kv_lora_rank = 4, 32, 32, 64 impl, kv_b_weight = _make_amx_mla_impl( diff --git a/tests/kernels/attention/test_attention_selector.py b/tests/kernels/attention/test_attention_selector.py index 0511fe7b07..53867a5edf 100644 --- a/tests/kernels/attention/test_attention_selector.py +++ b/tests/kernels/attention/test_attention_selector.py @@ -616,8 +616,7 @@ def test_non_causal_autoselect_backend(): ) def test_flash_attn_rejects_unhandled_kv_cache_dtypes(kv_cache_dtype: str): """FlashAttentionBackend must not claim support for kv_cache dtypes - that it cannot handle. - """ + that it cannot handle.""" from vllm.v1.attention.backends.flash_attn import FlashAttentionBackend assert not FlashAttentionBackend.supports_kv_cache_dtype(kv_cache_dtype) @@ -628,8 +627,7 @@ def test_flash_attn_accepts_handled_fp8_variants( kv_cache_dtype: str, monkeypatch: pytest.MonkeyPatch ): """FlashAttentionBackend must accept the two fp8 dtypes it can actually - handle: 'fp8' (alias for fp8_e4m3fn) and 'fp8_e4m3'. - """ + handle: 'fp8' (alias for fp8_e4m3fn) and 'fp8_e4m3'.""" import vllm.v1.attention.backends.fa_utils as fa_utils_mod from vllm.v1.attention.backends.flash_attn import FlashAttentionBackend diff --git a/tests/kernels/attention/test_cutlass_mla_decode.py b/tests/kernels/attention/test_cutlass_mla_decode.py index d56d72adba..7a5011b5ca 100644 --- a/tests/kernels/attention/test_cutlass_mla_decode.py +++ b/tests/kernels/attention/test_cutlass_mla_decode.py @@ -225,8 +225,7 @@ def test_cutlass_mla_decode_cross_layer_view(): """The kernel must read the cache's page-dim stride instead of assuming pages are packed back-to-back. A per-layer view into a cross-layer (block-major) cache has stride(0) inflated by num_layers; outputs must - match a contiguous cache holding the same data exactly. - """ + match a contiguous cache holding the same data exactly.""" device = torch.device("cuda:0") torch.set_default_dtype(torch.bfloat16) torch.set_default_device(device) diff --git a/tests/kernels/attention/test_flashinfer.py b/tests/kernels/attention/test_flashinfer.py index b786fac095..c6cba8d530 100644 --- a/tests/kernels/attention/test_flashinfer.py +++ b/tests/kernels/attention/test_flashinfer.py @@ -162,8 +162,7 @@ def test_fast_decode_plan_importable() -> None: @torch.inference_mode def test_fast_plan_decode_warmup_uses_full_plan(dtype: torch.dtype) -> None: """On the first call fast_plan_decode must route through self.plan() and - flip vllm_first_call to False on the wrapper object. - """ + flip vllm_first_call to False on the wrapper object.""" from unittest.mock import patch from vllm.v1.attention.backends.flashinfer import fast_plan_decode diff --git a/tests/kernels/attention/test_flashinfer_trtllm_attention.py b/tests/kernels/attention/test_flashinfer_trtllm_attention.py index b35005d361..48eb58b5e1 100644 --- a/tests/kernels/attention/test_flashinfer_trtllm_attention.py +++ b/tests/kernels/attention/test_flashinfer_trtllm_attention.py @@ -134,8 +134,7 @@ def make_quantized_kv_cache( head_size: int, ) -> tuple: """Quantize kv_cache based on dtype. Returns (kv_cache, kv_cache_sf, - kv_scale, ref_kv_cache, is_nvfp4_kv). - """ + kv_scale, ref_kv_cache, is_nvfp4_kv).""" is_nvfp4_kv = kv_quant_dtype == FP4_DTYPE if is_nvfp4_kv: data, scales, kv_scale, ref = make_nvfp4_kv_cache( diff --git a/tests/kernels/attention/test_kimi_k3_mla_fused_epilogue.py b/tests/kernels/attention/test_kimi_k3_mla_fused_epilogue.py index e86686ee86..aa7c836666 100644 --- a/tests/kernels/attention/test_kimi_k3_mla_fused_epilogue.py +++ b/tests/kernels/attention/test_kimi_k3_mla_fused_epilogue.py @@ -73,8 +73,7 @@ def _strided_context_inputs( ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]: """The real prefill-context layouts: ``k_nope``/``v`` as the two strided halves of one kv_b_proj output and ``k_pe`` as a column slice of the gather - workspace (left in the fp8 cache layout for a plain fp8 cache). - """ + workspace (left in the fp8 cache layout for a plain fp8 cache).""" kv_nope = _randn(num_tokens, num_heads, 256, dtype=dtype) k_nope, v = kv_nope.split((128, 128), dim=-1) workspace = _randn(num_tokens, 576, dtype=dtype) diff --git a/tests/kernels/attention/test_merge_attn_states.py b/tests/kernels/attention/test_merge_attn_states.py index 07295ed0b8..1b89e4db66 100644 --- a/tests/kernels/attention/test_merge_attn_states.py +++ b/tests/kernels/attention/test_merge_attn_states.py @@ -89,8 +89,7 @@ all_case_info: list[tuple] = [] @pytest.mark.parametrize("output_dtype", [torch.float32, torch.half, torch.bfloat16]) def test_merge_attn_states_both_empty(merge_fn, output_dtype) -> None: """When a token is empty on both sides (both LSE -inf), the 0/0 softmax - scales must not surface as NaN in the merged output. - """ + scales must not surface as NaN in the merged output.""" num_tokens, num_heads, head_size = 6, 8, 128 prefix_output = torch.zeros( num_tokens, num_heads, head_size, device=DEVICE, dtype=output_dtype diff --git a/tests/kernels/attention/test_minimax_m3.py b/tests/kernels/attention/test_minimax_m3.py index c7b763e7c7..a7e6d499c1 100644 --- a/tests/kernels/attention/test_minimax_m3.py +++ b/tests/kernels/attention/test_minimax_m3.py @@ -45,8 +45,7 @@ def kv_layout(request) -> KVCacheLayout: def _layer_stride_order(layout: KVCacheLayout, ndim: int) -> tuple[int, ...]: """Per-layer physical stride order for the given layout; the 3-dim - indexer side cache (H=1) is contiguous, so identity. - """ + indexer side cache (H=1) is contiguous, so identity.""" if ndim == 3: return (0, 1, 2) stride_order = layout.layer_view_order @@ -66,8 +65,7 @@ def _main_spec() -> FullAttentionSpec: def _main_kv_logical_shape(num_pages: int) -> tuple[int, ...]: """Standardized per-layer logical shape [B, H, N, C] for the main cache, - derived the same way the production allocator does. - """ + derived the same way the production allocator does.""" shape_bytes = compute_layer_kv_cache_shape_bytes(_main_spec(), num_pages) return (*shape_bytes[:-1], shape_bytes[-1] // DTYPE.itemsize) @@ -77,8 +75,7 @@ def _allocate_main_kv_via_contract( ) -> torch.Tensor: """Build the main KV cache exactly as the production allocator does for the given layout: allocate the physical (permuted) tensor, then expose the - inverse-permuted logical [B, H, N, C] view the backend sees. - """ + inverse-permuted logical [B, H, N, C] view the backend sees.""" logical_shape = _main_kv_logical_shape(num_pages) stride_order = _layer_stride_order(layout, len(logical_shape)) physical_shape = tuple(logical_shape[i] for i in stride_order) @@ -1379,8 +1376,7 @@ def test_amd_decode_index_topk_end_to_end( @pytest.mark.parametrize("num_idx_heads", [1, 4]) def test_decode_index_topk_fp8(num_idx_heads: int): """The standalone Triton path must score FP8 inputs in FP32 so its top-k - matches a reference computed from the dequantized FP8 values. - """ + matches a reference computed from the dequantized FP8 values.""" torch.manual_seed(0) topk, init_blocks, local_blocks, head_dim = 8, 0, 1, 128 decode_query_len = 1 @@ -1653,8 +1649,7 @@ def test_prefill_sparse_attention_correctness( def test_main_cache_layout_contract(): """The standardized per-layer logical shape is [B, H, N, C] with packed K/V content, and the legacy layout aliases resolve to the expected - per-layer stride orders. - """ + per-layer stride orders.""" nb, bs, h, d = 7, BLOCK_SIZE, NUM_KV_HEADS, HEAD_DIM logical = _main_kv_logical_shape(nb) assert logical == (nb, h, bs, 2 * d) @@ -1778,8 +1773,7 @@ def test_indexer_cache_squeezes_to_contiguous_3d(): """The indexer side cache is standardized 4D with H=1: under both layouts the allocator's logical view stays contiguous and squeezes (as `MiniMaxM3IndexerCache.bind_kv_cache` does) to the 3-dim - [num_blocks, block_size, head_dim] cache the kernels consume. - """ + [num_blocks, block_size, head_dim] cache the kernels consume.""" nb = 5 ispec = MLAAttentionSpec( block_size=BLOCK_SIZE, num_kv_heads=1, head_size=HEAD_DIM, dtype=DTYPE @@ -1799,8 +1793,7 @@ def test_indexer_cache_squeezes_to_contiguous_3d(): def test_hnd_allocation_is_packed_head_major(): """Under HND the backend-visible logical view is the packed head-major - physical allocation. - """ + physical allocation.""" nb, bs, h, d = 4, BLOCK_SIZE, NUM_KV_HEADS, HEAD_DIM logical = _main_kv_logical_shape(nb) stride_order = KVCacheLayout.LBHNC.layer_view_order @@ -1828,8 +1821,7 @@ def test_hnd_allocation_is_packed_head_major(): def test_main_cache_is_block_first_and_unpadded(): """The allocator's contiguous-view branch (not the padded-strided branch) is used for the main GQA cache: its spec is unpadded and the physical - layout keeps num_blocks as the first dimension under both layouts. - """ + layout keeps num_blocks as the first dimension under both layouts.""" spec = _main_spec() # Unpadded -> allocator uses kv_tensor.view(...) rather than as_strided(). assert spec.page_size_padded is None @@ -1851,8 +1843,7 @@ def _build_decode_inputs( ): """Shared decode setup: uniform query tokens per request, a non-identity block table, and topk indices selecting the current block plus older causal - blocks for each query token. - """ + blocks for each query token.""" active_batch = len(seq_lens_list) batch = active_batch + num_padded_reqs pages_per_req = [(s + BLOCK_SIZE - 1) // BLOCK_SIZE for s in seq_lens_list] @@ -2188,8 +2179,7 @@ def test_decode_sparse_attention_correctness( ): """Decode (split-K) parity under both layouts: this is the only coverage of the decode-site cache feed, and the strided HND case fails if the kernel - ignores the cache strides. - """ + ignores the cache strides.""" torch.manual_seed(0) q, block_table, seq_lens, topk_idx, num_pages = _build_decode_inputs( seq_lens_list, decode_query_len, num_padded_reqs @@ -2239,8 +2229,7 @@ def test_decode_wrong_layout_breaks_parity(): already contiguous-NHD (i.e. skipping the allocator's inverse permute) reorders the K/V content, so the decode output no longer matches the reference computed on the correct logical view. The mislabeled tensor keeps - the same shape as the correct view, so the kernel stays in bounds. - """ + the same shape as the correct view, so the kernel stays in bounds.""" torch.manual_seed(0) seq_lens_list = (130, 257) q, block_table, seq_lens, topk_idx, num_pages = _build_decode_inputs(seq_lens_list) @@ -2275,8 +2264,7 @@ def test_decode_wrong_layout_breaks_parity(): def test_main_cache_byte_identical_through_production_allocator(): """AC-2: drive the real allocator (`create_kv_cache_views`) for the M3 main `FullAttentionSpec` under HND and assert the backend-visible view has the - same shape, stride, and storage offset as the packed-HND allocation. - """ + same shape, stride, and storage offset as the packed-HND allocation.""" nb = 4 spec = _main_spec() raw = torch.zeros(nb * spec.page_size_bytes, dtype=torch.int8) @@ -2291,8 +2279,7 @@ def test_main_cache_byte_identical_through_production_allocator(): def test_padded_main_cache_is_flagged(): """AC-2.1 negative: the M3 main cache relies on the allocator's contiguous-view branch (`page_size_padded is None`). A spec that sets - `page_size_padded` is explicitly flagged rather than silently wrong-strided. - """ + `page_size_padded` is explicitly flagged rather than silently wrong-strided.""" def _require_unpadded_block_first(spec, stride_order): inv_order = [stride_order.index(i) for i in range(len(stride_order))] @@ -2329,8 +2316,7 @@ def test_padded_main_cache_is_flagged(): def test_reshape_and_cache_flash_write_persists(kv_layout: KVCacheLayout): """AC-5 write path: the `reshape_and_cache_flash` write site now consumes packed-content K/V split views. Writing through those views must persist - into the bound storage under both layouts. - """ + into the bound storage under both layouts.""" torch.manual_seed(0) num_pages = 4 kv_cache = _allocate_main_kv_via_contract(num_pages, kv_layout) diff --git a/tests/kernels/attention/test_mla_cross_layer_kernel_equivalence.py b/tests/kernels/attention/test_mla_cross_layer_kernel_equivalence.py index 8106ba37a6..ffdb76e176 100644 --- a/tests/kernels/attention/test_mla_cross_layer_kernel_equivalence.py +++ b/tests/kernels/attention/test_mla_cross_layer_kernel_equivalence.py @@ -23,8 +23,7 @@ pytestmark = pytest.mark.skipif( def test_concat_and_cache_mla_into_unified_slot_view(): """concat_and_cache_mla must write correctly into a per-layer view whose block stride is the full unified slot (block-major), with zero bleed into - the other layers' segments of the same slot. - """ + the other layers' segments of the same slot.""" from vllm import _custom_ops as ops torch.manual_seed(0) @@ -86,8 +85,7 @@ def test_concat_and_cache_mla_into_unified_slot_view(): def test_flashmla_dense_decode_unified_slot_view(): """FlashMLA dense decode (FLASHMLA backend, e.g. Kimi-K2-style dense MLA on Hopper) must read a unified-slot block-major view bit-identically to a - contiguous per-layer cache. - """ + contiguous per-layer cache.""" import vllm.v1.attention.ops.flashmla as fm ok, reason = fm.is_flashmla_dense_supported() @@ -152,8 +150,7 @@ def test_flashmla_dense_decode_unified_slot_view(): def test_flashinfer_mla_dense_decode_unified_slot_view(): """FlashInfer MLA dense decode must read a unified-slot block-major view (inflated stride(0), non-zero storage offset) bit-identically to a - contiguous per-layer cache. - """ + contiguous per-layer cache.""" try: from flashinfer.decode import trtllm_batch_decode_with_kv_cache_mla except ImportError: @@ -224,8 +221,7 @@ def test_flashinfer_mla_dense_decode_unified_slot_view(): def test_flashmla_fp8_sparse_decode_unified_slot_view(next_n: int): """FlashMLA fp8 sparse decode (DeepSeek V3.2/V4 DSA path) must read a unified-slot block-major view bit-identically to a contiguous fp8_ds_mla - cache, with finite nonzero output. - """ + cache, with finite nonzero output.""" import vllm.v1.attention.ops.flashmla as fm ok, reason = fm.is_flashmla_sparse_supported() @@ -314,8 +310,7 @@ def test_flashmla_fp8_sparse_decode_unified_slot_view(next_n: int): def test_indexer_k_quant_and_cache_into_unified_slot_view(): """indexer_k_quant_and_cache (DeepSeek V3.2/V4 DSA indexer K write) must write correctly into a per-layer view whose block stride is the full - unified slot, with zero bleed into the other layers' segments. - """ + unified slot, with zero bleed into the other layers' segments.""" from vllm import _custom_ops as ops torch.manual_seed(0) @@ -360,8 +355,7 @@ def test_indexer_k_quant_and_cache_into_unified_slot_view(): def test_flashattn_mla_dense_decode_unified_slot_view(): """FA3 decode (FLASH_ATTN_MLA backend) must read a unified-slot - block-major view bit-identically to a contiguous per-layer cache. - """ + block-major view bit-identically to a contiguous per-layer cache.""" try: from vllm.vllm_flash_attn import flash_attn_varlen_func except ImportError: @@ -434,8 +428,7 @@ def test_flashattn_mla_dense_decode_unified_slot_view(): def test_flashmla_dense_fp8_decode_unified_slot_view(): """FlashMLA dense fp8 decode (FLASHMLA backend with quantized KV cache) must read a unified-slot block-major view bit-identically to a contiguous - per-layer fp8 cache. - """ + per-layer fp8 cache.""" import vllm.v1.attention.ops.flashmla as fm ok, reason = fm.is_flashmla_dense_supported() @@ -506,8 +499,7 @@ def test_flashmla_dense_fp8_decode_unified_slot_view(): def test_flashinfer_mla_dense_fp8_decode_unified_slot_view(): """FlashInfer MLA dense decode with an fp8 KV cache must read a unified-slot block-major view bit-identically to a contiguous per-layer - cache. - """ + cache.""" try: from flashinfer.decode import trtllm_batch_decode_with_kv_cache_mla except ImportError: diff --git a/tests/kernels/attention/test_rocm_aiter_fa.py b/tests/kernels/attention/test_rocm_aiter_fa.py index 0fbe7bced2..dd2870ccf1 100644 --- a/tests/kernels/attention/test_rocm_aiter_fa.py +++ b/tests/kernels/attention/test_rocm_aiter_fa.py @@ -283,8 +283,7 @@ def _run_direct_flash_attn_case( # Backend contract tests -------------------------------------------------- def test_aiter_mha_backend_contract(): """The ROCm backend advertises the dtypes, shapes, and attention types it - is designed to handle. - """ + is designed to handle.""" from vllm.v1.attention.backend import AttentionType from vllm.v1.attention.backends.rocm_aiter_fa import AiterFlashAttentionBackend @@ -312,8 +311,7 @@ def test_aiter_mha_backend_contract(): def test_aiter_mha_backend_validates_kv_cache_block_size(): """The backend should reject KV cache specs that cannot be gathered - correctly by the ROCm kernel. - """ + correctly by the ROCm kernel.""" from vllm.v1.attention.backends.rocm_aiter_fa import AiterFlashAttentionBackend from vllm.v1.kv_cache_interface import FullAttentionSpec @@ -333,8 +331,7 @@ def test_aiter_mha_backend_validates_kv_cache_block_size(): def test_aiter_mha_backend_supports_compute_capability_matches_mi3xx_probe(): """The backend should trust the ROCm MI3xx probe instead of the raw torch - capability tuple. - """ + capability tuple.""" from vllm.platforms.interface import DeviceCapability from vllm.v1.attention.backends.rocm_aiter_fa import AiterFlashAttentionBackend @@ -359,8 +356,7 @@ def test_aiter_mha_env_flags_control_enablement( use_aiter, use_mha, expected, monkeypatch ): """Both the global AITER flag and the MHA-specific flag must be enabled - before the ROCm MHA path is considered active. - """ + before the ROCm MHA path is considered active.""" from vllm._aiter_ops import rocm_aiter_ops _assert_aiter_supported() @@ -378,8 +374,7 @@ def test_aiter_mha_env_flags_control_enablement( def test_aiter_mha_platform_gate_matches_install_and_arch(): """The global AITER availability check should only open on ROCm MI3xx when - the aiter package is installed. - """ + the aiter package is installed.""" from vllm._aiter_ops import IS_AITER_FOUND, is_aiter_found_and_supported assert is_aiter_found_and_supported() is ( @@ -650,8 +645,7 @@ def test_aiter_mha_multi_batch(num_heads, head_size, dtype): @pytest.mark.parametrize("num_blocks", DIRECT_NUM_BLOCKS) def test_aiter_fa_large_block_table_matches_reference(num_blocks): """The direct paged-KV path should stay stable for both normal and very - large block tables. - """ + large block tables.""" atol = 2e-2 rtol = 2e-2 _assert_aiter_supported() @@ -673,8 +667,7 @@ def test_aiter_fa_large_block_table_matches_reference(num_blocks): @pytest.mark.skipif(not on_mi3xx(), reason="MI300/MI350 ROCm only") def test_aiter_fa_sliding_window_matches_reference(): """The direct kernel should respect the same sliding-window causal mask as - the naive reference implementation. - """ + the naive reference implementation.""" atol = 2e-2 rtol = 2e-2 _assert_aiter_supported() diff --git a/tests/kernels/attention/test_rocm_aiter_mla_sparse_metadata_sync.py b/tests/kernels/attention/test_rocm_aiter_mla_sparse_metadata_sync.py index 17b59c0743..aabce97fac 100644 --- a/tests/kernels/attention/test_rocm_aiter_mla_sparse_metadata_sync.py +++ b/tests/kernels/attention/test_rocm_aiter_mla_sparse_metadata_sync.py @@ -111,8 +111,7 @@ def _make_mixed_common_metadata(): def _patch_build_deps(monkeypatch, events=None): """Stub the aiter kernel, triton helper and CUDA sync so ``build()`` runs - on CPU. - """ + on CPU.""" def fake_generate_sparse_seqlen_triton( query_lens, seq_lens, cu_query_lens, topk_token, num_tokens, max_query_len @@ -153,8 +152,7 @@ def test_build_populates_decode_only_split_fields(monkeypatch): def test_build_populates_mixed_split_fields(monkeypatch): """Mixed decode+prefill batch: split is reported, prefill fields stay - default because this impl always runs the MQA path. - """ + default because this impl always runs the MQA path.""" builder = _make_builder() _patch_build_deps(monkeypatch) diff --git a/tests/kernels/attention/test_triton_decode_attention.py b/tests/kernels/attention/test_triton_decode_attention.py index a46916e14e..5ac1d6cdcb 100644 --- a/tests/kernels/attention/test_triton_decode_attention.py +++ b/tests/kernels/attention/test_triton_decode_attention.py @@ -125,8 +125,7 @@ def _quantize_to_fp8(tensor: torch.Tensor): @pytest.mark.parametrize("PAGE_SIZE", [1, 16]) def test_decode_attention_fp8(B, L, H_Q, H_KV, D_QK, D_V, CACHE_SIZE, PAGE_SIZE): """Test FP8 KV cache path: quantize K/V to FP8, run kernel with scales, - and compare against BF16 reference output. - """ + and compare against BF16 reference output.""" assert CACHE_SIZE % PAGE_SIZE == 0 dtype = torch.bfloat16 seq_len = L @@ -249,8 +248,7 @@ def test_decode_attention_cross_layer_view(H_Q, H_KV, D_QK, D_V, is_mla, PAGE_SI """The kernel must honor the cache's page-dim stride, not assume pages are packed back-to-back. A per-layer view into a cross-layer (block-major) cache has stride(0) inflated by num_layers; outputs must match a - contiguous cache holding the same data exactly. - """ + contiguous cache holding the same data exactly.""" B = 3 seq_len = 1027 CACHE_SIZE = 16384 diff --git a/tests/kernels/core/test_fused_embed_norm.py b/tests/kernels/core/test_fused_embed_norm.py index fc30ab3aca..9da43dba83 100644 --- a/tests/kernels/core/test_fused_embed_norm.py +++ b/tests/kernels/core/test_fused_embed_norm.py @@ -41,8 +41,7 @@ def _rmsnorm(x: torch.Tensor, w: torch.Tensor, eps: float) -> torch.Tensor: def test_fused_embed_norm_matches_reference(): """Main-model fusion: the residual is the exact gather and the second output is a correct RMSNorm. The norm matches a full-precision reference to ~2 bf16 - ulp (rtol 1e-2) -- that gap is bf16 rounding, not the kernel. - """ + ulp (rtol 1e-2) -- that gap is bf16 rounding, not the kernel.""" set_random_seed(13) table = torch.randn(VOCAB, HIDDEN, dtype=DTYPE, device="cuda") ids = torch.randint(0, VOCAB, (NUM_TOKENS,), dtype=torch.int32, device="cuda") @@ -61,8 +60,7 @@ def test_fused_embed_norm_matches_reference(): @torch.inference_mode() def test_fused_embed_eh_norm_matches_reference(): """MTP fusion (folded gather) is bit-exact vs gathering the embeds and - feeding the untouched model-local ``fused_eh_norm``. - """ + feeding the untouched model-local ``fused_eh_norm``.""" set_random_seed(13) table = torch.randn(VOCAB, HIDDEN, dtype=DTYPE, device="cuda") ids = torch.randint(0, VOCAB, (NUM_TOKENS,), dtype=torch.int32, device="cuda") diff --git a/tests/kernels/core/test_fused_q_kv_rmsnorm.py b/tests/kernels/core/test_fused_q_kv_rmsnorm.py index 81382bdda9..3d0e2ac11e 100644 --- a/tests/kernels/core/test_fused_q_kv_rmsnorm.py +++ b/tests/kernels/core/test_fused_q_kv_rmsnorm.py @@ -62,8 +62,7 @@ def test_fused_q_kv_rmsnorm_outputs_are_packed(num_tokens: int): a [1, q_size] slice of a [1, q_size + kv_size] buffer used to produce a qr_out with row stride q_size + kv_size. Downstream dispatchers that require packed row-major inputs then reject the tensor and silently fall - back to a slower GEMM path on every decode step. - """ + back to a slower GEMM path on every decode step.""" device = "cuda" dtype = torch.bfloat16 q_size, kv_size = 192, 576 @@ -89,8 +88,7 @@ def test_fused_q_kv_rmsnorm_outputs_are_packed(num_tokens: int): def test_fused_q_kv_rmsnorm_launches_past_grid_y_cap(num_tokens: int): """Regression guard: grid used to be (2, num_tokens), hitting CUDA's 65535 grid-y cap at num_tokens >= 65536. The new grid (num_tokens, 2) - lifts that bound to 2**31-1. - """ + lifts that bound to 2**31-1.""" device = "cuda" dtype = torch.bfloat16 q_size, kv_size = 192, 576 diff --git a/tests/kernels/core/test_fused_rms_norm_gated.py b/tests/kernels/core/test_fused_rms_norm_gated.py index 74fdb00c30..86b8e79656 100644 --- a/tests/kernels/core/test_fused_rms_norm_gated.py +++ b/tests/kernels/core/test_fused_rms_norm_gated.py @@ -2,8 +2,7 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Tests that FusedRMSNormGated decomposes correctly under torch.compile, -matching the eager triton kernel output. -""" +matching the eager triton kernel output.""" import pytest import torch diff --git a/tests/kernels/core/test_rocm_aiter_ops.py b/tests/kernels/core/test_rocm_aiter_ops.py index b2bed636e9..c15afd72d7 100644 --- a/tests/kernels/core/test_rocm_aiter_ops.py +++ b/tests/kernels/core/test_rocm_aiter_ops.py @@ -579,8 +579,7 @@ def test_rocm_aiter_mla_dual_rmsnorm_group_quant_vs_sequential(m): def test_rocm_aiter_mla_dual_rmsnorm_group_quant_strided_split_view(): """Split-view inputs, as produced by the DeepSeek-V4 q/kv split, match - contiguous inputs. - """ + contiguous inputs.""" require_aiter() require_fp8() from vllm._aiter_ops import rocm_aiter_ops diff --git a/tests/kernels/core/test_vocab_parallel_embedding.py b/tests/kernels/core/test_vocab_parallel_embedding.py index fa50d2b3eb..b0038c084e 100644 --- a/tests/kernels/core/test_vocab_parallel_embedding.py +++ b/tests/kernels/core/test_vocab_parallel_embedding.py @@ -87,8 +87,7 @@ def _shard(full_table, si, rows_per_rank, dtype): @pytest.mark.parametrize("id_dtype", [torch.int32, torch.int64]) def test_matches_masked_gather(tp_size, vocab_size, org_vocab_size, hidden, id_dtype): """Every rank's partial output is bit-exact with the eager path, including - the added-vocab (LoRA) rows and the ids owned by another rank. - """ + the added-vocab (LoRA) rows and the ids owned by another rank.""" set_random_seed(7) dtype = torch.bfloat16 rows = pad_vocab_size(vocab_size, 64) // tp_size diff --git a/tests/kernels/helion/test_autotune.py b/tests/kernels/helion/test_autotune.py index f28e892109..8b42e145d4 100644 --- a/tests/kernels/helion/test_autotune.py +++ b/tests/kernels/helion/test_autotune.py @@ -59,8 +59,7 @@ class TestAutotuneDisabledKernel: def test_autotune_disabled_kernel_produces_valid_config(self): """Register a kernel with no configs (disabled), run autotune, - verify it produces a valid helion.Config. - """ + verify it produces a valid helion.Config.""" with dummy_kernel_registry(configs={}) as register: wrapper = register( "autotune_test_kernel", diff --git a/tests/kernels/helion/test_register.py b/tests/kernels/helion/test_register.py index 572a4126cf..dd4274bfaf 100644 --- a/tests/kernels/helion/test_register.py +++ b/tests/kernels/helion/test_register.py @@ -598,8 +598,7 @@ class TestHelionKernelWrapper: ) def test_init_eagerly_initializes_hop_path(self): """Test that register_kernel eagerly builds the configured kernel - on the HOP path (no custom op registration needed). - """ + on the HOP path (no custom op registration needed).""" from vllm.kernels.helion.utils import get_canonical_gpu_name configs: dict[CaseKey, helion.Config] = { @@ -634,8 +633,7 @@ class TestHelionKernelWrapper: ) def test_init_eagerly_initializes(self): """Test that register_kernel eagerly loads configs and detects GPU - during construction so __call__ needs no further initialization. - """ + during construction so __call__ needs no further initialization.""" from vllm.kernels.helion.utils import get_canonical_gpu_name with ( @@ -963,8 +961,7 @@ class TestTorchCompileHOP: def test_compiled_graph_contains_helion_hop(self): """Verify torch.compile on a HelionKernelWrapper emits a - helion_kernel_wrapper_mutation HOP node in the FX graph. - """ + helion_kernel_wrapper_mutation HOP node in the FX graph.""" configs: dict[CaseKey, helion.Config] = { CaseKey.default(): helion.Config(block_sizes=[4, 4]) } diff --git a/tests/kernels/ir/test_layernorm.py b/tests/kernels/ir/test_layernorm.py index e41b7c09d3..c324b189b9 100644 --- a/tests/kernels/ir/test_layernorm.py +++ b/tests/kernels/ir/test_layernorm.py @@ -368,8 +368,7 @@ class TestFusedAddRMSNorm: @pytest.mark.parametrize("provider", ["vllm_c"]) def test_inplace_semantics(self, dtype, n_tokens, hidden_size, epsilon, provider): """Test that inplace implementations reuse inputs, - for maybe_inplace overload but not for default overload. - """ + for maybe_inplace overload but not for default overload.""" impl = ir.ops.fused_add_rms_norm.impls[provider] if not impl.supported: pytest.skip(f"{provider} impl not supported on this platform") diff --git a/tests/kernels/mamba/cpu/test_cpu_gdn_ops.py b/tests/kernels/mamba/cpu/test_cpu_gdn_ops.py index 9495465b9e..c239f831c6 100644 --- a/tests/kernels/mamba/cpu/test_cpu_gdn_ops.py +++ b/tests/kernels/mamba/cpu/test_cpu_gdn_ops.py @@ -1055,8 +1055,7 @@ CONV_EQUIV_SEQ_LENS = [[1], [7], [64], [65], [1, 2, 3], [63, 64, 65], [128, 129] def _conv_fp32_oracle(x, weight, bias, seq_lens, activation="silu"): """High-precision conv reference: everything in float32, no bf16 rounding. - x: [total_tokens, dim] (no initial state). Returns [total_tokens, dim]. - """ + x: [total_tokens, dim] (no initial state). Returns [total_tokens, dim].""" xf = x.float() wf = weight.float().unsqueeze(1) bf = bias.float() @@ -1165,8 +1164,7 @@ def test_conv_cpp_no_worse_than_torch_vs_fp32(seq_lens): def test_conv_cpp_vnni_packed_matches_torch(seq_lens): """The exact runtime prefill sequence (VNNI-packed weight + SD-layout conv_state view + is_vnni=True) must match the torch fallback. Validates - the packing + layout handoff on any AVX-512BF16 CPU. - """ + the packing + layout handoff on any AVX-512BF16 CPU.""" x, weight, bias = _conv_inputs(sum(seq_lens)) out_torch, _ = _run_prefill_torch(x, weight, bias, seq_lens) out_vnni, _ = _run_prefill_cpp(x, weight, bias, seq_lens, is_vnni=True) @@ -1180,8 +1178,7 @@ def test_conv_cpp_vnni_packed_matches_torch(seq_lens): @torch.inference_mode() def test_conv_update_cpp_matches_torch(batch): """Decode conv: causal_conv1d_update_cpu matches causal_conv1d_update_torch, - including the in-place conv_state update (the next-step handoff). - """ + including the in-place conv_state update (the next-step handoff).""" from vllm.model_executor.layers.mamba.ops.cpu.causal_conv1d import ( causal_conv1d_update_torch, ) diff --git a/tests/kernels/mamba/test_mamba_ssm_configs.py b/tests/kernels/mamba/test_mamba_ssm_configs.py index 4330caa611..7ea1529f2e 100644 --- a/tests/kernels/mamba/test_mamba_ssm_configs.py +++ b/tests/kernels/mamba/test_mamba_ssm_configs.py @@ -122,8 +122,7 @@ def test_fallback_when_no_config(monkeypatch, tmp_path): def test_nearest_effective_batch_interpolation(monkeypatch, tmp_path): """When effective_batch = batch*nheads is not an exact key, the closest - key should be selected. - """ + key should be selected.""" _write_config( tmp_path, dstate=32, @@ -168,8 +167,7 @@ def test_nearest_effective_batch_interpolation(monkeypatch, tmp_path): def test_non_dict_json_returns_none(monkeypatch, tmp_path): """A valid JSON file that is not a dict (e.g. a list) must be ignored - and return None rather than raising AttributeError. - """ + and return None rather than raising AttributeError.""" device_name = get_ssm_device_name() config_path = tmp_path / get_ssm_config_file_name( _HEADDIM, 16, _CACHE_DTYPE, device_name @@ -191,8 +189,7 @@ def test_non_dict_json_returns_none(monkeypatch, tmp_path): def test_empty_config_falls_back_to_heuristic(monkeypatch, tmp_path): """An empty JSON object {} must not crash min() — should fall back - to the hard-coded heuristic. - """ + to the hard-coded heuristic.""" _write_config(tmp_path, dstate=64, payload={}) monkeypatch.setenv("VLLM_TUNED_CONFIG_FOLDER", str(tmp_path)) diff --git a/tests/kernels/mamba/test_replayssm_prefill_decode_equivalence_mamba2.py b/tests/kernels/mamba/test_replayssm_prefill_decode_equivalence_mamba2.py index fbc7b69187..063ff17dd3 100644 --- a/tests/kernels/mamba/test_replayssm_prefill_decode_equivalence_mamba2.py +++ b/tests/kernels/mamba/test_replayssm_prefill_decode_equivalence_mamba2.py @@ -68,8 +68,7 @@ def _run_prefill_decode_equivalence( the exact fp32 recurrence (and each other). All paths use the production dt flow (raw dt + softplus + a per-head dt_bias), so this also checks prefill and decode apply the softplus/bias preprocessing consistently. ``state_dtype`` - is the recurrent-state precision; ``act_dtype`` the activation/buffer one. - """ + is the recurrent-state precision; ``act_dtype`` the activation/buffer one.""" device = current_platform.device_type rtol, atol = _prefill_tolerances(act_dtype) set_random_seed(seed) diff --git a/tests/kernels/mamba/test_replayssm_standard_decode_mamba2.py b/tests/kernels/mamba/test_replayssm_standard_decode_mamba2.py index 6e5ada19bc..588ce52dbe 100644 --- a/tests/kernels/mamba/test_replayssm_standard_decode_mamba2.py +++ b/tests/kernels/mamba/test_replayssm_standard_decode_mamba2.py @@ -95,8 +95,7 @@ def _run_standard_decode( ) -> None: """Drive ``num_steps`` decode steps and check every path against the trusted recurrence. ``state_dtype`` is the recurrent-state precision; - ``act_dtype`` is the activation/buffer precision. - """ + ``act_dtype`` is the activation/buffer precision.""" device = "cuda" both_fp32 = state_dtype == torch.float32 and act_dtype == torch.float32 rtol, atol = _tolerances(torch.float32 if both_fp32 else torch.bfloat16) @@ -540,8 +539,7 @@ def test_replayssm_standard_decode_tp_head_shard_equivalence( separable: one run over all heads must equal concatenating ``tp`` independent per-rank runs on ``nheads // tp`` heads and ``ngroups // tp`` groups. This guards the per-rank divisors and group->head mapping the state-shape wiring - relies on. The real TP1==TP2 engine check lives in the v1/e2e suite. - """ + relies on. The real TP1==TP2 engine check lives in the v1/e2e suite.""" state_dtype, act_dtype = precision nheads, headdim, dstate, ngroups = geometry assert nheads % tp == 0 and ngroups % tp == 0 diff --git a/tests/kernels/moe/modular_kernel_tools/common.py b/tests/kernels/moe/modular_kernel_tools/common.py index dd17298cb3..8adfa6588c 100644 --- a/tests/kernels/moe/modular_kernel_tools/common.py +++ b/tests/kernels/moe/modular_kernel_tools/common.py @@ -167,8 +167,7 @@ class Config: def fe_supports_quant_scheme(self) -> bool: """Check if the fused experts class supports this quant config. - See https://github.com/ROCm/aiter/issues/2419 for AITER gaps. - """ + See https://github.com/ROCm/aiter/issues/2419 for AITER gaps.""" if self.quant_config is None or self.quant_dtype is None: return True if self.quant_dtype != torch.float8_e4m3fn: diff --git a/tests/kernels/moe/test_b12x.py b/tests/kernels/moe/test_b12x.py index de8f75d0e9..d0b1ce7cae 100644 --- a/tests/kernels/moe/test_b12x.py +++ b/tests/kernels/moe/test_b12x.py @@ -468,8 +468,7 @@ def test_deepseek_v4_flashinfer_cutlass_falls_through_to_w4a8( monkeypatch: pytest.MonkeyPatch, ) -> None: """Explicit flashinfer_cutlass must try the W4A8 variant when the BF16 - variant is unsupported (the BF16 variant is gated to SM90). - """ + variant is unsupported (the BF16 variant is gated to SM90).""" from vllm.model_executor.layers.fused_moe.experts.flashinfer_cutlass_moe import ( FlashInferExperts, ) diff --git a/tests/kernels/moe/test_batched_moe.py b/tests/kernels/moe/test_batched_moe.py index c4ebc5ff40..9be58e6337 100644 --- a/tests/kernels/moe/test_batched_moe.py +++ b/tests/kernels/moe/test_batched_moe.py @@ -129,8 +129,7 @@ def test_batched_mm( per_act_token_quant: bool, ): """Note: float8_e4m3fn is not supported on CUDA architecture < 89, - and those tests will be skipped on unsupported hardware. - """ + and those tests will be skipped on unsupported hardware.""" set_random_seed(7) use_fp8_w8a8 = dtype == torch.float8_e4m3fn @@ -269,8 +268,7 @@ def test_fused_moe_batched_experts( workspace_init, ): """Note: float8_e4m3fn is not supported on CUDA architecture < 89, - and those tests will be skipped on unsupported hardware. - """ + and those tests will be skipped on unsupported hardware.""" set_random_seed(7) use_fp8_w8a8 = dtype == torch.float8_e4m3fn @@ -651,8 +649,7 @@ def test_batched_experts_masked_activation_end_to_end( def test_batched_experts_end_to_end(m, n, k, e, topk): """End-to-end BatchedTritonExperts via the reference (no-comms) BatchedPrepareAndFinalize, validated against a torch reference. Exercises - the device-enablement path. - """ + the device-enablement path.""" from vllm.v1.worker.workspace import init_workspace_manager set_random_seed(7) diff --git a/tests/kernels/moe/test_block_int8.py b/tests/kernels/moe/test_block_int8.py index 84a4a0d2d1..415faafb3a 100644 --- a/tests/kernels/moe/test_block_int8.py +++ b/tests/kernels/moe/test_block_int8.py @@ -54,8 +54,7 @@ SEEDS = [0] # For test def torch_w8a8_block_int8_moe(a, w1, w2, w1_s, w2_s, score, topk, block_shape): """This function performs fused moe with block-wise quantization using - native torch. - """ + native torch.""" B, D = a.shape a = a.view(B, -1, D).repeat(1, topk, 1).reshape(-1, D) out = torch.zeros(B * topk, w2.shape[1], dtype=a.dtype, device=a.device) @@ -98,8 +97,7 @@ def setup_cuda(): @torch.inference_mode() def test_w8a8_block_int8_fused_moe(M, N, K, E, topk, block_size, dtype, seed): """Tests the fused_moe kernel with W8A8 INT8 block quantization against a - native torch reference. - """ + native torch reference.""" torch.manual_seed(seed) a = torch.randn((M, K), dtype=dtype) / 10 diff --git a/tests/kernels/moe/test_cpu_fused_moe.py b/tests/kernels/moe/test_cpu_fused_moe.py index e7af163b04..cf83ef6fc0 100644 --- a/tests/kernels/moe/test_cpu_fused_moe.py +++ b/tests/kernels/moe/test_cpu_fused_moe.py @@ -397,8 +397,7 @@ UNALIGNED_INTERMEDIATE_DIM = 176 class _StubMoELayer(torch.nn.Module): """Minimal stand-in for the real MoE layer module, exposing just what the unquantized CPU experts read/replace (w13_weight, w2_weight, the - router configuration, and optionally w13_bias/w2_bias). - """ + router configuration, and optionally w13_bias/w2_bias).""" def __init__( self, @@ -501,8 +500,7 @@ def test_cpu_fused_moe_unaligned_intermediate_size( act: MoEActivation, ): """CPU kernels handle unaligned intermediate sizes by zero-padding the - weights before prepacking. - """ + weights before prepacking.""" set_random_seed(0) batch_size = 64 intermediate_size = UNALIGNED_INTERMEDIATE_DIM diff --git a/tests/kernels/moe/test_flashinfer.py b/tests/kernels/moe/test_flashinfer.py index 9627e2c67d..2e022ede36 100644 --- a/tests/kernels/moe/test_flashinfer.py +++ b/tests/kernels/moe/test_flashinfer.py @@ -464,8 +464,7 @@ def test_trtllm_fp8_swiglu_clamp_support( ): """FlashInfer >= 0.6.18 applies the SwiGLU clamp for both block-scaled kernels with a SwiGLU activation (DeepSeek-V4 sets swiglu_limit); the - per-tensor kernel has no clamp, and Relu2 rejects the parameters. - """ + per-tensor kernel has no clamp, and Relu2 rejects the parameters.""" class _Experts(TrtLlmFp8ExpertsModular): @staticmethod diff --git a/tests/kernels/moe/test_gpt_oss_triton_kernels.py b/tests/kernels/moe/test_gpt_oss_triton_kernels.py index 0a16a31797..4afcba706c 100644 --- a/tests/kernels/moe/test_gpt_oss_triton_kernels.py +++ b/tests/kernels/moe/test_gpt_oss_triton_kernels.py @@ -377,8 +377,7 @@ def test_unit_shuffle(): @pytest.mark.parametrize("n_experts,topk", [(32, 4), (128, 4)]) def test_routing_data_from_sparse_topk_parity(n_tokens, n_experts, topk): """routing_data_from_sparse_topk must produce routing structures - identical to make_routing_data for the same topk result. - """ + identical to make_routing_data for the same topk result.""" from vllm.model_executor.layers.fused_moe.experts import ( gpt_oss_triton_kernels_moe as gptoss_moe, ) diff --git a/tests/kernels/moe/test_marlin_vs_trtllm_mxint4.py b/tests/kernels/moe/test_marlin_vs_trtllm_mxint4.py index b647439c49..97041e24b9 100644 --- a/tests/kernels/moe/test_marlin_vs_trtllm_mxint4.py +++ b/tests/kernels/moe/test_marlin_vs_trtllm_mxint4.py @@ -289,8 +289,7 @@ def test_marlin_vs_trtllm_mxint4_moe_kimik2(monkeypatch, m, n, k, e, topk, group @torch.inference_mode() def test_flashinfer_trtllm_mxint4_moe_wrapper(m, n, k, e, topk): """Test that the flashinfer_trtllm_mxint4_moe wrapper matches the raw - trtllm_mxint4_block_scale_moe kernel call. - """ + trtllm_mxint4_block_scale_moe kernel call.""" pytest.importorskip("flashinfer") from flashinfer import RoutingMethodType from flashinfer.fused_moe import trtllm_mxint4_block_scale_moe diff --git a/tests/kernels/moe/test_modular_kernel_combinations.py b/tests/kernels/moe/test_modular_kernel_combinations.py index 6c21eb0d9a..0c0e1d61f9 100644 --- a/tests/kernels/moe/test_modular_kernel_combinations.py +++ b/tests/kernels/moe/test_modular_kernel_combinations.py @@ -352,8 +352,7 @@ def test_modular_kernel_combinations_singlegpu( workspace_init, ): """Note: float8_e4m3fn is not supported on CUDA architecture < 89, - and those tests will be skipped on unsupported hardware. - """ + and those tests will be skipped on unsupported hardware.""" config = Config( Ms=Ms, K=k, diff --git a/tests/kernels/moe/test_moe_kernel_oracle.py b/tests/kernels/moe/test_moe_kernel_oracle.py index 6ba5753f8d..fbdf804a3b 100644 --- a/tests/kernels/moe/test_moe_kernel_oracle.py +++ b/tests/kernels/moe/test_moe_kernel_oracle.py @@ -21,8 +21,7 @@ from vllm.model_executor.layers.fused_moe.oracle.unquantized import ( class TestUnquantizedDelegation: """UnquantizedMoEKernelOracle methods must delegate to the existing - module-level functions; behaviour is bit-identical. - """ + module-level functions; behaviour is bit-identical.""" def test_make_kernel_delegates(self) -> None: quant_config = object() diff --git a/tests/kernels/moe/test_moe_layer.py b/tests/kernels/moe/test_moe_layer.py index 38b9dd0252..5b1af59731 100644 --- a/tests/kernels/moe/test_moe_layer.py +++ b/tests/kernels/moe/test_moe_layer.py @@ -315,8 +315,7 @@ def tp_chunk_gate_up( device: torch.device | int | None = None, ) -> torch.Tensor: """TP-chunk a combined [gate; up] weight, splitting each half separately - so every rank gets a portion of both gate and up. - """ + so every rank gets a portion of both gate and up.""" half = w.shape[dim] // 2 gate = chunk_by_rank( w.narrow(dim, 0, half), tp_rank, tp_size, dim=dim, device=device diff --git a/tests/kernels/moe/test_mxfp8_aiter_backend_selection.py b/tests/kernels/moe/test_mxfp8_aiter_backend_selection.py index e94882a310..51aff4ea3b 100644 --- a/tests/kernels/moe/test_mxfp8_aiter_backend_selection.py +++ b/tests/kernels/moe/test_mxfp8_aiter_backend_selection.py @@ -130,8 +130,7 @@ def test_is_supported_config(present, ep_size, supported, reason_substr): def test_explicit_moe_backend_aiter(): """--moe-backend aiter: returns FlyDSL when usable (TP or EP), else a clear - ValueError when the flydsl package is missing. - """ + ValueError when the flydsl package is missing.""" with _gfx950(), _flydsl_installed(True): assert ( _select_kernel_cls(Fp8MoeBackend.AITER_MXFP8, _config(1)) @@ -163,8 +162,7 @@ def test_gfx950_picks_aiter(): def test_gfx942_picks_emulation(): """Flydsl unusable (e.g. gfx942, no FlyDSL support) -> native Triton - dot_scaled backend wins instead. - """ + dot_scaled backend wins instead.""" with patch(f"{_AITER_MOD}.current_platform.supports_mx", return_value=False): backend, experts_cls = select_mxfp8_moe_backend(_config()) assert backend is Fp8MoeBackend.EMULATION diff --git a/tests/kernels/moe/test_rocm_aiter_moe.py b/tests/kernels/moe/test_rocm_aiter_moe.py index de4ae5ae31..0967f9499e 100644 --- a/tests/kernels/moe/test_rocm_aiter_moe.py +++ b/tests/kernels/moe/test_rocm_aiter_moe.py @@ -249,8 +249,7 @@ def _make_topk_ids( device: str = "cuda", ) -> torch.Tensor: """Generate distinct expert IDs per token with the same top-k shape as - production routing. - """ + production routing.""" router_logits = torch.randn(num_tokens, num_experts, device=device) _, topk_ids = torch.topk(torch.softmax(router_logits, dim=-1), k=topk, dim=-1) return topk_ids.to(torch.int32) @@ -444,8 +443,7 @@ def test_aiter_fused_moe_custom_op_registered(): def test_aiter_asm_moe_tkw1_custom_op_registered(): """The tkw1 custom op should stay registered for FP8 apply-router-weight - paths. - """ + paths.""" _assert_aiter_supported() import vllm._aiter_ops as aiter_ops # noqa: F401 @@ -455,8 +453,7 @@ def test_aiter_asm_moe_tkw1_custom_op_registered(): def test_aiter_fused_moe_fake_tensor_support(): """The fused-MoE op should preserve fake-tensor compatibility for - torch.compile-style tracing. - """ + torch.compile-style tracing.""" _assert_aiter_supported() import vllm._aiter_ops # noqa: F401 @@ -519,8 +516,7 @@ def test_aiter_moe_enablement_follows_env( monkeypatch: pytest.MonkeyPatch, ): """The fused-MoE gate should depend only on the main AITER toggle and the - MoE-specific toggle. - """ + MoE-specific toggle.""" from vllm._aiter_ops import rocm_aiter_ops _assert_aiter_supported() @@ -551,8 +547,7 @@ def test_aiter_moe_shared_experts_enablement_follows_env( monkeypatch: pytest.MonkeyPatch, ): """Shared-expert fusion should only be enabled when the fused-MoE path is - enabled too. - """ + enabled too.""" from vllm._aiter_ops import rocm_aiter_ops _assert_aiter_supported() @@ -693,8 +688,7 @@ def test_aiter_mxfp4_quant_scheme_support_matches_gfx950(): @pytest.mark.skipif(not on_gfx950(), reason="gfx950 ROCm only") def test_aiter_fused_moe_mi350_mxfp4_w4a16_accuracy(): """The gfx950 AITER MXFP4 W4A16 MoE path should match the dequantized - MXFP4 reference. - """ + MXFP4 reference.""" from vllm.model_executor.layers.fused_moe.activation import MoEActivation from vllm.model_executor.layers.fused_moe.experts.rocm_aiter_moe import ( rocm_aiter_fused_experts, @@ -743,8 +737,7 @@ def test_aiter_fused_moe_mi350_mxfp4_w4a16_accuracy(): @pytest.mark.skipif(not on_gfx950(), reason="gfx950 ROCm only") def test_aiter_fused_moe_mi350_mxfp4_w4a16_determinism(): """The gfx950 AITER MXFP4 W4A16 MoE path should stay bitwise - deterministic. - """ + deterministic.""" from vllm.model_executor.layers.fused_moe.activation import MoEActivation from vllm.model_executor.layers.fused_moe.experts.rocm_aiter_moe import ( rocm_aiter_fused_experts, @@ -837,8 +830,7 @@ def test_aiter_fused_moe_bf16_accuracy( intermediate_dim: int, ): """The ROCm AITER fused-MoE BF16 path should match the float32 reference - on representative shapes. - """ + on representative shapes.""" from vllm.model_executor.layers.fused_moe.experts.rocm_aiter_moe import ( ActivationMethod, QuantMethod, @@ -883,8 +875,7 @@ def test_aiter_fused_moe_bf16_accuracy( def test_aiter_fused_moe_gelu_accuracy(): """The GELU activation variant should stay aligned with the float32 - reference. - """ + reference.""" from vllm.model_executor.layers.fused_moe.experts.rocm_aiter_moe import ( ActivationMethod, QuantMethod, @@ -929,8 +920,7 @@ def test_aiter_fused_moe_gelu_accuracy(): def test_aiter_fused_moe_determinism(): """The BF16 fused-MoE kernel should stay bitwise deterministic for the - same inputs. - """ + same inputs.""" from vllm.model_executor.layers.fused_moe.experts.rocm_aiter_moe import ( ActivationMethod, QuantMethod, @@ -1085,8 +1075,7 @@ def test_aiter_fused_moe_mi3xx_bf16_accuracy(): ) def test_aiter_fused_moe_mi3xx_fp8_accuracy(): """The MI3xx FP8 per-tensor MoE path should stay within the measured FP8 - error budget. - """ + error budget.""" from tests.kernels.moe.utils import make_test_weights from vllm._aiter_ops import rocm_aiter_ops from vllm.model_executor.layers.fused_moe.experts.rocm_aiter_moe import ( diff --git a/tests/kernels/moe/test_routed_experts_capture_monolithic.py b/tests/kernels/moe/test_routed_experts_capture_monolithic.py index ba5eef6624..eec6180550 100644 --- a/tests/kernels/moe/test_routed_experts_capture_monolithic.py +++ b/tests/kernels/moe/test_routed_experts_capture_monolithic.py @@ -185,8 +185,7 @@ def test_trtllm_bf16_monolithic_routing_replay_records_valid_experts( ) -> None: """The capture callback should receive the int16 routed-expert IDs the kernel actually used, the values should be valid expert indices, and - each token should pick ``top_k`` distinct experts. - """ + each token should pick ``top_k`` distinct experts.""" if top_k > _DSV3_N_GROUP * _DSV3_TOPK_GROUP: pytest.skip( f"DSV3 requires top_k <= n_group * topk_group " @@ -265,8 +264,7 @@ def test_trtllm_bf16_monolithic_routing_replay_non_dsv3( routing_method: RoutingMethodType, ) -> None: """Routing replay works for non-DeepSeekV3 routing methods too. - FlashInfer's ``routing_replay_out`` is routing-method-agnostic. - """ + FlashInfer's ``routing_replay_out`` is routing-method-agnostic.""" torch.manual_seed(0) device = torch.device("cuda:0") @@ -319,8 +317,7 @@ def test_trtllm_bf16_monolithic_routing_replay_non_dsv3( def test_trtllm_bf16_monolithic_capture_disabled_skips_buffer_alloc() -> None: """With no callback installed the kernel should not see a - ``routing_replay_out`` tensor — verify the helper short-circuits. - """ + ``routing_replay_out`` tensor — verify the helper short-circuits.""" torch.manual_seed(0) device = torch.device("cuda:0") experts, _, _ = _make_bf16_monolithic_experts( @@ -342,8 +339,7 @@ def test_trtllm_bf16_monolithic_capture_disabled_skips_buffer_alloc() -> None: def test_trtllm_bf16_monolithic_supports_capture_for_all_routing() -> None: """FlashInfer's ``routing_replay_out`` is supported by all routing methods, so ``supports_routing_replay_capture`` should be True - regardless of routing method. - """ + regardless of routing method.""" device = torch.device("cuda:0") for routing_method in ( RoutingMethodType.DeepSeekV3, @@ -365,8 +361,7 @@ def test_trtllm_bf16_monolithic_supports_capture_for_all_routing() -> None: def test_trtllm_bf16_monolithic_capture_buffer_shape_and_dtype() -> None: """When capture is installed, the allocated buffer is int16 and shaped - ``(num_tokens, experts_per_token)``. - """ + ``(num_tokens, experts_per_token)``.""" device = torch.device("cuda:0") experts, _, _ = _make_bf16_monolithic_experts( num_experts=_DSV3_NUM_EXPERTS, @@ -597,8 +592,7 @@ def test_trtllm_fp8_block_scale_monolithic_routing_replay_records_valid_experts( top_k: int, ) -> None: """End-to-end: ``TrtLlmFp8ExpertsMonolithic`` (DeepSeekFp8 block-scale - path, DSV3 routing) captures valid expert IDs. - """ + path, DSV3 routing) captures valid expert IDs.""" if top_k > _DSV3_N_GROUP * _DSV3_TOPK_GROUP: pytest.skip( f"DSV3 requires top_k <= n_group * topk_group " @@ -784,8 +778,7 @@ def _run_nvfp4_monolithic( routing_bias: torch.Tensor, ) -> torch.Tensor: """The monolithic NVFP4 apply expects packed fp4 hidden states + the - matching fp8 per-block scale stored in the ``a1q_scale`` slot. - """ + matching fp8 per-block scale stored in the ``a1q_scale`` slot.""" # Stash the weight tensors on the experts in the locations the apply() # implementation reads from (it pulls them from quant_config / scales # already; w1/w2 come in as args). @@ -813,8 +806,7 @@ def test_trtllm_nvfp4_monolithic_routing_replay_records_valid_experts( top_k: int, ) -> None: """End-to-end: ``TrtLlmNvFp4ExpertsMonolithic`` captures valid expert IDs - on the DSV3 routing path. - """ + on the DSV3 routing path.""" if top_k > _DSV3_N_GROUP * _DSV3_TOPK_GROUP: pytest.skip( f"DSV3 requires top_k <= n_group * topk_group " diff --git a/tests/kernels/moe/test_routing.py b/tests/kernels/moe/test_routing.py index f922a3ebd3..174950e06c 100644 --- a/tests/kernels/moe/test_routing.py +++ b/tests/kernels/moe/test_routing.py @@ -250,8 +250,7 @@ def assert_aiter_routing_valid( the Python baseline (different group selection, scoring internals), so numerical comparison is not meaningful. Instead we verify the outputs satisfy the routing contract: correct shapes, valid expert - IDs, non-negative weights, and proper normalization. - """ + IDs, non-negative weights, and proper normalization.""" n_tokens = topk_weights.shape[0] # Shape diff --git a/tests/kernels/moe/test_routing_simulator.py b/tests/kernels/moe/test_routing_simulator.py index b1adcd53d9..2cb122122f 100644 --- a/tests/kernels/moe/test_routing_simulator.py +++ b/tests/kernels/moe/test_routing_simulator.py @@ -76,8 +76,7 @@ def test_basic_functionality( def test_routing_strategy_integration(monkeypatch, device): """Test that the routing strategy environment variable works with - FusedMoEFactory. - """ + FusedMoEFactory.""" pytest.importorskip("vllm.model_executor.layers.fused_moe.layer") import vllm.envs as envs @@ -158,8 +157,7 @@ def test_routing_strategy_integration(monkeypatch, device): def test_distribution_based_routing_with_custom_strategy(): """Test registering and using DistributionBasedRouting with custom - parameters. - """ + parameters.""" device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Register custom distribution-based strategy diff --git a/tests/kernels/moe/test_silu_mul_per_token_group_quant_fp8_colmajor.py b/tests/kernels/moe/test_silu_mul_per_token_group_quant_fp8_colmajor.py index 76744da8f4..204954d1fe 100644 --- a/tests/kernels/moe/test_silu_mul_per_token_group_quant_fp8_colmajor.py +++ b/tests/kernels/moe/test_silu_mul_per_token_group_quant_fp8_colmajor.py @@ -70,8 +70,7 @@ def reference_with_clamp( ) -> tuple[torch.Tensor, torch.Tensor]: """Pre-clamp inputs (gate from above, up symmetric) at the input dtype to match the C++ compute() template, then run the standard silu_and_mul + - quant reference. - """ + quant reference.""" N_2 = x.size(1) // 2 dtype = x.dtype gate = x[..., :N_2].to(torch.float32).clamp(max=clamp_limit).to(dtype) diff --git a/tests/kernels/moe/test_triton_moe_ptpc_fp8.py b/tests/kernels/moe/test_triton_moe_ptpc_fp8.py index 15cef0df38..8b10ff75e6 100644 --- a/tests/kernels/moe/test_triton_moe_ptpc_fp8.py +++ b/tests/kernels/moe/test_triton_moe_ptpc_fp8.py @@ -28,8 +28,7 @@ if current_platform.is_fp8_fnuz(): def native_w8a8_per_token_matmul(A, B, As, Bs, output_dtype=torch.float16): """Matrix multiplication function that supports per-token input - quantization and per-column weight quantization - """ + quantization and per-column weight quantization""" A = A.to(torch.float32) B = B.to(torch.float32) @@ -57,8 +56,7 @@ def fp8_mask(a, mask): def torch_w8a8_per_column_moe(a, w1, w2, w1_s, w2_s, score, topk): """This function performs fused moe with per-column int8 - quantization using native torch. - """ + quantization using native torch.""" B, D = a.shape # Perform per-token quantization a_q, a_s = ops.scaled_fp8_quant(a, use_per_token_if_dynamic=True) diff --git a/tests/kernels/moe/test_unquantized_backend_selection.py b/tests/kernels/moe/test_unquantized_backend_selection.py index 48e98f9c14..d4c037d978 100644 --- a/tests/kernels/moe/test_unquantized_backend_selection.py +++ b/tests/kernels/moe/test_unquantized_backend_selection.py @@ -150,8 +150,7 @@ def test_select_default_backend_by_platform( expected_backend, ): """Test default backend selection per platform with all optional - accelerators (FlashInfer, AITER) disabled. - """ + accelerators (FlashInfer, AITER) disabled.""" with patch( "vllm.model_executor.layers.fused_moe.oracle.unquantized.current_platform" ) as mock_platform: @@ -445,8 +444,7 @@ def test_select_cuda_flashinfer_cutlass_backend( mock_has_flashinfer, ): """Test CUDA backend selection when FlashInfer TRTLLM is not available - and FlashInfer CUTLASS is available. - """ + and FlashInfer CUTLASS is available.""" with ( patch.object(current_platform, "is_cuda", return_value=True), patch.object(current_platform, "is_rocm", return_value=False), diff --git a/tests/kernels/quant_utils.py b/tests/kernels/quant_utils.py index 93a21596ca..7e14ec95d3 100644 --- a/tests/kernels/quant_utils.py +++ b/tests/kernels/quant_utils.py @@ -159,8 +159,7 @@ def native_per_token_group_quant_fp8( x, group_size, eps=1e-10, dtype=torch.float8_e4m3fn ): """Function to perform per-token-group quantization on an input tensor - `x` using native torch. - """ + `x` using native torch.""" assert x.shape[-1] % group_size == 0, ( "the last dimension of `x` must be divisible by `group_size`" ) diff --git a/tests/kernels/quantization/test_aiter_hipb_mm_linear_kernel.py b/tests/kernels/quantization/test_aiter_hipb_mm_linear_kernel.py index 70abcbfc8e..c855d0e819 100644 --- a/tests/kernels/quantization/test_aiter_hipb_mm_linear_kernel.py +++ b/tests/kernels/quantization/test_aiter_hipb_mm_linear_kernel.py @@ -304,8 +304,7 @@ def test_hipb_mm_kernel_forward_matches_raw_aiter_hipb_mm(enable_hipb_mm_kernel) def test_hipb_mm_kernel_forward_accuracy(enable_hipb_mm_kernel): """Kernel output should match a dequantized fp32 reference within - fp8 per-token / per-channel quantization noise. - """ + fp8 per-token / per-channel quantization noise.""" weight_shape = (512, 4096) # (N, K) num_tokens = 32 _check_bpreshuffle_runtime_support(weight_shape, num_tokens=num_tokens) diff --git a/tests/kernels/quantization/test_int8_kernel.py b/tests/kernels/quantization/test_int8_kernel.py index c01929c5d1..4858ea47ad 100644 --- a/tests/kernels/quantization/test_int8_kernel.py +++ b/tests/kernels/quantization/test_int8_kernel.py @@ -30,8 +30,7 @@ if current_platform.is_cuda_alike() and not current_platform.has_device_capabili def native_w8a8_per_token_matmul(A, B, As, Bs, output_dtype=torch.float16): """Matrix multiplication function that supports per-token input - quantization and per-column weight quantization - """ + quantization and per-column weight quantization""" A = A.to(torch.float32) B = B.to(torch.float32) @@ -54,8 +53,7 @@ def native_w8a8_per_token_matmul(A, B, As, Bs, output_dtype=torch.float16): def torch_w8a8_per_column_moe(a, w1, w2, w1_s, w2_s, topk, topk_weight, topk_ids): """This function performs fused moe with per-column int8 quantization - using native torch. - """ + using native torch.""" B, D = a.shape # Perform per-token quantization a_q, a_s = per_token_quant_int8(a) diff --git a/tests/kernels/quantization/test_marlin_tile_padding.py b/tests/kernels/quantization/test_marlin_tile_padding.py index f160125809..027ffbf10c 100644 --- a/tests/kernels/quantization/test_marlin_tile_padding.py +++ b/tests/kernels/quantization/test_marlin_tile_padding.py @@ -360,8 +360,7 @@ def test_gptq_marlin_padded_round_trip(shape, group_size): def test_fp8_block_marlin_padded_round_trip(shape): """Block-quantized FP8 (e.g. Nemotron NVFP4 checkpoints' FP8 layers): group_size=128 exercises the lcm K-alignment in marlin_padded_nk and the - weight_scale_inv group-wise scale padding. - """ + weight_scale_inv group-wise scale padding.""" size_n, size_k = shape block = 128 dtype = torch.float16 @@ -411,8 +410,7 @@ def test_fp8_block_marlin_padded_round_trip(shape): @pytest.mark.parametrize("shape", [(200, 288), (4640, 512)]) def test_mxfp8_marlin_padded_round_trip(shape): """MXFP8 exercises the e8m0 scale path, where padded 0.0 scales clamp to - 2^-127 instead of zero and must still contribute nothing. - """ + 2^-127 instead of zero and must still contribute nothing.""" size_n, size_k = shape group_size = 32 # The e8m0-scale Marlin kernels are only instantiated for bf16 activations. @@ -459,8 +457,7 @@ def test_mxfp8_marlin_padded_round_trip(shape): @pytest.mark.parametrize("shape", [(200, 512), (4640, 512)]) def test_awq_zp_marlin_padded_round_trip(shape): """AWQ-style uint4 with runtime zero-points, padded the way - MarlinLinearKernel does: padded columns rely on (q=0 - zp=0) * scale=0. - """ + MarlinLinearKernel does: padded columns rely on (q=0 - zp=0) * scale=0.""" size_n, size_k = shape group_size = 128 dtype = torch.float16 @@ -695,8 +692,7 @@ def test_check_moe_marlin_supports_layer_padding(): @pytest.mark.parametrize("shape", [(96, 256, 8), (160, 512, 4)]) def test_fp8_marlin_moe_padded_round_trip(shape, quant): """FP8 weight-only MoE: pad a tile-misaligned intermediate and check the - real prepare + fused_marlin_moe against the dequantized reference. - """ + real prepare + fused_marlin_moe against the dequantized reference.""" from tests.kernels.utils import torch_experts from vllm.config import VllmConfig, set_current_vllm_config from vllm.model_executor.layers.fused_moe import fused_topk @@ -781,8 +777,7 @@ def test_fp8_marlin_moe_padded_round_trip(shape, quant): @pytest.mark.parametrize("shape", [(96, 256, 8), (160, 512, 4)]) def test_mxfp8_marlin_moe_padded_round_trip(shape): """MXFP8 weight-only MoE round-trip at a tile-misaligned intermediate, with - unit e8m0 scales so the reference is the exact fp8 dequant. - """ + unit e8m0 scales so the reference is the exact fp8 dequant.""" from tests.kernels.utils import torch_experts from vllm.config import VllmConfig, set_current_vllm_config from vllm.model_executor.layers.fused_moe import fused_topk diff --git a/tests/kernels/quantization/test_mxfp4_kernel_selection.py b/tests/kernels/quantization/test_mxfp4_kernel_selection.py index de9feb7dfa..4adfffa7c8 100644 --- a/tests/kernels/quantization/test_mxfp4_kernel_selection.py +++ b/tests/kernels/quantization/test_mxfp4_kernel_selection.py @@ -72,8 +72,7 @@ def test_true_w4a4_kernels_reject_unset_activation(kernel_cls): @pytest.mark.parametrize("kernel_cls", _TRUE_W4A4_KERNELS) def test_true_w4a4_kernels_reject_explicit_non_mxfp4_activation(kernel_cls): """FlashInfer/XPU/Aiter quantize activations to MXFP4 internally, so an - explicit request for a different activation format must be rejected. - """ + explicit request for a different activation format must be rejected.""" config = MxFp4LinearLayerConfig(activation_quant_key=kMxfp6E3M2Dynamic) can_implement, reason = kernel_cls.can_implement(config) assert not can_implement @@ -88,8 +87,7 @@ def test_weight_only_kernels_accept_unquantized_or_mxfp4_activation( """Marlin/Humming never quantize activations, so an unset activation key, or one that already describes MXFP4-shaped data, is tolerated. When an activation key is explicitly set, a warning must be logged noting that it - is ignored, since these kernels are weight-only (A16). - """ + is ignored, since these kernels are weight-only (A16).""" config = MxFp4LinearLayerConfig(activation_quant_key=activation_quant_key) with patch(f"{kernel_cls.__module__}.logger.warning_once") as warning_once: can_implement, reason = kernel_cls.can_implement(config) @@ -118,8 +116,7 @@ def test_weight_only_kernels_reject_non_mxfp4_activation(kernel_cls): ) def test_emulation_kernel_accepts_any_config(activation_quant_key, monkeypatch): """EmulationMxfp4LinearKernel is the universal fallback: it must accept - every supported activation format. - """ + every supported activation format.""" # `EmulationMxfp4LinearKernel.can_implement` gates on `has_quark()`, # which we are not testing here. monkeypatch.setattr( @@ -137,8 +134,7 @@ def test_emulation_kernel_accepts_any_config(activation_quant_key, monkeypatch): def test_emulation_kernel_derives_quant_dequant_func_from_config(monkeypatch): """quant_dequant_func must be derived purely from the config's activation - QuantKey, not set externally. - """ + QuantKey, not set externally.""" # `EmulationMxfp4LinearKernel.can_implement` gates on `has_quark()`, # which we are not testing here. monkeypatch.setattr( @@ -162,8 +158,7 @@ def test_emulation_kernel_derives_quant_dequant_func_from_config(monkeypatch): def test_aiter_kernel_is_supported_requires_native_mx_support(): """AiterMxfp4LinearKernel must not be selected on platforms without - native MX compute, even if AITER itself is importable. - """ + native MX compute, even if AITER itself is importable.""" with patch( "vllm.model_executor.kernels.linear.mxfp4.aiter.current_platform.supports_mx", return_value=False, @@ -199,8 +194,7 @@ class OOTMxFp4LinearKernel(MxFp4LinearKernel): @patch("vllm.model_executor.kernels.linear.current_platform") def test_init_mxfp4_linear_kernel_dispatches_to_registered_kernel(platform_mock): """init_mxfp4_linear_kernel should select a registered kernel that - reports itself as supported, and construct it with a fresh config. - """ + reports itself as supported, and construct it with a fresh config.""" platform_mock._enum = PlatformEnum.OOT register_linear_kernel(OOTMxFp4LinearKernel, PlatformEnum.OOT, "mxfp4") diff --git a/tests/kernels/quantization/test_mxfp4_triton_ep.py b/tests/kernels/quantization/test_mxfp4_triton_ep.py index 74996d64e3..1edaa86cac 100644 --- a/tests/kernels/quantization/test_mxfp4_triton_ep.py +++ b/tests/kernels/quantization/test_mxfp4_triton_ep.py @@ -16,8 +16,7 @@ import torch class TestTritonMoeForwardExpertMap: """Test that triton_kernel_moe_forward applies expert_map remapping - when expert_map is provided (EP active). - """ + when expert_map is provided (EP active).""" def test_expert_map_remap(self): device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/kernels/quantization/test_mxfp6_kernel_selection.py b/tests/kernels/quantization/test_mxfp6_kernel_selection.py index 2c0e94c0f5..5c5b1b3b9e 100644 --- a/tests/kernels/quantization/test_mxfp6_kernel_selection.py +++ b/tests/kernels/quantization/test_mxfp6_kernel_selection.py @@ -41,8 +41,7 @@ def test_can_implement_is_abstract(): def test_emulation_kernel_rejects_non_mxfp6_weights(): """EmulationMxfp6LinearKernel must not implement a non-MXFP6 weight - format. - """ + format.""" config = MxFp6LinearLayerConfig(weight_quant_key=kMxfp4Static) can_implement, reason = EmulationMxfp6LinearKernel.can_implement(config) assert not can_implement @@ -58,8 +57,7 @@ def test_emulation_kernel_accepts_any_supported_config( weight_quant_key, activation_quant_key ): """EmulationMxfp6LinearKernel is the only backend today: it must accept - every supported weight/activation format combination. - """ + every supported weight/activation format combination.""" config = MxFp6LinearLayerConfig( weight_quant_key=weight_quant_key, activation_quant_key=activation_quant_key ) @@ -104,8 +102,7 @@ class OOTMxFp6LinearKernel(MxFp6LinearKernel): def test_init_mxfp6_linear_kernel_dispatches_to_registered_kernel(platform_mock): """init_mxfp6_linear_kernel should select a registered kernel that reports itself as supported/able to implement the given config, and - construct it with that exact config. - """ + construct it with that exact config.""" platform_mock._enum = PlatformEnum.OOT register_linear_kernel(OOTMxFp6LinearKernel, PlatformEnum.OOT, "mxfp6") diff --git a/tests/kernels/quantization/test_per_token_group_quant.py b/tests/kernels/quantization/test_per_token_group_quant.py index c1226efcc8..6d3c91022e 100644 --- a/tests/kernels/quantization/test_per_token_group_quant.py +++ b/tests/kernels/quantization/test_per_token_group_quant.py @@ -118,8 +118,7 @@ def test_per_token_group_quant_fp8_packed( num_tokens, hidden_dim, group_size, poisoned_scales ): """Test the packed DeepGEMM quantization kernel against the Triton - reference (row-major, UE8M0 scales). - """ + reference (row-major, UE8M0 scales).""" device = "cuda" torch.manual_seed(42) @@ -257,8 +256,7 @@ def test_per_token_group_quant_fp8_packed_all_zero(): def test_per_token_group_quant_fp8_packed_mantissa_rounds_up(): """Inputs whose absmax/max_8bit produces a non-power-of-2 force the mantissa-rounding-up branch (exp_byte += 1). Locks down this behavior - before optimization. - """ + before optimization.""" device = "cuda" num_tokens, hidden_dim, group_size = 4, 7168, 128 @@ -330,8 +328,7 @@ def test_per_token_group_quant_fp8_packed_zero_fills_padded_output_q( ): """When output_q is allocated with shape (tma_aligned_mn, k) instead of (mn, k), the kernel must overwrite the padded mn rows with zeros so - callers can use ``torch.empty`` instead of ``torch.zeros``. - """ + callers can use ``torch.empty`` instead of ``torch.zeros``.""" device = "cuda" group_size = 128 torch.manual_seed(42) diff --git a/tests/kernels/quantization/test_quantized_embedding.py b/tests/kernels/quantization/test_quantized_embedding.py index 35c0e74713..0e4af0a0c1 100644 --- a/tests/kernels/quantization/test_quantized_embedding.py +++ b/tests/kernels/quantization/test_quantized_embedding.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Tests for the Triton dequant-gather kernel used by -``CompressedTensorsEmbeddingWNA16Int`` (quantized embedding lookup). -""" +``CompressedTensorsEmbeddingWNA16Int`` (quantized embedding lookup).""" import pytest import torch diff --git a/tests/kernels/quantization/test_rocm_aiter_grouped_quant.py b/tests/kernels/quantization/test_rocm_aiter_grouped_quant.py index 2a5a8081a2..c7f0f1eda3 100644 --- a/tests/kernels/quantization/test_rocm_aiter_grouped_quant.py +++ b/tests/kernels/quantization/test_rocm_aiter_grouped_quant.py @@ -29,8 +29,7 @@ pytestmark = pytest.mark.skipif( def test_rocm_aiter_group_fp8_quant_fake_implementation(): """Test that the fake implementation is correctly - defined for torch.ops.vllm.rocm_aiter_group_fp8_quant. - """ + defined for torch.ops.vllm.rocm_aiter_group_fp8_quant.""" # Create test tensors M = 128 N = 4096 @@ -50,8 +49,7 @@ def test_rocm_aiter_group_fp8_quant_fake_implementation(): def test_rocm_aiter_group_fp8_quant_torch_compile_with_cudagraph(): """Test that rocm_aiter_ops.group_fp8_quant with group size 128 can be used with - torch.compile in cudagraph mode. - """ + torch.compile in cudagraph mode.""" # Create test tensors M = 128 N = 4096 diff --git a/tests/kernels/quantization/test_rocm_mxfp4.py b/tests/kernels/quantization/test_rocm_mxfp4.py index 7002165af0..0e14e2d258 100644 --- a/tests/kernels/quantization/test_rocm_mxfp4.py +++ b/tests/kernels/quantization/test_rocm_mxfp4.py @@ -209,8 +209,7 @@ def test_rocm_aiter_fp4_enablement_follows_env_and_arch( @pytest.mark.parametrize("shape", LLAMA_SHAPES) def test_vllm_quant_dequant_mxfp4_matches_reference_on_large_shapes(shape, dtype): """The public vLLM MXFP4 QDQ helper should stay exact against the torch - reference even on larger Llama-like shapes. - """ + reference even on larger Llama-like shapes.""" from vllm.model_executor.layers.quantization.utils.mxfp4_utils import ( quant_dequant_mxfp4, ) diff --git a/tests/kernels/test_compressor_kv_cache.py b/tests/kernels/test_compressor_kv_cache.py index 3dc658250f..95ff6b3c05 100644 --- a/tests/kernels/test_compressor_kv_cache.py +++ b/tests/kernels/test_compressor_kv_cache.py @@ -670,8 +670,7 @@ def test_v41_rope_insert_plain_row(compress_ratio: int, store_fp8: bool): def test_v41_compressor_metadata_maps_tokens_to_their_ring(): """The ring group's generic slot mapping is disabled (all PAD), so the builder must map every real token to ``ring_block * capacity + pos % - capacity`` and keep padding tokens at PAD. - """ + capacity`` and keep padding tokens at PAD.""" from unittest.mock import MagicMock from vllm.models.deepseek_v41.compressor import CompressorMetadataBuilder @@ -1096,8 +1095,7 @@ def test_get_c128_boundary(starts, query_start_loc, expected): @pytest.mark.parametrize("block_size", [16, 64]) def test_deepseek_v4_attention_quant_cache_roundtrip(num_tokens: int, block_size: int): """compressed_kv → quantize_and_insert_k_cache → dequantize_and_gather_k_cache - → compare against original. - """ + → compare against original.""" HEAD_DIM = 512 NOPE_DIM = 448 HEAD_BYTES = 584 # 448 fp8 + 128 bf16 + 8 uint8 scale @@ -1309,8 +1307,7 @@ def test_dequantize_and_gather_k_cache( @pytest.mark.parametrize("block_size", [16, 64]) def test_indexer_quant_cache_roundtrip(num_tokens: int, block_size: int): """K → indexer_k_quant_and_cache → cp_gather_indexer_k_quant_cache - → manual dequant → compare against original. - """ + → manual dequant → compare against original.""" HEAD_DIM = 128 QUANT_BLOCK_SIZE = 128 # cache_stride = head_dim + (head_dim * 4 / quant_block_size) = 128 + 4 = 132 diff --git a/tests/kernels/test_cp_gather_fp8.py b/tests/kernels/test_cp_gather_fp8.py index d9157c4110..40c5ef5fdb 100644 --- a/tests/kernels/test_cp_gather_fp8.py +++ b/tests/kernels/test_cp_gather_fp8.py @@ -432,8 +432,7 @@ def test_cp_gather_fp8_with_sequence_starts(gather_seq_lens, seq_starts): ) def test_cp_gather_fp8_large_seqlens(seq_lens, block_size): """Correctness test with large sequence lengths matching benchmark - scenarios (8K-128K prefill). - """ + scenarios (8K-128K prefill).""" ( cache, block_table, diff --git a/tests/kernels/test_deepseek_v4_cpu_kernels.py b/tests/kernels/test_deepseek_v4_cpu_kernels.py index 9c3fddb6c1..81c03a0bca 100644 --- a/tests/kernels/test_deepseek_v4_cpu_kernels.py +++ b/tests/kernels/test_deepseek_v4_cpu_kernels.py @@ -85,8 +85,7 @@ def _decode_token_regions( cache: torch.Tensor, slot_mapping: torch.Tensor, block_size: int ): """Slice out, per valid token, the raw NoPE-fp8 / RoPE-bf16 / scale byte - regions this layout defines. - """ + regions this layout defines.""" valid = slot_mapping >= 0 idx = valid.nonzero(as_tuple=True)[0] slots = slot_mapping[idx] @@ -111,8 +110,7 @@ def _assert_cache_parity(cache_fused, cache_ref, slot_mapping, block_size): """NoPE fp8 + the UE8M0 scale byte are a deterministic quant of an un-rotated bf16 value, so they match tightly; the RoPE region is rotated in fp32 before its bf16 store and eager/kernel can round a tie to - opposite sides, so allow <=1 ULP there. - """ + opposite sides, so allow <=1 ULP there.""" nope_ref, rope_ref, scale_ref = _decode_token_regions( cache_ref, slot_mapping, block_size ) @@ -192,8 +190,7 @@ def _dup_padded_block_cache( num_blocks: int, block_size: int, width: int, pad_elems: int ) -> tuple[torch.Tensor, torch.Tensor]: """Two independently-stored padded caches with identical values, for ops - that mutate the cache in place. - """ + that mutate the cache in place.""" page_stride = block_size * width + pad_elems template = torch.randn(num_blocks, page_stride, dtype=torch.float32) @@ -210,8 +207,7 @@ def _run_save_partial_states_eager( ): """Reference: state_cache[block_idx, pos_in_block, :W] = kv; state_cache[..., W:] = score + ape[position % compress_ratio]; skip - slot < 0. Mutates state_cache in place, matching the op's contract. - """ + slot < 0. Mutates state_cache in place, matching the op's contract.""" state_width = kv.shape[-1] block_size = state_cache.shape[1] valid = slot_mapping >= 0 @@ -271,8 +267,7 @@ def _run_compress_eager( ): """Reference for the per-channel-softmax-pooling + RMSNorm + NoPE-UE8M0 quant + GPT-J RoPE math writing the main (head_dim=512) fp8_ds_mla - layout. - """ + layout.""" num_tokens, window = gather_slots.shape state_width = state_cache.shape[-1] // 2 state_block_size = state_cache.shape[1] @@ -449,8 +444,7 @@ def test_compress_norm_rope_store_cpu_matches_eager( def test_compress_norm_rope_store_cpu_non_contiguous_kv_cache_row_stride(): """The main (output) kv_cache is a separate physical buffer from the - state cache and can independently be a strided view. - """ + state cache and can independently be a strided view.""" eps = 1e-6 compress_ratio, overlap = 128, False num_tokens = 5 @@ -526,8 +520,7 @@ def _run_compress_indexer_eager( """Same softmax-pool + RMSNorm + GPT-J RoPE prologue as the head=512 path, but the indexer's cache quantizes all 128 post-RoPE dims as one FP8 block with a single raw fp32 scale per token (matching - _indexer_k_quant_and_cache_cpu's layout), not 7 separate UE8M0 blocks. - """ + _indexer_k_quant_and_cache_cpu's layout), not 7 separate UE8M0 blocks.""" num_tokens, window = gather_slots.shape state_width = state_cache.shape[-1] // 2 state_block_size = state_cache.shape[1] @@ -655,8 +648,7 @@ def _pack_flash_mla_cache(kv_f32: torch.Tensor, block_size: int): """Quantize kv_f32 ([N, HEAD_DIM]) into the fp8_ds_mla byte layout and return (cache, dequant_ref) -- the exact post-quantization value the kernel's dequant should reproduce. Slot id == row index, packed - contiguously from block 0. - """ + contiguously from block 0.""" n = kv_f32.shape[0] num_blocks = max(1, -(-n // block_size)) cache = _make_cache(num_blocks, block_size) @@ -714,8 +706,7 @@ def _flash_mla_eager( """MQA attention: gather the (already-dequantized) window+compressed KV rows referenced by *_slots (-1 = invalid/masked), append a learned per-head sink logit with zero value contribution, softmax, weighted - sum. - """ + sum.""" num_tokens, num_heads, _ = q.shape q_f32 = q.float() @@ -814,8 +805,7 @@ def test_flash_mla_cpu_kernel_matches_eager( def test_flash_mla_cpu_kernel_all_invalid_falls_back_to_sink(): """When every KV slot is masked out, softmax degenerates to the sink - logit alone and the output must be all-zero (no valid value rows). - """ + logit alone and the output must be all-zero (no valid value rows).""" torch.manual_seed(2) dtype = torch.bfloat16 num_tokens, num_heads, num_window = 3, 4, 5 @@ -855,8 +845,7 @@ def _qnorm_kv_insert_eager( q, kv, positions, cache, slot_mapping, cos_sin_cache, q_head_padded, eps, bs ): """Reference: per-head weight-free RMSNorm + GPT-J RoPE on Q; GPT-J RoPE - + UE8M0 FP8 quant + paged insert on KV. - """ + + UE8M0 FP8 quant + paged insert on KV.""" num_quant_blocks = NOPE_DIM // QUANT_BLOCK num_tokens_full, num_heads_q, _ = q.shape @@ -982,8 +971,7 @@ def test_qnorm_rope_kv_insert_cpu_kernel_matches_eager( @pytest.mark.parametrize("pad", [1, 5]) def test_qnorm_rope_kv_insert_cpu_kernel_dp_padding(pad: int): """slot_mapping shorter than q/kv rows: the KV branch must only touch - the first num_tokens rows while Q-norm+RoPE still runs on all rows. - """ + the first num_tokens rows while Q-norm+RoPE still runs on all rows.""" torch.manual_seed(1) dtype = torch.bfloat16 eps = 1e-6 @@ -1044,8 +1032,7 @@ def _inverse_gptj_rope_o_proj_eager( rope_dim: int, ) -> torch.Tensor: """NoPE dims pass through as fp32; the RoPE segment is de-rotated by - R(-pos) in GPT-J (interleaved even/odd) convention. - """ + R(-pos) in GPT-J (interleaved even/odd) convention.""" nope_dim = o.shape[-1] - rope_dim half_dim = rope_dim // 2 @@ -1111,8 +1098,7 @@ def _write_page( ) -> None: """Write k_fp8 ([block_size, INDEXER_HEAD_DIM]) and scale ([block_size] fp32) into one page row: K-region then scale-region, matching - compress_norm_rope_store_indexer_cpu's layout. - """ + compress_norm_rope_store_indexer_cpu's layout.""" k_region = page_row[: block_size * INDEXER_HEAD_DIM] k_region.copy_(k_fp8.view(torch.uint8).flatten()) scale_region = page_row[block_size * INDEXER_HEAD_DIM :].view(torch.float32) @@ -1148,8 +1134,7 @@ def _build_paged_mqa_logits_batch( ): """Fill pages (a pre-sized [n_pages, buf_width] uint8 tensor, possibly non-contiguous in dim 0) with deterministic-per-seed random K/scale - data. - """ + data.""" torch.manual_seed(seed) batch_size = len(seq_lens) max_seq_len = max(seq_lens) @@ -1215,8 +1200,7 @@ def test_fp8_paged_mqa_logits_cpu_non_contiguous_kv_cache_row_stride(): """The paged K-cache in production is a per-layer view into a shared multi-layer allocation, so its page stride generally exceeds the page byte width -- check the kernel reads a padded/strided buffer identically - to an equivalent tightly-packed one. - """ + to an equivalent tightly-packed one.""" block_size = 64 num_heads = 4 seq_lens = [1, block_size + 7, 3 * block_size] @@ -1342,8 +1326,7 @@ def test_fused_indexer_q_rope_quant_dispatches_to_cpu_kernel(): CPU op on a CPU tensor, not silently fall through to the Triton kernel (which would also "work" under triton-cpu, masking a dispatch regression). The dispatcher does its CPU import inside the CPU branch, - so the patch target is the source module. - """ + so the patch target is the source module.""" torch.manual_seed(0) num_tokens = 1 @@ -1410,8 +1393,7 @@ def _hc_head_torch( ) -> torch.Tensor: """Eager reference for hc_head_fused_cpu: round-trips the RMSNorm output through bf16 before the linear, matching the kernel's bf16 - arithmetic. - """ + arithmetic.""" hc_mult, hidden_size = hidden_states.shape[-2:] outer_shape = hidden_states.shape[:-2] hs_flat = hidden_states.reshape(-1, hc_mult, hidden_size) @@ -1493,8 +1475,7 @@ def test_mhc_post_cpu(num_tokens: int, hidden_size: int): @pytest.mark.parametrize("hidden_size", [4096, 7168]) def test_hc_head_cpu(num_tokens: int, hidden_size: int): """hc_head_fused_cpu vs. the _hc_head_torch eager reference it - replaces. - """ + replaces.""" torch.set_default_device(DEVICE) set_random_seed(0) hc_mult = 4 diff --git a/tests/kernels/test_engram.py b/tests/kernels/test_engram.py index 8deba1241a..c2a7607cba 100644 --- a/tests/kernels/test_engram.py +++ b/tests/kernels/test_engram.py @@ -383,8 +383,7 @@ def _hash_ids(requests, tables_meta, block_table, cache=None, capture=False): """Run the op on a batch of (token_ids, start, window) requests; `window` is the runner's [depth] lookback for that request (None = all unknown). Token IDs 14 and 22 stand in for image tokens that break n-grams. - Returns one [len(token_ids), ...] hash tensor per request. - """ + Returns one [len(token_ids), ...] hash tensor per request.""" token_map, multipliers, primes, offsets, block_size = tables_meta depth = multipliers.shape[1] - 1 @@ -443,8 +442,7 @@ def test_lookback_window_reproduces_single_instance(runner, capture): V2 supplies every lookback from its device token history and needs no slot cache. V1 supplies prompt positions only and reads generated positions from the slot cache it fills itself. Without any window the - first decode token hashes stale slots (negative control). - """ + first decode token hashes stale slots (negative control).""" block_size = 4 block_table = torch.tensor( [[3, 1, 5, 0], [2, 4, 6, 7]], dtype=torch.int32, device="cuda" @@ -710,8 +708,7 @@ def test_engram_lookup_reuses_jit_across_token_shapes(): def test_engram_lookup_matches_torch(cpu_offload, background, num_tokens): """The fused gather must be bit-exact with the torch dequant path it replaces, from HBM and from pinned host memory alike, and must contribute - zeros for rows another TP rank owns. - """ + zeros for rows another TP rank owns.""" layer = _make_embedding(cpu_offload) cols, rows = 24, layer.part_num_embeddings ids = torch.randint(0, rows, (num_tokens, cols), dtype=torch.int32, device="cuda") diff --git a/tests/kernels/test_fla_layernorm_guard.py b/tests/kernels/test_fla_layernorm_guard.py index fad8d90805..492c099bf1 100644 --- a/tests/kernels/test_fla_layernorm_guard.py +++ b/tests/kernels/test_fla_layernorm_guard.py @@ -336,8 +336,7 @@ def test_layer_norm_rows_per_block( @torch.inference_mode() def test_strided_input(dtype: torch.dtype) -> None: """Test that the kernel handles non-contiguous (strided) - inputs correctly. - """ + inputs correctly.""" set_random_seed(42) device = torch.device(DEVICE) num_tokens = 128 diff --git a/tests/kernels/test_fp32_router_gemm.py b/tests/kernels/test_fp32_router_gemm.py index b6c2a53ed8..d330abba53 100644 --- a/tests/kernels/test_fp32_router_gemm.py +++ b/tests/kernels/test_fp32_router_gemm.py @@ -97,8 +97,7 @@ def test_topk_routing_consistency(num_tokens: int, hidden_dim: int, num_experts: """The gate feeds top-k expert selection: the kernel's top-8 must match an fp64 reference's top-8 per token (ties tolerated). This is the business-level correctness of the router — numeric error only matters - if it flips the argsort. - """ + if it flips the argsort.""" _requires_sm90() top_k = 8 device = torch.device("cuda") diff --git a/tests/kernels/test_fused_deepseek_v32_norm_rope.py b/tests/kernels/test_fused_deepseek_v32_norm_rope.py index 6691de7ebf..7f74cde05d 100644 --- a/tests/kernels/test_fused_deepseek_v32_norm_rope.py +++ b/tests/kernels/test_fused_deepseek_v32_norm_rope.py @@ -854,8 +854,7 @@ def test_fused_q_no_indexer(num_tokens: int): @pytest.mark.parametrize("has_indexer", [True, False]) def test_fused_q_bf16_query(num_tokens: int, has_indexer: bool): """bf16-query path (FlashMLA sparse, SM90/SM100): only the RoPE'd q_pe is - produced (bf16, unquantized); ql_nope is consumed directly by the caller. - """ + produced (bf16, unquantized); ql_nope is consumed directly by the caller.""" torch.manual_seed(6) dev = "cuda" max_pos = 8192 diff --git a/tests/kernels/test_fused_deepseek_v4_qnorm_rope_kv_insert.py b/tests/kernels/test_fused_deepseek_v4_qnorm_rope_kv_insert.py index 3e95913a01..ced96bc401 100644 --- a/tests/kernels/test_fused_deepseek_v4_qnorm_rope_kv_insert.py +++ b/tests/kernels/test_fused_deepseek_v4_qnorm_rope_kv_insert.py @@ -176,8 +176,7 @@ def _call_fused( def _as_stored_fp8(t: torch.Tensor) -> torch.Tensor: """Reinterpret a float8_e4m3fn-typed kernel output under the real (FNUZ on - gfx942) encoding the kernel actually wrote, without touching the bytes. - """ + gfx942) encoding the kernel actually wrote, without touching the bytes.""" return t.contiguous().view(torch.uint8).view(FP8_STORE_DTYPE) @@ -713,8 +712,7 @@ def test_q_interleaved_is_orthogonal_to_norm_and_rope( @pytest.mark.parametrize("block_size", [16, 64]) def test_kv_path_with_dp_padding(num_tokens: int, pad: int, block_size: int): """slot_mapping.size(0) < q.size(0): the kernel must skip padded - tokens in the KV branch while still processing Q on all rows. - """ + tokens in the KV branch while still processing Q on all rows.""" torch.manual_seed(3) device = "cuda" dtype = torch.bfloat16 diff --git a/tests/kernels/test_fused_indexer_q_rope_quant.py b/tests/kernels/test_fused_indexer_q_rope_quant.py index 20ac8f19f1..0ce3a91851 100644 --- a/tests/kernels/test_fused_indexer_q_rope_quant.py +++ b/tests/kernels/test_fused_indexer_q_rope_quant.py @@ -574,8 +574,7 @@ def test_indexer_k_store_roundtrips_through_rocm_gather(block_size, compress_rat def test_fused_indexer_q_rope_quant_writes_bf16_weights(use_cutedsl): """The MXFP4 path can emit the per-head weights in bf16 (what DeepGEMM's sparse MQA-logits kernels take) instead of fp32; the values are the fp32 - result rounded once, so the scoring kernel needs no cast. - """ + result rounded once, so the scoring kernel needs no cast.""" if use_cutedsl and not has_cutedsl(): pytest.skip("cutedsl (cutlass) not installed") diff --git a/tests/kernels/test_fused_inv_rope_fp8_quant.py b/tests/kernels/test_fused_inv_rope_fp8_quant.py index 97ea8f7e34..03d5b7921f 100644 --- a/tests/kernels/test_fused_inv_rope_fp8_quant.py +++ b/tests/kernels/test_fused_inv_rope_fp8_quant.py @@ -446,8 +446,7 @@ def test_output_strides(num_tokens, num_heads, n_groups): def test_per_group_contiguity(num_tokens): """FP8 per-group slices must be contiguous. Scale per-group slices are column-major (T-stride=1) — not row-major contiguous, which is - correct for TMA loads. - """ + correct for TMA loads.""" num_heads, n_groups = 64, 8 heads_per_group = num_heads // n_groups max_pos = 4096 @@ -513,8 +512,7 @@ def test_scales_are_power_of_two(): def test_nope_dims_unchanged(): """Nope dimensions (first 448 per head) should only be quantized, not rotated. Verify by dequantizing and comparing against - quantize-only reference (no RoPE). - """ + quantize-only reference (no RoPE).""" num_tokens, num_heads, n_groups = 16, 64, 8 heads_per_group = num_heads // n_groups max_pos = 4096 @@ -905,8 +903,7 @@ def test_einsum_end_to_end(num_tokens, num_heads, n_groups): @torch.inference_mode() def test_with_real_deepseek_v4_rope(num_tokens, default_vllm_config): """Test with real DeepseekV4ScalingRotaryEmbedding (GPT-J style, - mscale=0, YaRN scaling) matching the production config. - """ + mscale=0, YaRN scaling) matching the production config.""" num_heads = 64 n_groups = 8 heads_per_group = num_heads // n_groups diff --git a/tests/kernels/test_mhc_kernels.py b/tests/kernels/test_mhc_kernels.py index 219e42c742..fafb37d97b 100644 --- a/tests/kernels/test_mhc_kernels.py +++ b/tests/kernels/test_mhc_kernels.py @@ -1372,8 +1372,7 @@ def _patch_first_rank_pp_group(monkeypatch): def test_deepseek_v4_mhc_broadcast_finalize_sums_hc_streams(monkeypatch): """First finalize (at the end of load_weights) allocates - hc_attn_fn_broadcast as hc_attn_fn summed over hc streams. - """ + hc_attn_fn_broadcast as hc_attn_fn summed over hc streams.""" _patch_first_rank_pp_group(monkeypatch) layer = _make_mhc_decoder_layer(hc_mult=2, hidden_size=8) model = SimpleNamespace(start_layer=0, end_layer=1, layers=[layer]) @@ -1388,8 +1387,7 @@ def test_deepseek_v4_mhc_broadcast_finalize_sums_hc_streams(monkeypatch): def test_deepseek_v4_mhc_broadcast_refit_refreshes_in_place(monkeypatch): """Re-finalizing after a weight refit must copy into the existing broadcast tensor so its address stays stable for captured CUDA graphs, - while picking up the new hc_attn_fn values. - """ + while picking up the new hc_attn_fn values.""" _patch_first_rank_pp_group(monkeypatch) layer = _make_mhc_decoder_layer(hc_mult=2, hidden_size=8) model = SimpleNamespace(start_layer=0, end_layer=1, layers=[layer]) diff --git a/tests/kernels/test_minimax_m3_amd_ops.py b/tests/kernels/test_minimax_m3_amd_ops.py index 45fafb0433..997c619809 100644 --- a/tests/kernels/test_minimax_m3_amd_ops.py +++ b/tests/kernels/test_minimax_m3_amd_ops.py @@ -403,8 +403,7 @@ def test_mxfp8_linear_emulation_bf16_at_load( ): """EmulationMxfp8LinearKernel load-time BF16 dequant (default) and the ``VLLM_MXFP8_EMULATION_DEQUANT_AT_LOAD=0`` per-step fallback must produce the - same result; the dtype-match (BF16/FP16 activations) must also hold. - """ + same result; the dtype-match (BF16/FP16 activations) must also hold.""" from vllm.model_executor.kernels.linear.mxfp8.emulation import ( EmulationMxfp8LinearKernel, ) @@ -518,8 +517,7 @@ def test_mxfp8_rocm_native_unaligned_k_dequantizes_at_load(shape): # produced EP garbage). def _capture_expert_mask(expert_mask, *, global_num_experts): """Drive the real ``AiterMxfp8Experts.apply`` mask branch and capture the - ``expert_mask`` it forwards to ``rocm_aiter_ops.fused_moe``. - """ + ``expert_mask`` it forwards to ``rocm_aiter_ops.fused_moe``.""" from types import SimpleNamespace from unittest import mock @@ -570,8 +568,7 @@ def _capture_expert_mask(expert_mask, *, global_num_experts): @pytest.mark.skipif(not current_platform.is_rocm(), reason="ROCm only") def test_aiter_mxfp8_apply_forwards_expert_mask_unchanged(): """AiterMxfp8Experts.apply forwards the precomputed 0/1 mask to aiter as-is - (no re-derivation that would collapse an already-0/1 mask to all-ones). - """ + (no re-derivation that would collapse an already-0/1 mask to all-ones).""" # 0/1 local-expert mask over global ids + trailing sentinel (rank owns 0..3). ep_mask = torch.tensor( [1, 1, 1, 1, 0, 0, 0, 0, 0], dtype=torch.int32, device=DEVICE @@ -585,8 +582,7 @@ def test_aiter_mxfp8_apply_forwards_expert_mask_unchanged(): def test_routed_experts_expert_map_delegates_to_kernel(): """RoutedExperts.expert_map returns the 0/1 mask only for kernels that set ``consumes_expert_mask`` (AITER), and the canonical -1 map otherwise -- keyed - on the resolved kernel, not the global aiter switch. - """ + on the resolved kernel, not the global aiter switch.""" from types import SimpleNamespace from vllm.model_executor.layers.fused_moe.routed_experts import RoutedExperts diff --git a/tests/kernels/test_shuffle_rows.py b/tests/kernels/test_shuffle_rows.py index 35c2f26442..4f32949eb7 100644 --- a/tests/kernels/test_shuffle_rows.py +++ b/tests/kernels/test_shuffle_rows.py @@ -17,8 +17,7 @@ from vllm.platforms import current_platform @pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16, torch.float32]) def test_shuffle_rows_basic(num_tokens: int, hidden_size: int, dtype: torch.dtype): """Test basic functionality of shuffle_rows with various tensor sizes and - dtypes. - """ + dtypes.""" if not current_platform.is_cuda(): pytest.skip("shuffle_rows requires CUDA") @@ -73,8 +72,7 @@ def test_shuffle_rows_permutation( @pytest.mark.parametrize("hidden_size", [256, 512]) def test_shuffle_rows_expansion(num_tokens: int, hidden_size: int): """Test shuffle_rows with expansion (more output tokens than input - tokens). - """ + tokens).""" if not current_platform.is_cuda(): pytest.skip("shuffle_rows requires CUDA") diff --git a/tests/kernels/test_top_k_per_row.py b/tests/kernels/test_top_k_per_row.py index f249adeaff..db49b8091b 100644 --- a/tests/kernels/test_top_k_per_row.py +++ b/tests/kernels/test_top_k_per_row.py @@ -1740,8 +1740,7 @@ def test_sparse_indexer_decode_topk_explicit_backends( ) -> None: """Every explicit sparse-indexer decode top-k backend must restrict each row to its seq_len (dirty data past the end must never be selected) and - match torch.topk on the valid region. - """ + match torch.topk on the valid region.""" from vllm.config import VllmConfig, set_current_vllm_config from vllm.model_executor.layers.indexer_topk import SparseIndexerTopk @@ -1812,8 +1811,7 @@ def test_sparse_indexer_decode_topk_short_seq_lens( backend: str, workspace_init ) -> None: """seq_len < next_n: derived per-row ends must clamp at 0 (the reference - kernels do max(0, ...)); negative ends are OOB for the ragged kernels. - """ + kernels do max(0, ...)); negative ends are OOB for the ragged kernels.""" from vllm.config import VllmConfig, set_current_vllm_config from vllm.model_executor.layers.indexer_topk import SparseIndexerTopk diff --git a/tests/lora/test_default_mm_loras.py b/tests/lora/test_default_mm_loras.py index 3c9505adba..e858331c93 100644 --- a/tests/lora/test_default_mm_loras.py +++ b/tests/lora/test_default_mm_loras.py @@ -132,8 +132,7 @@ 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, diff --git a/tests/lora/test_fused_moe_lora_kernel.py b/tests/lora/test_fused_moe_lora_kernel.py index 9ee0ed8584..8b5b3d577a 100644 --- a/tests/lora/test_fused_moe_lora_kernel.py +++ b/tests/lora/test_fused_moe_lora_kernel.py @@ -1123,8 +1123,7 @@ 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 @@ -1186,8 +1185,7 @@ 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 diff --git a/tests/lora/test_moe_lora_align_sum.py b/tests/lora/test_moe_lora_align_sum.py index df27752d2c..80ba0a56ca 100644 --- a/tests/lora/test_moe_lora_align_sum.py +++ b/tests/lora/test_moe_lora_align_sum.py @@ -249,8 +249,7 @@ 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 ) @@ -289,8 +288,7 @@ 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, diff --git a/tests/lora/test_moe_lora_ep_load.py b/tests/lora/test_moe_lora_ep_load.py index 52cccc6b06..60d0c2c9ba 100644 --- a/tests/lora/test_moe_lora_ep_load.py +++ b/tests/lora/test_moe_lora_ep_load.py @@ -19,8 +19,7 @@ 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,8 +42,7 @@ 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 ) diff --git a/tests/lora/test_punica_ops.py b/tests/lora/test_punica_ops.py index f2bb18aac2..34cbe061dc 100644 --- a/tests/lora/test_punica_ops.py +++ b/tests/lora/test_punica_ops.py @@ -45,8 +45,7 @@ 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: @@ -67,8 +66,7 @@ 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: diff --git a/tests/lora/test_punica_ops_fp8.py b/tests/lora/test_punica_ops_fp8.py index 18ac6fcd7a..e447cef9d8 100644 --- a/tests/lora/test_punica_ops_fp8.py +++ b/tests/lora/test_punica_ops_fp8.py @@ -877,8 +877,7 @@ 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) @@ -933,8 +932,7 @@ 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) diff --git a/tests/model_executor/layers/test_fused_shared_expert.py b/tests/model_executor/layers/test_fused_shared_expert.py index 6fdd99deaa..08fb6818e3 100644 --- a/tests/model_executor/layers/test_fused_shared_expert.py +++ b/tests/model_executor/layers/test_fused_shared_expert.py @@ -1319,8 +1319,7 @@ def test_fp8_shared_expert_fse_allows_symmetric_ignored_layers() -> None: def test_fp8_shared_expert_fse_expands_packed_projections() -> None: """Both shards of a fused projection ignored is symmetric within that - projection, so the mismatch reported is against the routed experts. - """ + projection, so the mismatch reported is against the routed experts.""" quant_config = _fp8_config( ignored_layers=[ "model.layers.0.mlp.shared_experts.gate_proj", @@ -1344,8 +1343,7 @@ def test_fp8_shared_expert_fse_expands_packed_projections() -> None: def test_fp8_shared_expert_fse_propagates_partial_shard_exclusion() -> None: """Half a fused projection excluded is rejected by `is_layer_skipped` - itself, exactly as it is in `Fp8Config.get_quant_method`. - """ + itself, exactly as it is in `Fp8Config.get_quant_method`.""" quant_config = _fp8_config( ignored_layers=["model.layers.0.mlp.shared_experts.gate_proj"] ) diff --git a/tests/model_executor/layers/test_mla_short_prefill_indexer.py b/tests/model_executor/layers/test_mla_short_prefill_indexer.py index 91fc039569..41a06d0546 100644 --- a/tests/model_executor/layers/test_mla_short_prefill_indexer.py +++ b/tests/model_executor/layers/test_mla_short_prefill_indexer.py @@ -346,8 +346,7 @@ def test_deepseek_v32_dispatches_selected_mha( def test_select_candidate_blocks_tolerates_empty_rows(): """Full-cudagraph decode pads the batch with seq_len-0 rows. The newest block pin must not index -1 for them (device-side assert); they select - no candidate blocks and real rows still pin their newest block. - """ + no candidate blocks and real rows still pin their newest block.""" block_size, topk_blocks = 8, 3 logits = torch.zeros(3, 64, device="cuda") logits[0, 3] = 5.0 # block 0 scores highest for row 0 @@ -458,8 +457,7 @@ def test_candidate_kernels_preserve_packed_bounds_and_padding( def _make_candidates(lens: torch.Tensor, num_candidates: int, cbk: int): """Production-faithful candidates: top min(avail, K) blocks per row — - full coverage for lens <= K*cbk, a fixed-size subset beyond that. - """ + full coverage for lens <= K*cbk, a fixed-size subset beyond that.""" avail = ((lens.cpu() + cbk - 1) // cbk).tolist() rows = [] for a in avail: @@ -495,8 +493,7 @@ def _candidate_token_mask( def _reference_topk(masked: torch.Tensor, topk: int) -> torch.Tensor: """Plain ``torch.topk`` over -inf-masked logits; slots past a row's valid - count are -1 (the indexer's "no token" sentinel). - """ + count are -1 (the indexer's "no token" sentinel).""" values, indices = masked.topk(topk, dim=1) return torch.where(values > float("-inf"), indices.int(), -1) @@ -509,8 +506,7 @@ def _assert_same_selection( ) -> None: """Both top-k index sets must pick the same multiset of logit values per row (-1 padding must match too). Indices themselves may differ: the - top-k kernels break ties among equal values in nondeterministic order. - """ + top-k kernels break ties among equal values in nondeterministic order.""" for r in range(logits.shape[0]): base = int(row_starts[r]) if row_starts is not None else 0 g, e = got[r][got[r] >= 0], expected[r][expected[r] >= 0] @@ -522,8 +518,7 @@ def _assert_same_selection( def _sparse_scratch(rows: int, num_sparse: int, topk: int) -> dict: """Caller-owned buffers the sparse path writes into (the metadata builder - owns these in production). - """ + owns these in production).""" i32 = dict(dtype=torch.int32, device="cuda") return dict( sparse_indices=torch.zeros(rows, num_sparse, **i32), @@ -538,8 +533,7 @@ def _expand_candidates_reference( """PyTorch reference for `candidate_blocks_to_sparse_indices`: expand each candidate block into ``cbk // sbk`` sparse blocks, keep those inside ``[0, ke - ks)``, sort ascending, anchor at ``ks // sbk``, pad by - repeating the last valid block, and count the valid sparse columns. - """ + repeating the last valid block, and count the valid sparse columns.""" ratio = cbk // sbk rows, num_candidates = candidates.shape num_sparse = num_candidates * ratio @@ -565,8 +559,7 @@ def _expand_candidates_reference( @pytest.mark.skipif(not torch.cuda.is_available(), reason="Triton kernel") def test_candidate_blocks_to_sparse_indices_math(): """Candidate->sparse-block expansion: ks anchoring, range filtering, - repeat-last padding, and the per-row valid column count (``end``). - """ + repeat-last padding, and the per-row valid column count (``end``).""" from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import ( candidate_blocks_to_sparse_indices, ) @@ -618,8 +611,7 @@ def test_candidate_blocks_to_sparse_indices_math(): def test_candidate_blocks_to_sparse_indices_matches_reference(cbk: int, sbk: int): """The Triton expansion equals the PyTorch reference on production-shaped random inputs, including strided (column-sliced) candidate rows and - strided output buffers. - """ + strided output buffers.""" from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import ( candidate_blocks_to_sparse_indices, ) @@ -689,8 +681,7 @@ def test_sparse_mqa_logits_prefill_matches_dense_masked(capture: bool): ``torch.topk`` over dense bf16 logits masked to the candidates (the two DeepGEMM kernels agree bitwise on candidate columns), incl. under CUDA graph capture, and a later layer reusing the step's expansion/schedule - selects the same values. - """ + selects the same values.""" deep_gemm = _skip_unless_sm100_sparse_kernels() from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import ( sparse_mqa_logits_prefill_chunk, @@ -780,8 +771,7 @@ def test_sparse_mqa_logits_prefill_matches_dense_masked(capture: bool): def _build_fp4_paged_cache(req_lens: torch.Tensor, page_kv: int, head_dim: int): """MXFP4 paged cache in DeepGEMM's fused layout: per page, all tokens' - fp4 data first, then their packed UE8M0 scales. - """ + fp4 data first, then their packed UE8M0 scales.""" device = req_lens.device pages_per = (req_lens + page_kv - 1) // page_kv num_pages, max_pages = int(pages_per.sum()), int(pages_per.max()) @@ -817,8 +807,7 @@ def test_sparse_mqa_logits_paged_matches_dense_masked(next_n: int, capture: bool """Paged sparse-MQA decode selects exactly the values ``torch.topk`` picks from the dense bf16 masked logits, incl. MTP rows (next_n > 1 flattened to one query row each), CUDA graph capture/replay and schedule reuse by a - later layer. - """ + later layer.""" deep_gemm = _skip_unless_sm100_sparse_kernels() from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import ( sparse_mqa_logits_paged_decode, @@ -927,8 +916,7 @@ def test_sparse_mqa_logits_paged_matches_dense_masked(next_n: int, capture: bool def test_sparse_mqa_logits_accuracy_vs_torch(): """Sparse-kernel numerics vs a PyTorch fp32 reference on the dequantized - MXFP4 inputs. - """ + MXFP4 inputs.""" _skip_unless_sm100_sparse_kernels() from deep_gemm.utils import cast_back_from_fp4 diff --git a/tests/model_executor/model_loader/test_ep_weight_filter.py b/tests/model_executor/model_loader/test_ep_weight_filter.py index 9d177f5991..0ff53d24e7 100644 --- a/tests/model_executor/model_loader/test_ep_weight_filter.py +++ b/tests/model_executor/model_loader/test_ep_weight_filter.py @@ -232,8 +232,7 @@ class TestShouldSkipWeight: class TestSafetensorsWeightsIteratorWithEpFilter: """Verify that EP filtering produces a strict subset of unfiltered loading - and that all expected dense + local expert weights are present. - """ + and that all expected dense + local expert weights are present.""" @pytest.fixture(scope="class") def gpt2_files(self): @@ -263,8 +262,7 @@ class TestSafetensorsWeightsIteratorWithEpFilter: def test_empty_filter_skips_experts_only(self, gpt2_files): """GPT-2 has no expert weights, so even an empty local_expert_ids - set should return all weights (all are dense). - """ + set should return all weights (all are dense).""" all_weights = dict(safetensors_weights_iterator(gpt2_files, False)) filtered_weights = dict( safetensors_weights_iterator(gpt2_files, False, local_expert_ids=set()) @@ -275,8 +273,7 @@ class TestSafetensorsWeightsIteratorWithEpFilter: class TestEpFilterOnSyntheticMoeWeights: """Create synthetic safetensors files with expert-like naming and verify - that the filter correctly skips non-local experts. - """ + that the filter correctly skips non-local experts.""" @pytest.fixture def synthetic_moe_files(self, tmp_path): diff --git a/tests/model_executor/model_loader/test_reload.py b/tests/model_executor/model_loader/test_reload.py index d123dcb750..b4a544d2fc 100644 --- a/tests/model_executor/model_loader/test_reload.py +++ b/tests/model_executor/model_loader/test_reload.py @@ -350,8 +350,7 @@ def test_marlin_post_load_preserves_runtime_tensor_addresses(monkeypatch, dist_i @pytest.mark.parametrize("variant", ["fp8", "mxfp8", "nvfp4"]) def test_marlin_prepare_layer_preserves_workspace_address(monkeypatch, variant): """The Marlin fallback prepare_* functions rerun on weight reload and must - reuse the workspace storage whose address captured CUDA graphs hold. - """ + reuse the workspace storage whose address captured CUDA graphs hold.""" from vllm import _custom_ops as ops from vllm.model_executor.layers.quantization.utils import ( marlin_utils, @@ -429,8 +428,7 @@ def test_marlin_prepare_layer_preserves_workspace_address(monkeypatch, variant): def test_marlin_make_workspace_new_rejects_incompatible_existing(monkeypatch): """An incompatible existing workspace means the address captured by CUDA - graphs is already unusable; allocating a replacement would hide that. - """ + graphs is already unusable; allocating a replacement would hide that.""" from vllm.model_executor.layers.quantization.utils import marlin_utils monkeypatch.setattr(marlin_utils, "num_compute_units", lambda _: 4) @@ -611,8 +609,7 @@ class _RecordingQuantMethod(QuantizeMethodBase): class _LateBiasLayer(torch.nn.Module): """Mimics an online-quantized linear: `weight` is created on meta by `create_weights()`, which wraps the loaders, and the linear base registers - `bias` afterwards. - """ + `bias` afterwards.""" def __init__(self, quant_method): super().__init__() diff --git a/tests/model_executor/test_deep_gemm_warmup.py b/tests/model_executor/test_deep_gemm_warmup.py index ada0737066..e71061e733 100644 --- a/tests/model_executor/test_deep_gemm_warmup.py +++ b/tests/model_executor/test_deep_gemm_warmup.py @@ -42,8 +42,7 @@ def _run_warmup(monkeypatch, layers) -> list[dict]: @pytest.mark.parametrize("scale_name", ["weight_scale", "weight_scale_inv"]) def test_registered_deep_gemm_layer_is_warmed_up(monkeypatch, scale_name) -> None: """Any layer stamped by the DeepGEMM kernel is warmed, regardless of the - quantization method that owns it or the name of its scale parameter. - """ + quantization method that owns it or the name of its scale parameter.""" layer = _block_fp8_layer(256, 128, scale_name) calls = _run_warmup(monkeypatch, [layer]) @@ -55,8 +54,7 @@ def test_registered_deep_gemm_layer_is_warmed_up(monkeypatch, scale_name) -> Non def test_n_multiple_of_64_matches_kernel_selection(monkeypatch) -> None: """DeepGEMM accepts N % 64 == 0 (e.g. DeepSeek kv_a_proj_with_mqa, N=576), - so warmup must not require N % 128 == 0. - """ + so warmup must not require N % 128 == 0.""" assert len(_run_warmup(monkeypatch, [_block_fp8_layer(576, 256)])) == 1 diff --git a/tests/model_executor/test_routed_experts_capture.py b/tests/model_executor/test_routed_experts_capture.py index ed10955f96..b146a235c1 100644 --- a/tests/model_executor/test_routed_experts_capture.py +++ b/tests/model_executor/test_routed_experts_capture.py @@ -326,8 +326,7 @@ def test_routed_experts_capturer_dp_unexpected_batch_raises(): def test_routed_experts_attention_group_is_shared_and_fail_closed(): """Both sides key routing data by this gid, so it must skip non-full-attention - groups rather than defaulting to 0, and fail closed when none exists. - """ + groups rather than defaulting to 0, and fail closed when none exists.""" common = dict(num_kv_heads=1, head_size=1, dtype=torch.float32) config = SimpleNamespace( kv_cache_groups=[ diff --git a/tests/model_executor/test_weight_utils.py b/tests/model_executor/test_weight_utils.py index d19ea0ed05..3dea587075 100644 --- a/tests/model_executor/test_weight_utils.py +++ b/tests/model_executor/test_weight_utils.py @@ -57,8 +57,7 @@ class TestMaybeRemapKvScaleName: def test_qkv_proj_k_scale(self): """Qwen3-MoE / llm-compressor format: qkv_proj.k_scale -> attn.k_scale - Regression test for https://github.com/vllm-project/vllm/issues/25047 - """ + Regression test for https://github.com/vllm-project/vllm/issues/25047""" result = maybe_remap_kv_scale_name( "model.layers.0.self_attn.qkv_proj.k_scale", self.PARAMS_DICT ) @@ -66,8 +65,7 @@ class TestMaybeRemapKvScaleName: def test_qkv_proj_v_scale(self): """Qwen3-MoE / llm-compressor format: qkv_proj.v_scale -> attn.v_scale - Regression test for https://github.com/vllm-project/vllm/issues/25047 - """ + Regression test for https://github.com/vllm-project/vllm/issues/25047""" result = maybe_remap_kv_scale_name( "model.layers.0.self_attn.qkv_proj.v_scale", self.PARAMS_DICT ) @@ -110,8 +108,7 @@ class TestMaybeRemapKvScaleName: def test_nvfp4_modelopt_k_proj_k_scale(self): """ModelOpt NVFP4 format (e.g. nvidia/Qwen3-30B-A3B-NVFP4): k_proj.k_scale -> attn.k_scale. - Validates that NVFP4 checkpoints are not broken by this change. - """ + Validates that NVFP4 checkpoints are not broken by this change.""" result = maybe_remap_kv_scale_name( "model.layers.0.self_attn.k_proj.k_scale", self.PARAMS_DICT ) @@ -120,8 +117,7 @@ class TestMaybeRemapKvScaleName: def test_nvfp4_modelopt_v_proj_v_scale(self): """ModelOpt NVFP4 format (e.g. nvidia/Qwen3-30B-A3B-NVFP4): v_proj.v_scale -> attn.v_scale. - Validates that NVFP4 checkpoints are not broken by this change. - """ + Validates that NVFP4 checkpoints are not broken by this change.""" result = maybe_remap_kv_scale_name( "model.layers.0.self_attn.v_proj.v_scale", self.PARAMS_DICT ) @@ -129,8 +125,7 @@ class TestMaybeRemapKvScaleName: def test_qwen3_vl_moe_qkv_proj_k_scale(self): """Qwen3-VL-MoE uses the same fused qkv_proj naming as Qwen3-MoE. - Regression test for qwen3_vl_moe.py fix (same bug as #25047). - """ + Regression test for qwen3_vl_moe.py fix (same bug as #25047).""" result = maybe_remap_kv_scale_name( "model.layers.0.self_attn.qkv_proj.k_scale", self.PARAMS_DICT ) @@ -138,8 +133,7 @@ class TestMaybeRemapKvScaleName: def test_qwen3_vl_moe_qkv_proj_v_scale(self): """Qwen3-VL-MoE uses the same fused qkv_proj naming as Qwen3-MoE. - Regression test for qwen3_vl_moe.py fix (same bug as #25047). - """ + Regression test for qwen3_vl_moe.py fix (same bug as #25047).""" result = maybe_remap_kv_scale_name( "model.layers.0.self_attn.qkv_proj.v_scale", self.PARAMS_DICT ) @@ -181,8 +175,7 @@ class TestKvCacheScaleMapper: """The `WeightsMapper` returned by `get_cache_scale_mapper` replaces the per-model `maybe_remap_kv_scale_name` calls. It must remap the same set of checkpoint formats (the non-`params_dict`-dependent ones) and be idempotent - so it composes safely with a model's own qkv/gate_up `hf_to_vllm_mapper`. - """ + so it composes safely with a model's own qkv/gate_up `hf_to_vllm_mapper`.""" def _mapper(self): # `get_cache_scale_mapper` does not use `self`; call it on the base @@ -272,8 +265,7 @@ class TestKvCacheScaleMapper: def test_composes_with_qkv_mapper(self): """Applied together with a model's qkv/gate_up mapper, the regex scale rules run before the substr rename, so scales are normalized to `.attn.` - and regular projections are still fused correctly. - """ + and regular projections are still fused correctly.""" from vllm.model_executor.models.utils import WeightsMapper model_mapper = WeightsMapper( diff --git a/tests/models/inkling/test_mm_towers.py b/tests/models/inkling/test_mm_towers.py index 51daa506c2..d969c8101a 100644 --- a/tests/models/inkling/test_mm_towers.py +++ b/tests/models/inkling/test_mm_towers.py @@ -42,8 +42,7 @@ def _assert_close_ulps( compare against the reference's local ulp spacing. ``pre_act`` (the reference pre-activation) adds derivative-propagated slack: near ``gelu(x) ~ 0`` an ulp-level input flip legitimately moves the output by - many of ITS (tiny) ulps, bounded by |gelu'| <= 1.13 times the input ulps. - """ + many of ITS (tiny) ulps, bounded by |gelu'| <= 1.13 times the input ulps.""" g, r = got.float(), ref.float() tol = torch.clamp(max_ulps * _bf16_spacing(ref), min=atol) if pre_act is not None: diff --git a/tests/models/kimi_k3/test_amd_latent_moe_runner.py b/tests/models/kimi_k3/test_amd_latent_moe_runner.py index 4346a72928..ec270c04fe 100644 --- a/tests/models/kimi_k3/test_amd_latent_moe_runner.py +++ b/tests/models/kimi_k3/test_amd_latent_moe_runner.py @@ -123,8 +123,7 @@ def _check_writes_only_its_own_shard( device: torch.device, tp_size: int, rank: int ) -> None: """Two ranks that swapped both weight rows and write offsets still sum to - the right total, so inspect each slice before the final collective. - """ + the right total, so inspect each slice before the final collective.""" transform = _build_transform(device) runner = _tail_runner(transform, tp_size) group = get_tp_group().device_group diff --git a/tests/models/kimi_k3/test_aux_attn_res_stream.py b/tests/models/kimi_k3/test_aux_attn_res_stream.py index 64cec452d2..26cb76a550 100644 --- a/tests/models/kimi_k3/test_aux_attn_res_stream.py +++ b/tests/models/kimi_k3/test_aux_attn_res_stream.py @@ -130,8 +130,7 @@ def test_disabled_reproduces_the_plain_residual_sum( def test_taps_the_consumer_layer_when_one_follows(recorder, monkeypatch): """The value the next layer reads is the mixture against *its* weights, - so the tap has to reach forward rather than use the current layer's. - """ + so the tap has to reach forward rather than use the current layer's.""" _set_last_rank(monkeypatch, True) _call(_stub_model(enabled=True), 1, torch.zeros(2), None, torch.zeros(2)) @@ -182,8 +181,7 @@ def test_pending_mlp_output_is_folded_in_rather_than_passed_as_delta( ): """The kernel writes an applied delta back into the prefix in place, which would double-add it into the live residual stream, so the pending output - has to arrive already summed into the prefix with `delta` left None. - """ + has to arrive already summed into the prefix with `delta` left None.""" _set_last_rank(monkeypatch, True) prefix_sum = torch.tensor([1.0, 2.0]) pending = torch.tensor([0.5, 0.25]) diff --git a/tests/models/kimi_k3/test_kda_metadata.py b/tests/models/kimi_k3/test_kda_metadata.py index 5dad5754b6..fa810217b1 100644 --- a/tests/models/kimi_k3/test_kda_metadata.py +++ b/tests/models/kimi_k3/test_kda_metadata.py @@ -727,8 +727,7 @@ def test_cudagraph_capture_metadata_avoids_device_to_host_copy( """`build_for_cudagraph_capture` is not capture-only: a DP rank with nothing scheduled re-stages its FULL-graph metadata through it on every dummy step, so it must not synchronize the device. The host-side draft counts have to - come from `query_start_loc_cpu` and match the device-derived values. - """ + come from `query_start_loc_cpu` and match the device-derived values.""" num_speculative_tokens = 2 batch = BatchSpec(seq_lens=[50, 30], query_lens=[3, 3]) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") diff --git a/tests/models/language/generation/test_gemma.py b/tests/models/language/generation/test_gemma.py index 307a572afd..c2c8e88e42 100644 --- a/tests/models/language/generation/test_gemma.py +++ b/tests/models/language/generation/test_gemma.py @@ -60,8 +60,7 @@ def test_checkpoint_lm_head_can_override_tied_config(monkeypatch) -> None: def test_gemma4_kv_shared_layer_loads_plain_q_proj() -> None: """KV-shared layers have q_proj instead of a packed qkv_proj; their redundant K/V tensors in original checkpoints have no parameter and are - skipped rather than failing the load. - """ + skipped rather than failing the load.""" model = torch.nn.Module() model.config = SimpleNamespace(num_experts=0) model.start_layer, model.end_layer = 0, 2 @@ -93,8 +92,7 @@ def test_gemma4_kv_shared_layer_loads_plain_q_proj() -> None: @pytest.mark.cpu_test def test_gemma3n_kv_shared_layer_mapper() -> None: """Only non-shared layers pack q/k/v into qkv_proj; KV-shared layers keep - q_proj and drop the redundant K/V tensors original checkpoints ship. - """ + q_proj and drop the redundant K/V tensors original checkpoints ship.""" config = SimpleNamespace(num_hidden_layers=4, num_kv_shared_layers=2) mapper = Gemma3nTextModel.hf_to_vllm_mapper | _kv_sharing_weights_mapper(config) weights = [ diff --git a/tests/models/language/generation/test_mistral.py b/tests/models/language/generation/test_mistral.py index a21c5c355a..fc774bc6e8 100644 --- a/tests/models/language/generation/test_mistral.py +++ b/tests/models/language/generation/test_mistral.py @@ -274,8 +274,7 @@ def test_mistral_function_calling(vllm_runner, model: str, dtype: str) -> None: def test_mistral_function_call_nested_json(): """Ensure that the function-name regex captures the entire outermost - JSON block, including nested braces. - """ + JSON block, including nested braces.""" # Create a minimal stub tokenizer that provides the few attributes the # parser accesses (`version` and `get_vocab`). diff --git a/tests/models/language/pooling/test_splade_sparse_pooler.py b/tests/models/language/pooling/test_splade_sparse_pooler.py index d470637477..0b3561f90f 100644 --- a/tests/models/language/pooling/test_splade_sparse_pooler.py +++ b/tests/models/language/pooling/test_splade_sparse_pooler.py @@ -29,8 +29,7 @@ from vllm.v1.worker.gpu.states import RequestState @torch.inference_mode def test_splade_pooler_matches_reference_formula(B, T, H, V): """Ensure SPLADESparsePooler forward() matches the mathematical formula: - log1p(relu(logits)) -> max over sequence length (after masking). - """ + log1p(relu(logits)) -> max over sequence length (after masking).""" torch.manual_seed(0) # Prepare [B] sequences of shape [T, H] diff --git a/tests/models/multimodal/generation/test_moondream3_moe.py b/tests/models/multimodal/generation/test_moondream3_moe.py index 41654d4a72..79d1862765 100644 --- a/tests/models/multimodal/generation/test_moondream3_moe.py +++ b/tests/models/multimodal/generation/test_moondream3_moe.py @@ -33,8 +33,7 @@ NUM_TOKENS = 3 class _StubGate(torch.nn.Module): """Router stand-in, so the test does not depend on platform-specific - ``ReplicatedLinear`` weight post-processing. - """ + ``ReplicatedLinear`` weight post-processing.""" def __init__(self, hidden_size: int, num_experts: int): super().__init__() diff --git a/tests/models/multimodal/generation/test_transformers_audio.py b/tests/models/multimodal/generation/test_transformers_audio.py index 11ed8e5178..9195579877 100644 --- a/tests/models/multimodal/generation/test_transformers_audio.py +++ b/tests/models/multimodal/generation/test_transformers_audio.py @@ -81,8 +81,7 @@ def test_transformers_audio_generation( under pytest can cause (possibly flaky) hangs, so they are grouped under the same config. Using VLLM_WORKER_MULTIPROC_METHOD=spawn avoids the deadlock and allows worker processes to terminate cleanly, and release - GPU memory between test runs until the issue is fixed. - """ + GPU memory between test runs until the issue is fixed.""" # TODO: Remove monkeypatch once # https://github.com/vllm-project/vllm/issues/17676 is fixed. disable_envs_cache() diff --git a/tests/models/multimodal/generation/vlm_utils/builders.py b/tests/models/multimodal/generation/vlm_utils/builders.py index 1f4783473d..1b7e2347be 100644 --- a/tests/models/multimodal/generation/vlm_utils/builders.py +++ b/tests/models/multimodal/generation/vlm_utils/builders.py @@ -294,8 +294,7 @@ def sample_frames_with_video_metadata( def apply_image_size_scaling(image, size: float | tuple[int, int], size_type: SizeType): """Applies a size scaler to one image; this can be an image size factor, - which scales the image while maintaining the aspect ratio - """ + which scales the image while maintaining the aspect ratio""" # Special case for embeddings; if it's a tensor, it's only valid if we # are considering size factors at constant scale, i.e., we just clone # the tensor diff --git a/tests/models/multimodal/processing/test_deepseek_ocr.py b/tests/models/multimodal/processing/test_deepseek_ocr.py index 1851244be0..2bcf5e05d3 100644 --- a/tests/models/multimodal/processing/test_deepseek_ocr.py +++ b/tests/models/multimodal/processing/test_deepseek_ocr.py @@ -108,8 +108,7 @@ class TestDeepseekOCREmptyImagesCrop: def test_mismatched_image_size_raises(self, processor): """Deliberately wrong image_size binding should still be caught - by TensorSchema validation. - """ + by TensorSchema validation.""" small_image = Image.new("RGB", (100, 100), color="green") result = processor( @@ -143,8 +142,7 @@ class TestDeepseekOCRInputValidation: def test_mismatched_image_count_raises_value_error(self, processor): """Two ```` tokens with one image must raise ValueError, not AssertionError (which would yield HTTP 500 and, under ``-O``, silently - drop the middle text segment). - """ + drop the middle text segment).""" image = Image.new("RGB", (100, 100), color="red") with pytest.raises(ValueError, match="does not match number of images"): processor(prompt=" and ", images=[image]) diff --git a/tests/models/multimodal/processing/test_llava_next_video.py b/tests/models/multimodal/processing/test_llava_next_video.py index 512440ee8e..c4fdecd21a 100644 --- a/tests/models/multimodal/processing/test_llava_next_video.py +++ b/tests/models/multimodal/processing/test_llava_next_video.py @@ -16,8 +16,7 @@ from ...utils import build_model_context class _StubModel: """Carries only the attributes the token-count method reads from `self`, so the real methods can be exercised without constructing - the full `nn.Module` (vision tower, language model, etc.). - """ + the full `nn.Module` (vision tower, language model, etc.).""" patch_grid_length: int pooled_grid_length: int @@ -32,8 +31,7 @@ get_mm_lora_token_counts = ( def test_num_mm_tokens_match_real_config(model_id): """The stored grid lengths must match what `__init__` derives from the real HF config, and the LoRA token counts must preserve the - frame-level scaling exactly. - """ + frame-level scaling exactly.""" ctx = build_model_context(model_id, limit_mm_per_prompt={"video": 1}) config = ctx.model_config.hf_config diff --git a/tests/models/multimodal/processing/test_molmo2.py b/tests/models/multimodal/processing/test_molmo2.py index 98ad241650..5633d47a97 100644 --- a/tests/models/multimodal/processing/test_molmo2.py +++ b/tests/models/multimodal/processing/test_molmo2.py @@ -70,8 +70,7 @@ def test_dummy_video_num_frames_override_honors_min_of_two( ): """A ``num_frames`` override below 2 must be ignored (the model needs at least 2 frames), matching the "cannot be less than 2, will be ignored" - warning. - """ + warning.""" builder = object.__new__(Molmo2DummyInputsBuilder) builder.info = SimpleNamespace( get_hf_processor=lambda: SimpleNamespace( diff --git a/tests/models/multimodal/processing/test_qwen3_vl.py b/tests/models/multimodal/processing/test_qwen3_vl.py index 47071c2f1b..c58904a9e2 100644 --- a/tests/models/multimodal/processing/test_qwen3_vl.py +++ b/tests/models/multimodal/processing/test_qwen3_vl.py @@ -31,8 +31,7 @@ def _build_video_mm_data( ``total_num_frames`` is set equal to the ndarray frame count so that HF's ``sample_frames`` indices stay within bounds of the - actual tensor that is passed. - """ + actual tensor that is passed.""" video = np.zeros((num_frames, height, width, 3), dtype=np.uint8) metadata = { "fps": original_fps, @@ -238,8 +237,7 @@ def _build_video_embeds_mm_data( grid_thw: tuple[int, int, int] = (2, 4, 4), ) -> dict[str, Any]: """Create an embeds-only video item as an EPD consumer receives it: - pre-computed embeddings plus the metadata published by the encoder. - """ + pre-computed embeddings plus the metadata published by the encoder.""" import torch t, h, w = grid_thw @@ -258,8 +256,7 @@ def test_processor_video_embeds_with_timestamps(model_id: str) -> None: """Embeds-only video input must size the placeholder range from the grid and the real timestamps published by the encoder (EC consumer path); synthesized or missing timestamps would change the token count - and break embedding merging downstream. - """ + and break embedding merging downstream.""" # `build_model_context` forces enable_mm_embeds off, so build the # config directly; keep the same online-availability skip behavior. HF_EXAMPLE_MODELS.find_hf_info(model_id).check_available_online(on_fail="skip") @@ -304,8 +301,7 @@ def test_processor_video_embeds_with_timestamps(model_id: str) -> None: def test_processor_video_embeds_missing_timestamps(model_id: str) -> None: """Timestamps are required metadata for video embeds: they size the placeholder range, so omitting them must fail loudly at parse time - instead of silently producing a wrong prompt. - """ + instead of silently producing a wrong prompt.""" ctx = build_model_context( model_id, limit_mm_per_prompt={"image": 0, "video": 1}, diff --git a/tests/models/multimodal/processing/test_transformers_audio.py b/tests/models/multimodal/processing/test_transformers_audio.py index 14007c8740..61517ea0af 100644 --- a/tests/models/multimodal/processing/test_transformers_audio.py +++ b/tests/models/multimodal/processing/test_transformers_audio.py @@ -116,8 +116,7 @@ def test_audio_multimodal_processor(model_id, processor_cls): @pytest.mark.parametrize("separator", [" and ", ""]) def test_audio_multiple_inputs(separator, processor_cls): """Multiple audios per prompt are each detected as a separate placeholder - and multi-modal item by the Transformers modelling backend. - """ + and multi-modal item by the Transformers modelling backend.""" model_id = "ibm-granite/granite-speech-3.3-2b" mm_processor = create_processor(model_id, processor_cls) diff --git a/tests/models/multimodal/processing/test_transformers_image.py b/tests/models/multimodal/processing/test_transformers_image.py index 731794da26..f5de7d66f4 100644 --- a/tests/models/multimodal/processing/test_transformers_image.py +++ b/tests/models/multimodal/processing/test_transformers_image.py @@ -83,8 +83,7 @@ def _process_two_images(processor_cls, separator: str): @pytest.mark.parametrize("processor_cls", PROCESSOR_CLASSES) def test_image_multiple_inputs(processor_cls): """Multiple images per prompt are each detected as a separate placeholder - and multi-modal item by the Transformers modelling backend. - """ + and multi-modal item by the Transformers modelling backend.""" result = _process_two_images(processor_cls, separator="\n and ") assert len(result["mm_placeholders"]["image"]) == 2 @@ -103,8 +102,7 @@ def test_image_adjacent_inputs(processor_cls): @pytest.mark.parametrize("processor_cls", PROCESSOR_CLASSES) def test_batch_padding_removed_from_image_items(processor_cls): """Emu3 pads every image up to the largest in the batch, which would leave an - item's data dependent on what it was processed with and so uncacheable. - """ + item's data dependent on what it was processed with and so uncacheable.""" mm_processor = create_processor("BAAI/Emu3-Chat-hf", processor_cls) image_token = mm_processor.info.get_hf_processor().image_token @@ -146,8 +144,7 @@ def _process_one_gemma3_image(processor_cls): @offsets_only def test_non_embedding_tokens_excluded_from_placeholders(): """Gemma3 wraps each image in text that carries no embeddings, which must be - inside the placeholder range but masked out of it. - """ + inside the placeholder range but masked out of it.""" _, result = _process_one_gemma3_image(OffsetsMultiModalProcessor) (placeholder,) = result["mm_placeholders"]["image"] @@ -159,8 +156,7 @@ def test_legacy_placeholders_hold_only_image_tokens(): """The legacy path spans whatever `mm_token_type_ids` attributes to the image, which for Gemma3 excludes the text wrapping it, unlike the replacement the offsets path spans. Gemma3 is also the sharp case for the mask: its `image_token_id` is the - marker in the unexpanded prompt, not the token the expansion repeats. - """ + marker in the unexpanded prompt, not the token the expansion repeats.""" hf_processor, result = _process_one_gemma3_image(LegacyMultiModalProcessor) (placeholder,) = result["mm_placeholders"]["image"] @@ -176,8 +172,7 @@ def test_tokens_structuring_an_image_are_masked_not_dropped(processor_cls): embeddings. Those belong inside the placeholder and masked out, because the token count the processor reports is over the whole span. Idefics3 also refuses a prompt holding `` when no images are passed, which is how the offsets path has to - tokenize it before splicing in the expansion. - """ + tokenize it before splicing in the expansion.""" mm_processor = create_processor( "HuggingFaceTB/SmolVLM-256M-Instruct", processor_cls ) @@ -197,8 +192,7 @@ def test_tokens_structuring_an_image_are_masked_not_dropped(processor_cls): @offsets_only def test_missing_replacement_offsets_names_the_processor(): """A processor that reports no replacement offsets cannot be served, which must - be said plainly rather than surfacing later as a field config mismatch. - """ + be said plainly rather than surfacing later as a field config mismatch.""" model_id = "llava-hf/llava-onevision-qwen2-0.5b-ov-hf" mm_processor = create_processor(model_id, OffsetsMultiModalProcessor) hf_processor_cls = type(mm_processor.info.get_hf_processor()) @@ -282,8 +276,7 @@ def test_repeated_image_hits_the_processor_cache(): def test_spliced_prompt_matches_hf_expansion(model_id, prompt): """The offsets path splices the expansion into a prompt tokenized without any multi-modal data, so its token ids have to come out the same as the ones the HF - processor produces itself, which is what the legacy path returns. - """ + processor produces itself, which is what the legacy path returns.""" prompt_ids = [] for processor_cls in (LegacyMultiModalProcessor, OffsetsMultiModalProcessor): mm_processor = create_processor(model_id, processor_cls) @@ -305,8 +298,7 @@ def test_spliced_prompt_matches_hf_expansion(model_id, prompt): def test_nested_image_fields_split_per_image(processor_cls): """Idefics3 returns image fields with a leading batch dimension, putting the rows belonging to each image one dimension further in. Slicing the batch dimension - instead handed the first image every row and the second an empty tensor. - """ + instead handed the first image every row and the second an empty tensor.""" mm_processor = create_processor( "HuggingFaceTB/SmolVLM-256M-Instruct", processor_cls ) diff --git a/tests/models/multimodal/processing/transformers_backend.py b/tests/models/multimodal/processing/transformers_backend.py index d748e89f20..dc49036e83 100644 --- a/tests/models/multimodal/processing/transformers_backend.py +++ b/tests/models/multimodal/processing/transformers_backend.py @@ -29,8 +29,7 @@ PROCESSOR_CLASSES = [ def create_processor(model_id: str, processor_cls): """Build a processor directly, because the registry only ever builds the one the - installed transformers version selects, leaving the other path untested. - """ + installed transformers version selects, leaving the other path untested.""" model_config = ModelConfig(model=model_id, model_impl="transformers") ctx = InputProcessingContext( model_config, cached_tokenizer_from_config(model_config) @@ -41,8 +40,7 @@ def create_processor(model_id: str, processor_cls): def create_cached_processor(model_id: str, processor_cls): """Build a processor backed by a real multi-modal processor cache, and hand the - cache back so a test can check it was actually used. - """ + cache back so a test can check it was actually used.""" model_config = ModelConfig(model=model_id, model_impl="transformers") model_config.multimodal_config.mm_processor_cache_gb = 4 ctx = InputProcessingContext( diff --git a/tests/models/multimodal/test_cohere_asr.py b/tests/models/multimodal/test_cohere_asr.py index a9c45f8405..85a9b59dd5 100644 --- a/tests/models/multimodal/test_cohere_asr.py +++ b/tests/models/multimodal/test_cohere_asr.py @@ -18,8 +18,7 @@ from vllm.model_executor.models.cohere_asr import CohereAsrForConditionalGenerat def test_get_num_audio_tokens_streaming_estimate(audio_duration_s, expected_tokens): """The duration-based estimate must convert ``window_stride`` (seconds) to a sample hop and divide by the encoder subsampling factor. Values are pinned to - concrete numbers so a rounding regression is actually caught. - """ + concrete numbers so a rounding regression is actually caught.""" model_config = SimpleNamespace( hf_config=SimpleNamespace( preprocessor={"window_stride": 0.01, "sample_rate": 16000}, diff --git a/tests/models/multimodal/test_mapping.py b/tests/models/multimodal/test_mapping.py index a167fe205d..95d6091421 100644 --- a/tests/models/multimodal/test_mapping.py +++ b/tests/models/multimodal/test_mapping.py @@ -78,8 +78,7 @@ def test_cosmos3_modelopt_quantizer_weights_mapper(): """ModelOpt/Diffusers FP8 checkpoints ship native fake-quant buffers (``*_quantizer._amax`` / ``._scale``) alongside the vLLM-consumable ``weight_scale`` / ``input_scale`` sidecars. vLLM must drop the former - (it has no parameter for them) while keeping the latter. - """ + (it has no parameter for them) while keeping the latter.""" from vllm.model_executor.models.cosmos3 import Cosmos3ForConditionalGeneration mapper = Cosmos3ForConditionalGeneration.hf_to_vllm_mapper diff --git a/tests/models/multimodal/test_nano_nemotron_vl.py b/tests/models/multimodal/test_nano_nemotron_vl.py index c64073ffe2..75900cde53 100644 --- a/tests/models/multimodal/test_nano_nemotron_vl.py +++ b/tests/models/multimodal/test_nano_nemotron_vl.py @@ -81,8 +81,7 @@ class _FakeTensor: """Sentinel stand-in for torch.Tensor in load_weights tests. Supports the .detach().clone() chain used by load_weights for buffered mm weights; both methods return self so identity (and the existing equality - assertions) are preserved through cloning. - """ + assertions) are preserved through cloning.""" def detach(self): return self @@ -166,8 +165,7 @@ def _make_mm_items_with_video_bytes( def test_extract_audio_from_videos_passes_max_duration(): """_extract_audio_from_videos must forward VLLM_MAX_AUDIO_DECODE_DURATION_S - to load_audio_pyav so decompression-bomb audio is rejected. - """ + to load_audio_pyav so decompression-bomb audio is rejected.""" dummy_audio = (np.zeros(16000, dtype=np.float32), 16000.0) mm_items = _make_mm_items_with_video_bytes(b"\x00" * 64) @@ -187,8 +185,7 @@ def test_extract_audio_from_videos_passes_max_duration(): def test_extract_audio_from_videos_rejects_oversized_audio(): """When load_audio_pyav raises due to duration limit the video is - marked as having no audio instead of crashing the server. - """ + marked as having no audio instead of crashing the server.""" mm_items = _make_mm_items_with_video_bytes(b"\x00" * 64) processor = object.__new__(NanoNemotronVLMultiModalProcessor) diff --git a/tests/models/qwen4_exp/test_config.py b/tests/models/qwen4_exp/test_config.py index c5ed11d0c6..9d30365b81 100644 --- a/tests/models/qwen4_exp/test_config.py +++ b/tests/models/qwen4_exp/test_config.py @@ -144,8 +144,7 @@ def test_qwen4_exp_mtp_override_sets_draft_config( def test_qwen4_exp_rejects_pipeline_parallel_only_with_ple(ple_layer_ids) -> None: """PLE needs raw input_ids, which non-first pipeline ranks never see. The rest of the architecture is PP-capable, so the refusal must be conditional - -- and must land before the engine spends time loading weights. - """ + -- and must land before the engine spends time loading weights.""" vllm_config = SimpleNamespace( model_config=SimpleNamespace( hf_text_config=_text_config(ple_layer_ids=ple_layer_ids), diff --git a/tests/models/test_deepseek_v4_fi_moe_ep.py b/tests/models/test_deepseek_v4_fi_moe_ep.py index 7007eb5aca..99d661e755 100644 --- a/tests/models/test_deepseek_v4_fi_moe_ep.py +++ b/tests/models/test_deepseek_v4_fi_moe_ep.py @@ -103,8 +103,7 @@ def test_fi_backend_strings_are_registered_mega_moe_backends(): @pytest.mark.parametrize("moe_backend", sorted(FLASHINFER_MOE_EP_BACKENDS)) def test_fi_moe_ep_backend_rejected_for_non_dsv4(moe_backend): """An FI moe_ep backend with a non-DSv4 model must fail at config time - instead of silently falling through to the generic FusedMoE path. - """ + instead of silently falling through to the generic FusedMoE path.""" with pytest.raises(ValueError, match="only supported for DeepSeek-V4"): validate_flashinfer_moe_ep_model(moe_backend, ["MixtralForCausalLM"]) @@ -120,8 +119,7 @@ def test_fi_moe_ep_backend_accepted_for_dsv4(moe_backend): ) def test_native_deep_gemm_mega_moe_not_arch_gated(architectures): """VLLM's own deep_gemm mega path is not DSv4-only (Kimi K3 uses it); - models validate their own constraints at construction time. - """ + models validate their own constraints at construction time.""" validate_flashinfer_moe_ep_model("deep_gemm_mega_moe", architectures) @@ -134,8 +132,7 @@ def test_all_mega_backends_get_sequence_parallel_moe(moe_backend): """Every mega backend must qualify for sequence-parallel MoE at TP>1/EP: the predicate once matched only the native backend string, which silently ran the fi backends full-batch with an all-reduce on - every rank — 0.42-0.65x native e2e at TP8. - """ + every rank — 0.42-0.65x native e2e at TP8.""" from vllm.models.deepseek_v4.nvidia.model import _use_sequence_parallel vllm_config = SimpleNamespace( @@ -179,8 +176,7 @@ def test_bootstrap_pins_the_device_vllm_bound(fake_flashinfer, monkeypatch): """The runtime must not rederive the device from LOCAL_RANK/rank: under a remapped CUDA_VISIBLE_DEVICES that ordinal points at the wrong GPU (CUDA_ERROR_ILLEGAL_ADDRESS in the weight transforms). vLLM passes the - device it already bound via BootstrapConfig.device. - """ + device it already bound via BootstrapConfig.device.""" import vllm.utils.flashinfer_moe_ep as mod pg = object() @@ -245,8 +241,7 @@ def test_ckpt_uses_nvfp4_experts_reads_moe_quant_algo(): def test_dequant_fp4_ue8m0_gran32_decodes_lut_and_scales(): """One 32-element scale group per row: low nibble is the even element, - high nibble the odd one, ue8m0 scale applies to the whole group. - """ + high nibble the odd one, ue8m0 scale applies to the whole group.""" packed = torch.arange(32, dtype=torch.uint8).reshape(2, 16) sf = torch.tensor([[127], [128]], dtype=torch.uint8) # 2**0, 2**1 diff --git a/tests/models/test_deepseek_v4_mega_moe.py b/tests/models/test_deepseek_v4_mega_moe.py index 31aad5395f..9a5723d233 100644 --- a/tests/models/test_deepseek_v4_mega_moe.py +++ b/tests/models/test_deepseek_v4_mega_moe.py @@ -783,8 +783,7 @@ def test_deepseek_v4_mega_moe_stages_shared_scale_tma_layout(shared_block_m): def test_deepseek_v4_pwal_hook_finalizes_mega_moe_and_mhc_broadcast(): """The loader invokes the model-level PWAL hook for every load format, so it must finalize megamoe + mhc broadcast weights to cover dummy - load, which skips load_weights(). - """ + load, which skips load_weights().""" calls = [] stub = SimpleNamespace( model=SimpleNamespace( @@ -801,8 +800,7 @@ def test_deepseek_v4_pwal_hook_finalizes_mega_moe_and_mhc_broadcast(): def test_deepseek_v4_drafter_pwal_hooks_finalize_mega_moe(): """MTP/DSpark drafters load as their own top-level models, so each needs its own PWAL hook now that the megamoe forward no longer finalizes - weights lazily on first use. - """ + weights lazily on first use.""" calls = [] mtp = SimpleNamespace(finalize_mega_moe_weights=lambda: calls.append("mtp")) DeepSeekV4MTP.process_weights_after_loading(mtp) diff --git a/tests/models/test_dspark_mla.py b/tests/models/test_dspark_mla.py index ee381ee36b..d30eb9e7c9 100644 --- a/tests/models/test_dspark_mla.py +++ b/tests/models/test_dspark_mla.py @@ -215,8 +215,7 @@ def test_v41_dspark_loads_linear_scales( ): """Checkpoint ``.scale`` maps to the quant method's scale parameter and loads untouched. MXFP8 block-scale expansion lives in the KMxfp8Static - loader (see tests/quantization/test_modelopt.py), not in load_weights. - """ + loader (see tests/quantization/test_modelopt.py), not in load_weights.""" from vllm.models.deepseek_v41.nvidia import dspark mxfp8 = scale_dtype != torch.float32 diff --git a/tests/models/test_qwen3_5_mtp_config.py b/tests/models/test_qwen3_5_mtp_config.py index 3c098d3ad5..6cf54dbc95 100644 --- a/tests/models/test_qwen3_5_mtp_config.py +++ b/tests/models/test_qwen3_5_mtp_config.py @@ -73,8 +73,7 @@ def test_mtp_override_extracts_n_predict_from_multimodal_wrapper( model_type: str, expected_arch: str ) -> None: """Verify that multimodal wrapper checkpoints with mtp_num_hidden_layers - in text_config resolve n_predict and architecture correctly. - """ + in text_config resolve n_predict and architecture correctly.""" cfg = SpeculativeConfig.hf_config_override( _multimodal_wrapper_mtp_config(model_type, mtp_layers=2) ) @@ -94,8 +93,7 @@ def test_mtp_override_top_level_precedence_over_nested_text_config( model_type: str, expected_arch: str ) -> None: """Verify that an explicit top-level mtp_num_hidden_layers takes precedence - over a nested text_config value. - """ + over a nested text_config value.""" cfg = _multimodal_wrapper_mtp_config(model_type, mtp_layers=2) cfg.mtp_num_hidden_layers = 3 overridden = SpeculativeConfig.hf_config_override(cfg) @@ -115,8 +113,7 @@ def test_mtp_override_downloads_real_hf_hub_configs( model_id: str, expected_arch: str ) -> None: """Verify that unmodified real-world checkpoints downloaded via - AutoConfig.from_pretrained resolve n_predict=1 from text_config. - """ + AutoConfig.from_pretrained resolve n_predict=1 from text_config.""" hf_config = AutoConfig.from_pretrained(model_id) cfg = SpeculativeConfig.hf_config_override(hf_config) assert cfg.model_type == "qwen3_5_mtp" diff --git a/tests/models/test_utils.py b/tests/models/test_utils.py index f9e7d69176..02903504c6 100644 --- a/tests/models/test_utils.py +++ b/tests/models/test_utils.py @@ -197,8 +197,7 @@ def test_merge_multimodal_embeddings_no_sync(): def test_get_rename_mapper_keeps_only_renames(): """`None` means "do not load", which is meaningless to the consumers of this mapper (LoRA name parsing, quantization config layer lists), and - applying it would silently shrink their lists. - """ + applying it would silently shrink their lists.""" mapper = WeightsMapper( orig_to_new_regex={re.compile(r"^drop_regex\."): None}, orig_to_new_substr={"drop_substr": None, "keep_substr": "kept"}, diff --git a/tests/models/test_vision.py b/tests/models/test_vision.py index b08661abc9..94edce45bf 100644 --- a/tests/models/test_vision.py +++ b/tests/models/test_vision.py @@ -512,8 +512,7 @@ def _reference_input_norm( def test_fused_input_norm_matches_reference(num_patches: int): """FusedInputNorm must equal the plain affine, including for num_patches above the cuDNN batch-norm grid limit (~65535) that previously raised - CUDNN_STATUS_INTERNAL_ERROR (issue #51717). - """ + CUDNN_STATUS_INTERNAL_ERROR (issue #51717).""" channel = 3 patch_size = 14 * 14 image_mean = [0.48145466, 0.4578275, 0.40821073] diff --git a/tests/models/transformers/fusers/test_linear.py b/tests/models/transformers/fusers/test_linear.py index d26d742dd3..bcad62765a 100644 --- a/tests/models/transformers/fusers/test_linear.py +++ b/tests/models/transformers/fusers/test_linear.py @@ -251,8 +251,7 @@ class UnderscoreInplaceParallelLinears(FourParallelLinears): class PlainQKV(nn.Module): """q/k/v returned as a bare tuple: no reshape stands between the calls and - the return, so both QKVFuser and MergedColumnParallelFuser can rewrite it. - """ + the return, so both QKVFuser and MergedColumnParallelFuser can rewrite it.""" def __init__(self, hidden: int = 32, heads: int = 4, head_dim: int = 8): super().__init__() @@ -339,8 +338,7 @@ class GuardedVAttention(FakeAttention): """Gemma 4-style: `v_proj` is called once but also read in a `None` guard. The guard is a fusion invariant (the fuser only binds instances where the - projection exists), so it folds to `True` and the call still fuses. - """ + projection exists), so it folds to `True` and the call still fuses.""" def forward( self, hidden_states, attention_mask=None, past_key_values=None, **kwargs @@ -370,8 +368,7 @@ class TruthyGuardAttention(FakeAttention): An `nn.Linear` is always truthy, so the guard folds to `True` and the call still fuses (the projection is a proven invariant, exactly as for a `None` - guard). - """ + guard).""" def forward( self, hidden_states, attention_mask=None, past_key_values=None, **kwargs @@ -402,8 +399,7 @@ class StatementGuardVAttention(FakeAttention): The `if`'s test is not an `ast.Compare`, so the identity-check scan skips it; `_in_boolean_context` folds the test to `True` (an `nn.Linear` is always truthy) and the call inside the now-`if True:` body still fuses, with the - live `else` surviving the rewrite. - """ + live `else` surviving the rewrite.""" def forward( self, hidden_states, attention_mask=None, past_key_values=None, **kwargs @@ -432,8 +428,7 @@ class BranchedKVAttention(FakeAttention): The three calls do not share a block, so the fused GEMM must be hoisted to the innermost block that dominates all of them (the function body). The - live `if`/`else` must survive the rewrite. - """ + live `if`/`else` must survive the rewrite.""" is_kv_shared_layer = False @@ -464,8 +459,7 @@ class RebindArgAttention(FakeAttention): The branch is dead at trace time so the match succeeds, but the source rewrite must refuse: hoisting the GEMM above the rebind would feed k/v a - different input. Result: no fusion. - """ + different input. Result: no fusion.""" recompute = False @@ -496,8 +490,7 @@ class InPlaceMutatedArgAttention(FakeAttention): Like `RebindArgAttention`, but the mutation keeps the name in a `Load` context (`hidden_states.mul_(2)`), so a bare `Name`-store check would miss it. The rewrite must still refuse: hoisting the GEMM above the mutation changes - the value k/v see. Result: no fusion. - """ + the value k/v see. Result: no fusion.""" recompute = False @@ -527,8 +520,7 @@ class AliasMutatedArgAttention(FakeAttention): `hidden_states.view(-1)` shares storage with its base, so `alias.mul_(2)` changes what k/v read without ever naming `hidden_states` as a target. Only - tracking names that may alias the input catches it. Result: no fusion. - """ + tracking names that may alias the input catches it. Result: no fusion.""" recompute = False @@ -559,8 +551,7 @@ class FunctionalInplaceArgAttention(FakeAttention): `F.relu(hidden_states, inplace=True)` writes through an argument, so the name appears only in a `Load` context inside a call that is not a method on - it -- invisible to a trailing-underscore method check. Result: no fusion. - """ + it -- invisible to a trailing-underscore method check. Result: no fusion.""" recompute = False @@ -590,8 +581,7 @@ class SubscriptMutatedArgAttention(FakeAttention): `hidden_states[..., 0] = 0` leaves the name in a `Load` context on the subscript's value, so it too evades a bare `Name`-store check. The rewrite - must refuse for the same reason. Result: no fusion. - """ + must refuse for the same reason. Result: no fusion.""" recompute = False @@ -621,8 +611,7 @@ class NonFoldableRefAttention(FakeAttention): Deleting `v_proj` would break `isinstance(self.v_proj, nn.Linear)`: it reads the projection's type, not just whether it exists, so the fuser cannot fold - it and must refuse rather than rewrite it. - """ + it and must refuse rather than rewrite it.""" def forward( self, hidden_states, attention_mask=None, past_key_values=None, **kwargs @@ -847,8 +836,7 @@ def test_glu_identifies_down_projection(): It is forced to `RowParallelLinear` in `update_attrs` so its sharded input matches the column-parallel merged gate/up; `None` when there is no such - projection to force (fusion of gate/up still applies). - """ + projection to force (fusion of gate/up still applies).""" with torch.device("meta"): assert get_fuser(GLUMLP(), GLUFuser).down_name == "down_proj" assert get_fuser(ReversedGLUMLP(), GLUFuser).down_name == "down_proj" @@ -1009,8 +997,7 @@ def test_bypass_existence_guard_folds_identity_none_check(expr, expected): The projection is a proven invariant (it exists as an `nn.Linear`), so an `is (not) None` guard has a constant truth value; folding it lets the call be rewritten away without changing the guard's outcome. `==`/`!=` are excluded - (see the refusal test) because a subclass may override `__eq__`/`__ne__`. - """ + (see the refusal test) because a subclass may override `__eq__`/`__ne__`.""" funcdef, ref = _guard_funcdef(expr) bypass_existence_guard(funcdef, ref, "v_proj") test = next(node for node in ast.walk(funcdef) if isinstance(node, ast.IfExp)).test @@ -1029,8 +1016,7 @@ def test_bypass_existence_guard_folds_bare_truthiness(expr): An `nn.Linear` has no `__bool__`/`__len__`, so it is always truthy; in a pure boolean position (a test, or a `not` operand) the reference can be replaced by - `True`, letting the projection be deleted. - """ + `True`, letting the projection be deleted.""" funcdef, ref = _guard_funcdef(expr) bypass_existence_guard(funcdef, ref, "v_proj") # No `self.v_proj` reference survives; a literal `True` took its place. @@ -1045,8 +1031,7 @@ def test_bypass_existence_guard_folds_bare_if_statement(): The `len(node.ops) == 1` `Compare` scan skips it (it is not a comparison at all); `_in_boolean_context` then matches the `if`'s test and folds it, so the - bare-truthiness statement form is handled, not silently dropped. - """ + bare-truthiness statement form is handled, not silently dropped.""" funcdef = ast.parse( "def f(self, a, b):\n if self.v_proj:\n return a\n return b" ).body[0] @@ -1078,8 +1063,7 @@ def test_bypass_existence_guard_refuses_non_guard_reference(expr): Rewriting it is unsafe (its value depends on more than the projection's existence), so the fuser refuses rather than change semantics. `==`/`!=` are refused too: `is_linear` accepts `nn.Linear` subclasses that could override - `__eq__`/`__ne__`, so equality need not agree with `is (not) None`. - """ + `__eq__`/`__ne__`, so equality need not agree with `is (not) None`.""" funcdef, ref = _guard_funcdef(expr) with pytest.raises(ValueError, match="outside an existence guard"): bypass_existence_guard(funcdef, ref, "v_proj") @@ -1119,8 +1103,7 @@ def test_merged_column_fuser_folds_existence_guard(): Guard folding lives on `StackedFuser`, not just `QKVFuser`, because every stacked fuser deletes the projections it merges -- a surviving reference to - one would fail at runtime. - """ + one would fail at runtime.""" with torch.device("meta"): module = GuardedParallelLinears() fuser = MergedColumnParallelFuser.match(trace(module), module) @@ -1146,8 +1129,7 @@ def test_merged_column_fuser_rejects_input_mutation(cls): The mutation may be direct (`x.add_(1)`), through a view that shares the input's storage, or through a call that writes an argument in place (`F.relu(x, inplace=True)`, `torch.relu_(x)`). Each one silently changes the - fused result, so the rewrite must refuse rather than fuse. - """ + fused result, so the rewrite must refuse rather than fuse.""" with torch.device("meta"): module = cls() fuser = MergedColumnParallelFuser.match(trace(module), module) @@ -1205,8 +1187,7 @@ def test_merged_column_fuser_supports_any_number_of_linears( def test_merged_name_is_unique_per_linear_names(): """The computed name must not collide across different projections, so - stacking two unrelated fusions can never clobber packed_modules_mapping. - """ + stacking two unrelated fusions can never clobber packed_modules_mapping.""" ab_c = MergedColumnParallelFuser(source_cls="M", linear_names=("a_b", "c")) a_bc = MergedColumnParallelFuser(source_cls="M", linear_names=("a", "b_c")) assert ab_c.merged_name != a_bc.merged_name @@ -1222,8 +1203,7 @@ def test_heterogeneous_instances_fall_back_to_merged_column_fuser( layer whose out_features aren't a multiple of its own head_dim (as a misconfigured or heterogeneous checkpoint might have) fails QKVFuser's validation and must still fuse via the generic fallback, while a - well-formed sibling of the same class keeps using QKVFuser. - """ + well-formed sibling of the same class keeps using QKVFuser.""" with torch.device("meta"): container = nn.Module() container.compatible = PlainQKV(head_dim=8) @@ -1244,8 +1224,7 @@ def test_detects_and_rewrites_packed_qkv(kv_heads): """A single projection split into q/k/v must be re-sharded, not merged. Only the split sizes change: `QKVParallelLinear` loads the packed - checkpoint weight as-is, and shards q by heads while replicating k/v. - """ + checkpoint weight as-is, and shards q by heads while replicating k/v.""" with torch.device("meta"): meta = PackedQKVAttention(kv_heads=kv_heads) fuser = get_fuser(meta, PackedQKVFuser) @@ -1276,8 +1255,7 @@ def test_detects_and_rewrites_packed_qkv(kv_heads): def test_per_head_split_is_not_packed_qkv(): """The split must consume the whole projection, else its sizes are head - widths and re-sharding by them would be wrong. - """ + widths and re-sharding by them would be wrong.""" with torch.device("meta"): assert get_fuser(PerHeadSplitAttention(), PackedQKVFuser) is None @@ -1397,8 +1375,7 @@ def test_act_and_mul_derived_from_module(default_vllm_config): def _wider_model_config(head_dim: int) -> SimpleNamespace: """A model whose global head size is twice `head_dim`, as a wider layer - elsewhere in a heterogeneous checkpoint would make it. - """ + elsewhere in a heterogeneous checkpoint would make it.""" return SimpleNamespace( model_config=SimpleNamespace(get_head_size=lambda: 2 * head_dim), quant_config=None, diff --git a/tests/models/transformers/fusers/test_mla.py b/tests/models/transformers/fusers/test_mla.py index 366123389f..9f51ab5662 100644 --- a/tests/models/transformers/fusers/test_mla.py +++ b/tests/models/transformers/fusers/test_mla.py @@ -45,8 +45,7 @@ def _attention(q_lora_rank: int | None): def _match(q_lora_rank: int | None) -> MLAFuser | None: """Match a meta `DeepseekV2Attention` directly (bypassing the per-class - `get_fuser` cache, so both q_lora variants of the same class are seen). - """ + `get_fuser` cache, so both q_lora variants of the same class are seen).""" attn = _attention(q_lora_rank) return MLAFuser.match(trace(attn), attn) @@ -82,8 +81,7 @@ def test_discovers_modules_with_q_lora(): def test_q_lora_stacks_qkv_a_proj(): """The MLA layer reads `q_a_proj` and `kv_a_proj_with_mqa` fused into one - down-projection, so both checkpoint weights must remap into it. - """ + down-projection, so both checkpoint weights must remap into it.""" fuser = _match(q_lora_rank=64) assert isinstance(fuser, MLAFuser) prefix = "model.layers.0.self_attn" @@ -104,8 +102,7 @@ def test_update_forward_rewrites_real_attention(q_lora_rank): The q-LoRA path hoists the merged down-projection to a top-level statement while its calls sit inside the `q_lora_rank` branches, so the region it spans is wide; a check that over-approximates aliasing would silently refuse - here and cost the fusion rather than fail loudly. - """ + here and cost the fusion rather than fail loudly.""" fuser = _match(q_lora_rank) assert isinstance(fuser, MLAFuser) fuser.update_forward(_attention(q_lora_rank)) @@ -129,8 +126,7 @@ class _Norm(nn.Module): class RenamedMLA(nn.Module): """An MLA-shaped attention whose children have non-standard names, proving - discovery is by structure and not attribute name. - """ + discovery is by structure and not attribute name.""" def __init__(self): super().__init__() @@ -157,8 +153,7 @@ class RenamedMLA(nn.Module): def test_discovers_modules_under_arbitrary_names(): """Discovery is purely structural: `RenamedMLA` gives its children non-standard - names, and `match` still locates each projection by dataflow. - """ + names, and `match` still locates each projection by dataflow.""" with torch.device("meta"): module = RenamedMLA() fuser = MLAFuser.match(trace(module), module) diff --git a/tests/models/transformers/fusers/test_moe.py b/tests/models/transformers/fusers/test_moe.py index a465116920..7de4589eef 100644 --- a/tests/models/transformers/fusers/test_moe.py +++ b/tests/models/transformers/fusers/test_moe.py @@ -277,8 +277,7 @@ def test_moe_fuser_matches_scaled_router(): def test_moe_fuser_matches_grouped_router(): """Group masking between the score and the routing top-k still matches: the - scorer is anchored on the routing (last) top-k, not the group one. - """ + scorer is anchored on the routing (last) top-k, not the group one.""" with torch.device("meta"): block = MoEBlock(GroupedRouter) fuser = MoEBlockFuser.match(block, "experts") @@ -288,8 +287,7 @@ def test_moe_fuser_matches_grouped_router(): def test_moe_fuser_matches_correction_router(): """A score-correction bias buffer (DeepSeek-V3 noaux) is allowed; the - rebuilt gate carries it in fp32 for FusedMoE's biased routers. - """ + rebuilt gate carries it in fp32 for FusedMoE's biased routers.""" with torch.device("meta"): block = MoEBlock(CorrectionRouter) fuser = MoEBlockFuser.match(block, "experts") @@ -300,8 +298,7 @@ def test_moe_fuser_matches_correction_router(): def test_moe_fuser_reads_router_dtype_from_the_gate(): """A router that computes its logits in fp32 must keep routing in fp32 when rebuilt, even though no config field names the dtype. The cast back to the - activation dtype after the top-k must not be mistaken for the routing dtype. - """ + activation dtype after the top-k must not be mistaken for the routing dtype.""" with torch.device("meta"): fp32 = MoEBlockFuser.match(MoEBlock(Fp32Router), "experts") default = MoEBlockFuser.match(MoEBlock(TopKRouter), "experts") @@ -320,8 +317,7 @@ def test_moe_fuser_detects_shared_experts(): def test_moe_fuser_skips_shared_detection_without_extra_children(): """With only experts and gate, shared-expert detection (and its block trace) - is skipped, so a gate-derived add is not misread as a shared expert. - """ + is skipped, so a gate-derived add is not misread as a shared expert.""" with torch.device("meta"): block = MoEBlockNoShared() fuser = MoEBlockFuser.match(block, "experts") @@ -366,8 +362,7 @@ def test_moe_fuser_declines_unsupported(block_cls): def test_moe_fuser_ignores_nested_returns(): """A tuple `return` inside a nested helper must not decline a block whose own - forward returns a single tensor. - """ + forward returns a single tensor.""" with torch.device("meta"): block = MoEBlockNestedTupleReturn() assert isinstance(MoEBlockFuser.match(block, "experts"), MoEBlockFuser) @@ -375,8 +370,7 @@ def test_moe_fuser_ignores_nested_returns(): def test_moe_fuser_router_requires_connected_dataflow(): """A gate with linear + softmax + top-k present but not wired as a router - (top-k selects over the input, not the scored logits) is not detected. - """ + (top-k selects over the input, not the scored logits) is not detected.""" with torch.device("meta"): block = MoEBlock(DisconnectedRouter) assert MoEBlockFuser.match(block, "experts") is None diff --git a/tests/models/transformers/fusers/test_rms_norm.py b/tests/models/transformers/fusers/test_rms_norm.py index dacf79f77a..153f7863bd 100644 --- a/tests/models/transformers/fusers/test_rms_norm.py +++ b/tests/models/transformers/fusers/test_rms_norm.py @@ -83,8 +83,7 @@ class ToleranceRMSNorm(NamedEpsRMSNorm): class LiteralEpsRMSNorm(RMSNorm): """eps is a literal in the source, and an unrelated attribute happens to - hold the same value: matching on the value alone would bind to it. - """ + hold the same value: matching on the value alone would bind to it.""" def __init__(self, hidden: int = 16, eps: float = 1e-5): super().__init__(hidden, eps) @@ -96,8 +95,7 @@ class LiteralEpsRMSNorm(RMSNorm): class AmbiguousEpsRMSNorm(nn.Module): """Two attributes hold the eps value, and the forward reads the second, so - their order cannot pick it. - """ + their order cannot pick it.""" def __init__(self, hidden: int = 16, eps: float = 1e-6): super().__init__() @@ -233,8 +231,7 @@ def test_weightless_norm_has_no_hidden_size(default_vllm_config): def test_fused_rms_norm_op_default_eps(default_vllm_config): """`torch.nn.RMSNorm` (a single `F.rms_norm` call) matches via the fast path; - its default `eps=None` resolves to `finfo(dtype).eps` in `fuse`. - """ + its default `eps=None` resolves to `finfo(dtype).eps` in `fuse`.""" from vllm.model_executor.layers.layernorm import RMSNorm as VLLMRMSNorm with torch.device("meta"): @@ -250,8 +247,7 @@ def test_fused_rms_norm_op_default_eps(default_vllm_config): def test_eps_is_derived_per_instance(default_vllm_config): """Two instances of the same norm class with different eps must fuse to their - own eps: the type-cached fuser holds only structure, not this value. - """ + own eps: the type-cached fuser holds only structure, not this value.""" with torch.device("meta"): for eps in (1e-5, 1e-6): module = RMSNorm(16, eps=eps) @@ -263,8 +259,7 @@ def test_eps_is_derived_per_instance(default_vllm_config): @pytest.mark.parametrize("cls", [NamedEpsRMSNorm, ToleranceRMSNorm]) def test_eps_attr_is_found_by_value_not_name(cls, default_vllm_config): """The eps attribute is identified by holding the traced value, so a norm - stays per-instance correct whatever it names it. - """ + stays per-instance correct whatever it names it.""" with torch.device("meta"): for eps in (1e-5, 1e-6): module = cls(16, eps=eps) @@ -276,8 +271,7 @@ def test_eps_attr_is_found_by_value_not_name(cls, default_vllm_config): def test_literal_eps_is_not_mistaken_for_an_attribute(default_vllm_config, caplog): """A literal eps is recognised as coming from no attribute, even when one - holds the same value, and is taken from the traced source instead. - """ + holds the same value, and is taken from the traced source instead.""" logger = "vllm.model_executor.models.transformers.fusers.rms_norm" with caplog.at_level("DEBUG", logger=logger), torch.device("meta"): module = LiteralEpsRMSNorm() @@ -290,8 +284,7 @@ def test_literal_eps_is_not_mistaken_for_an_attribute(default_vllm_config, caplo def test_ambiguous_eps_attrs_are_disambiguated(default_vllm_config): """When several attributes hold the eps value, the one the forward actually - reads is identified, and they are all left as they were found. - """ + reads is identified, and they are all left as they were found.""" with torch.device("meta"): module = AmbiguousEpsRMSNorm(16, eps=1e-6) before = dict(vars(module)) @@ -308,8 +301,7 @@ def test_ambiguous_eps_attrs_are_disambiguated(default_vllm_config): def test_fused_norm_is_gather_capable(default_vllm_config): """Every weighted fused norm is emitted gather-capable, so a norm on a head-sharded projection (OLMoE-style) self-corrects at runtime with no QKV-specific - plumbing. A full-width input skips the gather and equals a plain norm. - """ + plumbing. A full-width input skips the gather and equals a plain norm.""" from vllm.model_executor.layers.layernorm import GemmaRMSNorm, RMSNorm from vllm.model_executor.models.transformers.fusers import rms_norm @@ -331,8 +323,7 @@ def test_fused_norm_is_gather_capable(default_vllm_config): def test_gathered_norm_rejects_uneven_sharding(default_vllm_config): """A sharded input (narrower than the full-width weight) that does not tile - the weight evenly across ranks is rejected before any collective. - """ + the weight evenly across ranks is rejected before any collective.""" from vllm.model_executor.models.transformers.fusers import rms_norm norm = rms_norm.TPAwareRMSNorm(hidden_size=8, eps=1e-6) diff --git a/tests/models/transformers/test_layer_registry.py b/tests/models/transformers/test_layer_registry.py index cc809837ae..9e20e2ba54 100644 --- a/tests/models/transformers/test_layer_registry.py +++ b/tests/models/transformers/test_layer_registry.py @@ -28,8 +28,7 @@ def fake_hw_layernorm(monkeypatch): A `SimpleNamespace` stands in for the module: `importlib.import_module` returns it from `sys.modules` and `getattr` resolves `RMSNorm`, while its attributes are set at construction (no `ModuleType` attribute-set that mypy - rejects, no constant `setattr` that ruff rejects). - """ + rejects, no constant `setattr` that ruff rejects).""" module = types.SimpleNamespace(RMSNorm=type("HwRMSNorm", (), {})) monkeypatch.setitem(sys.modules, HW_MODULE, module) return module @@ -82,8 +81,7 @@ def test_act_and_mul_falls_back_for_unknown_activation( @pytest.fixture(scope="module") def tiny_llama_path(tmp_path_factory): """A randomly-initialized microscopic Llama saved to disk (with an ungated - tokenizer) so vLLM can load it like any local checkpoint. - """ + tokenizer) so vLLM can load it like any local checkpoint.""" from transformers import AutoTokenizer, LlamaConfig, LlamaForCausalLM tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer") diff --git a/tests/multimodal/media/test_audio.py b/tests/multimodal/media/test_audio.py index 55736fbe2a..0404535e1b 100644 --- a/tests/multimodal/media/test_audio.py +++ b/tests/multimodal/media/test_audio.py @@ -54,8 +54,7 @@ def test_audio_media_io_load_base64(dummy_audio_bytes): def test_audio_media_io_load_base64_rejects_malformed(dummy_audio_bytes): """Malformed base64 must surface as a ValueError so the server answers 400. Without strict decoding the bad characters are dropped, the garbage reaches - libsndfile, and the client gets a 500 instead. - """ + libsndfile, and the client gets a 500 instead.""" encoded = base64.b64encode(dummy_audio_bytes).decode("utf-8") malformed = encoded[:8] + "!!!@@@###" + encoded[8:] @@ -134,8 +133,7 @@ def test_small_file_passes_memory_guard(): def test_memory_guard_rejects_large_allocation(): """A file whose frames*channels*4 exceeds the byte limit must be - rejected before allocating the buffer. - """ + rejected before allocating the buffer.""" # 100_000 frames * 8 channels * 4 bytes = 3.2 MB payload = _make_flac_bytes(frames=100_000, channels=8, samplerate=48000) # Set limit to 1 MiB — should reject @@ -150,8 +148,7 @@ def test_memory_guard_rejects_large_allocation(): def test_forged_samplerate_rejected_by_memory_guard(): """The PoC scenario: high sample rate fools the duration guard but - the memory guard catches the large frame*channel allocation. - """ + the memory guard catches the large frame*channel allocation.""" # Forged high sample rate: 655350 Hz, 8 channels, 1M frames # Duration guard sees: 1_000_000 / 655_350 = 1.5s → passes # Memory: 1_000_000 * 8 * 4 = 32 MB @@ -212,8 +209,7 @@ def test_load_audio_unknown_backend_rejected(dummy_audio_bytes): def test_load_audio_auto_falls_back_without_torchcodec(dummy_audio_bytes): """`auto` must fall back to the soundfile → PyAV chain when torchcodec - is not importable. - """ + is not importable.""" ref_audio, ref_sr = load_audio_soundfile(BytesIO(dummy_audio_bytes), sr=None) with patch.object(audio_module, "load_audio_torchcodec", side_effect=ImportError): audio, sr = load_audio(BytesIO(dummy_audio_bytes), sr=None, backend="auto") @@ -223,8 +219,7 @@ def test_load_audio_auto_falls_back_without_torchcodec(dummy_audio_bytes): def test_load_audio_auto_falls_back_without_ffmpeg(dummy_audio_bytes): """Torchcodec installed but system ffmpeg missing (`AudioDecoder is None`) - must surface as ImportError so `auto` falls back to soundfile → PyAV. - """ + must surface as ImportError so `auto` falls back to soundfile → PyAV.""" ref_audio, ref_sr = load_audio_soundfile(BytesIO(dummy_audio_bytes), sr=None) with patch.object(audio_module, "AudioDecoder", None): with pytest.raises(ImportError, match="torchcodec audio backend"): @@ -239,8 +234,7 @@ def test_load_audio_auto_falls_back_when_libtorchcodec_unloadable( ): """Torchcodec loads its ffmpeg-backed core lazily at decoder construction; a "Could not load libtorchcodec" RuntimeError there (no system ffmpeg) - must also surface as ImportError so `auto` falls back. - """ + must also surface as ImportError so `auto` falls back.""" class _UnloadableDecoder: def __init__(self, *args, **kwargs): diff --git a/tests/multimodal/media/test_connector.py b/tests/multimodal/media/test_connector.py index 64145e0fea..b222d57d3c 100644 --- a/tests/multimodal/media/test_connector.py +++ b/tests/multimodal/media/test_connector.py @@ -228,8 +228,7 @@ async def test_fetch_image_local_files_with_space_in_name(image_url: str): @pytest.mark.asyncio async def test_fetch_image_data_url_with_params(): """RFC 2397 allows parameters between the mediatype and the base64 - marker; they must not be rejected or leak into the media type. - """ + marker; they must not be rejected or leak into the media type.""" connector = MediaConnector() image = Image.new("RGB", (4, 4), color=(255, 0, 0)) diff --git a/tests/multimodal/media/test_video.py b/tests/multimodal/media/test_video.py index 2205b7c7ff..90310d6e6d 100644 --- a/tests/multimodal/media/test_video.py +++ b/tests/multimodal/media/test_video.py @@ -398,8 +398,7 @@ def test_pynvvideocodec_unrelated_error_propagates( class TestMergeKwargsGpuBackendPolicy: """Verify that merge_kwargs blocks request-level GPU backend selection - when the static (engine-level) config did not configure that backend. - """ + when the static (engine-level) config did not configure that backend.""" def test_pynvvideocodec_requires_gpu(self): assert VIDEO_LOADER_REGISTRY.backend_requires_gpu(PYNVVIDEOCODEC_VIDEO_BACKEND) @@ -492,8 +491,7 @@ class TestMergeKwargsGpuBackendPolicy: def test_static_pynv_with_different_runtime_gpu_backend(self): """If static sets pynv via video_backend but runtime tries to set it - via the codec-level 'backend' key (without a static match), strip it. - """ + via the codec-level 'backend' key (without a static match), strip it.""" result = VideoMediaIO.merge_kwargs( default_kwargs={"video_backend": "pynvvideocodec"}, runtime_kwargs={"backend": "pynvvideocodec"}, @@ -532,8 +530,7 @@ class TestMergeKwargsGpuBackendPolicy: def test_strips_request_level_device(self): """The decode device is a startup-only knob: a request must not move decoding onto the GPU when the startup config did not opt in, nor off - it when it did. - """ + it when it did.""" result = VideoMediaIO.merge_kwargs( default_kwargs={"backend": "torchcodec"}, runtime_kwargs={"device": "cuda"}, @@ -558,8 +555,7 @@ class TestMergeKwargsGpuBackendPolicy: def test_switching_backend_drops_stale_codec_options(default_kwargs): """Codec-specific options from the static config must not leak into a different codec backend selected per-request, where they would fail the - new backend's option validation. - """ + new backend's option validation.""" result = VideoMediaIO.merge_kwargs( default_kwargs={**default_kwargs, "num_frames": 8}, runtime_kwargs={"backend": "opencv"}, @@ -581,8 +577,7 @@ def test_pynvvc_frames_normalized_to_nhwc(layout: str): """PyNvVideoCodec frame batches are normalized to NHWC regardless of the per-frame layout the decoder emits (it has varied across versions), so the HF video processors (which materialize a PIL image per frame) receive the - same NHWC shape as every other video backend. - """ + same NHWC shape as every other video backend.""" torch = pytest.importorskip("torch") n, h, w, c = 4, 5, 6, 3 diff --git a/tests/multimodal/test_hasher.py b/tests/multimodal/test_hasher.py index 34ecc1c1f6..1b738eeeb8 100644 --- a/tests/multimodal/test_hasher.py +++ b/tests/multimodal/test_hasher.py @@ -141,8 +141,7 @@ def test_hash_collision_video_num_frames(): def test_hash_video_tensor_frames(): """Videos holding tensor frames (e.g. NVDEC-decoded) hash like - array-framed ones, from the original bytes without a D2H copy. - """ + array-framed ones, from the original bytes without a D2H copy.""" source = b"x" * 100 def item_for_hash(frames): diff --git a/tests/multimodal/test_image.py b/tests/multimodal/test_image.py index ad1ce31628..ea7f18611c 100644 --- a/tests/multimodal/test_image.py +++ b/tests/multimodal/test_image.py @@ -80,8 +80,7 @@ def test_l_mode_no_trns_to_rgb(): def test_exif_transpose_normalizes_orientation(): """Image with EXIF orientation 3 (180-degree rotation) should be - normalized so pixel data matches visual display. - """ + normalized so pixel data matches visual display.""" # Built synthetically because the existing assets are PNGs which # don't carry EXIF orientation metadata; we need a JPEG with an # injected EXIF orientation=3 tag. diff --git a/tests/multimodal/test_parse.py b/tests/multimodal/test_parse.py index 9c4dbed0f0..2649f80777 100644 --- a/tests/multimodal/test_parse.py +++ b/tests/multimodal/test_parse.py @@ -59,8 +59,7 @@ def test_frame_size_hwc_chw(frame): def test_video_with_metadata_tensor_passthrough(): """Tensor frames pass through unchanged regardless of device: HF video processors accept tensors, and device-resident frames (e.g. NVDEC-decoded) - must not be copied back to host. - """ + must not be copied back to host.""" frames = torch.zeros((4, H, W, 3), dtype=torch.uint8) video, metadata = MultiModalDataParser()._get_video_with_metadata(frames) @@ -71,8 +70,7 @@ def test_video_with_metadata_tensor_passthrough(): @pytest.mark.skipif(not torch.cuda.is_available(), reason="Requires CUDA") def test_video_with_metadata_keeps_device_tensor(): """Device-resident frames (e.g. NVDEC-decoded) pass through as tensors, - so a device-side HF processor can consume them without a D2H copy. - """ + so a device-side HF processor can consume them without a D2H copy.""" frames = torch.zeros((4, H, W, 3), dtype=torch.uint8, device="cuda") video, metadata = MultiModalDataParser()._get_video_with_metadata(frames) diff --git a/tests/multimodal/test_registry.py b/tests/multimodal/test_registry.py index 4a08d4fdf6..6ca8874014 100644 --- a/tests/multimodal/test_registry.py +++ b/tests/multimodal/test_registry.py @@ -57,8 +57,7 @@ def test_dummy_inputs_scheduler_budget( @pytest.mark.core_model def test_supports_multimodal_inputs(model_id, limit_mm_per_prompt, expected): """Test supports_multimodal_inputs returns correct boolean for various - configs. - """ + configs.""" ctx = build_model_context( model_id, limit_mm_per_prompt=limit_mm_per_prompt, diff --git a/tests/multimodal/test_utils.py b/tests/multimodal/test_utils.py index 994e1afc8b..97f46de13c 100644 --- a/tests/multimodal/test_utils.py +++ b/tests/multimodal/test_utils.py @@ -231,8 +231,7 @@ def test_group_and_batch_mm_items_splits_shared_data_by_dtype(): def test_encode_image_url_uncommon_format_has_valid_mimetype(): """A format missing from mimetypes.types_map must still produce a - well-formed type/subtype media type, not a bare 'image'. - """ + well-formed type/subtype media type, not a bare 'image'.""" # ".tga" is not registered in mimetypes.types_map, so it exercises the # fallback path; Pillow can still encode it. url = encode_image_url(Image.new("RGB", (2, 2)), format="TGA") diff --git a/tests/multimodal/test_video.py b/tests/multimodal/test_video.py index 1bc65e86a9..432521c11f 100644 --- a/tests/multimodal/test_video.py +++ b/tests/multimodal/test_video.py @@ -1214,8 +1214,7 @@ def test_torchcodec_backend_rejects_frame_recovery(dummy_video_path): @pytest.mark.skipif(not current_platform.is_cuda(), reason="Requires CUDA") def test_torchcodec_backend_cuda_decodes_on_gpu(dummy_video_path): """With device="cuda", torchcodec decodes via NVDEC and keeps the frames - on the GPU instead of returning a host-side numpy array. - """ + on the GPU instead of returning a host-side numpy array.""" pytest.importorskip("torchcodec") with open(dummy_video_path, "rb") as f: @@ -1508,8 +1507,7 @@ def test_glm46v_duration_estimation_from_fps(): class TestGLMGASamplingCaps: """Regression tests for GHSA-58v5-2m8f-94pr: request-controlled fps and max_frames must not create intermediate allocations larger than - the actual frame count. - """ + the actual frame count.""" @staticmethod def _source( @@ -1563,8 +1561,7 @@ def test_glm5next_backend_selected_for_processor(): """Glm5NextVideoProcessor maps to the glm5next loader so only the sampled frames are decoded instead of the whole container. Both the borrowed-config spelling and the dedicated Glm5next class name (landing - with the new checkpoint) must resolve. - """ + with the new checkpoint) must resolve.""" for name in ("Glm5NextVideoProcessor", "Glm5nextVideoProcessor"): assert VIDEO_LOADER_REGISTRY.get_backend_for_video_processor(name) == "glm5next" @@ -1586,8 +1583,7 @@ def test_glm5next_backend_indices_match_sampler( total_frames, original_fps, duration, fps, max_frames ): """The loader must select exactly the frames the processor's sampler - would, with target.fps mapping onto the raw-fps override. - """ + would, with target.fps mapping onto the raw-fps override.""" from vllm.transformers_utils.processors.glm5next import ( glm_sample_frame_indices, ) @@ -1615,8 +1611,7 @@ def test_glm5next_backend_indices_match_sampler( def test_glm5next_backend_metadata_contract(): """create_hf_metadata reports the subset so the processor skips - re-sampling (do_sample_frames=False) and keeps the original totals. - """ + re-sampling (do_sample_frames=False) and keeps the original totals.""" source = VideoSourceMetadata(total_frames_num=900, original_fps=30.0, duration=30.0) target = VideoTargetMetadata(num_frames=-1, fps=-1, max_duration=-1) indices = Glm5NextVideoBackend.compute_frames_index_to_sample(source, target) @@ -1645,8 +1640,7 @@ def test_glm5next_backend_metadata_contract(): def _write_gray_video(tmp_path, total_frames, fps, size=(32, 32)): """Synthetic clip whose frame i is flat gray level i (near-lossless under - mp4v), so a decoded frame's level maps back to its source index. - """ + mp4v), so a decoded frame's level maps back to its source index.""" cv2 = pytest.importorskip("cv2") path = tmp_path / f"gray_{total_frames}_{fps}.mp4" @@ -1687,8 +1681,7 @@ class _CountingCap: def test_glm5next_backend_codec_parity(tmp_path, backend): """Every codec samples the same GLM indices and decodes the same frames; the OpenCV seek reader and torchcodec batched index-exact decode - must agree. - """ + must agree.""" if backend == "torchcodec": pytest.importorskip("torchcodec") @@ -1718,8 +1711,7 @@ def test_glm5next_backend_codec_parity(tmp_path, backend): def test_glm5next_backend_decodes_only_sampled_frames(tmp_path): """End to end over a synthetic clip: load_bytes returns exactly the - sampler's frame count, with the right frame content at each index. - """ + sampler's frame count, with the right frame content at each index.""" pytest.importorskip("cv2") total_frames, fps = 60, 10 @@ -1745,8 +1737,7 @@ def test_glm5next_backend_decodes_only_sampled_frames(tmp_path): def test_glm5next_read_frames_seeks_past_large_gaps(tmp_path): """Sparse targets must not walk the container: the stock reader grabs - every frame up to the last index; the GLM reader seeks instead. - """ + every frame up to the last index; the GLM reader seeks instead.""" cv2 = pytest.importorskip("cv2") total_frames, fps = 200, 10 @@ -1773,8 +1764,7 @@ def test_glm5next_read_frames_seeks_past_large_gaps(tmp_path): def test_glm5next_read_frames_dense_walk_matches_stock(tmp_path): """Dense targets keep the sequential walk (seeking would be slower) and - return the same frames as the stock reader. - """ + return the same frames as the stock reader.""" cv2 = pytest.importorskip("cv2") total_frames, fps = 120, 10 diff --git a/tests/parser/cohere/test_reasoning.py b/tests/parser/cohere/test_reasoning.py index 374c65aaae..8c3311e838 100644 --- a/tests/parser/cohere/test_reasoning.py +++ b/tests/parser/cohere/test_reasoning.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Reasoning extraction, reasoning-end gating and parser selection for the -unified Cohere Command parser. -""" +unified Cohere Command parser.""" from __future__ import annotations diff --git a/tests/parser/cohere/utils.py b/tests/parser/cohere/utils.py index 0696b9c24a..f26df5296c 100644 --- a/tests/parser/cohere/utils.py +++ b/tests/parser/cohere/utils.py @@ -76,8 +76,7 @@ def token_deltas( ) -> list[tuple[str, list[int]]]: """Split ``text`` into ``(delta_text, delta_token_ids)`` steps of ``chunk_size`` tokens, buffering incomplete multi-byte sequences (trailing - U+FFFD) into the next step as real streaming does. - """ + U+FFFD) into the next step as real streaming does.""" ids = tokenizer.encode(text) deltas: list[tuple[str, list[int]]] = [] prev = "" @@ -101,8 +100,7 @@ def make_parser( model_config=None, ) -> Parser: """Resolve the unified Cohere parser through ``ParserManager`` by registry - name (``cohere_command3`` / ``cohere_command4``). - """ + name (``cohere_command3`` / ``cohere_command4``).""" cls = ParserManager.get_parser(name, name, enable_auto_tools=True) assert cls is not None return cls( @@ -119,8 +117,7 @@ def drive_parser( deltas: list[tuple[str, list[int]]], ) -> list[DeltaMessage]: """Feed ``deltas`` through ``parse_delta`` (flushing on the last one) and - return the non-``None`` messages in order. - """ + return the non-``None`` messages in order.""" out: list[DeltaMessage] = [] for i, (text, ids) in enumerate(deltas): delta = parser.parse_delta(text, ids, request, finished=i == len(deltas) - 1) diff --git a/tests/parser/engine/test_deepseek_v32.py b/tests/parser/engine/test_deepseek_v32.py index aacde642fc..8db4e0cc76 100644 --- a/tests/parser/engine/test_deepseek_v32.py +++ b/tests/parser/engine/test_deepseek_v32.py @@ -289,8 +289,7 @@ class TestStreaming: class TestMissingFunctionCallsWrapper: """An invoke without the ``<|DSML|function_calls>`` wrapper is still a - tool call (V3.2 counterpart of #48931). - """ + tool call (V3.2 counterpart of #48931).""" def test_non_streaming(self, mock_tokenizer, mock_request): text = _invoke("fn", _param("k", "true", "v")) diff --git a/tests/parser/engine/test_deepseek_v4.py b/tests/parser/engine/test_deepseek_v4.py index 0c8a375ac3..7cbf9791a7 100644 --- a/tests/parser/engine/test_deepseek_v4.py +++ b/tests/parser/engine/test_deepseek_v4.py @@ -334,8 +334,7 @@ class TestMissingToolCallsWrapper: ): """Text after a tool block is dropped whether or not the closing wrapper is present, so a missing ```` does not - change what the client sees. - """ + change what the client sees.""" text = "pre\n" + self._ORPHAN if trailing_end: text += DSML_TOOL_END @@ -916,8 +915,7 @@ class TestParallelUnwrapping: class TestStreamingWrapperConsistency: """Streamed arg deltas must stay consistent with final extraction - when wrapper params like 'arguments' are unwrapped. - """ + when wrapper params like 'arguments' are unwrapped.""" def test_streaming_wrapper_unwrap_consistency(self, mock_tokenizer, mock_request): tool = _make_tool("get_weather", {"location": {"type": "string"}}) @@ -1198,8 +1196,7 @@ class TestDelegatingParserLargeDelta: ) def test_eos_not_leaked_when_reasoning_never_ends(self, chunk_size): """EOS must not leak into reasoning_content when the model never - emits (generation ends while still in REASONING state). - """ + emits (generation ends while still in REASONING state).""" eos_text = "<|end▁of▁sentence|>" eos_id = 128801 vocab = { @@ -1288,8 +1285,7 @@ class TestMalformedDsmlNoise: self, mock_tokenizer, mock_request, wrapper ): """Like the real wrapper, a corrupted one inside ```` closes - the reasoning block and starts the tool call. - """ + the reasoning block and starts the tool call.""" text = f"thinking{wrapper}\n{self._INNER}" parser = self._parser(mock_tokenizer, thinking=True) reasoning, content = parser.extract_reasoning(text, mock_request) @@ -1333,8 +1329,7 @@ class TestMalformedDsmlNoise: prose mention of the real wrapper: the opener starts a tool block and the rest of the message is dropped. That is pre-existing behavior of ``<|DSML|tool_calls>``; the variants must not differ from it either - way. - """ + way.""" template = "The opener looks like {} and then params follow. Done." text = template.format(wrapper) reference = template.format(DSML_TOOL_START) @@ -1358,8 +1353,7 @@ class TestMalformedDsmlNoise: @pytest.mark.parametrize("chunk_size", [1, 3, None], ids=lambda c: f"chunk={c}") def test_delegating_parser_corrupted_wrapper(self, wrapper, chunk_size): """The serving-layer shape: reasoning and tool adapters on separate - engines, with the corrupted opener arriving as plain text. - """ + engines, with the corrupted opener arriving as plain text.""" tokens = _dsv4_tokens( reasoning="Checking the weather.", tool_name="get_weather", diff --git a/tests/parser/engine/test_delegating_replay.py b/tests/parser/engine/test_delegating_replay.py index 7aaad7c4df..2bc4338785 100644 --- a/tests/parser/engine/test_delegating_replay.py +++ b/tests/parser/engine/test_delegating_replay.py @@ -174,8 +174,7 @@ _TOOL_CALL_SAMPLES = [ ) def test_delegating_parse_tool_choice_none(parser_cls, parser_name, sample): """Non-streaming parse() with tool_choice='none' via DelegatingParser - must not leak special tokens into content. - """ + must not leak special tokens into content.""" tokenizer = make_mock_tokenizer(sample) validated_tools = ( _TOOLS_VALIDATOR.validate_python(sample.tools) if sample.tools else None diff --git a/tests/parser/engine/test_engine.py b/tests/parser/engine/test_engine.py index f638cd599f..36fa1ad8d0 100644 --- a/tests/parser/engine/test_engine.py +++ b/tests/parser/engine/test_engine.py @@ -275,8 +275,7 @@ class TestStreaming: def test_unmatched_close_brace_does_not_poison_depth(self): """A stray } in malformed JSON must not kill streaming for - all subsequent content. - """ + all subsequent content.""" engine = StreamingParserEngine(_hermes_config(), tokenizer=None) engine.feed("", []) @@ -292,8 +291,7 @@ class TestStreaming: def test_json_args_no_premature_close_brace(self): """Closing braces of the top-level JSON shouldn't be streamed - until confirmed by the end tag. - """ + until confirmed by the end tag.""" engine = StreamingParserEngine(_hermes_config(), tokenizer=None) engine.feed("", []) @@ -348,8 +346,7 @@ class TestLexerBufferFlush: def test_buffered_prefix_emitted_in_current_state(self): """Text buffered by the lexer (e.g. '<') must be emitted as - REASONING_CHUNK before THINK_END transitions to CONTENT. - """ + REASONING_CHUNK before THINK_END transitions to CONTENT.""" engine = StreamingParserEngine(_think_config(), _make_think_tokenizer()) events = engine.feed("", [_START_ID]) @@ -387,13 +384,11 @@ class TestLexerBufferFlush: class TestTokenIdFiltering: """When token IDs are available, lex-matched terminals that also - have token_id_terminal entries should be demoted to content. - """ + have token_id_terminal entries should be demoted to content.""" def test_lex_matched_terminal_demoted_after_token_ids_seen(self): """After receiving token IDs, text that matches a token-ID - terminal should be treated as content, not trigger a transition. - """ + terminal should be treated as content, not trigger a transition.""" engine = StreamingParserEngine(_hermes_config(), _make_hermes_tokenizer()) # First feed with a non-special token ID to set _ever_had_token_ids @@ -414,8 +409,7 @@ class TestTokenIdFiltering: def test_scanner_matched_terminal_bypasses_filter(self): """PreLexedTerminals from the scanner bypass the filter and - still trigger state transitions. - """ + still trigger state transitions.""" engine = StreamingParserEngine(_hermes_config(), _make_hermes_tokenizer()) events = engine.feed("", [_TOOL_START_ID]) @@ -428,8 +422,7 @@ class TestTokenIdFiltering: def test_no_filtering_without_token_ids(self): """When no token IDs are ever provided (non-streaming), - text matching still triggers transitions. - """ + text matching still triggers transitions.""" engine = StreamingParserEngine(_hermes_config(), _make_hermes_tokenizer()) events = engine.feed('{"name": "f"}', []) @@ -441,8 +434,7 @@ class TestTokenIdFiltering: def test_mixed_text_then_real_tool_call(self): """Text mentioning tool syntax followed by a real special-token - tool call. - """ + tool call.""" engine = StreamingParserEngine(_hermes_config(), _make_hermes_tokenizer()) events1 = engine.feed("Mention in text. ", [1, 2, 3, 4]) @@ -502,8 +494,7 @@ class TestReasoningTokenCounts: def _func_prefix_config() -> ParserEngineConfig: """Config mixing token-ID terminals (TOOL_START/END) with - text-only terminals (FUNC_PREFIX) and fallback transitions. - """ + text-only terminals (FUNC_PREFIX) and fallback transitions.""" return ParserEngineConfig( name="func_prefix_test", terminals={ @@ -572,13 +563,11 @@ def _make_func_prefix_tokenizer(): class TestTextOnlyFallbackFiltering: """When token IDs are available, transitions marked - skip_in_token_id_mode should be skipped. - """ + skip_in_token_id_mode should be skipped.""" def test_func_prefix_in_prose_demoted_in_strict_mode(self): """ in prose should NOT trigger a tool call - when strict mode is active. - """ + when strict mode is active.""" engine = StreamingParserEngine( _func_prefix_config(), _make_func_prefix_tokenizer() ) @@ -595,8 +584,7 @@ class TestTextOnlyFallbackFiltering: def test_normal_flow_after_tool_start_still_works(self): """TOOL_START (special token) -> FUNC_PREFIX (text) should - still parse a tool call normally in strict mode. - """ + still parse a tool call normally in strict mode.""" engine = StreamingParserEngine( _func_prefix_config(), _make_func_prefix_tokenizer() ) @@ -616,8 +604,7 @@ class TestTextOnlyFallbackFiltering: def test_fallback_fires_without_token_ids(self): """When no token IDs are provided, fallback transitions should - still fire normally. - """ + still fire normally.""" engine = StreamingParserEngine( _func_prefix_config(), _make_func_prefix_tokenizer() ) @@ -631,8 +618,7 @@ class TestTextOnlyFallbackFiltering: def test_tool_between_fallback_blocked_in_strict_mode(self): """The (TOOL_BETWEEN, FUNC_PREFIX) fallback should also be - blocked in strict mode. - """ + blocked in strict mode.""" engine = StreamingParserEngine( _func_prefix_config(), _make_func_prefix_tokenizer() ) @@ -662,8 +648,7 @@ class TestNoUnusedTokenizerAttr: class TestArgsResetOnReentry: """When leaving TOOL_ARGS and later re-entering (e.g. two tool calls), the entering-TOOL_ARGS block resets args tracking. The - redundant reset on exit was removed. - """ + redundant reset on exit was removed.""" @staticmethod def _multi_tool_config() -> ParserEngineConfig: @@ -738,8 +723,7 @@ class TestArgsResetOnReentry: class TestToolPreambleFinish: """finish() in TOOL_PREAMBLE state emits TOOL_CALL_END when a tool - call was started (tool_index >= 0), but not when tool_index is -1. - """ + call was started (tool_index >= 0), but not when tool_index is -1.""" @staticmethod def _preamble_with_tool_call_start_config() -> ParserEngineConfig: @@ -798,8 +782,7 @@ class TestToolPreambleFinish: class TestRegexTerminalInfraRemoved: """TerminalDef.priority, LexerShape.regex_terminals, and the regex - matching loop were removed. - """ + matching loop were removed.""" def test_terminal_def_no_priority(self): import regex as re @@ -824,8 +807,7 @@ class TestRegexTerminalInfraRemoved: class TestMultiCharTerminalInArgs: """Regression: multi-char terminals falling through in TOOL_ARGS - must be fed char-by-char via _feed_args_text, not _feed_args_char. - """ + must be fed char-by-char via _feed_args_text, not _feed_args_char.""" @staticmethod def _newline_config() -> ParserEngineConfig: @@ -917,8 +899,7 @@ class TestSkipToolParsing: def _message_header_config(reasoning_end: bool) -> ParserEngineConfig: """MESSAGE_HEADER-based grammar whose tool opener optionally carries - REASONING_END, mirroring the two shapes a transition table can take. - """ + REASONING_END, mirroring the two shapes a transition table can take.""" return ParserEngineConfig( name=f"message_header_test_{reasoning_end}", initial_state=ParserState.MESSAGE_HEADER, diff --git a/tests/parser/engine/test_gemma4_streaming_reasoning.py b/tests/parser/engine/test_gemma4_streaming_reasoning.py index ab83bdf5ed..ae21d69fc3 100644 --- a/tests/parser/engine/test_gemma4_streaming_reasoning.py +++ b/tests/parser/engine/test_gemma4_streaming_reasoning.py @@ -1097,8 +1097,7 @@ class TestNonStreamingReasoningPlusToolCalls: def test_both_extractions_independent(self, parser, request_obj): """Calling extract_reasoning then extract_tool_calls on the same - parser instance should both work (each resets the engine). - """ + parser instance should both work (each resets the engine).""" model_output = FULL_MODEL_OUTPUT reasoning, _ = parser.extract_reasoning(model_output, request_obj) @@ -1112,8 +1111,7 @@ class TestNonStreamingReasoningPlusToolCalls: class TestAdapterExtractReasoning: """The reasoning adapter's extract_reasoning uses skip_tool_parsing - so tool call text is preserved as content for the tool adapter. - """ + so tool call text is preserved as content for the tool adapter.""" @pytest.fixture def adapter(self, mock_tokenizer): @@ -1154,8 +1152,7 @@ class TestAdapterExtractReasoning: class TestGemma4SchemaAwareTypeCoercion: """Verify that streaming and non-streaming produce identical type-fixed arguments when tool schemas declare string parameters - but the model outputs bare numbers/booleans. - """ + but the model outputs bare numbers/booleans.""" @pytest.fixture def tools(self): @@ -1185,8 +1182,7 @@ class TestGemma4SchemaAwareTypeCoercion: def test_streaming_string_param_not_coerced(self, parser_with_tools, mock_request): """A numeric value for a string-typed param must remain a string - in the streamed output, matching the non-streaming result. - """ + in the streamed output, matching the non-streaming result.""" chunks = [ "<|tool_call>", "call:update_record{", @@ -1217,8 +1213,7 @@ class TestGemma4SchemaAwareTypeCoercion: def test_streaming_matches_non_streaming(self, parser_with_tools, mock_request): """Concatenated streaming deltas must produce the same arguments - as non-streaming extraction. - """ + as non-streaming extraction.""" text = "<|tool_call>call:update_record{zipcode:12345}" non_streaming = parser_with_tools.extract_tool_calls(text, mock_request) @@ -1239,8 +1234,7 @@ class TestGemma4SchemaAwareTypeCoercion: class TestGemma4SchemaCoercionBoolNumberNull: """Verify that _fix_arg_types coerces string values to non-string - schema types for the Gemma4 parser. - """ + schema types for the Gemma4 parser.""" @pytest.fixture def tools(self): @@ -1301,8 +1295,7 @@ class TestGemma4SchemaCoercionBoolNumberNull: def test_streaming_type_stability(self, parser_with_tools, mock_request): """Values streamed incrementally must not cause prefix - incompatibility when types are coerced. - """ + incompatibility when types are coerced.""" text = ( "<|tool_call>call:configure{" "enabled:true," @@ -1402,8 +1395,7 @@ BARE_THOUGHT_SEQUENCE.append((TOOL_CALL_END_ID, "")) class TestBareThoughtWithoutChannelOpener: """When the model omits <|channel> and starts with bare ``thought``, the parser should auto-inject the channel opener so reasoning is - captured correctly. - """ + captured correctly.""" @pytest.fixture def bare_thought_tokenizer(self): @@ -1474,8 +1466,7 @@ class TestBareThoughtWithoutChannelOpener: def test_bare_thought_token_at_end_of_stream(self, request_obj): """When the stream ends with just "thought" (no \\n), the parser - should treat it as the thought prefix token, not real reasoning. - """ + should treat it as the thought prefix token, not real reasoning.""" seq: list[tuple[int, str]] = [ (CHANNEL_START_ID, "<|channel>"), (3000, "thought"), diff --git a/tests/parser/engine/test_glm47_moe.py b/tests/parser/engine/test_glm47_moe.py index fe6d0ec5c5..58fe7aa28c 100644 --- a/tests/parser/engine/test_glm47_moe.py +++ b/tests/parser/engine/test_glm47_moe.py @@ -61,8 +61,7 @@ class TestIsReasoningEnd: def test_previous_turn_tool_call_ignored(self, parser): """A finished tool call from an earlier turn says nothing about the - turn currently being generated. - """ + turn currently being generated.""" prompt = [THINK_S, TEXT, TOOL_S, TEXT, TOOL_E, OBSERVATION, TEXT, ASSISTANT] assert not parser.is_reasoning_end(prompt) @@ -89,8 +88,7 @@ class TestExtractContentIds: def test_falls_back_to_tool_call(self, parser): """Without ````, content starts at the opener itself so the - tool parser still receives a well-formed call. - """ + tool parser still receives a well-formed call.""" ids = [THINK_S, TEXT, TOOL_S, 30, TOOL_E] assert parser.extract_content_ids(ids) == [TOOL_S, 30, TOOL_E] diff --git a/tests/parser/engine/test_inkling.py b/tests/parser/engine/test_inkling.py index c38e74544c..9026d548df 100644 --- a/tests/parser/engine/test_inkling.py +++ b/tests/parser/engine/test_inkling.py @@ -70,8 +70,7 @@ _MARKERS = sorted(_TML_VOCAB, key=len, reverse=True) def _tokenize(text: str) -> list[tuple[int, str]]: """Tokenize like the real stream: markers are atomic special tokens, plain text becomes one token per character (matching the mock - tokenizer's ``chr``-based decode). - """ + tokenizer's ``chr``-based decode).""" tokens: list[tuple[int, str]] = [] i = 0 while i < len(text): @@ -88,8 +87,7 @@ def _tokenize(text: str) -> list[tuple[int, str]]: def _stream(parser, request, text: str, chunk_size: int): """Stream production-shaped deltas: ``chunk_size`` tokens per delta, - with delta_token_ids covering every token (specials and text). - """ + with delta_token_ids covering every token (specials and text).""" tokens = _tokenize(text) results = [] previous_text = "" @@ -121,8 +119,7 @@ def _stream(parser, request, text: str, chunk_size: int): def _stream_text_only(parser, request, text: str, chunk_size: int): """Stream text-only deltas (no token ids), chunked at arbitrary character boundaries — exercises the text-lexing fallback path, - including markers split across chunks. - """ + including markers split across chunks.""" results = [] previous_text = "" for start in range(0, len(text), chunk_size): @@ -173,8 +170,7 @@ def _stream_delegating(parser, request, text, chunk_size, prompt_token_ids): """Stream ``text`` through ``DelegatingParser.parse_delta``, ``chunk_size`` tokens per delta; return ``(content, reasoning, ordered tool names, ordered tool arguments)``. Arguments arrive in fragments, so they are - concatenated per tool index. - """ + concatenated per tool index.""" tokens = _tokenize(text) content, reasoning = "", "" tools: dict[int, str] = {} @@ -526,8 +522,7 @@ class TestToolCallFiltering: """Inkling equivalents of the generic tool-call-filtering replay tests (Inkling is excluded from those in test_replay.py: its structural role/kind tokens and shared block-end token don't fit the generic - reasoning/tool split model). - """ + reasoning/tool split model).""" def test_skip_tool_parsing_round_trip(self, mock_tokenizer, mock_request): # First pass (reasoning adapter, skip_tool_parsing): reasoning is @@ -825,8 +820,7 @@ class TestDelegatingTwoPass: ): """The optional function name between ``<|message_model|>`` and the content-kind marker is metadata: the buffered header must be - discarded on the way out, not flushed into content. - """ + discarded on the way out, not flushed into content.""" tools = [_function_tool()] mock_request.tools = tools content, _, names, args = _stream_delegating( @@ -843,8 +837,7 @@ class TestDelegatingTwoPass: def test_content_state_tool_start_streaming(self, mock_tokenizer, mock_request): """Same opener reached from CONTENT rather than MESSAGE_HEADER: a text block closed with no ``<|message_model|>`` before the tool - block. Preceding text must reach content exactly once, unmarked. - """ + block. Preceding text must reach content exactly once, unmarked.""" tools = [_function_tool()] mock_request.tools = tools content, _, names, args = _stream_delegating( @@ -866,8 +859,7 @@ def test_content_tool_start_emits_reasoning_end_in_reasoning_pass(): boundary (#49876), but the header-flush path (MESSAGE_HEADER --END_MESSAGE--> CONTENT) reaches CONTENT without one, so a tool block opening from there relies on this transition - alone to hand off to the tool pass. - """ + alone to hand off to the tool pass.""" engine = StreamingParserEngine(inkling_config(), tokenizer=None) engine.skip_tool_parsing = True engine.reset(initial_state=ParserState.CONTENT) @@ -884,8 +876,7 @@ def test_skip_reasoning_parsing_inert_for_shared_markers(): markers. Inkling has none — ``<|end_message|>`` is labelled THINK_END yet also closes text, header, and tool blocks — so the flag must be inert: a tool block still closes through its transition and following - text returns to CONTENT instead of leaking into the argument stream. - """ + text returns to CONTENT instead of leaking into the argument stream.""" engine = StreamingParserEngine(inkling_config(), tokenizer=None) engine.skip_reasoning_parsing = True engine.reset(initial_state=ParserState.CONTENT) @@ -905,8 +896,7 @@ class TestToolParserWithoutReasoningParser: labels ``<|end_message|>`` as THINK_END; a bypass keyed on the label would neutralize the closer of every block kind, leaking markers into content and leaving tool calls unterminated. Structure must keep - parsing exactly as with the reasoning parser attached. - """ + parsing exactly as with the reasoning parser attached.""" GEN_PROMPT = [_TML_VOCAB[MSG_MODEL]] diff --git a/tests/parser/engine/test_nemotron_v3.py b/tests/parser/engine/test_nemotron_v3.py index 201ddc4e78..a7f166f9f3 100644 --- a/tests/parser/engine/test_nemotron_v3.py +++ b/tests/parser/engine/test_nemotron_v3.py @@ -56,8 +56,7 @@ def parser(): class TestNemotronSwap: def test_enable_thinking_false_swaps(self, parser): """When enable_thinking=False, model output without think tags - should have reasoning swapped to content. - """ + should have reasoning swapped to content.""" text = "The answer is 42." request = _make_request(enable_thinking=False) reasoning, content = parser.extract_reasoning(text, request) @@ -74,8 +73,7 @@ class TestNemotronSwap: def test_no_swap_when_content_exists(self, parser): """With enable_thinking=False but real giving content, - no swap occurs. - """ + no swap occurs.""" text = "Some reasoning.Actual content here." request = _make_request(enable_thinking=False) reasoning, content = parser.extract_reasoning(text, request) @@ -182,13 +180,11 @@ class TestStreaming: class TestParseDeltaTokenIdFiltering: """parse_delta must not trigger tool call parsing when - appears as regular text rather than as a special token ID. - """ + appears as regular text rather than as a special token ID.""" def test_tool_call_text_in_reasoning_is_not_parsed(self, parser): """Literal in model reasoning should be content, - not a tool call. - """ + not a tool call.""" request = _make_request() text = ( @@ -214,8 +210,7 @@ class TestParseDeltaTokenIdFiltering: def test_special_token_id_still_triggers_tool_call(self, parser): """When the scanner matches a special token ID, the tool call - must still be parsed correctly. - """ + must still be parsed correctly.""" request = _make_request() parser.parse_delta( @@ -255,8 +250,7 @@ class TestParseDeltaTokenIdFiltering: def test_text_discussion_then_real_tool_call(self, parser): """Model discusses tool syntax in reasoning, then makes a real - tool call via special tokens. - """ + tool call via special tokens.""" request = _make_request() r1 = parser.parse_delta( diff --git a/tests/parser/engine/test_parser_engine.py b/tests/parser/engine/test_parser_engine.py index a64ab2ecd5..8fd7c4d262 100644 --- a/tests/parser/engine/test_parser_engine.py +++ b/tests/parser/engine/test_parser_engine.py @@ -323,8 +323,7 @@ class TestEventsToDelta: def test_multiple_arg_chunks_same_batch_coalesced(self): """Multiple events for the same tool in one batch must produce - at most one DeltaToolCall per index. - """ + at most one DeltaToolCall per index.""" engine = _make_engine() events = [ SemanticEvent(EventType.TOOL_CALL_START, tool_index=0), @@ -552,8 +551,7 @@ class TestPostToolContentDeferral: """Regression: content after TOOL_CALL_END in the same batch must not produce a mixed DeltaMessage(content=..., tool_calls=...) — that causes split_delta to reorder content before tool_calls, breaking the Responses - API state machine. - """ + API state machine.""" def test_text_after_tool_end_deferred(self): engine = _make_engine() @@ -607,8 +605,7 @@ class TestPostToolContentDeferral: """Deferred content from batch N must not mix with arg-continuation tool events in batch N+1 — that creates a DeltaMessage with both content and nameless tool_calls, which crashes the Responses API - state machine (name=None → Pydantic ValidationError). - """ + state machine (name=None → Pydantic ValidationError).""" engine = _make_engine() engine._content_has_nonws = True @@ -837,8 +834,7 @@ class TestBuildExtractedResult: class TestEngineBasedPath: """Tests for the _engine_based accumulation behavior in - DelegatingParser.parse_delta. - """ + DelegatingParser.parse_delta.""" def test_engine_based_true_when_both_parsers_engine(self): r = SimpleNamespace(engine_based_streaming=True) @@ -884,8 +880,7 @@ class TestEngineBasedPath: class TestParseTokenIdPassthrough: """parse() must forward model_output_token_ids to _single_pass_parse - so that token-ID-based strict terminal matching is active. - """ + so that token-ID-based strict terminal matching is active.""" def test_literal_tool_tag_in_content_preserved_with_token_ids(self, mock_request): engine = _make_engine(_hermes_config()) @@ -1109,8 +1104,7 @@ class TestAdapterFinishOnStreamEnd: def test_lexer_buffer_flushed_on_finished(self): """Text buffered as a potential terminal prefix must be emitted - as content when the stream ends. - """ + as content when the stream ends.""" tokenizer = make_mock_tokenizer(_VOCAB) parser = _CombinedDelegating(tokenizer) request = _make_delegating_request() @@ -1128,8 +1122,7 @@ class TestAdapterFinishOnStreamEnd: def test_args_buffer_flushed_on_finished(self): """Pending arg buffer text must be emitted when stream ends - mid-tool-call (closing brace held back in buffer). - """ + mid-tool-call (closing brace held back in buffer).""" tokenizer = make_mock_tokenizer(_VOCAB) parser = _CombinedDelegating(tokenizer) request = _make_delegating_request() @@ -1365,8 +1358,7 @@ class TestSkipToolSpanForwarding: class TestToolAdapterForwardsKwargs: """ParserEngineToolAdapter.__init__ must forward **kwargs to the - parser engine class so chat_template_kwargs reach model parsers. - """ + parser engine class so chat_template_kwargs reach model parsers.""" @pytest.mark.parametrize( "enable_thinking,expected_state", @@ -1396,8 +1388,7 @@ class TestToolAdapterForwardsKwargs: class TestExtractContentIdsNoEmptyReturn: """extract_content_ids must return input_ids (not []) when there is - no THINK_END token ID and _reasoning_ended is True. - """ + no THINK_END token ID and _reasoning_ended is True.""" _NO_THINK_CONFIG = ParserEngineConfig(name="no_think_end", token_id_terminals={}) @@ -1795,8 +1786,7 @@ class TestDropSpecialTokens: def test_drops_special_token_by_id_from_content(self): """A special token (not a configured terminal) is dropped when - it arrives as its actual token ID. - """ + it arrives as its actual token ID.""" config = ParserEngineConfig( name="drop_content_test", terminals={}, @@ -1831,8 +1821,7 @@ class TestDropSpecialTokens: def test_drops_via_text_fallback_when_no_token_ids(self): """When no token IDs are provided, text-based lexer catches - drop tokens as a fallback. - """ + drop tokens as a fallback.""" engine = _make_engine( vocab=_DROP_VOCAB, special_tokens=list(_DROP_VOCAB.keys()), @@ -1845,8 +1834,7 @@ class TestDropSpecialTokens: def test_regular_tokens_spelling_special_survive(self): """Regular tokens that spell out a drop-token string survive - when token IDs prove they are not the special token. - """ + when token IDs prove they are not the special token.""" vocab = {**_DROP_VOCAB, "h": 72, "<": 73, "bos": 74, ">": 75, "w": 76} engine = _make_engine( vocab=vocab, @@ -1862,8 +1850,7 @@ class TestDropSpecialTokens: def test_configured_terminal_not_treated_as_drop(self): """Tokens already in config.terminals (like ) are handled - by the state machine, not the drop mechanism. - """ + by the state machine, not the drop mechanism.""" engine = _make_engine( vocab=_DROP_VOCAB, special_tokens=list(_DROP_VOCAB.keys()), @@ -1918,8 +1905,7 @@ class TestDropSpecialTokens: def test_drops_applied_with_skip_tool_parsing(self): """Drop tokens are always dropped, even with skip_tool_parsing. DROP_TERMINALs have no transitions by construction, so no parser - pass can use them. - """ + pass can use them.""" for initial_state in (ParserState.REASONING, ParserState.CONTENT): engine = _make_engine( vocab=_DROP_VOCAB, @@ -1935,8 +1921,7 @@ class TestDropSpecialTokens: def test_transitions_unaffected_by_drop_in_reasoning_with_skip_tool_parsing(self): """With skip_tool_parsing in REASONING state, drop tokens are - removed but configured terminals still fire their transitions. - """ + removed but configured terminals still fire their transitions.""" engine = _make_engine( vocab=_DROP_VOCAB, special_tokens=list(_DROP_VOCAB.keys()), @@ -1972,8 +1957,7 @@ class TestDropSpecialTokens: def test_mixed_configured_and_drop_terminals(self): """Configured terminals trigger transitions while drop terminals - are silently removed in the same stream. - """ + are silently removed in the same stream.""" engine = _make_engine( vocab=_DROP_VOCAB, special_tokens=list(_DROP_VOCAB.keys()), @@ -1997,8 +1981,7 @@ class TestTruncatedToolOpenerStreamParity: """Regression tests for #47137: when generation terminates inside a ```` opener that has not been promoted to a tool call (via ``max_tokens`` or a ``stop`` string), the non-streaming path - must drop the incomplete markup, matching the streaming path. - """ + must drop the incomplete markup, matching the streaming path.""" _QWEN3_VOCAB = { "": 100, @@ -2044,8 +2027,7 @@ class TestTruncatedToolOpenerStreamParity: ) def test_truncated_opener_dropped_in_both_paths(self, mock_request, chunks): """A cutoff inside the opener yields no content and no tool calls - in both the non-streaming and streaming paths. - """ + in both the non-streaming and streaming paths.""" text = "".join(chunks) _, content, tool_calls = self._make_parser().parse( @@ -2058,8 +2040,7 @@ class TestTruncatedToolOpenerStreamParity: def test_content_before_truncated_opener_preserved(self, mock_request): """Only the incomplete markup is dropped; content generated before - the opener is returned identically by both paths. - """ + the opener is returned identically by both paths.""" chunks = ["Checking the weather. ", "", "\n", "", "garbage", "", " B"] text = "".join(chunks) @@ -2088,8 +2068,7 @@ class TestTruncatedToolOpenerStreamParity: def test_complete_tool_call_still_promoted(self, mock_request): """Sanity check: a complete tool call still parses in the - non-streaming path after the truncation fix. - """ + non-streaming path after the truncation fix.""" text = ( "\n" "\n" @@ -2109,8 +2088,7 @@ class TestThinkMarkupWithoutReasoningParser: """With no reasoning parser configured, reasoning markup is plain content: engine-backed tool parsers must return it verbatim in both the non-streaming and streaming paths, not consume the markers or - reclassify the block as reasoning and drop it. - """ + reclassify the block as reasoning and drop it.""" _VOCAB = { "": 90, @@ -2176,8 +2154,7 @@ class TestThinkMarkupWithoutReasoningParser: def test_think_block_preserved_alongside_tool_call(self, mock_request): """The tools-called branch also returns the tool parser's content; - a think block preceding a promoted tool call must survive in it. - """ + a think block preceding a promoted tool call must survive in it.""" think = "plan" text = think + ( "\n" diff --git a/tests/parser/engine/test_qwen3.py b/tests/parser/engine/test_qwen3.py index b8f96294cb..07a025876a 100644 --- a/tests/parser/engine/test_qwen3.py +++ b/tests/parser/engine/test_qwen3.py @@ -318,8 +318,7 @@ class TestStreaming: def test_streaming_args_arrive_incrementally(self, parser, mock_request): """Arguments must stream as intermediate deltas, not batch at - tool-end. - """ + tool-end.""" chunks = [ "\n", "\n", @@ -524,8 +523,7 @@ class TestStreaming: def test_streaming_split_tool_call_tag(self, parser, mock_request): """ arrives as a single special token; the rest of - the content is split into fine-grained chunks. - """ + the content is split into fine-grained chunks.""" chunks = [ "\n", "\n", @@ -702,8 +700,7 @@ class TestArgConverter: class TestSchemaAwareTypeCoercion: """Verify that _fix_arg_types corrects miscoerced values using the - tool schema. - """ + tool schema.""" @pytest.fixture def tools(self): @@ -845,8 +842,7 @@ class TestAnyOfTypeCoercion: def test_anyof_string_param_not_coerced(self, parser_with_anyof, mock_request): """A param with anyOf including 'string' must not be coerced - to integer. - """ + to integer.""" text = ( "\n" "\n" @@ -862,8 +858,7 @@ class TestAnyOfTypeCoercion: class TestSchemaCoercionBoolNumberNull: """Verify that _fix_arg_types coerces string values to non-string - schema types using coerce_to_schema_type. - """ + schema types using coerce_to_schema_type.""" @pytest.fixture def tools(self): diff --git a/tests/parser/engine/test_qwen3_reasoning.py b/tests/parser/engine/test_qwen3_reasoning.py index d8e8096fd3..3f285e4d03 100644 --- a/tests/parser/engine/test_qwen3_reasoning.py +++ b/tests/parser/engine/test_qwen3_reasoning.py @@ -276,8 +276,7 @@ class TestIsReasoningEndTurnBoundaries: def test_empty_boundary_config_keeps_global_walk(self): """Configs without turn_boundary_tokens keep the pre-existing - behavior: any in the sequence ends reasoning. - """ + behavior: any in the sequence ends reasoning.""" cfg = qwen3_config(turn_boundary_tokens=frozenset()) parser = Qwen3Parser( make_mock_tokenizer(_QWEN3_VOCAB), parser_engine_config=cfg @@ -289,8 +288,7 @@ class TestIsReasoningEndTurnBoundaries: def test_boundary_tokens_missing_from_vocab_keep_global_walk(self): """Boundary tokens absent from the vocabulary resolve to nothing, so subclasses reusing the default on a non-ChatML vocab keep the - pre-existing behavior. - """ + pre-existing behavior.""" vocab = { token: token_id for token, token_id in _QWEN3_VOCAB.items() @@ -301,8 +299,7 @@ class TestIsReasoningEndTurnBoundaries: def test_boundary_with_thinking_disabled_is_end(self, mock_tokenizer): """With thinking disabled (initial state CONTENT) a walk that stops at a turn - boundary must report reasoning as ended: the model never emits a marker. - """ + boundary must report reasoning as ended: the model never emits a marker.""" parser = Qwen3Parser( mock_tokenizer, chat_template_kwargs={"enable_thinking": False} ) @@ -310,8 +307,7 @@ class TestIsReasoningEndTurnBoundaries: def test_boundary_with_thinking_enabled_not_end(self, parser): """With thinking disabled (initial state REASONING) a walk that stops at a turn - boundary must keep reasoning open - """ + boundary must keep reasoning open""" assert not parser.is_reasoning_end([_IM_START_ID, _TEXT_ID]) @@ -672,8 +668,7 @@ class TestTrailingWhitespaceStripping: class TestWhitespaceStrippingDisabled: """When strip_trailing_reasoning_whitespace is False, - trailing whitespace in reasoning must be preserved. - """ + trailing whitespace in reasoning must be preserved.""" @pytest.fixture def parser_no_strip(self): @@ -731,8 +726,7 @@ class TestThinkingDisabled: def test_thinking_disabled_streaming_content_only(self, mock_tokenizer): """Plain text with thinking disabled must stream as content, not reasoning. Before the fix, the REASONING initial state caused all - output to be emitted as reasoning chunks. - """ + output to be emitted as reasoning chunks.""" p = Qwen3Parser( mock_tokenizer, chat_template_kwargs={"enable_thinking": False}, diff --git a/tests/parser/engine/test_replay.py b/tests/parser/engine/test_replay.py index 75fdbfca0f..fee74f8d2c 100644 --- a/tests/parser/engine/test_replay.py +++ b/tests/parser/engine/test_replay.py @@ -440,8 +440,7 @@ class TestToolCallFilteringReplay: ) class TestToolCallFilteringNonStreaming: """Non-streaming parse() with tool_choice='none' must suppress tool - calls and not leak special tokens into content. - """ + calls and not leak special tokens into content.""" def test_parse(self, parser_cls, sample, think_end, tool_start): tokenizer = make_mock_tokenizer(sample) @@ -484,8 +483,7 @@ _WS_TOOL_SAMPLES = [(t[0], t[1]) for t in _TOOL_CALL_SAMPLES if "whitespace" in ) class TestToolChoiceNoneStreamingParity: """Streaming and non-streaming must return the same content - when tool_choice='none' suppresses tool calls. - """ + when tool_choice='none' suppresses tool calls.""" def test_content_matches(self, parser_cls, sample): tokenizer = make_mock_tokenizer(sample) @@ -543,8 +541,7 @@ def _inject_drop_tokens(sample): class TestDropTokenReplay: """Verify unconfigured special tokens are silently dropped across - all parsers and chunk sizes. - """ + all parsers and chunk sizes.""" @pytest.mark.parametrize( "parser_info", @@ -601,8 +598,7 @@ class TestDropTokenNonStreaming: class TestAdapterReferences: """Verify make_adapters sets reasoning/tool parser class refs on parser engine - parser classes so the serving layer finds them and calls adjust_request. - """ + parser classes so the serving layer finds them and calls adjust_request.""" @pytest.mark.parametrize( "parser_name", diff --git a/tests/parser/engine/test_seed_oss.py b/tests/parser/engine/test_seed_oss.py index 1598321359..e01f2fd9f6 100644 --- a/tests/parser/engine/test_seed_oss.py +++ b/tests/parser/engine/test_seed_oss.py @@ -129,8 +129,7 @@ def test_single_tool_call(tool_parser, mock_request): def test_malformed_function_end_does_not_drop_siblings(tool_parser, mock_request): """Regression for #46314: a malformed ```` with no closing ``>`` - on the header must not discard the other, well-formed calls. - """ + on the header must not discard the other, well-formed calls.""" text = ( f"{TOOL_CALL_START}\n\n{TOOL_CALL_END}" f"{TOOL_CALL_START}\n\n" @@ -172,8 +171,7 @@ def test_reasoning_then_tool_call(parser): def test_streaming_think_end_and_tool_call_same_delta(parser): """```` and ```` arriving in one delta must - not leak the terminal tokens into the reasoning text. - """ + not leak the terminal tokens into the reasoning text.""" reasoning, content = simulate_reasoning_streaming( parser, [ diff --git a/tests/parser/engine/test_ufffd_reasoning_transition.py b/tests/parser/engine/test_ufffd_reasoning_transition.py index 6497a6c29f..ffd2ead95d 100644 --- a/tests/parser/engine/test_ufffd_reasoning_transition.py +++ b/tests/parser/engine/test_ufffd_reasoning_transition.py @@ -146,8 +146,7 @@ class TestUfffdReasoningTransition: def test_byte_fallback_tokenizer_produces_ufffd(self): """Validate the fixture: decode() returns U+FFFD for isolated - byte-fallback token IDs, proving the old code path would leak. - """ + byte-fallback token IDs, proving the old code path would leak.""" vocab = dict(_MODEL_CONFIGS[0].values[0]) tokenizer = ByteFallbackMockTokenizer(vocab, _SHARED_TOKENS, _SHARED_UFFFD_IDS) assert tokenizer.decode([200]) == "�" diff --git a/tests/parser/engine/trace_builder.py b/tests/parser/engine/trace_builder.py index 347df05b4d..36e347fc57 100644 --- a/tests/parser/engine/trace_builder.py +++ b/tests/parser/engine/trace_builder.py @@ -992,8 +992,7 @@ def _inkling_block( ) -> None: """Append one Inkling content block; blocks after the first start with the ``<|message_model|>`` role token (the first block continues the - generation prompt directly). - """ + generation prompt directly).""" if segs: segs.append(("<|message_model|>", True)) segs.append((kind_token, True)) diff --git a/tests/parser/mistral/test_tool_calls.py b/tests/parser/mistral/test_tool_calls.py index 8645a38dd3..25b41f44c2 100644 --- a/tests/parser/mistral/test_tool_calls.py +++ b/tests/parser/mistral/test_tool_calls.py @@ -492,8 +492,7 @@ def test_extract_tool_calls_pre_v11_regex_fallback( ): """The regex fallback path finds valid JSON via regex when the primary raw_decode fails on leading junk. It should re-serialize arguments - and return a valid tool call. - """ + and return a valid tool call.""" model_output = ( '[TOOL_CALLS] junk [{"name": "add", "arguments":{"a": 1, "b": 2}}] trail' ) @@ -2004,8 +2003,7 @@ def test_streaming_pre_v11_parallel_calls_batched_deltas( mistral_pre_v11_tool_parser, mistral_pre_v11_tokenizer, chunk_size, driver ): """A batched delta spanning the boundary between two parallel calls must - keep them on distinct indices (the bug collapsed both onto index 0). - """ + keep them on distinct indices (the bug collapsed both onto index 0).""" model_output = ( '[TOOL_CALLS] [{"name": "add", "arguments": {"a": 3.5, "b": 4}}, ' '{"name": "get_current_weather", "arguments": ' @@ -2123,8 +2121,7 @@ def test_reasoning_active_no_think_block_no_leak( chunk_size, ): """Tool call without a preceding think block must not leak as content - when the reasoning parser is active. - """ + when the reasoning parser is active.""" accumulated_content = "" function_names: list[str] = [] function_args_strs: list[str] = [] @@ -2225,8 +2222,7 @@ def test_adjust_request_pre_v11_required_clears_response_format( response_format so the tool schema is the sole structured-output constraint, matching the base ToolParser (otherwise the request either hits the "multiple constraints" engine error or, with no constraint, - rambles to finish_reason='length'). - """ + rambles to finish_reason='length').""" request = _make_request(tool_choice="required", response_format=response_format) result = mistral_pre_v11_tool_parser.adjust_request(request) @@ -2243,8 +2239,7 @@ def test_adjust_request_non_mistral_tokenizer_required_injects_schema( ) -> None: """The guided-schema injection must also fire for non-Mistral (e.g. HF-mode) tokenizers driving the Mistral tool parser, mirroring the base ToolParser so - required + response_format does not fall back to an unconstrained ramble. - """ + required + response_format does not fall back to an unconstrained ramble.""" request = _make_request( tool_choice="required", response_format={"type": "json_object"} ) diff --git a/tests/parser/test_streaming.py b/tests/parser/test_streaming.py index 6c4158b814..cad16746be 100644 --- a/tests/parser/test_streaming.py +++ b/tests/parser/test_streaming.py @@ -229,8 +229,7 @@ def _boundary_chunks(tokenizer, parser, end_token_id=None): def test_parse_delta_reasoning_not_dropped_on_boundary(tokenizer, request_obj): """Regression: reasoning must not be lost when a multi-token delta - spans the reasoning/tool-call boundary. - """ + spans the reasoning/tool-call boundary.""" parser = make_parser(tokenizer, reasoning=True, tool=True) chunks = _boundary_chunks(tokenizer, parser) results = stream_chunks(parser, tokenizer, chunks, request_obj) @@ -248,8 +247,7 @@ def test_parse_delta_reasoning_not_dropped_on_boundary(tokenizer, request_obj): def test_parse_delta_reasoning_boundary_no_tool_parser(tokenizer, request_obj): """When no tool parser is active, boundary-spanning chunks must still - preserve reasoning and pass post- text as content. - """ + preserve reasoning and pass post- text as content.""" parser = make_parser(tokenizer, reasoning=True, tool=False) chunks = _boundary_chunks(tokenizer, parser) results = stream_chunks(parser, tokenizer, chunks, request_obj) @@ -263,8 +261,7 @@ def test_parse_delta_reasoning_boundary_no_tool_parser(tokenizer, request_obj): def test_parse_delta_reasoning_only_no_think_leak(tokenizer, request_obj): """Regression: must not leak into content when streaming - token-by-token with reasoning=True, tool=False. - """ + token-by-token with reasoning=True, tool=False.""" parser = make_parser(tokenizer, reasoning=True, tool=False) results = stream_text( parser, tokenizer, MODEL_OUTPUT, request_obj, prompt_token_ids=[] @@ -306,8 +303,7 @@ def test_parse_delta_reasoning_only_thinking_disabled(tokenizer, request_obj): def test_parse_delta_finished_no_flush_without_tool_call_delta(tokenizer, request_obj): """When finished=True but the final parse_delta produces no - tool-call delta, unstreamed args are not flushed. - """ + tool-call delta, unstreamed args are not flushed.""" parser = make_parser(tokenizer, reasoning=False, tool=True) results = stream_text( @@ -330,8 +326,7 @@ def test_parse_delta_finished_no_flush_without_tool_call_delta(tokenizer, reques def test_parse_delta_finished_no_extra_args_when_fully_streamed(tokenizer, request_obj): """When all args have been streamed, finished=True must not - produce extra or duplicate arguments. - """ + produce extra or duplicate arguments.""" parser = make_parser(tokenizer, reasoning=False, tool=True) results = stream_text( parser, tokenizer, MODEL_OUTPUT, request_obj, prompt_token_ids=[] @@ -351,8 +346,7 @@ def test_parse_delta_finished_no_extra_args_when_fully_streamed(tokenizer, reque def test_parse_delta_finished_appends_remaining_args(tokenizer, request_obj): """When finished=True and the tool parser has unstreamed args, - parse_delta appends the remaining arguments to the tool-call delta. - """ + parse_delta appends the remaining arguments to the tool-call delta.""" parser = make_parser(tokenizer, reasoning=False, tool=True) token_ids = tokenizer.encode(MODEL_OUTPUT, add_special_tokens=False) @@ -499,8 +493,7 @@ def test_engine_reasoning_hermes_tool_token_by_token(tokenizer, request_obj): """Qwen3 engine reasoning + Hermes tool parser, token-by-token. Sanity check that the mixed engine/non-engine configuration works - when tokens arrive one at a time (no deferred content). - """ + when tokens arrive one at a time (no deferred content).""" parser = Qwen3ReasoningHermesToolParser(tokenizer) assert parser._reasoning_parser.engine_based_streaming is True @@ -527,8 +520,7 @@ def test_engine_reasoning_hermes_tool_boundary(tokenizer, request_obj): When and are in the same chunk with aligned text and token IDs, the engine processes both terminals and returns - the text as content. - """ + the text as content.""" parser = Qwen3ReasoningHermesToolParser(tokenizer) end_token_id = parser._reasoning_parser._parser_engine._reasoning_end_token_id chunks = _boundary_chunks(tokenizer, parser, end_token_id=end_token_id) @@ -559,8 +551,7 @@ def test_engine_reasoning_hermes_tool_text_holdback(tokenizer, request_obj): Without the fix, finish_streaming() is never called at the reasoning->tool transition when _engine_based is False, so the '<' is lost and the Hermes parser sees 'tool_call>...' instead of - '...'. - """ + '...'.""" parser = Qwen3ReasoningHermesToolParser(tokenizer) vocab = tokenizer.get_vocab() think_end_id = vocab[""] @@ -651,8 +642,7 @@ def test_engine_reasoning_no_tool_batched_content_passthrough(tokenizer, request batched delta carries ```` plus the following content (as happens with stream_interval > 1). The post-```` text must be emitted as content -- not dropped, not reclassified as - reasoning -- and the ```` marker must not leak either way. - """ + reasoning -- and the ```` marker must not leak either way.""" parser = Qwen3ReasoningNoToolParser(tokenizer) assert parser._reasoning_parser.engine_based_streaming is True assert parser._tool_parser is None @@ -680,8 +670,7 @@ def _decode_stream_deltas(tokenizer, groups): This mirrors how vLLM's detokenizer feeds ``parse_delta`` in production: byte-level UTF-8 hold-back means a character whose bytes span multiple tokens is only surfaced once complete (a naive - per-token ``decode`` would instead emit U+FFFD replacement chars). - """ + per-token ``decode`` would instead emit U+FFFD replacement chars).""" from tokenizers.decoders import DecodeStream stream = DecodeStream(skip_special_tokens=False) @@ -713,8 +702,7 @@ def test_engine_reasoning_hermes_tool_multibyte_holdback(tokenizer, request_obj) ``DecodeStream``. Its UTF-8 hold-back yields the correct character round-trip (a naive per-token decode would corrupt it), verifying the boundary stays byte-safe for multi-token - characters. - """ + characters.""" parser = Qwen3ReasoningHermesToolParser(tokenizer) vocab = tokenizer.get_vocab() think_end_id = vocab[""] diff --git a/tests/plugins_tests/test_endpoint_plugins.py b/tests/plugins_tests/test_endpoint_plugins.py index 97b74b7bc0..2d92153900 100644 --- a/tests/plugins_tests/test_endpoint_plugins.py +++ b/tests/plugins_tests/test_endpoint_plugins.py @@ -81,8 +81,7 @@ def test_no_plugins_loaded_when_allowlist_is_empty_string( ): """`VLLM_PLUGINS=""` parses to `[""]`, not `None` (see `vllm.envs`), so it must be treated as a (non strict) allowlist matching no plugin name, not - as "unset". - """ + as "unset".""" monkeypatch.setenv("VLLM_PLUGINS", "") assert load_endpoint_plugins(("generate",)) == [] @@ -167,8 +166,7 @@ def test_attach_is_noop_when_nothing_discovered(monkeypatch: pytest.MonkeyPatch) async def test_init_state_is_noop_without_phase_a(monkeypatch: pytest.MonkeyPatch): """`init_app_state` callers that never ran `build_app` (e.g. `run_batch.py`, which builds a bare `State()`) must not crash just - because `state.endpoint_plugins` was never set. - """ + because `state.endpoint_plugins` was never set.""" from starlette.datastructures import State monkeypatch.setenv("VLLM_PLUGINS", "dummy_admin_endpoint_plugin") @@ -186,8 +184,7 @@ async def test_render_server_attaches_endpoint_plugins_with_no_engine_client( """The CPU only render server has no `EngineClient` but a plugin eligible for the `render` task (`required_tasks` is `None` or includes `"render"`) still gets its routes attached at Phase A. Phase B passes `None` for - `engine_client` and it's up to the plugin to handle that. - """ + `engine_client` and it's up to the plugin to handle that.""" monkeypatch.setenv("VLLM_PLUGINS", "dummy_admin_endpoint_plugin") args = _build_args() @@ -213,8 +210,7 @@ async def test_render_server_attaches_endpoint_plugins_with_no_engine_client( @pytest.mark.asyncio async def test_endpoint_plugin_end_to_end(monkeypatch: pytest.MonkeyPatch): """Phase A (attach) + Phase B (init) wired through `build_app` then - exercised with a real HTTP request against the worked example plugin. - """ + exercised with a real HTTP request against the worked example plugin.""" monkeypatch.setenv("VLLM_PLUGINS", "dummy_admin_endpoint_plugin") args = _build_args() diff --git a/tests/plugins_tests/test_io_processor_plugins.py b/tests/plugins_tests/test_io_processor_plugins.py index c5c226cb54..14e1a2d576 100644 --- a/tests/plugins_tests/test_io_processor_plugins.py +++ b/tests/plugins_tests/test_io_processor_plugins.py @@ -38,8 +38,7 @@ def my_plugin_entry_points(): """Patch importlib.metadata.entry_points to expose a single 'my_plugin' entry point backed by DummyIOProcessor, exercising the full plugin-loading code path: entry_points → plugin.load() → func() → - resolve_obj_by_qualname → IOProcessor.__init__. - """ + resolve_obj_by_qualname → IOProcessor.__init__.""" qualname = f"{DummyIOProcessor.__module__}.{DummyIOProcessor.__qualname__}" ep = MagicMock() ep.name = "my_plugin" diff --git a/tests/quantization/test_auto_round.py b/tests/quantization/test_auto_round.py index a2fed9a2d4..2bc463b593 100644 --- a/tests/quantization/test_auto_round.py +++ b/tests/quantization/test_auto_round.py @@ -382,8 +382,7 @@ def test_inc_get_quant_method_unquantized_layer_with_model_prefix( layer_factory, ) -> None: """``model.``-prefixed extra_config entries trigger early exit for both - LinearBase and ParallelLMHead layers. - """ + LinearBase and ParallelLMHead layers.""" config = make_config(extra_config={"model.layer": {"bits": 16}}) layer = layer_factory() @@ -396,8 +395,7 @@ def test_inc_get_quant_method_unquantized_routed_experts_with_model_prefix( monkeypatch, ) -> None: """``model.``-prefixed extra_config entries trigger early exit for - RoutedExperts layers, returning UnquantizedFusedMoEMethod. - """ + RoutedExperts layers, returning UnquantizedFusedMoEMethod.""" class DummyUnquantizedFusedMoEMethod: def __init__(self, moe_config) -> None: @@ -420,8 +418,7 @@ def test_inc_get_quant_method_unquantized_routed_experts_with_model_prefix( def test_inc_get_quant_method_unknown_layer_with_model_prefix_returns_none() -> None: """``model.``-prefixed extra_config entries return None for unhandled - layer types (non-Linear, non-MoE). - """ + layer types (non-Linear, non-MoE).""" config = make_config(extra_config={"model.unknown": {"bits": 16}}) method = config.get_quant_method(DummyLayer(), "unknown") @@ -736,8 +733,7 @@ def test_wna16_cuda_low_bit_moe_routes_to_humming(monkeypatch, bits) -> None: @pytest.mark.parametrize("bits", [4, 8]) def test_wna16_cuda_high_bit_skips_humming(monkeypatch, bits) -> None: """4/8-bit int stays on the Marlin/GPTQ/AWQ path even on CUDA so a single - model can mix high-bit Marlin and low-bit humming layers. - """ + model can mix high-bit Marlin and low-bit humming layers.""" called = {"humming": False} monkeypatch.setattr(current_platform, "is_cuda", lambda: True) @@ -1668,8 +1664,7 @@ def test_inc_get_quant_method_unquantized_moe_returns_unquantized( monkeypatch, ) -> None: """Early-exit returns UnquantizedFusedMoEMethod for FusedMoE layers - when extra_config has bits >= 16. - """ + when extra_config has bits >= 16.""" config = make_config(extra_config={"layer": {"bits": 16}}) layer = object.__new__(RoutedExperts) layer.moe_config = None # UnquantizedFusedMoEMethod accepts moe_config diff --git a/tests/quantization/test_fp8.py b/tests/quantization/test_fp8.py index 44a508ed57..65e119b083 100644 --- a/tests/quantization/test_fp8.py +++ b/tests/quantization/test_fp8.py @@ -213,8 +213,7 @@ def test_deepseek_v41_vl_mapper_routes_linear_scales( ): """The VL wrapper must map ``.scale`` keys to the parameter the linear quant method registers, as the text model does. A hardcoded - ``weight_scale_inv`` raised KeyError for native MXFP8 checkpoints. - """ + ``weight_scale_inv`` raised KeyError for native MXFP8 checkpoints.""" from vllm.models.deepseek_v41.nvidia import model as model_module from vllm.models.deepseek_v41.nvidia import vl_model as vl_module diff --git a/tests/quantization/test_gfx950_moe.py b/tests/quantization/test_gfx950_moe.py index 3adcb020b6..b71e952b76 100644 --- a/tests/quantization/test_gfx950_moe.py +++ b/tests/quantization/test_gfx950_moe.py @@ -160,8 +160,7 @@ def test_qwen38_tep8_auto_fallback_respects_explicit_backend( @pytest.fixture def mxfp4_oracle_config(): """Stub the config the oracle reads (``model_config.quantization_config``) - so backend dispatch resolves without a real model / user override. - """ + so backend dispatch resolves without a real model / user override.""" from unittest.mock import patch with patch( diff --git a/tests/quantization/test_humming_mxfp4_block_fp8.py b/tests/quantization/test_humming_mxfp4_block_fp8.py index bf508dda89..dbec989df3 100644 --- a/tests/quantization/test_humming_mxfp4_block_fp8.py +++ b/tests/quantization/test_humming_mxfp4_block_fp8.py @@ -85,8 +85,7 @@ def test_block_fp8_activation_quant_config_is_block_quantized(): (FP8 dtype, [1, 128] block, not per-act-token). This is what makes the DeepEP prepare/finalize step quantize activations to block FP8 *before* the all-to-all dispatch instead of deferring to Humming -- and what makes - HummingExpertsBase.expects_unquantized_inputs return False. - """ + HummingExpertsBase.expects_unquantized_inputs return False.""" from vllm.model_executor.layers.quantization.utils.humming_utils import ( make_humming_moe_quant_config, ) @@ -108,8 +107,7 @@ def test_block_fp8_activation_quant_config_is_block_quantized(): def test_default_activation_quant_config_defers_to_humming(): """Without a block activation shape the config stays per-token (the deferred path): Humming quantizes internally, preserving pre-existing behavior for - every non-block-FP8 scheme. - """ + every non-block-FP8 scheme.""" from vllm.model_executor.layers.quantization.utils.humming_utils import ( make_humming_moe_quant_config, ) diff --git a/tests/quantization/test_int8_moe_oracle.py b/tests/quantization/test_int8_moe_oracle.py index 048b0e645a..8c838a785b 100644 --- a/tests/quantization/test_int8_moe_oracle.py +++ b/tests/quantization/test_int8_moe_oracle.py @@ -70,8 +70,7 @@ def _make_int8_moe_config(moe_backend: str = "auto") -> FusedMoEConfig: ) def test_int8_dynamic_schemes_dispatch_to_triton(weight_key, activation_key): """Both dynamic-activation INT8 MoE schemes (per-channel + per-tensor - weights) select the Triton backend. - """ + weights) select the Triton backend.""" config = _make_int8_moe_config() backend, experts_cls = select_int8_moe_backend( config, weight_key=weight_key, activation_key=activation_key diff --git a/tests/quantization/test_modelopt.py b/tests/quantization/test_modelopt.py index 8e590d7c3f..60b207c184 100644 --- a/tests/quantization/test_modelopt.py +++ b/tests/quantization/test_modelopt.py @@ -587,8 +587,7 @@ def test_modelopt_fp8_pb_wo_checkpoint_setup(monkeypatch, dist_init, workspace_i def test_modelopt_nvfp4_config_dispatches_w4a4_method(): """``quant_method="NVFP4"`` (W4A4) resolves to a ``(kNvfp4Static, kNvfp4Dynamic)`` QuantSpec under the generic - ``ModelOptLinearMethod``. - """ + ``ModelOptLinearMethod``.""" from vllm.model_executor.layers.linear import LinearBase config = ModelOptNvFp4Config( @@ -637,8 +636,7 @@ def test_modelopt_linear_method_builder_registry_override(monkeypatch): """The bespoke-method escape hatch: a format registered in ``LINEAR_METHOD_BUILDERS`` routes that algo to its own method instead of the generic ``ModelOptLinearMethod``. This is how a format that cannot be a - ``(weight, activation)`` key pair plugs into dispatch. - """ + ``(weight, activation)`` key pair plugs into dispatch.""" from vllm.model_executor.layers.linear import LinearBase from vllm.model_executor.layers.quantization import modelopt as m @@ -669,8 +667,7 @@ def test_modelopt_linear_method_builder_registry_override(monkeypatch): def test_modelopt_w4a16_respects_linear_backend(linear_backend, kernel_cls): """W4A16 (`activation=None`) kernel selection honors ``--linear-backend``: ``use_a16=True`` defaults to Marlin, but an explicit backend wins. The - generic method routes this through ``select_linear_kernel``. - """ + generic method routes this through ``select_linear_kernel``.""" from vllm.config.quantization import QuantSpec from vllm.model_executor.layers.quantization.modelopt import ( RuntimeDtypes, @@ -941,8 +938,7 @@ def test_modelopt_fp8_pb_wo_hides_output_padding(monkeypatch): def test_modelopt_fp8_pb_wo_rejects_non_128_input(): """Input width must still be a multiple of 128 (same as #53132, which only pads the output). A partial input block is refused loudly rather than - silently loading wrong scales. - """ + silently loading wrong scales.""" from vllm.model_executor.layers.quantization import modelopt as mo from vllm.model_executor.layers.quantization.utils.quant_utils import ( kFp8Static128BlockSym, diff --git a/tests/quantization/test_online_mxfp4.py b/tests/quantization/test_online_mxfp4.py index 8d29b4602c..9495a15ba6 100644 --- a/tests/quantization/test_online_mxfp4.py +++ b/tests/quantization/test_online_mxfp4.py @@ -411,8 +411,7 @@ def test_online_mxfp4_moe_matches_quark( ) -> tuple[torch.Tensor, torch.Tensor]: """Place the source weights into buffers of the padded size, the way the weight loader writes only the unpadded slice of a larger - allocation. - """ + allocation.""" w13 = torch.full( (num_experts, 2 * intermediate_size, hidden_size), padding_value, diff --git a/tests/quantization/test_per_token_kv_cache.py b/tests/quantization/test_per_token_kv_cache.py index 419b079d21..4d61932118 100644 --- a/tests/quantization/test_per_token_kv_cache.py +++ b/tests/quantization/test_per_token_kv_cache.py @@ -490,8 +490,7 @@ def test_per_token_head_negative_slot_skipped(qcfg: QuantConfig): ) def test_process_weights_sets_placeholder_scales(kv_cache_dtype: str): """Per-token-head should set _k_scale=1.0, _v_scale=1.0 - and delete checkpoint attrs. - """ + and delete checkpoint attrs.""" from vllm.model_executor.layers.quantization.kv_cache import ( BaseKVCacheMethod, ) diff --git a/tests/reasoning/test_kimi_k3_reasoning_parser.py b/tests/reasoning/test_kimi_k3_reasoning_parser.py index dad70ea8d6..ea5b374e6e 100644 --- a/tests/reasoning/test_kimi_k3_reasoning_parser.py +++ b/tests/reasoning/test_kimi_k3_reasoning_parser.py @@ -276,8 +276,7 @@ def _reference_is_reasoning_end(input_ids: list[int]) -> bool: def test_is_reasoning_end_streaming_only_scans_the_step_window(): """The decode-step check must not re-derive the answer from the whole sequence: an already-closed think block earlier in the sequence is the - engine's business (it latches `reasoning_ended`), not this call's. - """ + engine's business (it latches `reasoning_ended`), not this call's.""" parser = KimiK3ReasoningParser(DummyTokenizer()) prompt = [*CLOSE_IDS, *OPEN_IDS, 9, 9, 9] @@ -287,8 +286,7 @@ def test_is_reasoning_end_streaming_only_scans_the_step_window(): def test_is_reasoning_end_streaming_detects_marker_across_step_boundary(): """A 3-token marker can be split over decode steps; the check carries the - preceding len(marker)-1 tokens so the final token still completes it. - """ + preceding len(marker)-1 tokens so the final token still completes it.""" parser = KimiK3ReasoningParser(DummyTokenizer()) history = [*OPEN_IDS, 5, *CLOSE_IDS[:2]] @@ -299,8 +297,7 @@ def test_is_reasoning_end_streaming_detects_marker_across_step_boundary(): def test_is_reasoning_end_streaming_reopened_block_is_not_ended(): """Kimi K3 may close and immediately reopen the think channel inside one window (speculative decoding lands several tokens per step). The newest - marker wins, matching is_reasoning_end. - """ + marker wins, matching is_reasoning_end.""" parser = KimiK3ReasoningParser(DummyTokenizer()) window = [*CLOSE_IDS, *OPEN_IDS] @@ -327,8 +324,7 @@ def test_is_reasoning_end_streaming_thinking_disabled(): def test_reasoning_end_matches_reference_over_marker_dense_sequences(seed): """Both the full-sequence check and the per-step check must agree with the two-scan reference, on sequences where the markers (which share the suffix - [2, 3]) collide and overlap constantly. - """ + [2, 3]) collide and overlap constantly.""" import random rnd = random.Random(seed) diff --git a/tests/renderers/test_chat_utils_prompt_embeds.py b/tests/renderers/test_chat_utils_prompt_embeds.py index bcaff9b944..bbd4dc5c5f 100644 --- a/tests/renderers/test_chat_utils_prompt_embeds.py +++ b/tests/renderers/test_chat_utils_prompt_embeds.py @@ -116,8 +116,7 @@ def test_prompt_embeds_keys_registered(): def test_ensure_placeholder_token_is_single_token_and_idempotent(tokenizer): """Ensure the placeholder token is a single token and that multiple calls to - "ensure" are idempotent, across all tokenizer families. - """ + "ensure" are idempotent, across all tokenizer families.""" tid1 = _ensure_prompt_embeds_placeholder_token(tokenizer) tid2 = _ensure_prompt_embeds_placeholder_token(tokenizer) assert tid1 == tid2 @@ -470,8 +469,7 @@ def test_build_mixed_prompt_embeds(stream): @pytest.mark.parametrize("role", ["user", "system"]) async def test_end_to_end_expand_and_build(tokenizer, parse_fn, role): """Full renderer pipeline: parse -> chat template -> expand -> locate - -> build mixed prompt, across tokenizers, roles, and sync/async. - """ + -> build mixed prompt, across tokenizers, roles, and sync/async.""" tokenizer.chat_template = _SIMPLE_CHAT_TEMPLATE tid = _ensure_prompt_embeds_placeholder_token(tokenizer) @@ -526,8 +524,7 @@ async def test_end_to_end_expand_and_build(tokenizer, parse_fn, role): @pytest.mark.asyncio async def test_end_to_end_multi_message_conversation(tokenizer, parse_fn): """Full pipeline with prompt_embeds spread across system + user messages, - verifying ordering and positioning in the final token stream. - """ + verifying ordering and positioning in the final token stream.""" tokenizer.chat_template = _SIMPLE_CHAT_TEMPLATE tid = _ensure_prompt_embeds_placeholder_token(tokenizer) diff --git a/tests/renderers/test_gemma4_chat_template.py b/tests/renderers/test_gemma4_chat_template.py index c244b26723..7d6b0b05f8 100644 --- a/tests/renderers/test_gemma4_chat_template.py +++ b/tests/renderers/test_gemma4_chat_template.py @@ -33,8 +33,7 @@ def _render(template, messages, **kwargs): class TestGemma4ChatTemplate: def test_basic_multiturn_thinking_disabled(self, gemma4_template): """With enable_thinking=False (default), generation prompt ends with - an empty thought channel to suppress thinking. - """ + an empty thought channel to suppress thinking.""" messages = [ {"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi there!"}, @@ -50,8 +49,7 @@ class TestGemma4ChatTemplate: def test_basic_multiturn_thinking_enabled(self, gemma4_template): """With enable_thinking=True, generation prompt ends with model - turn opener (no thought suppression). - """ + turn opener (no thought suppression).""" messages = [ {"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi there!"}, @@ -146,8 +144,7 @@ class TestGemma4ChatTemplate: def test_tool_responses_openai_style(self, gemma4_template): """role='tool' messages are formatted as <|tool_response> blocks - with content dumped as-is. - """ + with content dumped as-is.""" messages = [ {"role": "user", "content": "Weather?"}, { @@ -205,8 +202,7 @@ class TestGemma4ChatTemplate: def test_generation_prompt_not_after_tool_response(self, gemma4_template): """add_generation_prompt=True should NOT add <|turn>model when the - last message type was tool_response (the model turn continues). - """ + last message type was tool_response (the model turn continues).""" messages = [ {"role": "user", "content": "Weather?"}, { @@ -233,8 +229,7 @@ class TestGemma4ChatTemplate: def test_reasoning_in_tool_chains(self, gemma4_template): """Reasoning field on assistant with tool_calls after last user - message emits <|channel>thought\\n.... - """ + message emits <|channel>thought\\n....""" messages = [ {"role": "user", "content": "Calculate something"}, { @@ -280,8 +275,7 @@ class TestGemma4ChatTemplate: def test_strip_thinking_in_model_content(self, gemma4_template): """<|channel>... in model content is stripped by the - strip_thinking macro. - """ + strip_thinking macro.""" messages = [ {"role": "user", "content": "Hi"}, { @@ -295,8 +289,7 @@ class TestGemma4ChatTemplate: def test_multi_turn_tool_chain(self, gemma4_template): """assistant->tool->assistant->tool produces exactly one - <|turn>model (later assistants continue the same turn). - """ + <|turn>model (later assistants continue the same turn).""" messages = [ {"role": "user", "content": "Do two things"}, { @@ -353,8 +346,7 @@ class TestGemma4ChatTemplate: def test_tool_response_with_multimodal_content(self, gemma4_template): """Multimodal placeholders in tool messages are emitted after the - tool_response block. - """ + tool_response block.""" messages = [ {"role": "user", "content": "Download the image and describe it."}, { @@ -388,8 +380,7 @@ class TestGemma4ChatTemplate: def test_tool_response_with_all_modalities(self, gemma4_template): """All multimodal types (image, audio, video) in a single tool - response are rendered. - """ + response are rendered.""" messages = [ {"role": "user", "content": "Process media"}, { diff --git a/tests/renderers/test_hf.py b/tests/renderers/test_hf.py index 624108a206..833656aa3c 100644 --- a/tests/renderers/test_hf.py +++ b/tests/renderers/test_hf.py @@ -308,8 +308,7 @@ def test_resolve_chat_template_kwargs(sample_json_schema, model, expected_kwargs def test_resolve_chat_template_resolves_name(): """When chat_template is a name, resolve_chat_template should return - the actual Jinja content so that kwargs detection works correctly. - """ + the actual Jinja content so that kwargs detection works correctly.""" from unittest.mock import MagicMock jinja_content = "{{ messages }}{% if tools %}{{ tools }}{% endif %}" @@ -331,8 +330,7 @@ def test_resolve_chat_template_resolves_name(): def test_resolve_chat_template_kwargs_with_template_name(): """Ensures template kwargs are not silently dropped when chat_template - was originally a template name that has been resolved to Jinja content. - """ + was originally a template name that has been resolved to Jinja content.""" from unittest.mock import MagicMock jinja_content = ( @@ -934,8 +932,7 @@ EFFORT_BREAKING_TEMPLATE = ( class TestApplyChatTemplateEffortTolerant: """Chat templates that reject unsupported reasoning_effort values should - surface a 400-style client error instead of crashing the request. - """ + surface a 400-style client error instead of crashing the request.""" @pytest.fixture def model_config(self): diff --git a/tests/renderers/test_process_multi_modal_uuids.py b/tests/renderers/test_process_multi_modal_uuids.py index 992177a3a6..8987782d71 100644 --- a/tests/renderers/test_process_multi_modal_uuids.py +++ b/tests/renderers/test_process_multi_modal_uuids.py @@ -49,8 +49,7 @@ def _build_text_only_renderer() -> HfRenderer: def test_text_only_model_mm_data_maps_to_bad_request(): """Sending multimodal data to a text-only model is a client mistake, so it - must surface as a ValueError and reach the client as HTTP 400, not 500. - """ + must surface as a ValueError and reach the client as HTTP 400, not 500.""" renderer = _build_text_only_renderer() with pytest.raises(ValueError, match="text-only") as exc_info: diff --git a/tests/renderers/test_prompt_embeds_payload_validation.py b/tests/renderers/test_prompt_embeds_payload_validation.py index fec937a4b7..bec28c4c49 100644 --- a/tests/renderers/test_prompt_embeds_payload_validation.py +++ b/tests/renderers/test_prompt_embeds_payload_validation.py @@ -127,8 +127,7 @@ def test_a_long_reason_is_truncated_and_says_how_much_was_left_out(model_config) def test_a_short_reason_is_passed_through_whole(model_config): """A reason that fits is not annotated -- the count only appears when it is - telling the reader something. - """ + telling the reader something.""" reason = "invalid magic number; corrupt file?" assert len(reason) <= _MAX_EMBED_ERROR_REASON_CHARS diff --git a/tests/renderers/test_sparse_tensor_concurrent_race.py b/tests/renderers/test_sparse_tensor_concurrent_race.py index c627dc31cb..a1683eee0b 100644 --- a/tests/renderers/test_sparse_tensor_concurrent_race.py +++ b/tests/renderers/test_sparse_tensor_concurrent_race.py @@ -218,8 +218,7 @@ class TestCrossLoaderLockSharing: def test_prompt_and_image_share_lock(self, model_config): """Prompt and image loaders cannot run their sparse guards - concurrently. - """ + concurrently.""" valid_prompt = _encode_tensor(_create_valid_dense_tensor()) valid_image = _encode_tensor(_create_valid_dense_tensor(hidden_size=10)) diff --git a/tests/renderers/test_sparse_tensor_validation.py b/tests/renderers/test_sparse_tensor_validation.py index d90ad1e09a..6cb26a8a1d 100644 --- a/tests/renderers/test_sparse_tensor_validation.py +++ b/tests/renderers/test_sparse_tensor_validation.py @@ -157,8 +157,7 @@ class TestPromptEmbedsValidation: def test_hidden_size_mismatch_rejected(self, model_config): """Tensors whose trailing dim doesn't match the model's hidden_size - must be rejected at parse time. - """ + must be rejected at parse time.""" # opt-125m has hidden_size=768, passing 512 triggers the check. wrong_hidden = torch.randn(10, 512, dtype=torch.float32) encoded = _encode_tensor(wrong_hidden) @@ -169,8 +168,7 @@ class TestPromptEmbedsValidation: def test_float_dtype_mismatch_cast_to_model_dtype(self, model_config): """Tensors whose dtype doesn't match the model's dtype but are still floating-point are cast, since API clients generally can't know the - server's `--dtype` setting ahead of time. - """ + server's `--dtype` setting ahead of time.""" # Fixture pins model dtype to float32, upload a bfloat16 tensor. mismatched_float = torch.randn(10, 768, dtype=torch.bfloat16) encoded = _encode_tensor(mismatched_float) @@ -183,8 +181,7 @@ class TestPromptEmbedsValidation: def test_non_float_dtype_rejected(self, model_config): """Non-floating-point dtypes cannot be safely cast for embeddings (e.g. integer tensors almost certainly indicate caller confusion), - so they are rejected at parse time. - """ + so they are rejected at parse time.""" non_float = torch.randint(0, 100, (10, 768), dtype=torch.int32) encoded = _encode_tensor(non_float) @@ -193,8 +190,7 @@ class TestPromptEmbedsValidation: def test_non_2d_tensor_rejected(self, model_config): """Tensors that aren't 2D (even after squeezing a leading dim) - must be rejected with a clear error. - """ + must be rejected with a clear error.""" # A 1D tensor cannot be interpreted as (num_tokens, hidden_size). bad = torch.randn(768, dtype=torch.float32) encoded = _encode_tensor(bad) @@ -204,8 +200,7 @@ class TestPromptEmbedsValidation: def test_non_tensor_payload_rejected(self, model_config): """Deserializing to a non-Tensor object must raise a clear error - instead of propagating an AssertionError. - """ + instead of propagating an AssertionError.""" # `torch.save` will serialize a plain dict; `weights_only=True` allows # loading built-in containers, so this exercises the isinstance check. buffer = io.BytesIO() @@ -463,8 +458,7 @@ class TestEmbeddingDecodeSizeLimit: def test_default_limit_would_reject_the_real_payload(self): """The shipped default has to bound the actual attack, not just the shrunken shape used above. Checked arithmetically so no test ever asks - the allocator for 4 TiB. - """ + the allocator for 4 TiB.""" dense_bytes = BOMB_SHAPE[0] * BOMB_SHAPE[1] * 4 assert dense_bytes > envs.VLLM_MAX_EMBED_DECODE_BYTES > 0 @@ -522,8 +516,7 @@ class TestEmbeddingDecodeSizeLimit: @pytest.mark.parametrize("io_cls,parameter", EMBEDDING_MEDIA_IO) def test_media_io_rejects_non_tensor_payload(self, io_cls, parameter): """These three had no `isinstance` check, so a non-tensor payload - surfaced as an `AttributeError` (500) rather than a 4xx. - """ + surfaced as an `AttributeError` (500) rather than a 4xx.""" buffer = io.BytesIO() torch.save({"not": "a tensor"}, buffer) encoded = base64.b64encode(buffer.getvalue()).decode("utf-8") diff --git a/tests/renderers/test_token_offsets.py b/tests/renderers/test_token_offsets.py index 973ea175cb..fc9192bb43 100644 --- a/tests/renderers/test_token_offsets.py +++ b/tests/renderers/test_token_offsets.py @@ -26,8 +26,7 @@ def fast_tokenizer(): def _make_base_renderer_with(tokenizer): """Build a minimal BaseRenderer subclass that exposes the tokenizer so we can call ``_tokenize_prompt`` directly. BaseRenderer is abstract because of - ``render_messages``; we just need a stub. - """ + ``render_messages``; we just need a stub.""" from vllm.renderers.base import BaseRenderer class _StubRenderer(BaseRenderer): @@ -92,8 +91,7 @@ class TestTokenizePromptOffsets: def test_base_renderer_without_override_yields_no_offsets(self, fast_tokenizer): """A renderer that does not override ``_can_produce_offsets`` never emits offsets, even with a fast tokenizer and the flag set. This locks - in the base-default-False / subclass-override design. - """ + in the base-default-False / subclass-override design.""" from vllm.renderers.base import BaseRenderer class _BareRenderer(BaseRenderer): @@ -127,8 +125,7 @@ class TestTokenizePromptOffsets: def test_slow_tokenizer_with_flag_no_offsets(self, fast_tokenizer): """Force is_fast=False to simulate a Slow tokenizer: the flag is set - but offsets must not be returned because it cannot produce them. - """ + but offsets must not be returned because it cannot produce them.""" from unittest.mock import PropertyMock, patch renderer = _make_base_renderer_with(fast_tokenizer) @@ -147,8 +144,7 @@ class TestTokenizePromptOffsets: @pytest.mark.parametrize("mm_key", ["multi_modal_data", "multi_modal_uuids"]) def test_multimodal_with_flag_no_offsets(self, fast_tokenizer, mm_key): """Offsets index the text prompt, which is meaningless once multimodal - data is interleaved, so they are suppressed when MM inputs are present. - """ + data is interleaved, so they are suppressed when MM inputs are present.""" renderer = _make_base_renderer_with(fast_tokenizer) params = TokenizeParams(max_total_tokens=None, return_token_offsets=True) prompt = {"prompt": "Hello.", mm_key: {"image": ["x"]}} @@ -160,8 +156,7 @@ class TestTokenizePromptOffsets: @pytest.mark.asyncio async def test_tokenize_prompt_async_returns_offsets(self, fast_tokenizer): """The async path offloads the sync tokenizer; it must yield the same - offsets as the sync path. - """ + offsets as the sync path.""" renderer = _make_base_renderer_with(fast_tokenizer) params = TokenizeParams(max_total_tokens=None, return_token_offsets=True) diff --git a/tests/test_cmake_utils.py b/tests/test_cmake_utils.py index 572bc76caa..5d217433db 100644 --- a/tests/test_cmake_utils.py +++ b/tests/test_cmake_utils.py @@ -40,8 +40,7 @@ def test_extract_archs_prefers_sass_target_over_corrupted_virtual_arch( ): """Torch's autodetection can emit a bogus arch=compute_* half (e.g. capability 12.1 corrupted to arch=compute_20,code=sm_121); the SASS - target must win, while PTX-only entries keep the virtual arch. - """ + target must win, while PTX-only entries keep the virtual arch.""" repo_root = Path(__file__).parents[1] script = tmp_path / "test_extract_archs.cmake" script.write_text( diff --git a/tests/test_config.py b/tests/test_config.py index 4b37b4f56e..ce2580934a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -441,8 +441,7 @@ def test_no_hisparse_connector_keeps_attention_config_unset(monkeypatch): def test_rocm_keeps_compiled_deepseek_defaults(monkeypatch): """ROCm keeps the DSA models (DeepSeek V3.2/V4, GLM-5.2) on their compiled - MRV1 paths and off breakable cudagraphs by default. - """ + MRV1 paths and off breakable cudagraphs by default.""" from vllm.config.vllm import ( ROCM_DEFAULT_MRV1_ARCHITECTURES, default_breakable_cudagraph_architectures, @@ -657,8 +656,7 @@ def test_v2_model_runner_supports_extract_hidden_states(): def test_dflash2_draft_forces_v2_model_runner(): """A DFlash2 draft must reach the V2 speculator, the only one that runs its - candidate selector; on V1 it would draft as DFlash1 without raising. - """ + candidate selector; on V1 it would draft as DFlash1 without raising.""" def config(method, architectures): return SimpleNamespace( @@ -771,8 +769,7 @@ def test_late_piecewise_restrictions_without_compilation(monkeypatch, engine_kwa def test_resolve_cudagraph_mode_skips_mamba_block_check_while_profiling(): """Cudagraph memory profiling uses a minimal KV cache, so the Mamba - block-count guard must only fire for the real cache sizing. - """ + block-count guard must only fire for the real cache sizing.""" kv_cache_config = SimpleNamespace(has_mamba_layers=True, num_blocks=4) compilation_config = CompilationConfig( @@ -1097,8 +1094,7 @@ def test_v1_model_runner_rejects_v2_only_features(): def test_batch_sharded_sampling_rejects_return_sampling_mask(): """The batch-sharded gather drops sampling masks, so the combination must - fail loudly instead of returning ``sampling_mask=None``. - """ + fail loudly instead of returning ``sampling_mask=None``.""" config = SimpleNamespace( parallel_config=SimpleNamespace( enable_batch_sharded_sampling=True, tensor_parallel_size=2 @@ -2195,8 +2191,7 @@ class MockConfig: @patch("vllm.transformers_utils.runai_utils.ObjectStorageModel.pull_files") def test_s3_url_model_tokenizer_paths(mock_pull_files, s3_url): """Test that S3 URLs create deterministic local directories for model and - tokenizer. - """ + tokenizer.""" # Mock pull_files to avoid actually downloading files during tests mock_pull_files.return_value = None @@ -2294,8 +2289,7 @@ def test_s3_url_different_models_create_different_directories(mock_pull_files): @patch("vllm.transformers_utils.runai_utils.ObjectStorageModel.pull_files") def test_s3_url_different_model_and_tokenizer(mock_pull_files): """Test that when model and tokenizer are different cloud URIs, - pull_files receives the correct URI for each. - """ + pull_files receives the correct URI for each.""" mock_pull_files.return_value = None model_url = "s3://bucket/model/" @@ -2840,8 +2834,7 @@ def test_vllm_config_explicit_overrides(): def test_fusion_pass_op_priority(): """This test checks that custom op enablement & IR op priority - correctly control default fusions - """ + correctly control default fusions""" # Default config, O2, rms_norm+quant fusion disabled cfg1 = VllmConfig() assert not cfg1.compilation_config.pass_config.fuse_norm_quant @@ -2925,8 +2918,7 @@ def test_needs_dp_coordination( def test_fault_tolerance_requires_single_api_server(): """Fault tolerance assumes one AsyncMPClient manages all engines, so it - is incompatible with API server scale-out (_api_process_count > 1). - """ + is incompatible with API server scale-out (_api_process_count > 1).""" with pytest.raises(ValueError, match="single API server"): ParallelConfig(enable_fault_tolerance=True, _api_process_count=2) @@ -2936,8 +2928,7 @@ def test_fault_tolerance_requires_single_api_server(): def test_renderer_num_workers_with_mm_cache(): """Disallow renderer_num_workers > 1 with the mm processor cache only for - pooling models, whose preprocessing runs on the renderer workers. - """ + pooling models, whose preprocessing runs on the renderer workers.""" mm_model = "Qwen/Qwen2-VL-2B-Instruct" # Should raise: pooling + multi-worker + cache enabled (default cache_gb=4) @@ -3263,8 +3254,7 @@ def test_watermarking_forces_model_runner_v2(monkeypatch): def test_mtp_draft_uses_model_weights_not_local_cache(mock_model_config_cls): """Regression test: MTP + runai_streamer should use model_weights (original S3 URL) for the draft model, not model (local cache dir set by - pull_runai_model_from_obj_storage). - """ + pull_runai_model_from_obj_storage).""" from unittest.mock import MagicMock s3_url = "s3://my-bucket/Qwen3-35B-A3B-FP8" diff --git a/tests/test_logger.py b/tests/test_logger.py index f051fe205b..2ff100151b 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -51,8 +51,7 @@ def test_trace_function_call(): def test_default_vllm_root_logger_configuration(monkeypatch): """This test presumes that VLLM_CONFIGURE_LOGGING (default: True) and VLLM_LOGGING_CONFIG_PATH (default: None) are not configured and default - behavior is activated. - """ + behavior is activated.""" monkeypatch.setenv("VLLM_LOGGING_COLOR", "0") _configure_vllm_root_logger() @@ -76,8 +75,7 @@ def test_default_vllm_root_logger_configuration(monkeypatch): def test_descendent_loggers_depend_on_and_propagate_logs_to_root_logger(monkeypatch): """This test presumes that VLLM_CONFIGURE_LOGGING (default: True) and VLLM_LOGGING_CONFIG_PATH (default: None) are not configured and default - behavior is activated. - """ + behavior is activated.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1") monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False) @@ -107,8 +105,7 @@ def test_descendent_loggers_depend_on_and_propagate_logs_to_root_logger(monkeypa def test_logger_configuring_can_be_disabled(monkeypatch): """This test calls _configure_vllm_root_logger again to test custom logging config behavior, however mocks are used to ensure no changes in behavior or - configuration occur. - """ + configuration occur.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "0") monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False) @@ -120,8 +117,7 @@ def test_logger_configuring_can_be_disabled(monkeypatch): def test_an_error_is_raised_when_custom_logging_config_file_does_not_exist(monkeypatch): """This test calls _configure_vllm_root_logger again to test custom logging config behavior, however it fails before any change in behavior or - configuration occurs. - """ + configuration occurs.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1") monkeypatch.setenv( "VLLM_LOGGING_CONFIG_PATH", @@ -137,8 +133,7 @@ def test_an_error_is_raised_when_custom_logging_config_file_does_not_exist(monke def test_an_error_is_raised_when_custom_logging_config_is_invalid_json(monkeypatch): """This test calls _configure_vllm_root_logger again to test custom logging config behavior, however it fails before any change in behavior or - configuration occurs. - """ + configuration occurs.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1") with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file: @@ -165,8 +160,7 @@ def test_an_error_is_raised_when_custom_logging_config_is_unexpected_json( ): """This test calls _configure_vllm_root_logger again to test custom logging config behavior, however it fails before any change in behavior or - configuration occurs. - """ + configuration occurs.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1") with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file: @@ -182,8 +176,7 @@ def test_an_error_is_raised_when_custom_logging_config_is_unexpected_json( def test_custom_logging_config_is_parsed_and_used_when_provided(monkeypatch): """This test calls _configure_vllm_root_logger again to test custom logging config behavior, however mocks are used to ensure no changes in behavior or - configuration occur. - """ + configuration occur.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1") valid_logging_config = { @@ -207,8 +200,7 @@ def test_custom_logging_config_is_parsed_and_used_when_provided(monkeypatch): def test_custom_logging_config_causes_an_error_if_configure_logging_is_off(monkeypatch): """This test calls _configure_vllm_root_logger again to test custom logging config behavior, however mocks are used to ensure no changes in behavior or - configuration occur. - """ + configuration occur.""" monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "0") valid_logging_config = { diff --git a/tests/test_ray_env.py b/tests/test_ray_env.py index 43ec51a8f8..945b2d80b6 100644 --- a/tests/test_ray_env.py +++ b/tests/test_ray_env.py @@ -15,8 +15,7 @@ from vllm.v1.executor.ray_utils import WORKER_SPECIFIC_ENV_VARS class TestDefaultPrefixes: """Built-in prefixes (VLLM_, LMCACHE_, NCCL_, UCX_, HF_, HUGGING_FACE_) - should be forwarded without any extra configuration. - """ + should be forwarded without any extra configuration.""" @patch.dict(os.environ, {"LMCACHE_LOCAL_CPU": "True"}, clear=False) def test_lmcache_prefix(self): @@ -54,8 +53,7 @@ class TestDefaultExtraVars: def test_pythonhashseed_in_result(self): """PYTHONHASHSEED should always be in the result set (as a name to - copy) regardless of whether it is actually set in os.environ. - """ + copy) regardless of whether it is actually set in os.environ.""" result = get_env_vars_to_copy() assert "PYTHONHASHSEED" in result diff --git a/tests/tokenizers_/test_deepseek_v4.py b/tests/tokenizers_/test_deepseek_v4.py index aac88553e6..a55aa57666 100644 --- a/tests/tokenizers_/test_deepseek_v4.py +++ b/tests/tokenizers_/test_deepseek_v4.py @@ -452,8 +452,7 @@ def test_deepseek_v4_image_blocks_become_placeholders(): def test_deepseek_v4_image_sentinel_ids_match_tokenizer(): """The borrowed sentinel ids must line up with the reserved - ``<|place_holder_mm_span_XXXX|>`` tokens in the tokenizer. - """ + ``<|place_holder_mm_span_XXXX|>`` tokens in the tokenizer.""" from vllm.models.deepseek_v4.common.mm_preprocess import ( IMAGE_SENTINEL_BASE_ID, IMAGE_SENTINEL_TOKEN_NAMES, diff --git a/tests/tokenizers_/test_hf.py b/tests/tokenizers_/test_hf.py index f1dfd046b9..61c81302f0 100644 --- a/tests/tokenizers_/test_hf.py +++ b/tests/tokenizers_/test_hf.py @@ -51,8 +51,7 @@ def _check_consistency(target: TokenizerLike, expected: TokenizerLike): def test_thread_pool_tokenizer_pickle(model_id: str): """Regression test for issue #45433: the thread-pool tokenizer wrapper reconstructs through maybe_make_thread_pool on unpickling, which used to - fall off the end and return None. - """ + fall off the end and return None.""" reference_tokenizer = AutoTokenizer.from_pretrained(model_id) pooled_tokenizer = maybe_make_thread_pool(deepcopy(reference_tokenizer)) diff --git a/tests/tool_parsers/test_apertus_tool_parser.py b/tests/tool_parsers/test_apertus_tool_parser.py index f3cf5fcaf4..5ab0a2bcc7 100644 --- a/tests/tool_parsers/test_apertus_tool_parser.py +++ b/tests/tool_parsers/test_apertus_tool_parser.py @@ -341,8 +341,7 @@ class TestStreamingExtraction: def test_mtp_streaming_massive_chunk(self, parser, mock_request): """Simulates MTP predicting text, tool calls, - and trailing text all in a single chunk. - """ + and trailing text all in a single chunk.""" chunks = [ "Sure! " '<|tools_prefix|>[{"get_weather": {"location": "London"}}]<|tools_suffix|>' @@ -375,8 +374,7 @@ class TestStreamingExtraction: def test_mtp_streaming_skip_and_catch_up(self, parser, mock_request): """Simulates MTP chunks that jump over entire tools - (e.g., from middle of tool 1 to middle of tool 3). - """ + (e.g., from middle of tool 1 to middle of tool 3).""" chunks = [ '<|tools_prefix|>[{"t1": {"a": 1}', '}, {"t2": {"b": 2}}, {"t3": {"c": 3', @@ -395,8 +393,7 @@ class TestStreamingExtraction: def test_vllm_streaming_character_by_character(self, parser, mock_request): """Simulates worst-case vLLM fragmentation where - chunks arrive character-by-character. - """ + chunks arrive character-by-character.""" text = ( 'Hi <|tools_prefix|>[{"get_weather": ' '{"location": "London"}}]<|tools_suffix|> ' @@ -414,8 +411,7 @@ class TestStreamingExtraction: def test_vllm_streaming_empty_deltas(self, parser, mock_request): """Simulates vLLM stream producing empty string chunks - (e.g., hidden tokens or artifacts). - """ + (e.g., hidden tokens or artifacts).""" chunks = [ "Wait", "", diff --git a/tests/tool_parsers/test_deepseekv32_tool_parser.py b/tests/tool_parsers/test_deepseekv32_tool_parser.py index d0d032167a..40ad6033d3 100644 --- a/tests/tool_parsers/test_deepseekv32_tool_parser.py +++ b/tests/tool_parsers/test_deepseekv32_tool_parser.py @@ -173,8 +173,7 @@ class TestExtractToolCalls: def test_string_attr_true_coerced_by_schema(self): """string="true" delivers a string, but the engine's schema-aware - type fixer coerces it to the schema type (integer). - """ + type fixer coerces it to the schema type (integer).""" tool = ChatCompletionToolsParam( function=FunctionDefinition( name="score", @@ -288,8 +287,7 @@ class TestExtractToolCalls: def test_string_attr_true_coerced_by_composed_schema(self): """string="true" delivers a JSON string, but the engine's schema-aware - type fixer coerces it to the composed schema type (object). - """ + type fixer coerces it to the composed schema type (object).""" tool = ChatCompletionToolsParam( function=FunctionDefinition( name="set_timer", @@ -323,8 +321,7 @@ class TestExtractToolCalls: def test_arguments_wrapper_repaired(self): """A single 'arguments' wrapper parameter must be unwrapped when it - is not part of the tool schema and the inner object matches schema fields. - """ + is not part of the tool schema and the inner object matches schema fields.""" tool = ChatCompletionToolsParam( function=FunctionDefinition( name="get_weather", @@ -495,8 +492,7 @@ class TestExtractToolCalls: def test_null_coerced_back_to_string_by_schema(self): """string="false" with 'null' is json-parsed to None, but the - engine's schema fixer coerces it back to "null" for string schemas. - """ + engine's schema fixer coerces it back to "null" for string schemas.""" tool = ChatCompletionToolsParam( function=FunctionDefinition( name="echo", @@ -659,8 +655,7 @@ class TestExtractToolCallsStreaming: def test_string_attr_true_coerced_by_schema_streaming(self): """Streaming: string='true' delivers a string but the engine's - schema fixer coerces it to the schema type (integer). - """ + schema fixer coerces it to the schema type (integer).""" tool = ChatCompletionToolsParam( function=FunctionDefinition( name="score", @@ -976,8 +971,7 @@ class TestExtractToolCallsStreaming: def test_no_marker_leak_chunked(self, parser): """Chunked streaming must NOT leak DSML start-marker fragments - as content (GitHub #40801). - """ + as content (GitHub #40801).""" full_text = build_tool_call("fn", {"k": "v"}) deltas = self._stream_chunked(parser, full_text, chunk_size=5) content = "".join(d.content for d in deltas if d.content is not None) @@ -987,8 +981,7 @@ class TestExtractToolCallsStreaming: def test_no_marker_leak_with_prefix_chunked(self, parser): """Content before a tool call must not include start-marker - fragments when chunked (GitHub #40801). - """ + fragments when chunked (GitHub #40801).""" full_text = "Hello!" + build_tool_call("fn", {"a": "b"}) deltas = self._stream_chunked(parser, full_text, chunk_size=5) content = "".join(d.content for d in deltas if d.content is not None) @@ -1000,8 +993,7 @@ class TestExtractToolCallsStreaming: def test_no_marker_leak_char_by_char(self, parser): """Character-by-character streaming must not leak marker - fragments (GitHub #40801). - """ + fragments (GitHub #40801).""" full_text = build_tool_call("fn", {"k": "v"}) deltas = self._stream_chunked(parser, full_text, chunk_size=1) content = "".join(d.content for d in deltas if d.content is not None) @@ -1011,8 +1003,7 @@ class TestExtractToolCallsStreaming: def test_no_marker_leak_all_split_points(self, parser): """Start token split at every possible boundary must not - leak (GitHub #40801). - """ + leak (GitHub #40801).""" for chunk_size in range(1, len(FC_START) + 2): p = make_parser() full_text = build_tool_call("fn", {"k": "v"}) @@ -1024,8 +1015,7 @@ class TestExtractToolCallsStreaming: def test_false_partial_marker_emitted(self, parser): """Text ending with a prefix of the start token that turns out - NOT to be a marker must still be emitted as content. - """ + NOT to be a marker must still be emitted as content.""" full_text = "<|DSM some regular text" deltas = self._stream_chunked(parser, full_text, chunk_size=3) content = "".join(d.content for d in deltas if d.content is not None) diff --git a/tests/tool_parsers/test_gemma4_tool_parser.py b/tests/tool_parsers/test_gemma4_tool_parser.py index bfb12ff157..97ed0cd69d 100644 --- a/tests/tool_parsers/test_gemma4_tool_parser.py +++ b/tests/tool_parsers/test_gemma4_tool_parser.py @@ -124,8 +124,7 @@ def mock_request(): class TestParseGemma4Args: """Values are returned as strings; type coercion to proper JSON types - happens at the engine layer. - """ + happens at the engine layer.""" def test_empty_string(self): assert _parse_gemma4_args("") == {} diff --git a/tests/tool_parsers/test_gigachat3_tool_parser.py b/tests/tool_parsers/test_gigachat3_tool_parser.py index be9eb06f88..e5a1692ffa 100644 --- a/tests/tool_parsers/test_gigachat3_tool_parser.py +++ b/tests/tool_parsers/test_gigachat3_tool_parser.py @@ -18,8 +18,7 @@ from vllm.tool_parsers import ToolParser, ToolParserManager @pytest.fixture(scope="function") def default_tokenizer() -> TokenizerLike: """Override module-scoped default_tokenizer because gigachat tests - mutate the tokenizer via ``add_tokens``. - """ + mutate the tokenizer via ``add_tokens``.""" return AutoTokenizer.from_pretrained("openai-community/gpt2") diff --git a/tests/tool_parsers/test_kimi_k3_named_tool_choice.py b/tests/tool_parsers/test_kimi_k3_named_tool_choice.py index 740f4c3013..36b04b67b1 100644 --- a/tests/tool_parsers/test_kimi_k3_named_tool_choice.py +++ b/tests/tool_parsers/test_kimi_k3_named_tool_choice.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Named tool choice for Kimi K3: allowed when the XTML structural tag is -attached (strict tool calling), rejected otherwise. -""" +attached (strict tool calling), rejected otherwise.""" import pytest diff --git a/tests/tool_parsers/test_lfm2_tool_parser.py b/tests/tool_parsers/test_lfm2_tool_parser.py index 599aec7d92..9ed30e1598 100644 --- a/tests/tool_parsers/test_lfm2_tool_parser.py +++ b/tests/tool_parsers/test_lfm2_tool_parser.py @@ -416,8 +416,7 @@ def test_tool_call( def test_empty_tool_call_block(body: str, lfm2_tokenizer: TokenizerLike): """An empty block ([] or [ ]) means the model called no tools; it must not report tools_called=True with zero tool calls (the invariant - run_tool_extraction asserts). - """ + run_tool_extraction asserts).""" cls = ToolParserManager.get_tool_parser("lfm2") model_output = f"{TOOL_CALL_START}[{body}]{TOOL_CALL_END}" @@ -437,8 +436,7 @@ def test_whitespace_after_start_token(lfm2_tokenizer: TokenizerLike): not break parsing. The streaming path used to feed the indented text to ast.parse verbatim, so every completion candidate raised IndentationError and the call was silently dropped (non-streaming - stripped it and succeeded). - """ + stripped it and succeeded).""" cls = ToolParserManager.get_tool_parser("lfm2") model_output = f"{TOOL_CALL_START} [{SIMPLE_FUNCTION_OUTPUT}]{TOOL_CALL_END}" @@ -478,8 +476,7 @@ def test_streaming_full_block_and_trailing_in_single_delta( ): """The entire <|tool_call_start|>[...]<|tool_call_end|> block plus trailing assistant text arrive in one delta. Trailing content must - still be emitted — not silently dropped. - """ + still be emitted — not silently dropped.""" tool_parser: ToolParser = ToolParserManager.get_tool_parser("lfm2")(lfm2_tokenizer) full_text = f"{TOOL_CALL_START}[{SIMPLE_FUNCTION_OUTPUT}]{TOOL_CALL_END}\nDone." @@ -494,8 +491,7 @@ def test_streaming_leading_content_and_full_block_in_single_delta( lfm2_tokenizer: TokenizerLike, ): """Leading assistant text plus the entire tool block arrive in one - delta. Leading content must be emitted — not silently dropped. - """ + delta. Leading content must be emitted — not silently dropped.""" tool_parser: ToolParser = ToolParserManager.get_tool_parser("lfm2")(lfm2_tokenizer) full_text = ( f"Let me check. {TOOL_CALL_START}[{SIMPLE_FUNCTION_OUTPUT}]{TOOL_CALL_END}" @@ -512,8 +508,7 @@ def test_streaming_leading_block_and_trailing_in_single_delta( lfm2_tokenizer: TokenizerLike, ): """Leading text + complete tool block + trailing text in one delta. - Both leading and trailing content must be preserved. - """ + Both leading and trailing content must be preserved.""" tool_parser: ToolParser = ToolParserManager.get_tool_parser("lfm2")(lfm2_tokenizer) full_text = ( "Let me check. " @@ -534,8 +529,7 @@ def test_echoed_tool_call_body_not_leaked_to_content( """LFM2 sometimes emits the tool call body again after the first <|tool_call_end|>, capped with a second <|tool_call_end|>. The echoed body must not surface as assistant content — neither in - streaming nor non-streaming paths. - """ + streaming nor non-streaming paths.""" tool_parser: ToolParser = ToolParserManager.get_tool_parser("lfm2")(lfm2_tokenizer) body = ( "[grocery.orderIngredients(" @@ -570,8 +564,7 @@ def test_streaming_char_by_char_multi_dict_list(lfm2_tokenizer: TokenizerLike): character at a time. Every prefix lands in some partial-parse state (mid-key, mid-value, open quote inside dict, empty dict, etc.). The parser must not raise — incomplete prefixes should silently wait for - more text instead of logging exceptions. - """ + more text instead of logging exceptions.""" tool_parser: ToolParser = ToolParserManager.get_tool_parser("lfm2")(lfm2_tokenizer) full_text = ( f"{TOOL_CALL_START}[grocery.orderIngredients(" @@ -602,8 +595,7 @@ def test_streaming_char_by_char_multi_dict_list(lfm2_tokenizer: TokenizerLike): def test_streaming_dotted_name_in_single_delta(lfm2_tokenizer: TokenizerLike): """A pythonic call with a dotted/attribute function name (e.g. ``domain.method(arg=...)``) must be parsed correctly in streaming mode - just as in non-streaming mode. - """ + just as in non-streaming mode.""" tool_parser: ToolParser = ToolParserManager.get_tool_parser("lfm2")(lfm2_tokenizer) full_text = f"{TOOL_CALL_START}[{DOTTED_NAME_FUNCTION_OUTPUT}]{TOOL_CALL_END}" @@ -619,8 +611,7 @@ def test_adjust_request_disables_skip_special_tokens( """When tools are present, the parser must force ``skip_special_tokens=False`` so the engine does not strip the <|tool_call_start|>/<|tool_call_end|> sentinels before they reach the - parser. - """ + parser.""" from vllm.entrypoints.openai.chat_completion.protocol import ( ChatCompletionRequest, ) diff --git a/tests/tool_use/test_muse_glimmer.py b/tests/tool_use/test_muse_glimmer.py index 6232f10e43..77f99a47ec 100644 --- a/tests/tool_use/test_muse_glimmer.py +++ b/tests/tool_use/test_muse_glimmer.py @@ -220,8 +220,7 @@ def test_reasoning_then_parallel_calls(): def _stream(raw: str, chunk: int): """Feed ``raw`` incrementally in ``chunk``-char steps through BOTH streaming - parsers; return (reasoning, content, tool_calls). - """ + parsers; return (reasoning, content, tool_calls).""" reasoning, content, toolcalls = [], [], [] prev = "" i = 0 diff --git a/tests/tool_use/test_tool_choice_required.py b/tests/tool_use/test_tool_choice_required.py index bead3c6f32..f37a3c9681 100644 --- a/tests/tool_use/test_tool_choice_required.py +++ b/tests/tool_use/test_tool_choice_required.py @@ -376,8 +376,7 @@ WEB_SEARCH_TOOL = WebSearchTool(type="web_search") class TestNonFunctionToolsSkipped: """Non-function tools (web_search, etc.) must be silently skipped - by the tool-schema utilities instead of raising TypeError. - """ + by the tool-schema utilities instead of raising TypeError.""" def test_find_tool_properties_skips_web_search(self): tools = [WEB_SEARCH_TOOL, FUNCTION_TOOL] diff --git a/tests/transformers_utils/processors/test_glm5next.py b/tests/transformers_utils/processors/test_glm5next.py index 0e24d9853b..917a3f627c 100644 --- a/tests/transformers_utils/processors/test_glm5next.py +++ b/tests/transformers_utils/processors/test_glm5next.py @@ -330,8 +330,7 @@ def test_sample_frames_fps_interval(video_processor): def test_defaults_mirror_checkpoint_config(): """Bare instantiation matches the checkpoint's ``processor_config.json`` - token-budget style defaults; ``size`` carries no budget. - """ + token-budget style defaults; ``size`` carries no budget.""" image_processor = Glm5NextImageProcessor() assert image_processor.patch_expand_factor == 1 assert image_processor.min_image_tokens == 16 @@ -365,8 +364,7 @@ def test_missing_token_budgets_rejected(): def test_video_config_fields_land(): """fps_interval / max_frame_count_dynamic from the dedicated config - shape sampling without any request overrides. - """ + shape sampling without any request overrides.""" proc = Glm5NextVideoProcessor( fps_interval=4, max_frame_count_dynamic=32, diff --git a/tests/transformers_utils/test_config.py b/tests/transformers_utils/test_config.py index 18b33147f6..fb7a7145ff 100644 --- a/tests/transformers_utils/test_config.py +++ b/tests/transformers_utils/test_config.py @@ -188,8 +188,7 @@ def test_model_config_generation_fallback_forwards_code_revision(): def test_safetensors_metadata_of_repo_without_safetensors(): """A repo storing its weights in another format is an answer, not a failure, - so it must not be retried. - """ + so it must not be retried.""" from huggingface_hub.errors import LocalEntryNotFoundError, NotASafetensorsRepoError get_safetensors_metadata = MagicMock( @@ -228,8 +227,7 @@ def test_mrope_num_dims(section_key, mrope_section, expected_num_dims): @pytest.mark.parametrize("section_name", ["mrope_section", "xdrope_section"]) def test_mrope_num_dims_from_config_attribute(section_name): """Some configs expose the section as an attribute rather than under - `rope_parameters`. - """ + `rope_parameters`.""" config = PretrainedConfig() setattr(config, section_name, [16, 16, 16, 16]) diff --git a/tests/transformers_utils/test_hf_overrides_model_type.py b/tests/transformers_utils/test_hf_overrides_model_type.py index 242594d631..b739b4294a 100644 --- a/tests/transformers_utils/test_hf_overrides_model_type.py +++ b/tests/transformers_utils/test_hf_overrides_model_type.py @@ -22,8 +22,7 @@ def test_hf_overrides_model_type_returns_correct_config_class(): """When hf_overrides sets model_type to a registered custom type whose checkpoint has a *different* model_type on disk, get_config() must return an instance of the registered config class — not the class that matches - the on-disk model_type. - """ + the on-disk model_type.""" # Register the custom config _CONFIG_REGISTRY["test_custom_model"] = _TestCustomConfig diff --git a/tests/utils.py b/tests/utils.py index 5b988d2740..81f82d98c8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -72,8 +72,7 @@ FP8_DTYPE = current_platform.fp8_dtype() def prewarm_hf_cache(assets: list[tuple[str, str]]) -> None: """Pre-populate the HF cache for (repo_id, filename) pairs that upstream trust_remote_code modules would otherwise fetch from third-party CDNs - (often unreachable from US-based CI). - """ + (often unreachable from US-based CI).""" if HF_HUB_OFFLINE: return for repo_id, filename in assets: @@ -893,8 +892,7 @@ class RemoteOpenAIServerCustom(RemoteOpenAIServer): max_wait_seconds: float | None = None, ) -> None: """Store custom child process function then invoke superclass - constructor which will indirectly launch it. - """ + constructor which will indirectly launch it.""" self.child_process_fxn = child_process_fxn super().__init__( model=model, diff --git a/tests/utils_/test_gpu_sync_debug.py b/tests/utils_/test_gpu_sync_debug.py index efcda2dfd8..10b550c0a1 100644 --- a/tests/utils_/test_gpu_sync_debug.py +++ b/tests/utils_/test_gpu_sync_debug.py @@ -59,8 +59,7 @@ def test_with_env_set(monkeypatch, mode): @create_new_process_for_each_test() def test_other_threads_are_not_policed(monkeypatch): """A background thread that syncs deliberately must not be broken by the - check being armed on the thread running the decorated function. - """ + check being armed on the thread running the decorated function.""" monkeypatch.setattr(gsd, "_SYNC_CHECK_MODE", "error") monkeypatch.setattr(gsd, "_sync_check_enabled", True) @@ -85,8 +84,7 @@ def test_other_threads_are_not_policed(monkeypatch): def test_allow_on_other_thread_does_not_disarm(monkeypatch): """`gpu_sync_allowed()` on one thread must not suppress the check on another. It is scoped by ContextVar rather than torch's process-global - sync debug mode, which a previous implementation mutated. - """ + sync debug mode, which a previous implementation mutated.""" monkeypatch.setattr(gsd, "_SYNC_CHECK_MODE", "error") monkeypatch.setattr(gsd, "_sync_check_enabled", True) @@ -115,8 +113,7 @@ def test_allow_on_other_thread_does_not_disarm(monkeypatch): def test_suppressing_works_while_compiling(monkeypatch): """`_suppressing` wraps torch compile entry points, which run with `torch.compiler.is_compiling()` true. `gpu_sync_allowed()` deliberately - no-ops in that state, so `_suppressing` must not route through it. - """ + no-ops in that state, so `_suppressing` must not route through it.""" monkeypatch.setattr(gsd, "_SYNC_CHECK_MODE", "error") monkeypatch.setattr(gsd, "_sync_check_enabled", True) # Emulate being inside a torch compile, as inductor passes are. @@ -148,8 +145,7 @@ def test_copy_checker_is_traceable_while_compiling(monkeypatch): def test_sync_debug_mode_restored_after_checked_call(monkeypatch): """The mode is armed only for the duration of a checked call. Leaving it on process-wide made every sync outside a checked region emit a - `UserWarning` whenever our handler was not the installed one. - """ + `UserWarning` whenever our handler was not the installed one.""" monkeypatch.setattr(gsd, "_SYNC_CHECK_MODE", "error") monkeypatch.setattr(gsd, "_sync_check_enabled", True) @@ -294,8 +290,7 @@ def test_genuinely_async_transfers_pass(monkeypatch): asynchronous in both directions -- even with a dtype conversion, which runs GPU-side, and even permuted (e.g. transposed), which uses pitched cudaMemcpy2D/3DAsync; D2H `Tensor.to` allocates a pinned destination. - None of these may be flagged. - """ + None of these may be flagged.""" monkeypatch.setattr(gsd, "_SYNC_CHECK_MODE", "error") monkeypatch.setattr(gsd, "_sync_check_enabled", True) gsd._install_copy_checkers() diff --git a/tests/utils_/test_network_utils.py b/tests/utils_/test_network_utils.py index e2935a2549..02889c20f6 100644 --- a/tests/utils_/test_network_utils.py +++ b/tests/utils_/test_network_utils.py @@ -29,8 +29,7 @@ def test_get_file_store_init_method_is_unique(): def _call_with_timeout(func, timeout: float = 10.0): """Run func in a daemon thread so a livelock regression fails the test - quickly instead of hanging the suite. - """ + quickly instead of hanging the suite.""" result: dict = {} def target(): @@ -97,8 +96,7 @@ def test_get_open_port_skips_reserved_dp_master_ports( monkeypatch: pytest.MonkeyPatch, ): """VLLM_PORT == VLLM_DP_MASTER_PORT must not livelock by returning the - same free-but-reserved port forever (upstream issue #50024). - """ + same free-but-reserved port forever (upstream issue #50024).""" base = 42123 with monkeypatch.context() as m: m.setenv("VLLM_PORT", str(base)) @@ -111,8 +109,7 @@ def test_get_open_ports_list_skips_reserved_dp_master_ports( monkeypatch: pytest.MonkeyPatch, ): """The VLLM_PORT band scan must not hand out ports inside the window - reserved for the data parallel master process. - """ + reserved for the data parallel master process.""" base = 42223 reserved = range(base, base + 10) with monkeypatch.context() as m: @@ -128,8 +125,7 @@ def test_get_open_port_ephemeral_skips_reserved_range( monkeypatch: pytest.MonkeyPatch, ): """An ephemeral port that happens to fall in the reserved range is - replaced by a rescan starting past the range. - """ + replaced by a rescan starting past the range.""" base = 42323 with monkeypatch.context() as m: m.delenv("VLLM_PORT", raising=False) @@ -148,8 +144,7 @@ def test_get_open_port_ephemeral_without_dp_master_port( monkeypatch: pytest.MonkeyPatch, ): """Without VLLM_PORT and VLLM_DP_MASTER_PORT, an ephemeral port is - returned as before. - """ + returned as before.""" with monkeypatch.context() as m: m.delenv("VLLM_PORT", raising=False) m.delenv("VLLM_DP_MASTER_PORT", raising=False) diff --git a/tests/utils_/test_numa_utils.py b/tests/utils_/test_numa_utils.py index 845fdda2a1..9f718703a7 100644 --- a/tests/utils_/test_numa_utils.py +++ b/tests/utils_/test_numa_utils.py @@ -157,8 +157,7 @@ def test_pct_binding_filters_cpus(monkeypatch): ) def test_pct_binding_fires_on_every_capable_sku(monkeypatch, sku, expected_cpus): """Each SKU in ``_PCT_CAPABLE_SKUS`` engages the gate at its own - expected ``highest_perf`` and uses its own priority-core stride. - """ + expected ``highest_perf`` and uses its own priority-core stride.""" sku_config = numa_utils._PCT_CAPABLE_SKUS[sku] _patch_pct_gates( monkeypatch, @@ -243,8 +242,7 @@ def test_get_numactl_args_engine_core_baseline_spans_shard_numa_nodes(): def test_get_numactl_args_engine_core_pct_spans_shard_numa_nodes(monkeypatch): """PCT: EngineCore for a multi-NUMA shard binds to the union of priority cores across all shard nodes, so worker `--physcpubind` is always a - subset of EngineCore's `cpus_allowed`. - """ + subset of EngineCore's `cpus_allowed`.""" _patch_pct_gates( monkeypatch, model_match=True, @@ -294,8 +292,7 @@ def test_get_numactl_args_engine_core_pct_external_launcher_spans_local_nodes( """external_launcher (or multi-node-within-DP, or Ray) hits the fallback branch. EngineCore must still span every local NUMA node so it can mp-spawn its local workers without ``--physcpubind`` - strict-validation failures. - """ + strict-validation failures.""" _patch_pct_gates( monkeypatch, model_match=True, @@ -319,8 +316,7 @@ def test_get_numactl_args_engine_core_pct_external_launcher_spans_local_nodes( def test_get_numactl_args_engine_core_baseline_multi_node_within_dp_spans_locals(): """Multi-node-within-DP fallback: bind EngineCore to all local NUMA - nodes that the visible ``numa_bind_nodes`` reference. - """ + nodes that the visible ``numa_bind_nodes`` reference.""" vllm_config = _make_config( numa_bind=True, numa_bind_nodes=[0, 0, 0, 0, 1, 1, 1, 1], @@ -343,8 +339,7 @@ def test_get_numactl_args_engine_core_skips_user_cpu_list(monkeypatch): ``--physcpubind`` spawns need. We fall back to ``--cpunodebind`` over the shard's NUMA nodes instead. PCT auto-detect is also bypassed when the user is explicit (its priority-core union may not be a superset - of the user's per-worker cores). - """ + of the user's per-worker cores).""" _patch_pct_gates(monkeypatch, model_match=True, highest_perf=46) vllm_config = _make_config( numa_bind=True, @@ -397,8 +392,7 @@ def test_get_numactl_args_requires_detectable_nodes(monkeypatch): def test_configure_subprocess_rejects_unknown_process_kind(): """configure_subprocess only knows 'worker' and 'EngineCore'; anything else must raise ValueError instead of silently routing to the worker - path. - """ + path.""" vllm_config = _make_config(numa_bind=True, numa_bind_nodes=[0]) with ( pytest.raises(ValueError, match="process_kind"), diff --git a/tests/v1/attention/test_attention_backends.py b/tests/v1/attention/test_attention_backends.py index af9ed0c6b0..66a1c5c088 100644 --- a/tests/v1/attention/test_attention_backends.py +++ b/tests/v1/attention/test_attention_backends.py @@ -1392,8 +1392,7 @@ def test_non_causal_backend_correctness( model: str, ): """Test backend's correctness with non-causal (bidirectional) decoder - attention, as used by DFlash speculative decoding. - """ + attention, as used by DFlash speculative decoding.""" def bidirectional_mask_mod( b: torch.Tensor, diff --git a/tests/v1/attention/test_attention_backends_selection.py b/tests/v1/attention/test_attention_backends_selection.py index 0481ebc790..8486d216a1 100644 --- a/tests/v1/attention/test_attention_backends_selection.py +++ b/tests/v1/attention/test_attention_backends_selection.py @@ -115,8 +115,7 @@ def test_mamba_layers_have_unified_interface( layer_class, expected_backend, expected_mamba_type ): """Test that all Mamba layers have the unified get_attn_backend - interface. - """ + interface.""" assert hasattr(layer_class, "get_attn_backend"), ( f"{layer_class.__name__} should have get_attn_backend method" ) diff --git a/tests/v1/attention/test_attention_splitting.py b/tests/v1/attention/test_attention_splitting.py index ff0e06514e..bad0f61b7c 100644 --- a/tests/v1/attention/test_attention_splitting.py +++ b/tests/v1/attention/test_attention_splitting.py @@ -164,8 +164,7 @@ def apply_split_decodes_and_prefills( treat_short_extends_as_decodes: bool = True, ): """Helper function to apply split_decodes_and_prefills and return - the results. - """ + the results.""" device = torch.device("cpu") seq_lens = [10 * (i + 1) for i in range(len(query_lens))] common_metadata = create_common_attn_metadata( diff --git a/tests/v1/attention/test_dcp_a2a_pack_mask.py b/tests/v1/attention/test_dcp_a2a_pack_mask.py index 34621900d5..cff1228baf 100644 --- a/tests/v1/attention/test_dcp_a2a_pack_mask.py +++ b/tests/v1/attention/test_dcp_a2a_pack_mask.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """The empty-shard mask fused into the DCP A2A pack kernel must be bit-exact -with the eager ``mask_dcp_empty_shards_`` pass it replaces. -""" +with the eager ``mask_dcp_empty_shards_`` pass it replaces.""" import pytest import torch diff --git a/tests/v1/attention/test_dspark_noncausal_sparse_mla.py b/tests/v1/attention/test_dspark_noncausal_sparse_mla.py index 6f61a6aeed..d5c7941314 100644 --- a/tests/v1/attention/test_dspark_noncausal_sparse_mla.py +++ b/tests/v1/attention/test_dspark_noncausal_sparse_mla.py @@ -495,8 +495,7 @@ def test_dspark_noncausal_sparse_mla_matches_sdpa( num_heads, ): """Non-causal (window ∪ block, future-pointing) per-token indices must match - a dense SDPA reference over the same indices, for both sparse-MLA backends. - """ + a dense SDPA reference over the same indices, for both sparse-MLA backends.""" _skip_if_backend_unavailable(backend_cls, kv_cache_dtype, block_size) window, block, topk_width = _DSPARK_CONFIGS[config_name] diff --git a/tests/v1/attention/test_flashinfer_mla_sparse_sm90.py b/tests/v1/attention/test_flashinfer_mla_sparse_sm90.py index c712cb5844..8dc082b08b 100644 --- a/tests/v1/attention/test_flashinfer_mla_sparse_sm90.py +++ b/tests/v1/attention/test_flashinfer_mla_sparse_sm90.py @@ -231,8 +231,7 @@ def test_plan_uses_state_params(monkeypatch): def test_kv_lens_host_formula(): """Per-row host lengths: context == position + 1; capped at - index_topk + trailing-pool remainder past the sparse threshold. - """ + index_topk + trailing-pool remainder past the sparse threshold.""" builder = object.__new__(FlashInferMLASparseSM90Builder) builder._index_topk = 2048 builder._index_kpool = 4 diff --git a/tests/v1/attention/test_gdn_metadata_builder.py b/tests/v1/attention/test_gdn_metadata_builder.py index c8032d9eaa..221f933d89 100644 --- a/tests/v1/attention/test_gdn_metadata_builder.py +++ b/tests/v1/attention/test_gdn_metadata_builder.py @@ -187,8 +187,7 @@ def test_gdn_build_classification(test_case: GDNBuildTestCase): def test_has_initial_state_after_reclassification(): """After reclassification, num_prefills > 0 so the prefill kernel path should compute has_initial_state. For the reclassified request with - context_lens > 0, the corresponding entry must be True. - """ + context_lens > 0, the corresponding entry must be True.""" builder = _create_gdn_builder(num_speculative_tokens=2) batch = BatchSpec(seq_lens=[65, 20], query_lens=[1, 3]) meta = _build(builder, batch, num_decode_draft_tokens=[-1, 2]) diff --git a/tests/v1/attention/test_indexer_dcp_localize.py b/tests/v1/attention/test_indexer_dcp_localize.py index 4175bb6ff5..8bc409adb7 100644 --- a/tests/v1/attention/test_indexer_dcp_localize.py +++ b/tests/v1/attention/test_indexer_dcp_localize.py @@ -56,8 +56,7 @@ def _ref_stable_topk_from_candidates_fp64( ) -> torch.Tensor: """Pure-PyTorch reference for the CuteDSL stable-topk selector order (score desc, then lowest global token id). Selects the same SET as the - kernel; only the set is compared in tests. - """ + kernel; only the set is compared in tests.""" num_rows, num_candidates = candidate_scores.shape device = candidate_scores.device select_k = min(k, num_candidates) @@ -122,8 +121,7 @@ def _dcp_lse_merge( class _FakeDCPGroup: """Single-process stand-in: ``all_gather`` returns the pre-built concatenation of every rank's packed ``(score, global_id)`` candidates, - mirroring the one packed all-gather the merge issues. - """ + mirroring the one packed all-gather the merge issues.""" def __init__(self, gathered_packed: torch.Tensor) -> None: self.gathered_packed = gathered_packed @@ -209,8 +207,7 @@ def _merge_local_topks_global_with_fake_dcp( """Run ``_merge_dcp_topk_global`` for every rank against a faked all-gather and return each rank's global-index result (all ranks should agree). The fake pre-builds the packed candidate concatenation the merge's - single ``all_gather`` would return. - """ + single ``all_gather`` would return.""" # The merge is now CuteDSL-only (no PyTorch fallback), so it runs the real # Triton pack + CuteDSL selector kernels even behind the faked all-gather. if not current_platform.is_cuda() or not has_cutedsl(): @@ -712,8 +709,7 @@ def test_dcp_filter_compaction_matches_reference( """In-kernel compaction must, for every row, produce exactly the rank-owned physical slots packed into [0, valid_count) with -1 in the tail -- the same SET a reference filter + sort/gather produces. Uses wide rows (> BLOCK_N - valid slots), with interior -1 gaps. - """ + valid slots), with interior -1 gaps.""" device = torch.device("cuda") torch.manual_seed(7) dcp_size = 2 @@ -871,8 +867,7 @@ def test_decode_topk_pads_surplus_with_negative_one(): so a non-(-1) pad would be silently attended. This is the common case under DCP, where each rank's local seq_len = global / world is usually << topk. Checked on the *set* of valid indices (the kernel may order them by score, - not position). - """ + not position).""" torch.manual_seed(0) device = torch.device("cuda") topk = 8 @@ -918,8 +913,7 @@ def test_sparse_decode_dcp_short_context_matches_non_dcp(): """End-to-end DCP decode where the global seq_len < topk (so every rank's local top-k is surplus-padded). Exercises the kernel surplus -> merge mask -> global top-k -> physical localize -> LSE merge chain for the common - short-context decode case, vs the non-DCP reference. - """ + short-context decode case, vs the non-DCP reference.""" torch.manual_seed(4) device = torch.device("cuda") world = 2 diff --git a/tests/v1/attention/test_kpool_tail_slot_mapping.py b/tests/v1/attention/test_kpool_tail_slot_mapping.py index 6377d7df46..0966f9b20a 100644 --- a/tests/v1/attention/test_kpool_tail_slot_mapping.py +++ b/tests/v1/attention/test_kpool_tail_slot_mapping.py @@ -58,8 +58,7 @@ def test_tail_backend_layout_matches_kernel_pointer_arithmetic(): def make_tail_block_table(own_blocks, width=64): """Tail-group block table as BlockTables produces it: column 0 holds the request's single KpoolTailManager block, the remaining columns are never - written and stay zero. - """ + written and stay zero.""" bt = torch.zeros(len(own_blocks), width, dtype=torch.int32) bt[:, 0] = torch.tensor(own_blocks, dtype=torch.int32) return bt @@ -67,8 +66,7 @@ def make_tail_block_table(own_blocks, width=64): def legacy_generic_tail_slots(block_table, query_start_loc, positions): """Reference of the generic ``_compute_slot_mappings_kernel`` arithmetic - (block_table.py:305-313) applied to the tail group's table. - """ + (block_table.py:305-313) applied to the tail group's table.""" slots = [] for req in range(block_table.shape[0]): for i in range(query_start_loc[req], query_start_loc[req + 1]): @@ -109,8 +107,7 @@ def make_batch(per_req_positions, padded_len=None): def test_legacy_generic_mapping_collapses_onto_block_zero(): """The bug: with the manager's 1-column block table, the generic kernel - maps every pos >= kpool onto tail block 0, and distinct requests collide. - """ + maps every pos >= kpool onto tail block 0, and distinct requests collide.""" own_blocks = [5, 9] per_req = [list(range(10)), list(range(12))] # prompts of len 10 and 12 positions, qsl, _, num_actual, num_reqs = make_batch(per_req) @@ -140,8 +137,7 @@ def test_legacy_generic_mapping_collapses_onto_block_zero(): def test_circular_mapping_isolates_requests(): """The fix: every token lands in its own request's block at pos % kpool, and no slot is ever shared by two different requests (slots do recur - within a request every kpool positions -- that is the circular design). - """ + within a request every kpool positions -- that is the circular design).""" own_blocks = [5, 9] per_req = [list(range(10)), list(range(12))] positions, qsl, slot_mapping, num_actual, num_reqs = make_batch(per_req) @@ -169,8 +165,7 @@ def test_circular_mapping_isolates_requests(): def test_circular_mapping_matches_generic_for_short_requests(prompt_len): """For pos < kpool the generic kernel already picks the own block, so the two mappings agree while every position fits the request's first block - (single-request behavior is unchanged). - """ + (single-request behavior is unchanged).""" own_blocks = [7] per_req = [list(range(prompt_len))] positions, qsl, slot_mapping, num_actual, num_reqs = make_batch(per_req) @@ -280,8 +275,7 @@ class TailRingMirror: """Mirror of _kpool_tail_seed_kernel / _kpool_decode_update_batched_kernel addressing: block = tail_slot // kpool, ring offset = pos % kpool; a pool completing at pos reads ring slots (pool_start + s) % kpool and uses the - current token's own K/score for the last member. - """ + current token's own K/score for the last member.""" def __init__(self, num_blocks, kpool=KPOOL): self.kpool = kpool @@ -324,8 +318,7 @@ def tail_slot_for(mapping, req, pos, own_block): def run_scenario(mapping, interleave): """Requests A (block 5, prompt len 9) and B (block 9, prompt len 11) - decode concurrently; returns A's boundary pool [8, 9, 10, 11]. - """ + decode concurrently; returns A's boundary pool [8, 9, 10, 11].""" ring = TailRingMirror(num_blocks=16) blocks = {"A": 5, "B": 9} prompts = {"A": 9, "B": 11} diff --git a/tests/v1/attention/test_mamba_update_block_table.py b/tests/v1/attention/test_mamba_update_block_table.py index f281213221..f4451fe7af 100644 --- a/tests/v1/attention/test_mamba_update_block_table.py +++ b/tests/v1/attention/test_mamba_update_block_table.py @@ -28,8 +28,7 @@ def _make_vllm_config( block_size: int | None = None, ): """Create a minimal mock VllmConfig with only the fields the builder - accesses, avoiding any model download / HF config inspection. - """ + accesses, avoiding any model download / HF config inspection.""" speculative_config = ( SimpleNamespace( num_speculative_tokens=num_speculative_tokens, @@ -75,8 +74,7 @@ def test_mamba_single_token_prompt_runs_as_prefill(): def test_update_block_table_copies_block_idx_to_persistent_buffers(): """update_block_table() must write block_idx tensors to the current builder's persistent buffers, not leave them pointing to a different - builder's buffers. - """ + builder's buffers.""" block_size = 16 max_model_len = 256 num_reqs = 4 @@ -180,8 +178,7 @@ def test_state_indices_tensor_d_includes_num_speculative_blocks(): bug 1: with mamba_cache_mode='all' and speculative decoding enabled, the cudagraph buffer for state_indices_tensor_d must allocate the same per-request column count as the runtime block table, which includes - num_speculative_blocks trailing scratch columns. - """ + num_speculative_blocks trailing scratch columns.""" block_size = 16 max_model_len = 256 max_num_seqs = 4 @@ -214,8 +211,7 @@ def test_block_idx_cudagraph_capture_padded_by_num_reqs(): bug 2: with mamba_cache_mode='all' and spec decode, _update_metadata_for _cudagraph_capture must slice block_idx_last_{scheduled,computed}_token by the request count (padded_bs == num_reqs), not by num_decode_tokens. - Past num_decodes, the slice must be zero-filled. - """ + Past num_decodes, the slice must be zero-filled.""" block_size = 16 max_model_len = 256 max_num_seqs = 8 @@ -295,8 +291,7 @@ def test_block_idx_prev_step_persistent_buffer_allocated(): block_idx_last_scheduled_token_prev_step as a persistent buffer with the same shape as the existing block_idx_last_{scheduled,computed}_token buffers, so cudagraph capture records a stable pointer for the prev-step - input anchor consumed by mamba_mixer2's input gather. - """ + input anchor consumed by mamba_mixer2's input gather.""" block_size = 16 max_model_len = 256 max_num_seqs = 8 @@ -324,8 +319,7 @@ def test_block_idx_prev_step_persistent_buffer_allocated(): def test_block_idx_prev_step_persistent_buffer_skipped_without_spec_decode(): """Without spec decode, the prev-step buffer is unused and must not be - allocated — the input anchor reduces to last_computed_token. - """ + allocated — the input anchor reduces to last_computed_token.""" block_size = 16 max_model_len = 256 max_num_seqs = 8 @@ -349,8 +343,7 @@ def test_block_idx_prev_step_cudagraph_capture_uses_persistent_buffer(): """_update_metadata_for_cudagraph_capture must copy the prev-step anchor into the builder's persistent buffer (so cudagraph replay reads from the same underlying memory), pad past num_decodes with zero, and return a - slice of the persistent buffer in the metadata. - """ + slice of the persistent buffer in the metadata.""" block_size = 16 max_model_len = 256 max_num_seqs = 8 diff --git a/tests/v1/attention/test_mla_backends.py b/tests/v1/attention/test_mla_backends.py index 5a8fdea204..597ffb03fc 100644 --- a/tests/v1/attention/test_mla_backends.py +++ b/tests/v1/attention/test_mla_backends.py @@ -171,8 +171,7 @@ def test_glm5_flashinfer_masked_mha_routing( def test_concat_k_nope_k_pe_matches_torch_cat(qk_rope_head_dim): """The K concat used by the MLA prefill context loop must equal torch.cat of k_nope with the broadcast k_pe; with no RoPE part it returns k_nope itself - instead of allocating and copying. - """ + instead of allocating and copying.""" torch.manual_seed(0) num_tokens, num_heads, qk_nope_head_dim = 5, 4, 256 k_nope = torch.randn(num_tokens, num_heads, qk_nope_head_dim, dtype=torch.bfloat16) diff --git a/tests/v1/attention/test_mla_prefill_quant_output.py b/tests/v1/attention/test_mla_prefill_quant_output.py index 211cde663b..220f6a198d 100644 --- a/tests/v1/attention/test_mla_prefill_quant_output.py +++ b/tests/v1/attention/test_mla_prefill_quant_output.py @@ -134,8 +134,7 @@ def test_flash_attn_registers_warmup_only_for_fa4( def test_flash_attn_prefill_backend_signature_accepts_fused_kwargs(): """run_prefill_new_tokens must accept out/output_scale so the direct - (non-**kwargs) call in forward_mha type- and runtime-checks. - """ + (non-**kwargs) call in forward_mha type- and runtime-checks.""" import inspect params = inspect.signature( @@ -151,8 +150,7 @@ def test_flash_attn_prefill_backend_signature_accepts_fused_kwargs(): def test_mla_impl_forward_mha_accepts_output_scale(): """The abstract MLA impl forward_mha must carry output_scale so every - override (and the unconditional forward_impl call) stays compatible. - """ + override (and the unconditional forward_impl call) stays compatible.""" import inspect from vllm.v1.attention.backend import MLAAttentionImpl @@ -179,8 +177,7 @@ _FUSED_FP8_SKIP = _fused_fp8_skip_reason() def test_fa4_fused_fp8_output_matches_post_quant(default_vllm_config): """FA4's fused FP8 write (output_scale, flash-attention#135) must match the bf16-attention + standalone static-FP8-quant path it replaces, since - production uses the same output_scale for both. - """ + production uses the same output_scale for both.""" from vllm.model_executor.layers.quantization.input_quant_fp8 import QuantFP8 from vllm.model_executor.layers.quantization.utils.quant_utils import GroupShape from vllm.platforms import current_platform diff --git a/tests/v1/attention/test_mla_prefill_selector.py b/tests/v1/attention/test_mla_prefill_selector.py index fa52b1484b..098eddfbf6 100644 --- a/tests/v1/attention/test_mla_prefill_selector.py +++ b/tests/v1/attention/test_mla_prefill_selector.py @@ -315,8 +315,7 @@ class TestBackendValidation: def test_flash_attn_accepts_glm53_flash_nope_dimensions(self): """(256, 0, 256) runs the same FA kernels as GLM-5's (192, 64, 256); a - RoPE-carrying 320-wide query does not. - """ + RoPE-carrying 320-wide query does not.""" try: from vllm.v1.attention.backends.mla.prefill.flash_attn import ( FlashAttnPrefillBackend, diff --git a/tests/v1/attention/test_replayssm_metadata_builder.py b/tests/v1/attention/test_replayssm_metadata_builder.py index 351fe00068..89cb0f5664 100644 --- a/tests/v1/attention/test_replayssm_metadata_builder.py +++ b/tests/v1/attention/test_replayssm_metadata_builder.py @@ -257,8 +257,7 @@ def test_replayssm_write_pos(case: ReplaySSMBuildCase): def test_resumed_request_differs_from_fresh(): """Same token count, different decode_base: fresh (base 100) -> write_pos 5, - resumed (base 105) -> write_pos 0. - """ + resumed (base 105) -> write_pos 0.""" builder = _create_replayssm_builder(16) batch = BatchSpec(seq_lens=[106, 106], query_lens=[1, 1]) common = create_common_attn_metadata(batch, BLOCK_SIZE, DEVICE).replace( diff --git a/tests/v1/attention/test_rocm_attention_backends_selection.py b/tests/v1/attention/test_rocm_attention_backends_selection.py index 01018a630c..2342a279a3 100644 --- a/tests/v1/attention/test_rocm_attention_backends_selection.py +++ b/tests/v1/attention/test_rocm_attention_backends_selection.py @@ -517,8 +517,7 @@ def test_auto_selection_for_kv_connector( aiter_found, expected_backend, mock_vllm_config, mock_get_cdna_version ): """Auto-selection with a KV connector and AITER enabled resolves to unified attn, - and to triton attn if AITER not enabled. - """ + and to triton attn if AITER not enabled.""" from vllm.platforms.rocm import RocmPlatform with patch( diff --git a/tests/v1/attention/test_sparse_indexer_decode_seq_lens.py b/tests/v1/attention/test_sparse_indexer_decode_seq_lens.py index 9cbb7a6f8f..d87a82c37b 100644 --- a/tests/v1/attention/test_sparse_indexer_decode_seq_lens.py +++ b/tests/v1/attention/test_sparse_indexer_decode_seq_lens.py @@ -102,8 +102,7 @@ def expected_row_seq_lens(per_req_positions, batch_size, next_n): def test_legacy_flat_layout_misaligns_and_bleeds(): """The bug: ``positions[:n] + 1`` with padded-row coordinates reads other - requests' positions and prefill positions. - """ + requests' positions and prefill positions.""" decode_lens, per_req, positions = make_non_uniform_batch() batch_size = decode_lens.shape[0] next_n = int(decode_lens.max()) @@ -138,8 +137,7 @@ def test_helper_uniform_layout_matches_flat_slice(): def test_helper_padded_layout_per_row(): """Non-uniform batches map every padded row to its own token's position; - pad rows get 0 (empty tail). - """ + pad rows get 0 (empty tail).""" decode_lens, per_req, positions = make_non_uniform_batch() out = _decode_topk_seq_lens(positions, decode_lens, 8, 3, 4, requires_padding=True) expected = expected_row_seq_lens(per_req, 3, 4) @@ -151,8 +149,7 @@ def test_helper_padded_layout_per_row(): def expand_tail_region(dec_seq): """Run the production pure-torch expand + append pair (the fused kernel replicates it exactly on the identity path) and return the tail columns - [TOPK_TOKENS, TOPK_TOKENS + KPOOL - 1). - """ + [TOPK_TOKENS, TOPK_TOKENS + KPOOL - 1).""" rows = dec_seq.shape[0] pool_ids = torch.arange(SELECT_K, dtype=torch.int64).expand(rows, SELECT_K) valid = torch.ones_like(pool_ids, dtype=torch.bool) @@ -166,8 +163,7 @@ def expand_tail_region(dec_seq): def test_tail_expansion_legacy_vs_fixed(): """End-to-end tail consequence: the fixed mapping appends exactly the request's trailing incomplete pool; the legacy flat slice drops real tail - tokens and emits indices far past the request's own sequence. - """ + tokens and emits indices far past the request's own sequence.""" decode_lens, per_req, positions = make_non_uniform_batch() n = 12 fixed = _decode_topk_seq_lens( diff --git a/tests/v1/attention/test_sparse_mla_backends.py b/tests/v1/attention/test_sparse_mla_backends.py index ecaf71d55b..8ff52ecb38 100644 --- a/tests/v1/attention/test_sparse_mla_backends.py +++ b/tests/v1/attention/test_sparse_mla_backends.py @@ -909,8 +909,7 @@ def test_index_group_convert_during_piecewise_capture(): runs in the following eager break. The convert's side stream must not wait on ``logical_topk_ready`` there: an event recorded inside a captured segment is graph-local, and an eager wait on it raises - cudaErrorInvalidValue. - """ + cudaErrorInvalidValue.""" device = torch.device(DEVICE_TYPE) num_tokens, num_topk, num_requests, blocks_per_req, block_size = 8, 128, 4, 4, 16 @@ -1049,8 +1048,7 @@ def test_triton_convert_rejects_req_id_longer_than_token_indices(): req_id but the output is allocated like token_indices, so a full-batch req_id combined with an MQA-subset token_indices wrote past the end of the output buffer. The wrapper must reject the length mismatch instead - of corrupting memory. - """ + of corrupting memory.""" device = torch.device(DEVICE_TYPE) num_topk_tokens = 128 block_size = 64 @@ -1105,8 +1103,7 @@ def test_flashmla_forward_bf16_kv_slices_req_id_to_mqa_tokens(): is active, forward_mqa only receives the leading decode tokens, but _forward_bf16_kv passed the full-batch req_id_per_token to the index conversion, making it write past the end of its output buffer. The call - site must slice req_id_per_token to the MQA tokens. - """ + site must slice req_id_per_token to the MQA tokens.""" device = torch.device(DEVICE_TYPE) num_topk_tokens = 128 block_size = 64 @@ -1204,8 +1201,7 @@ def test_split_prefill_chunks(seq_lens, max_buf, expected): ) def test_masked_mha_workspace_fits_single_request_boundary(max_query_len, expected): """A 32K prefill needs the default workspace exactly; shrinking it would - push a supported request onto MQA. - """ + push a supported request onto MQA.""" assert ( _masked_mha_workspace_fits( batch_size=1, @@ -1263,8 +1259,7 @@ def test_is_masked_mha_available_model_dims( ): """The allow-list gates masked MHA per exact model geometry: the DeepSeek-V3.2, GLM-5 and NoPE GLM-5.3-Flash layouts on an SM100-family GPU with FA4 and an - unquantized KV cache, nothing else. - """ + unquantized KV cache, nothing else.""" import vllm.model_executor.layers.attention.sparse_mla_attention as mod monkeypatch.setattr( @@ -3604,8 +3599,7 @@ def test_fp8_mixed_batch_dcp_neutralizes_empty_rows(monkeypatch): """A decode row whose top-k shard holds no local candidates (all -1) has undefined kernel out/lse; it must come back as (0, -inf), the identity of the cross-rank LSE merge, or a NaN would survive the merge even at zero - weight (0 * NaN = NaN). - """ + weight (0 * NaN = NaN).""" num_tokens, num_heads, head_dim = 3, 2, 3 q = torch.empty(num_tokens, num_heads, head_dim, device=DEVICE_TYPE) local_indices = torch.tensor( @@ -3778,8 +3772,7 @@ def test_hisparse_fp8_prefill_gather_uses_dedicated_stream(monkeypatch): def test_sparse_impl_observes_repointed_indexer_buffer(): """The MTP proposer repoints the draft's indexer at the target model's buffer after the backend impl is built, so the impl must resolve the buffer per read. - Snapshotting it in __init__ leaves the layer reading indices nothing writes. - """ + Snapshotting it in __init__ leaves the layer reading indices nothing writes.""" impl = object.__new__(FlashInferMLASparseImpl) own = torch.zeros(4, 8, dtype=torch.int32) target = torch.ones(4, 8, dtype=torch.int32) @@ -3795,8 +3788,7 @@ def test_sparse_impl_observes_repointed_indexer_buffer(): def test_explicit_topk_buffer_supersedes_indexer(): """Backbone skip-topk layers have no indexer, and the proposer also assigns the - shared buffer directly onto draft submodules. - """ + shared buffer directly onto draft submodules.""" impl = object.__new__(FlashInferMLASparseImpl) indexer = SimpleNamespace( topk_indices_buffer=torch.zeros(2, 2, dtype=torch.int32), @@ -3811,8 +3803,7 @@ def test_explicit_topk_buffer_supersedes_indexer(): def test_sparse_mla_common_impl_resolves_buffer_lazily(): """Guards the whole SparseMLACommonImpl family at once: a backend that - snapshots the buffer instead silently loses MTP buffer sharing. - """ + snapshots the buffer instead silently loses MTP buffer sharing.""" assert issubclass(SparseMLACommonImpl, SharedTopkIndicesBuffer) assert isinstance(SparseMLACommonImpl.topk_indices_buffer, property), ( "topk_indices_buffer must stay a lazily-resolved property" diff --git a/tests/v1/attention/test_trtllm_attention_integration.py b/tests/v1/attention/test_trtllm_attention_integration.py index 36c2a710d5..1a49a3895c 100644 --- a/tests/v1/attention/test_trtllm_attention_integration.py +++ b/tests/v1/attention/test_trtllm_attention_integration.py @@ -198,8 +198,7 @@ def _create_nvfp4_hnd_kv_cache( def _run_trtllm_integration(batch_spec, kv_cache_dtype="auto", model_name=MODEL): """Run TRTLLM attention through the full FlashInfer pipeline - and compare against an SDPA reference. - """ + and compare against an SDPA reference.""" set_random_seed(42) device = torch.device(f"{DEVICE_TYPE}:0") @@ -427,8 +426,7 @@ def _run_trtllm_integration(batch_spec, kv_cache_dtype="auto", model_name=MODEL) def test_trtllm_gen_full_attention_integration(batch_spec_name: str): """Test TRTLLM gen-full attention through the full FlashInfer MetadataBuilder.build() -> FlashInferImpl.forward() pipeline, - with real TRTLLM kernels on Blackwell. - """ + with real TRTLLM kernels on Blackwell.""" _run_trtllm_integration(BATCH_SPECS[batch_spec_name]) @@ -439,8 +437,7 @@ def test_trtllm_gen_full_attention_integration(batch_spec_name: str): @torch.inference_mode() def test_trtllm_gen_nvfp4_kv_integration(batch_spec_name: str): """Test TRTLLM attention with nvfp4 KV cache through the full - FlashInfer MetadataBuilder.build() -> FlashInferImpl.forward() pipeline. - """ + FlashInfer MetadataBuilder.build() -> FlashInferImpl.forward() pipeline.""" _run_trtllm_integration( BATCH_SPECS[batch_spec_name], kv_cache_dtype="nvfp4", diff --git a/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py b/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py index eeb977adef..393ec48465 100644 --- a/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py +++ b/tests/v1/core/prefix_cache/test_partial_prefix_cache_hits.py @@ -2,8 +2,7 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Fine-grained partial prefix-cache hits for hybrid (full attention + mamba "align") models: scheduler chunk splitting, partial tail registration, CoW -on partial hits, and same-step deferral. -""" +on partial hits, and same-step deferral.""" from math import lcm from types import SimpleNamespace @@ -175,8 +174,7 @@ def test_mamba_align_split_partial_tail_schedule(dcp_world_size: int): """Chunk ends with partial hits on: block-aligned chunks, one extra stop at the prompt's last hash boundary (registering the partial tail), then the remaining tokens. block=512, hash=32, prompt=10000, budget=8192: - 0 -> 8192 -> 9728 -> 9984 -> 10000. - """ + 0 -> 8192 -> 9728 -> 9984 -> 10000.""" block_size = 512 scheduler_block_size = block_size * dcp_world_size hash_block_size = 32 @@ -744,8 +742,7 @@ def test_hash_aligned_query_end_uses_regular_partial_tail(): def test_external_mamba_hit_same_block_uses_running_cow_on_continue(): """An external mid-block hit must become a running request even when its - first continuation does not need another Mamba block. - """ + first continuation does not need another Mamba block.""" hash_block_size = 2 mamba_block_size = 4 * hash_block_size kv_cache_config = KVCacheConfig( @@ -817,8 +814,7 @@ def test_external_mamba_hit_same_block_uses_running_cow_on_continue(): def test_boundary_state_offloads_returns_cow_target(): """Boundary hand-offs expose aligned snapshots and the partial-tail CoW - target, never the overwritten CoW source. - """ + target, never the overwritten CoW source.""" hash_block_size = 2 block_size = 2 * hash_block_size kv_cache_config = KVCacheConfig( @@ -1004,8 +1000,7 @@ def test_connector_finish_registers_partial_tail_before_cleanup(): def test_boundary_state_offload_dropped_when_request_freed_before_drain(): """A hand-off recorded in the same scheduling pass as the request's death must not be drained: its release hook has already run, so draining would - leak a pinned block. - """ + leak a pinned block.""" hash_block_size = 2 block_size = 2 * hash_block_size kv_cache_config = KVCacheConfig( @@ -1052,8 +1047,7 @@ def test_boundary_state_offload_dropped_when_request_freed_before_drain(): def test_boundary_state_offloads_block_aligned_prompt(): """A prompt ending on a block boundary registers no CoW partial tail; its - boundary state block is handed off as a snapshot instead (once). - """ + boundary state block is handed off as a snapshot instead (once).""" hash_block_size = 2 block_size = 2 * hash_block_size kv_cache_config = KVCacheConfig( @@ -1107,8 +1101,7 @@ def test_boundary_state_offloads_block_aligned_prompt(): def test_truncate_computed_blocks_preserves_sparse_prefix_positions(): """truncate_computed_blocks slices each group by its own block size, keeps null placeholders in the retained prefix, and leaves the original - lookup result untouched (pure view, no refcount changes). - """ + lookup result untouched (pure view, no refcount changes).""" hash_block_size = 2 kv_cache_config = KVCacheConfig( num_blocks=24, @@ -1163,8 +1156,7 @@ def test_truncate_computed_blocks_preserves_sparse_prefix_positions(): def test_truncate_computed_blocks_allows_short_mamba_group_only(): """External state may replace a short Mamba hit, but other groups must - cover the aligned local endpoint. - """ + cover the aligned local endpoint.""" hash_block_size = 2 kv_cache_config = KVCacheConfig( num_blocks=24, @@ -1306,8 +1298,7 @@ def test_hybrid_mamba_partial_tail_owner_continue_preserves_later_hit(): def test_hybrid_mamba_moved_partial_entry_defers_same_step_hit(): """The owner's move re-arms the same-step guard: the moved entry is filled by this step's copy, and chained same-step copies read stale - sources, so a request hitting it in the move step must be deferred. - """ + sources, so a request hitting it in the move step must be deferred.""" hash_block_size = 2 block_size = 2 * hash_block_size kv_cache_config = KVCacheConfig( @@ -1597,8 +1588,7 @@ def test_hybrid_partial_hash_truncates_full_attention_hit_length(): def test_cow_retained_blocks_returned_for_release(): """new_step_starts returns the CoW copy retentions instead of freeing - them; the scheduler owns releasing them once the copy has run. - """ + them; the scheduler owns releasing them once the copy has run.""" hash_block_size = 2 block_size = 2 * hash_block_size kv_cache_config = KVCacheConfig( @@ -1651,8 +1641,7 @@ def test_cow_retained_blocks_returned_for_release(): def test_free_cow_retained_blocks_defers_until_copy_step_processed(): """Scheduler releases CoW retentions immediately when the copy's step has - been processed (or deferral is off), and defers them otherwise. - """ + been processed (or deferral is off), and defers them otherwise.""" from collections import deque freed: list = [] @@ -1689,8 +1678,7 @@ def test_free_cow_retained_blocks_defers_until_copy_step_processed(): def test_full_attention_eagle_drops_one_hash_unit(): """With fine-grained partial hits, eagle rewinds the hit by one hash unit instead of a whole cache block: the tail block's KV is append-only, so it - still covers the reduced length and stays in the hit as a partial block. - """ + still covers the reduced length and stays in the hit as a partial block.""" from vllm.v1.core.block_pool import BlockPool from vllm.v1.core.single_type_kv_cache_manager import FullAttentionManager @@ -1766,8 +1754,7 @@ def test_hybrid_partial_hit_with_eagle_stays_within_group_blocks(): """Regression: with eagle, the mamba group must not receive the eagle lookup margin — its finder never applies the drop, so it could return a hit past the blocks the (dropped) full-attention group covers, crashing - the consumer's CoW with block_idx >= len(req_blocks). - """ + the consumer's CoW with block_idx >= len(req_blocks).""" hash_block_size = 2 block_size = 2 * hash_block_size kv_cache_config = KVCacheConfig( @@ -2369,8 +2356,7 @@ def test_retention_snapshots_handed_off_with_exact_block_ids(): """Under sparse retention, each retained mamba boundary state block is handed to the connector with its exact block id. Connectors must not resolve align-mode state blocks positionally because the block table is not - append-only. - """ + append-only.""" hash_block_size = 2 block_size = 4 manager = make_kv_cache_manager( @@ -2411,8 +2397,7 @@ def test_snapshot_handoff_dense_default_retention(): """With dense (default) retention, every materialized mamba boundary state block is handed off — regular mamba-align + prefix-match-unit deployments get store-able boundary snapshots without setting a - prefix-cache retention interval. - """ + prefix-cache retention interval.""" hash_block_size = 2 block_size = 4 manager = make_kv_cache_manager( @@ -2444,8 +2429,7 @@ def test_snapshot_handoff_dense_default_retention(): def _run_chunked_prefill(manager, req, chunk_size, num_chunks): """Prefill ``req`` one ``chunk_size`` chunk per scheduler step, yielding the - boundary-state hand-offs offered (and claimed) at each step. - """ + boundary-state hand-offs offered (and claimed) at each step.""" computed_blocks, num_computed, _ = manager.get_computed_blocks(req) for step in range(num_chunks): manager.new_step_starts() @@ -2509,8 +2493,7 @@ def test_boundary_states_offered_past_prompt_for_resumed_prefill(): ``num_prompt_tokens``. A resumed request re-prefills its generated tokens and every group re-saves them, so filtering on the original prompt length would silently strip the mamba key for boundaries full attention still - stores; only the connector knows where its save window ends. - """ + stores; only the connector knows where its save window ends.""" block_size = 8 prompt_len = block_size manager = make_kv_cache_manager( diff --git a/tests/v1/core/test_async_scheduler.py b/tests/v1/core/test_async_scheduler.py index 097878ff7d..7e27a4517e 100644 --- a/tests/v1/core/test_async_scheduler.py +++ b/tests/v1/core/test_async_scheduler.py @@ -552,8 +552,7 @@ def _create_async_pp_scheduler( def _assert_ordered_subset(delivered: list[int], emitted: list[int]) -> None: """Delivered tokens must be an order-preserving subset of the emitted - tokens with no duplicates (tokens are globally unique). - """ + tokens with no duplicates (tokens are globally unique).""" it = iter(emitted) for token in delivered: assert token in it, f"token {token} delivered out of order or twice" @@ -563,8 +562,7 @@ def _assert_positions_consistent(req, engine: PipelinedEngine) -> None: """The i-th delivered output token must be one the runner sampled for exactly sequence position prompt_len + i: catches a preempted request's stale output landing on a position the resumed request resampled (or - vice versa), which token-stream equality alone cannot see. - """ + vice versa), which token-stream equality alone cannot see.""" for i, token in enumerate(req.output_token_ids): expected = req.num_prompt_tokens + i actual = engine.emitted_position[token] diff --git a/tests/v1/core/test_contiguous_kv_packing.py b/tests/v1/core/test_contiguous_kv_packing.py index f3692672e9..2fcf70c6ef 100644 --- a/tests/v1/core/test_contiguous_kv_packing.py +++ b/tests/v1/core/test_contiguous_kv_packing.py @@ -178,8 +178,7 @@ def _shared_layout_config(): class TestCSALinearGrouping: """A CSA + linear-attention model (sparse attention with a compressor ring, plus sharded GDN and one TP-replicated PLE state) goes through the generic - packed-group path; no model-specific branch is involved. - """ + packed-group path; no model-specific branch is involved.""" @staticmethod def _mamba_groups(groups): @@ -194,8 +193,7 @@ class TestCSALinearGrouping: def test_replicated_state_gets_its_own_group(self): """The PLE state is TP-replicated and a different size, so it must not share a manager group with the sharded GDN states (the NIXL worker - requires exactly one single-layer replicated group). - """ + requires exactly one single-layer replicated group).""" groups = get_kv_cache_groups(_shared_layout_config(), _make_csa_linear_specs()) mamba_groups = self._mamba_groups(groups) @@ -248,8 +246,7 @@ class TestCSALinearGrouping: def test_scratch_group_survives_computed_block_truncation(self): """The scratch group contributes no computed blocks, so truncating a lookup result must skip it: its block size is the ring capacity, which - neither divides the hit length nor bounds the (empty) block list. - """ + neither divides the hit length nor bounds the (empty) block list.""" config = _shared_layout_config() config.cache_config.enable_prefix_caching = True groups = get_kv_cache_groups(config, _make_csa_linear_specs()) @@ -363,8 +360,7 @@ class TestCSALinearGrouping: per page size, which is emitted whole, or a single-layer state that cannot be split at all -- the mamba layers must be sized against it. Sizing them against a narrower bucket splits them past what the block - already fits, spending a pool block per extra group for no saving. - """ + already fits, spending a pool block per extra group for no saving.""" config = _mock_vllm_config("BLNHC") config.speculative_config = None specs = {} @@ -409,8 +405,7 @@ class TestSlidingWindowBucketCap: unbalanced 8-layer paged MLA bucket. Left whole, the SWA bucket would set the block width and the MLA group would fill under a third of every block; capped, it splits into groups no wider than the MLA - page. - """ + page.""" config = _shared_layout_config() specs: dict[str, KVCacheSpec] = {} for layer, ratio in ((2, 2), (8, 2), (14, 2), (20, 1)): @@ -611,8 +606,7 @@ class TestCompressorRingGroup: """DeepSeek-V4.1 compressor state: a CircularBufferSpec ring (capacity 8) beside 128-token paged MLA groups and 64-token SWA groups. The ring claims one block per request, never hashes, and does not disturb the - scheduler/hash block sizes the paged groups imply. - """ + scheduler/hash block sizes the paged groups imply.""" config = _shared_layout_config() config.cache_config.enable_prefix_caching = True specs: dict[str, KVCacheSpec] = { diff --git a/tests/v1/core/test_encoder_cache_manager.py b/tests/v1/core/test_encoder_cache_manager.py index 7f0747abe0..3948f7c6e3 100644 --- a/tests/v1/core/test_encoder_cache_manager.py +++ b/tests/v1/core/test_encoder_cache_manager.py @@ -367,8 +367,7 @@ def test_free_request_with_duplicate_mm_hashes(): """Freeing a request whose two inputs share the same mm_hash must fully clean up request_cached_ids. After the first free_encoder_input call, cached[mm_hash] becomes empty; the second call must still remove the - remaining input_id from request_cached_ids. - """ + remaining input_id from request_cached_ids.""" manager = EncoderCacheManager(cache_size=20) req = MockRequest("r1", ["imgA", "imgA"], [4, 4]) @@ -384,8 +383,7 @@ def test_free_request_with_duplicate_mm_hashes(): def test_duplicate_mm_hash_stays_referenced_until_last_free(): """`cached` holds one reference per request, not per position, so freeing - the first of two occurrences must not release the entry. - """ + the first of two occurrences must not release the entry.""" manager = EncoderCacheManager(cache_size=20) req = MockRequest("r1", ["imgA", "imgA"], [4, 4]) @@ -406,8 +404,7 @@ def test_duplicate_mm_hash_stays_referenced_until_last_free(): def test_duplicate_mm_hash_is_not_evicted_before_last_use(): """An item repeated within one request (an image carried across conversation turns) must not become reclaimable capacity while a later - occurrence still has to be spliced in, or the encoder recomputes it. - """ + occurrence still has to be spliced in, or the encoder recomputes it.""" manager = EncoderCacheManager(cache_size=8) req = MockRequest("r1", ["imgA", "imgA"], [4, 4]) other = MockRequest("r2", ["imgB"], [8]) diff --git a/tests/v1/core/test_kv_cache_utils.py b/tests/v1/core/test_kv_cache_utils.py index a0600abd85..3c82180474 100644 --- a/tests/v1/core/test_kv_cache_utils.py +++ b/tests/v1/core/test_kv_cache_utils.py @@ -2593,8 +2593,7 @@ def test_get_kv_cache_config_kpool_tail_coowns_indexer_tensor(): """The kpool tail parasitizes the indexer tensors instead of getting its own: sibling idx/tail tensors paired by layer order, zero standalone tail bytes, one shared block per request, and no prefix-caching leakage from - the kpool-sized scratch group. - """ + the kpool-sized scratch group.""" model_config = ModelConfig(max_model_len=8192) vllm_config = VllmConfig(model_config=model_config) @@ -2665,8 +2664,7 @@ def test_get_kv_cache_config_kpool_tail_coowns_indexer_tensor(): def test_glm5_kpool_tail_does_not_drag_hash_block_size(): """The tail's kpool-sized scratch block (4 tokens) must not constrain the - prefix-cache hash granularity: participating groups alone decide it. - """ + prefix-cache hash granularity: participating groups alone decide it.""" model_config = ModelConfig(max_model_len=8192) vllm_config = VllmConfig(model_config=model_config) @@ -2742,8 +2740,7 @@ def test_get_kv_cache_config_mamba_hybrid_sharing_infeasible_no_indexer(): def test_get_kv_cache_config_mamba_hybrid_sharing_prepadded_mamba(): """Platform-prepadded mamba pages (mamba_page_size_padded hint) must not - disable slot sharing; the layout re-pads them to the MLA page. - """ + disable slot sharing; the layout re-pads them to the MLA page.""" model_config = ModelConfig(max_model_len=8192) vllm_config = VllmConfig(model_config=model_config) @@ -2774,8 +2771,7 @@ def test_get_kv_cache_config_mamba_hybrid_sharing_prepadded_mamba(): def test_get_kv_cache_config_mamba_hybrid_sharing_pp_balanced_projection(): """Round-robin mamba grouping keeps practical PP splits balanced: every stage's largest projected mamba group slice fits its projected MLA - layers, so per-stage slot tensors all have an MLA owner. - """ + layers, so per-stage slot tensors all have an MLA owner.""" model_config = ModelConfig(max_model_len=8192) vllm_config = VllmConfig(model_config=model_config) @@ -2819,8 +2815,7 @@ def test_get_kv_cache_config_mamba_hybrid_sharing_pp_group_count_bump(monkeypatc """PP=4's default partition [11,11,12,11] leaves stage 0 with 2 MLA layers but a round-robin slice of 3 under the minimum 4 mamba groups; grouping bumps to 5 groups so every stage's projection keeps sharing - on instead of silently falling back on stage 0. - """ + on instead of silently falling back on stage 0.""" from vllm.config import ParallelConfig from vllm.distributed.utils import get_pp_indices @@ -2869,8 +2864,7 @@ def test_get_kv_cache_config_mamba_hybrid_sharing_pp_starved_stage(monkeypatch): def test_get_kv_cache_config_mamba_hybrid_sharing_beats_cross_layers_flag(): """Hybrid slot sharing must take precedence over the experimental enable_cross_layers_blocks packed layout: generic packing would give the - MLA slots a strided view, breaking the contiguous virtual split. - """ + MLA slots a strided view, breaking the contiguous virtual split.""" model_config = ModelConfig(max_model_len=8192) kv_transfer_config = KVTransferConfig( kv_connector="NixlConnector", @@ -3172,8 +3166,7 @@ def test_multi_run_layer_compact_strides_place_hoisted_heads(): """A layer-compact run region is its own dense allocation: under LHBNC the head groups sit between the layers and the blocks, so a run's block stride is one head group's slice, not the whole page (regression test for setStorage out-of-bounds - on ROCm hybrid models). - """ + on ROCm hybrid models).""" full = new_kv_cache_spec() swa = new_sliding_window_spec(sliding_window=full.block_size * 2) page = full.page_size_bytes @@ -3252,8 +3245,7 @@ def test_mla_with_incompatible_swa_uses_one_full_allocation_group(caplog_vllm): def test_hidden_states_with_tp_scales_page_size(): """When TP shrinks KV pages below the hidden-state per-token cost, get_kv_cache_groups must scale up target block sizes so that the - common page accommodates the unsharded hidden states. - """ + common page accommodates the unsharded hidden states.""" # Simulate TP=4 sharding a model with 8 KV heads → 2 per rank. # KV page = block_size(16) * num_kv_heads(2) * head_size(64) * dtype(2) # = 16 * 2 * 64 * 2 = 4096 bytes. @@ -4083,8 +4075,7 @@ def test_check_enough_kv_cache_memory_reserves_null_block(): def test_is_full_attention_spec_unwraps_uniform_type_specs(): """``UniformTypeKVCacheSpecs`` is not a ``FullAttentionSpec``, so callers - scanning groups with a bare isinstance miss DeepSeek-V4-shaped configs. - """ + scanning groups with a bare isinstance miss DeepSeek-V4-shaped configs.""" common = dict(num_kv_heads=1, head_size=1, dtype=torch.float32) full = FullAttentionSpec(block_size=4, **common) mla = MLAAttentionSpec(block_size=4, **common) @@ -4253,8 +4244,7 @@ def test_no_warning_when_draft_group_is_identified(caplog_vllm): def _deepseek_v4_specs(model_version="deepseek_v4"): """DeepseekV4-shaped specs: full MLA layers plus sliding-window MLA layers - at differing page sizes, with the MTP draft layer registered last. - """ + at differing page sizes, with the MTP draft layer registered last.""" return { "model.layers.0.self_attn.attn": new_mla_spec(), "model.layers.1.self_attn.attn": new_mla_spec(), diff --git a/tests/v1/core/test_output.py b/tests/v1/core/test_output.py index 4e1e22eb8e..ee8a4a0e78 100644 --- a/tests/v1/core/test_output.py +++ b/tests/v1/core/test_output.py @@ -55,8 +55,7 @@ def _mm_feature(offset: int, length: int) -> MultiModalFeatureSpec: def test_strip_covered_mm_data() -> None: """Items fully inside the computed prefix lose their data; items touching - the uncomputed region keep it; already-None data stays None. - """ + the uncomputed region keep it; already-None data stays None.""" from dataclasses import replace covered = _mm_feature(offset=0, length=100) @@ -108,8 +107,7 @@ def _mm_feature_mixed(offset: int, length: int) -> MultiModalFeatureSpec: def test_strip_covered_mm_data_mrope() -> None: """For M-RoPE models, covered items keep their keep_on_cpu metadata fields - (the worker needs them to compute positions); payload fields are dropped. - """ + (the worker needs them to compute positions); payload fields are dropped.""" covered = _mm_feature_mixed(offset=0, length=100) uncovered = _mm_feature_mixed(offset=300, length=100) @@ -129,8 +127,7 @@ def test_strip_covered_mm_data_shm_address_item() -> None: """SHM address descriptors must survive stripping even when covered: the worker needs the address to resolve the payload and to acknowledge the sender's writer reference. Stripping it crashed the SHM receiver cache on - the second identical request (vllm-project/vllm#54994). - """ + the second identical request (vllm-project/vllm#54994).""" address_item = MultiModalKwargsItem( { "address": MultiModalFieldElem(data=4096, field=MultiModalBatchedField()), diff --git a/tests/v1/core/test_prefix_caching.py b/tests/v1/core/test_prefix_caching.py index 653d485a82..01bf73b6e7 100644 --- a/tests/v1/core/test_prefix_caching.py +++ b/tests/v1/core/test_prefix_caching.py @@ -126,8 +126,7 @@ def make_kv_cache_manager(kv_cache_config: KVCacheConfig, **kwargs) -> KVCacheMa """Build a ``KVCacheManager``, deriving ``scheduler_block_size`` from the config (LCM of group block sizes) unless explicitly provided. This mirrors ``resolve_kv_cache_block_sizes`` for the non-context-parallel case used by - these tests, so callers don't have to pass it at every site. - """ + these tests, so callers don't have to pass it at every site.""" kwargs.setdefault( "scheduler_block_size", lcm(*(g.kv_cache_spec.block_size for g in kv_cache_config.kv_cache_groups)), @@ -3330,8 +3329,7 @@ def test_kv_cache_events_with_lora(blocks_to_cache: int): @pytest.mark.parametrize("group_id", [0, 1, 2]) def test_block_stored_event_group_idx(group_id: int): """Test BlockStored events emitted by cache_full_blocks carry the correct - group_idx. - """ + group_idx.""" block_size = 4 num_tokens = block_size * 2 @@ -3624,8 +3622,7 @@ def test_block_removed_event_group_idx(group_id: int): def test_emit_cached_block_events(): """emit_cached_block_events emits one BlockStored for already-cached (reused) prefix blocks, carrying the correct group_idx / - parent_block_hash / token_ids, and without mutating block state. - """ + parent_block_hash / token_ids, and without mutating block state.""" block_size = 4 num_cached_blocks = 3 kv_cache_group_id = 1 @@ -3738,8 +3735,7 @@ def test_emit_cached_block_events_zero_cached(): def test_eagle_enabled_removes_last_block(): """Verify Eagle does NOT remove blocks when request - length is divisible by block size. - """ + length is divisible by block size.""" block_size = 16 manager = make_kv_cache_manager( make_kv_cache_config(block_size, num_blocks=10), @@ -4142,8 +4138,7 @@ def test_hybrid_cache_blocks_swa_tail_window_only(): (its right-to-left scan stops once a contiguous match is found). Blocks earlier in the segment can never serve a hit, so ``HybridKVCacheCoordinator.cache_blocks`` should skip them rather than - polluting the prefix-cache hash map. - """ + polluting the prefix-cache hash map.""" block_size = 8 # Full attn block_size=32, SWA block_size=8, sw=8 -> lcm=32. # tail = ceil(7/8) = 1; per_segment = 32/8 = 4. @@ -4214,8 +4209,7 @@ def test_hybrid_cache_blocks_clamped_to_lcm(): Chunks past the last lcm-aligned boundary can never participate in a cache hit (find_longest_cache_hit always returns lcm-aligned hits), so caching them only pollutes the prefix-cache hash map and keeps blocks - on the LRU list that could otherwise return to the free pool. - """ + on the LRU list that could otherwise return to the free pool.""" block_size = 16 # Full attn block_size=32, SWA block_size=16 -> lcm=32. kv_cache_config = KVCacheConfig( @@ -4350,8 +4344,7 @@ def test_hybrid_local_kv_retention_interval_aligns_in_manager(): ) def test_hybrid_local_kv_retention_interval_rejects_invalid(interval, expected_match): """A retention interval that is negative or not a multiple of - scheduler_block_size errors out at construction time. - """ + scheduler_block_size errors out at construction time.""" block_size = 8 kv_cache_config = KVCacheConfig( num_blocks=100, @@ -4821,8 +4814,7 @@ def test_block_lookup_cache_multi_blocks_per_key(): def test_can_fit_full_sequence_swa_cap_admits_long_prompt(): """Hybrid full+SWA model with a pool sized at the startup minimum should admit a prompt longer than the SWA cap, because SlidingWindowManager - recycles blocks during chunked prefill (issue #39734). - """ + recycles blocks during chunked prefill (issue #39734).""" block_size = 16 sliding_window = 4 * block_size # 64 tokens max_num_batched_tokens = 8 * block_size # 128 tokens @@ -4917,8 +4909,7 @@ def test_full_sequence_admission_reserves_device_blocks_for_immediate_chunk( def test_can_fit_full_sequence_full_attention_still_gates_oversized(): """The cap only loosens the SWA group; a prompt that exceeds the - full-attention pool capacity must still be rejected. - """ + full-attention pool capacity must still be rejected.""" block_size = 16 sliding_window = 4 * block_size max_num_batched_tokens = 8 * block_size @@ -5037,8 +5028,7 @@ def _take_free_blocks(manager: KVCacheManager, num_blocks: int) -> list[KVCacheB without removing them. These ref_cnt==0 blocks stand in for evictable cache-hit blocks left behind by a previous (e.g. preempted) request, and sitting at the head guarantees a later group's external ``get_new_blocks`` - would contend for them on unpatched code (issue #33775). - """ + would contend for them on unpatched code (issue #33775).""" blocks: list[KVCacheBlock] = [] head = manager.block_pool.free_block_queue.fake_free_list_head for _ in range(num_blocks): @@ -5049,8 +5039,7 @@ def _take_free_blocks(manager: KVCacheManager, num_blocks: int) -> list[KVCacheB def _assert_no_double_allocation(manager: KVCacheManager, req_id: str) -> None: """No physical block may be handed out twice across groups, and every - block referenced by the request must have a live ref_cnt. - """ + block referenced by the request must have a live ref_cnt.""" block_ids = manager.get_blocks(req_id).get_block_ids() flat = [block_id for group in block_ids for block_id in group] assert len(set(flat)) == len(flat), "Block IDs are not unique across groups" @@ -5077,8 +5066,7 @@ def _cross_group_cache_hit( ) -> Request: """Allocate ``req_id`` with a per-group local prefix hit plus external (connector) computed tokens, driving the coordinator's two-phase path. - Returns the allocated request so callers can free it (e.g. to preempt). - """ + Returns the allocated request so callers can free it (e.g. to preempt).""" block_size = _two_phase_block_size(manager) hit_blocks = _take_free_blocks(manager, num_groups * local_blocks_per_group) cache_hit = KVCacheBlocks( @@ -5173,8 +5161,7 @@ def test_swa_free_split_keeps_cached_tail_ahead_of_scratch(): """Dense retention: freeing an SWA request must place its uncached scratch blocks at the front of the free queue (recycled first) and keep its cached checkpoint blocks at the back (retained for prefix - hits). This split is always-on, independent of the retention interval. - """ + hits). This split is always-on, independent of the retention interval.""" block_size = 8 kv_cache_config = KVCacheConfig( num_blocks=100, @@ -5285,8 +5272,7 @@ def _make_pure_swa_manager(block_size, sliding_window, num_blocks=100, **kwargs) def test_pure_swa_retention_interval_caches_sparse_tails(): """Sparse retention must work for a pure-SWA single-group model, not just hybrid models: only the per-interval tails plus the latest replay tail are - cached, and a replay still hits the latest replayable boundary. - """ + cached, and a replay still hits the latest replayable boundary.""" block_size = 16 manager = _make_pure_swa_manager( block_size, sliding_window=block_size, retention_interval=64 @@ -5358,8 +5344,7 @@ def test_pure_swa_retention_latest_only(): def test_pure_swa_dense_retention_caches_all(): """With retention set to ``None``, a pure-SWA model keeps dense behavior: - every block boundary is a potential hit, so all blocks are cached. - """ + every block boundary is a potential hit, so all blocks are cached.""" block_size = 16 manager = _make_pure_swa_manager(block_size, sliding_window=block_size) @@ -5388,8 +5373,7 @@ def test_mamba_reachable_block_mask_sparsifies_retention(): """Mamba state-snapshot retention: with a configured retention interval, the manager keeps one cached state per interval-sized segment (plus the latest replay boundary) instead of a snapshot per block, which is what - lets a small attention block_size avoid Mamba dominating the KV pool. - """ + lets a small attention block_size avoid Mamba dominating the KV pool.""" from vllm.v1.core.single_type_kv_cache_manager import MambaManager block_size = 16 @@ -5427,8 +5411,7 @@ def test_mamba_reachable_block_mask_pins_shared_prefix(): """A Marconi-detected shared prefix (``shared_prefix_boundary``) lands before ``num_prompt`` so the replay-boundary rule alone would drop it. The mask must pin the single state block ending on that boundary so sparse retention does - not defeat cross-request shared-prefix reuse. - """ + not defeat cross-request shared-prefix reuse.""" from vllm.v1.core.single_type_kv_cache_manager import MambaManager block_size = 16 @@ -5476,8 +5459,7 @@ def test_mamba_shared_prefix_survives_zero_retention(): detection) keeps its Mamba state block cached under ``prefix_cache_retention_interval=0``, which otherwise retains only the end-of-prompt replay boundary. Without this, a shared prefix (junction - before ``num_prompt``) would be recomputed by every sharing request. - """ + before ``num_prompt``) would be recomputed by every sharing request.""" block_size = 16 # 16-block (256-token) prompt; replay boundary is block 240 // 16 - 1 = 14. @@ -5519,8 +5501,7 @@ def test_mamba_shared_prefix_reuse_under_zero_retention(): detecting request must stay reusable by a later request under ``prefix_cache_retention_interval=0``. Without the pin the junction is masked out and the later request misses; with it (and under dense) the reuse - is preserved. - """ + is preserved.""" block_size = 16 def last_req_hit(retention, pin): @@ -5603,8 +5584,7 @@ def test_swa_reachable_block_mask_final_partial_segment(): def test_swa_reachable_block_mask_pins_shared_prefix(): """SWA analog of the Mamba pin: the shared-prefix junction must keep the ``need``-block sliding-window tail ending on that boundary (not a single - block), so a windowed hit can land there under sparse retention. - """ + block), so a windowed hit can land there under sparse retention.""" from vllm.v1.core.single_type_kv_cache_manager import SlidingWindowManager block_size = 16 @@ -5649,8 +5629,7 @@ def test_swa_reachable_block_mask_pins_shared_prefix(): def test_swa_reachable_block_mask_with_dcp_scaling(): """DCP shards each block's KV across ranks, scaling the effective block size. Verify that dcp_world_size > 1 scales block size in reachability calculations, - producing different masks than dcp_world_size=1. - """ + producing different masks than dcp_world_size=1.""" from vllm.v1.core.single_type_kv_cache_manager import SlidingWindowManager block_size = 16 @@ -5709,8 +5688,7 @@ def test_swa_reachable_block_mask_sub_block_alignment_is_dense( multiple of the DCP-scaled block size) cannot be represented exactly. This happens for hybrid offloading (e.g. Gemma), where alignment_tokens is the full-attention chunk size and need not divide the SWA block size. The mask - must fall back to dense (None) rather than raise. - """ + must fall back to dense (None) rather than raise.""" from vllm.v1.core.single_type_kv_cache_manager import SlidingWindowManager spec = SlidingWindowSpec( @@ -5738,8 +5716,7 @@ def test_mamba_reachable_block_mask_ignores_dcp(): """Mamba uses TP, not DCP: each rank holds the full recurrent state, so a state block spans kv_cache_spec.block_size tokens regardless of DCP. The mask must not scale by dcp_world_size, so retention granularity is - identical for any DCP world size. - """ + identical for any DCP world size.""" from vllm.v1.core.single_type_kv_cache_manager import MambaManager spec = MambaSpec( @@ -5773,8 +5750,7 @@ def test_mamba_reachable_block_mask_ignores_dcp(): def test_mamba_reachable_block_mask_large_dcp_stays_sparse(): """A large DCP world size must not scale the Mamba block size, so it can - never collapse sparse retention into dense caching. - """ + never collapse sparse retention into dense caching.""" from vllm.v1.core.single_type_kv_cache_manager import MambaManager spec = MambaSpec( @@ -5809,8 +5785,7 @@ def test_swa_shared_prefix_reuse_under_zero_retention(): """SWA cross-request analog: a partial shared prefix's sliding-window tail must stay reusable under ``prefix_cache_retention_interval=0``. Without the pin the junction window is masked out and a later request misses; with - it (and under dense) reuse is preserved. - """ + it (and under dense) reuse is preserved.""" block_size = 16 def last_req_hit(retention, pin): diff --git a/tests/v1/core/test_scheduler.py b/tests/v1/core/test_scheduler.py index 5774ec0146..3239ec25a0 100644 --- a/tests/v1/core/test_scheduler.py +++ b/tests/v1/core/test_scheduler.py @@ -538,8 +538,7 @@ def test_throttle_defers_inflight_prefill_chunk(): """DP prefill balancing throttles ALL prefill compute on a throttled step, not just new admissions: an in-progress (chunked) prefill already in the running queue is also deferred, so the step runs decode-only, while a - separate decode keeps being scheduled. - """ + separate decode keeps being scheduled.""" scheduler = create_scheduler( max_num_seqs=16, max_num_batched_tokens=50, enable_chunked_prefill=True ) @@ -593,8 +592,7 @@ def test_throttle_capacity_bound_guard_admits(): """Saturation guard: if a cadence-aligned release step cannot drain the waiting prefill queue (it ran out of token budget), the throttle backs off on the next step so the backlog cannot grow into a TTFT avalanche -- prefills are - admitted even though throttle_prefills is set. - """ + admitted even though throttle_prefills is set.""" scheduler = create_scheduler( max_num_seqs=16, max_num_batched_tokens=200, enable_chunked_prefill=True ) @@ -1293,8 +1291,7 @@ def test_pending_hisparse_reclamation_defers_preemption(monkeypatch): def test_prefix_cache_query_not_inflated_by_connector_defer(): """The GPU prefix-cache query is recorded at admission, so a request the - connector defers several times is counted once, not once per retry. - """ + connector defers several times is counted once, not once per retry.""" num_defers_before_matching = 3 scheduler = create_scheduler( enable_prefix_caching=True, @@ -1322,8 +1319,7 @@ def test_prefix_cache_query_not_inflated_by_connector_defer(): def test_preemption_re_records_prefix_cache_query(): """A preempted request re-enters the lookup on resume, so its recomputation - is counted again into the preempted stats. - """ + is counted again into the preempted stats.""" scheduler = create_scheduler(enable_prefix_caching=True) request = create_requests(num_requests=1)[0] scheduler.add_request(request) @@ -1359,8 +1355,7 @@ def test_preemption_re_records_prefix_cache_query(): def test_prefix_cache_stats_not_recorded_when_caching_disabled(): """With prefix caching off there is no local lookup, so admitting a request - records no phantom miss. - """ + records no phantom miss.""" scheduler = create_scheduler(enable_prefix_caching=False) for request in create_requests(num_requests=2): scheduler.add_request(request) @@ -1374,8 +1369,7 @@ def test_prefix_cache_stats_not_recorded_when_caching_disabled(): def test_prefix_cache_stats_counted_once_for_retried_then_scheduled_request(): """A real cache hit rejected once by allocate_slots and admitted on the next - step is counted exactly once, hits included. - """ + step is counted exactly once, hits included.""" block_size = 16 scheduler = create_scheduler( enable_prefix_caching=True, @@ -3094,8 +3088,7 @@ def create_requests_with_priority( def test_priority_scheduling_basic_ordering(): """Test that requests are scheduled in priority order - (lower value = higher priority). - """ + (lower value = higher priority).""" scheduler = create_scheduler_with_priority() # Create requests with different priorities @@ -3124,8 +3117,7 @@ def test_priority_scheduling_basic_ordering(): def test_priority_scheduling_arrival_time_tiebreaker(): """Test that arrival time is used - as tiebreaker when priorities are equal. - """ + as tiebreaker when priorities are equal.""" scheduler = create_scheduler_with_priority() # Create requests with same priority but different arrival times @@ -3282,8 +3274,7 @@ def test_priority_scheduling_preemption(): def test_priority_scheduling_no_preemption_when_space_available(): """Test that preemption doesn't happen - when there's space for new requests. - """ + when there's space for new requests.""" scheduler = create_scheduler_with_priority( max_num_seqs=3, # Allow 3 concurrent requests max_num_batched_tokens=200, # Sufficient token budget @@ -3336,8 +3327,7 @@ def test_priority_scheduling_no_preemption_when_space_available(): def test_priority_scheduling_preemption_victim_selection(): """Test that the correct victim is selected for - preemption based on priority and arrival time. - """ + preemption based on priority and arrival time.""" # This test verifies the priority-based victim selection logic # by checking the waiting queue order after adding requests with different # priorities @@ -3457,8 +3447,7 @@ def test_priority_scheduling_waiting_queue_order(): def test_priority_scheduling_fcfs_fallback(): """Test that FCFS behavior is maintained when all - requests have same priority. - """ + requests have same priority.""" scheduler = create_scheduler_with_priority() # Create requests with same priority but different arrival times @@ -3527,8 +3516,7 @@ def test_priority_scheduling_with_limited_slots(): def test_priority_scheduling_heap_property(): """Test that the waiting queue maintains heap - property for priority scheduling. - """ + property for priority scheduling.""" scheduler = create_scheduler_with_priority( max_num_seqs=1, # Only one request can run at a time ) @@ -3753,8 +3741,7 @@ def test_priority_scheduling_preemption_and_resumption_when_out_of_kv( use_ec_connector, ec_role, use_v2_model_runner ): """Test that priority scheduling preempts lower priority requests - when out of KV cache space. - """ + when out of KV cache space.""" # Create scheduler with very limited memory to force preemption scheduler = create_scheduler_with_priority( max_num_seqs=2, # Allow multiple requests @@ -3899,8 +3886,7 @@ def test_chunked_prefill_disabled_for_encoder_decoder( enable_chunked_prefill: bool, is_encoder_decoder: bool, expect_enabled: bool ) -> None: """Validate that chunked prefill is appropriately disabled for - encoder-decoder models. - """ + encoder-decoder models.""" scheduler_config = SchedulerConfig( enable_chunked_prefill=enable_chunked_prefill, is_encoder_decoder=is_encoder_decoder, @@ -3929,8 +3915,7 @@ def _validate_chunked_prefill_settings_for_encoder_decoder( scheduler_config: SchedulerConfig, is_encoder_decoder: bool, expect_enabled: bool ) -> None: """Validate chunked prefill settings in the scheduler config for - encoder-decoder models. - """ + encoder-decoder models.""" assert scheduler_config.enable_chunked_prefill is expect_enabled if is_encoder_decoder: # Encoder-decoder models should automatically disable chunked multimodal @@ -4020,8 +4005,7 @@ def _assert_right_encoder_inputs( ): """Verify that requests/mm_hashes should (not) in scheduled encoder input If check_exist is False, this function returns True - if requests are NOT in encoder inputs - """ + if requests are NOT in encoder inputs""" # Get the scheduled encoder inputs # NOTE: scheduled_encoder_inputs is a dictionary with request id as key scheduled_encoder_inputs = output.scheduled_encoder_inputs @@ -4182,8 +4166,7 @@ def test_ec_connector_text_only_request(use_kv_connector): @pytest.mark.parametrize("use_kv_connector", [False, True]) def test_ec_connector_cache_hit_external_load(use_kv_connector): """Test ec_consumer loads from external cache when hit. - A normal basic operation for EPD disaggrgation - """ + A normal basic operation for EPD disaggrgation""" scheduler = create_scheduler( model="llava-hf/llava-1.5-7b-hf", enable_prefix_caching=True, @@ -4630,8 +4613,7 @@ def test_priority_scheduling_ec_connector_preemption_and_resumption( cache_exist, use_kv_connector ): """Test that priority scheduling preempts lower priority requests - when out of KV cache space. - """ + when out of KV cache space.""" # Create scheduler with very limited memory to force preemption scheduler = create_scheduler_with_priority( model="llava-hf/llava-1.5-7b-hf", @@ -5300,8 +5282,7 @@ def test_scheduler_kv_connector_stats(): def test_ec_connector_update_connector_output_called(): """Test that worker-side EC connector output is forwarded to the - EC connector's update_connector_output hook. - """ + EC connector's update_connector_output hook.""" scheduler = create_scheduler( model="llava-hf/llava-1.5-7b-hf", use_ec_connector=True, @@ -5506,8 +5487,7 @@ def test_variable_length_cross_attn_block_allocation(): def test_cross_attn_blocks_not_over_allocated(): """Test that cross-attention blocks are not over-allocated compared to - what each request actually needs. - """ + what each request actually needs.""" from math import ceil block_size = 16 @@ -5603,8 +5583,7 @@ def test_cross_attn_blocks_not_under_allocated(): def test_cross_attn_zero_blocks_without_encoder_inputs(): """Test that requests without encoder inputs get zero cross-attention - blocks, even when the scheduler is configured for encoder-decoder. - """ + blocks, even when the scheduler is configured for encoder-decoder.""" block_size = 16 scheduler = _create_encoder_decoder_scheduler(block_size=block_size) @@ -5709,8 +5688,7 @@ def test_free_encoder_inputs_respects_unconfirmed_placeholders(): evicted entry and crashes the engine with "Encoder cache miss". The scheduler must retain the input until the *confirmed* progress (num_computed_tokens - num_output_placeholders) passes the range end, so - that no pending rejection can rewind into the range. - """ + that no pending rejection can rewind into the range.""" scheduler = create_scheduler( model="llava-hf/llava-1.5-7b-hf", num_speculative_tokens=3, @@ -5821,8 +5799,7 @@ def test_free_encoder_inputs_defers_for_eagle_lookahead(): position so the drafter's +1 look-ahead mm-embedding gather (which reads one position past the target's computed range) still finds it cached. This is the primary mechanism that prevents the drafter "Encoder cache miss"; the - worker-side token-embedding fallback is only a backstop. - """ + worker-side token-embedding fallback is only a backstop.""" scheduler = create_scheduler(model="llava-hf/llava-1.5-7b-hf") # create_scheduler only builds ngram spec configs; force the eagle path that # _free_encoder_inputs keys off (its read-ahead deferral). @@ -5852,8 +5829,7 @@ def test_free_encoder_inputs_defers_for_eagle_lookahead(): def test_free_encoder_inputs_unchanged_without_spec_decode(): """Without speculative decoding, encoder inputs are freed as soon as - num_computed_tokens passes the placeholder range, as before. - """ + num_computed_tokens passes the placeholder range, as before.""" scheduler = create_scheduler(model="llava-hf/llava-1.5-7b-hf") mm_positions = [[PlaceholderRange(offset=50, length=100)]] request = create_requests( @@ -5884,8 +5860,7 @@ def test_encoder_cache_retained_across_preemption_and_resume(): encoder input must pull the still-cached entry back out of `freeable` without scheduling a recompute, keeping the scheduler and worker consistent. The spec-rollback retention margin does not gate this path, - so it is covered separately here. - """ + so it is covered separately here.""" scheduler = create_scheduler( model="llava-hf/llava-1.5-7b-hf", num_speculative_tokens=3, @@ -5929,8 +5904,7 @@ def test_encoder_cache_recomputed_when_evicted_during_preemption(): pressure before it resumes, the scheduler reports the mm_hash as freed (so the worker drops it) and a resume must schedule a recompute rather than assume the worker still holds it. check_and_update_cache must - return False so the encoder input is re-scheduled. - """ + return False so the encoder input is re-scheduled.""" scheduler = create_scheduler( model="llava-hf/llava-1.5-7b-hf", num_speculative_tokens=3, @@ -6581,8 +6555,7 @@ def _decode_ready_request(scheduler): def test_update_draft_token_ids_strips_ngram_padding(): """ngram_gpu pads unfilled draft slots with -1; manager validation must - strip them before grammar.validate_tokens (which otherwise raises). - """ + strip them before grammar.validate_tokens (which otherwise raises).""" scheduler = create_scheduler(num_speculative_tokens=4) request = _decode_ready_request(scheduler) @@ -6601,8 +6574,7 @@ def test_update_draft_token_ids_strips_ngram_padding(): def test_update_draft_token_ids_in_output_strips_padding(): """Same guard on the output path; the -1 pad-back for the rejected count - is preserved (only the input to manager validation is stripped). - """ + is preserved (only the input to manager validation is stripped).""" scheduler = create_scheduler(num_speculative_tokens=4) request = _decode_ready_request(scheduler) diff --git a/tests/v1/core/test_swa_inflight_window_free.py b/tests/v1/core/test_swa_inflight_window_free.py index beaf5203f2..737796a4bf 100644 --- a/tests/v1/core/test_swa_inflight_window_free.py +++ b/tests/v1/core/test_swa_inflight_window_free.py @@ -97,8 +97,7 @@ def test_num_in_flight_tokens_accounting(): def test_swa_free_waits_for_in_flight_step(): """Async: out-of-window blocks stay allocated until the step that still - reads them has been processed. - """ + reads them has been processed.""" scheduler = _create_swa_scheduler(async_scheduling=True) request = create_requests( num_requests=1, num_tokens=NUM_PROMPT_TOKENS, block_size=BLOCK_SIZE @@ -133,8 +132,7 @@ def test_swa_free_waits_for_in_flight_step(): def test_swa_free_immediate_when_sync(): """Sync: no in-flight step at schedule time, frees happen at the first - decode allocation as before. - """ + decode allocation as before.""" scheduler = _create_swa_scheduler(async_scheduling=False) request = create_requests( num_requests=1, num_tokens=NUM_PROMPT_TOKENS, block_size=BLOCK_SIZE @@ -173,8 +171,7 @@ def test_swa_admission_cap_accounts_for_overlapping_batches(): def test_chunked_local_free_waits_for_in_flight_step(): """Chunked-local attention frees whole chunks left of the current one, and is exposed to the same load-WAR: with async scheduling those chunks must - stay allocated until the in-flight step that still reads them settles. - """ + stay allocated until the in-flight step that still reads them settles.""" scheduler = _create_chunked_scheduler(async_scheduling=True) request = create_requests( num_requests=1, num_tokens=NUM_PROMPT_TOKENS, block_size=BLOCK_SIZE @@ -229,8 +226,7 @@ def test_connector_finish_frees_on_settled_basis(): is handed to a KV connector (simple CPU offload / NIXL store), must use the same processed-token basis. Otherwise the connector reads/hands off a block the still-in-flight step is optimistically counted as done with, which is - the load-path WAR this fix closes. - """ + the load-path WAR this fix closes.""" scheduler = create_scheduler( block_size=BLOCK_SIZE, async_scheduling=True, diff --git a/tests/v1/cudagraph/test_breakable_cudagraph.py b/tests/v1/cudagraph/test_breakable_cudagraph.py index 3e87770d4e..b0b49a9567 100644 --- a/tests/v1/cudagraph/test_breakable_cudagraph.py +++ b/tests/v1/cudagraph/test_breakable_cudagraph.py @@ -80,8 +80,7 @@ def test_piecewise_capture_builds_fresh_metadata_for_both_passes(): @pytest.fixture(autouse=True) def _reset_breakable_tls(): """Defensively clear thread-local capture state between tests so a - failure in one test can't leak "nested capture" errors into the next. - """ + failure in one test can't leak "nested capture" errors into the next.""" from vllm.compilation.breakable_cudagraph import BreakableCUDAGraphCapture BreakableCUDAGraphCapture._tls.active = None @@ -291,8 +290,7 @@ def test_capture_replay_matches_eager_simple(cuda_capture_stream): def test_decorator_breaks_when_invoked_inside_capture(cuda_capture_stream): """Verify @eager_break_during_capture correctly routes through add_eager when inside a capture context, and runs straight through - when there's no active capture. - """ + when there's no active capture.""" from vllm.compilation.breakable_cudagraph import ( BreakableCUDAGraphCapture, eager_break_during_capture, @@ -554,8 +552,7 @@ def _mock_vllm_config(): def test_wrapper_falls_through_on_runtime_mode_mismatch(): """A PIECEWISE-scoped wrapper runs other modes eagerly, capturing - nothing, so an outer CUDAGraphWrapper can own them. - """ + nothing, so an outer CUDAGraphWrapper can own them.""" from vllm.compilation.breakable_cudagraph import BreakableCUDAGraphWrapper from vllm.config import CUDAGraphMode from vllm.forward_context import BatchDescriptor, set_forward_context diff --git a/tests/v1/determinism/test_rms_norm_batch_invariant.py b/tests/v1/determinism/test_rms_norm_batch_invariant.py index d0a4c5c5b2..5699a661c1 100644 --- a/tests/v1/determinism/test_rms_norm_batch_invariant.py +++ b/tests/v1/determinism/test_rms_norm_batch_invariant.py @@ -275,8 +275,7 @@ def test_rms_norm_per_block_quant_batch_invariant( hidden_size: int, dtype: torch.dtype, seed: int ): """C++ ``rms_norm_per_block_quant`` must be batch invariant across the - block threshold (compiled fp8 block-quant path; block pinned to 512). - """ + block threshold (compiled fp8 block-quant path; block pinned to 512).""" import vllm._custom_ops as ops device = torch.device(DEVICE_TYPE) diff --git a/tests/v1/distributed/test_async_llm_dp.py b/tests/v1/distributed/test_async_llm_dp.py index 4c544fab7b..cb23910566 100644 --- a/tests/v1/distributed/test_async_llm_dp.py +++ b/tests/v1/distributed/test_async_llm_dp.py @@ -547,8 +547,7 @@ async def test_dp_pause_keep_then_resume(expert_parallel: bool): async def test_dp_pause_keep_race_staggered_engines(): """Race: send pause(keep) to engine 0, then add two requests, then pause(keep) to engine 1. Ensures no deadlock when pause - requests are staggered and requests arrive in between. - """ + requests are staggered and requests arrive in between.""" if DP_SIZE != 2: pytest.skip("test_dp_pause_keep_race_staggered_engines requires DP_SIZE=2") @@ -718,8 +717,7 @@ async def test_dp_pause_barrier_request_deadlock(): async def test_dp_pause_wait_mode_drains_in_flight(): """mode="wait" through the DP consensus path: the pause lets the in-flight request run to completion while the consensus is pending, - resolves only once drained, and the engine generates again on resume. - """ + resolves only once drained, and the engine generates again on resume.""" with ExitStack() as after: engine = AsyncLLM.from_engine_args(_get_dp_pause_engine_args(True)) after.callback(engine.shutdown) @@ -750,8 +748,7 @@ async def test_dp_pause_wait_mode_drains_in_flight(): async def test_dp_pause_while_asleep(): """Pausing a sleeping DP engine: sleeping ranks skip dummy batches yet must still reach the pause consensus, and the completion barrier must - be harmless on workers whose memory is unmapped. - """ + be harmless on workers whose memory is unmapped.""" with ExitStack() as after: engine = AsyncLLM.from_engine_args(_get_dp_pause_engine_args(True)) after.callback(engine.shutdown) @@ -787,8 +784,7 @@ async def test_dp_pause_completion_implies_device_idle( """A resolved pause future promises an idle device. Inflate the dummy batches the pause consensus manufactures so any work the pause fails to wait on stays visible, then require a quiet worker stream the moment - pause_generation() returns. - """ + pause_generation() returns.""" with ExitStack() as after: # The probes below ship functions through collective_rpc. monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1") diff --git a/tests/v1/distributed/test_external_lb_dp.py b/tests/v1/distributed/test_external_lb_dp.py index 95a31f3709..b53d0d8af0 100644 --- a/tests/v1/distributed/test_external_lb_dp.py +++ b/tests/v1/distributed/test_external_lb_dp.py @@ -24,8 +24,7 @@ TP_SIZE = int(os.getenv("TP_SIZE", "1")) class ExternalLBServerManager: """Manages data parallel vLLM server instances for external - load balancer testing. - """ + load balancer testing.""" def __init__( self, diff --git a/tests/v1/distributed/test_hybrid_lb_dp.py b/tests/v1/distributed/test_hybrid_lb_dp.py index 748370f37c..fcd3c69af5 100644 --- a/tests/v1/distributed/test_hybrid_lb_dp.py +++ b/tests/v1/distributed/test_hybrid_lb_dp.py @@ -30,8 +30,7 @@ DP_SIZE_LOCAL = DP_SIZE // NUM_NODES # 2 ranks per node class HybridLBServerManager: """Manages hybrid data parallel vLLM server instances where each node runs a single logical API server that balances requests only to the - DP engines running on that same node. - """ + DP engines running on that same node.""" def __init__( self, diff --git a/tests/v1/distributed/test_internal_lb_dp.py b/tests/v1/distributed/test_internal_lb_dp.py index 9fe8c9f0af..b438d898b3 100644 --- a/tests/v1/distributed/test_internal_lb_dp.py +++ b/tests/v1/distributed/test_internal_lb_dp.py @@ -107,8 +107,7 @@ async def _run_request_bursts( class MultinodeInternalLBServerManager: """Manages multi-node data parallel vLLM server instances for internal - load balancer testing using --headless mode. - """ + load balancer testing using --headless mode.""" def __init__( self, @@ -242,8 +241,7 @@ class MultinodeInternalLBServerManager: class APIOnlyServerManager: """Manages API-only server (Node 0) and headless engines server (Node 1) - for testing separated API server and engine configuration. - """ + for testing separated API server and engine configuration.""" def __init__( self, @@ -645,8 +643,7 @@ async def test_api_only_multinode_dp_completion_streaming( model_name: str, ) -> None: """Test API-only server streaming with all engines on separate - headless server. - """ + headless server.""" prompt = "What is an LLM?" async def make_streaming_request(): diff --git a/tests/v1/distributed/test_pp_dp_v2.py b/tests/v1/distributed/test_pp_dp_v2.py index f2a274019b..1e5d4267f4 100644 --- a/tests/v1/distributed/test_pp_dp_v2.py +++ b/tests/v1/distributed/test_pp_dp_v2.py @@ -82,8 +82,7 @@ async def _generate(engine: AsyncLLM, prompt: str, max_tokens: int) -> int: @pytest.mark.parametrize("async_scheduling", [True, False]) async def test_pp_dp_v2_low_concurrency(async_scheduling: bool): """A single in-flight request at a time, repeated, to exercise the - PP slot ring under empty batches between decodes. - """ + PP slot ring under empty batches between decodes.""" with ExitStack() as after: engine = AsyncLLM.from_engine_args(_engine_args(async_scheduling)) after.callback(engine.shutdown) @@ -97,8 +96,7 @@ async def test_pp_dp_v2_low_concurrency(async_scheduling: bool): @pytest.mark.parametrize("async_scheduling", [True, False]) async def test_pp_dp_v2_mid_concurrency(async_scheduling: bool): """64 concurrent requests, staggered, to exercise the steady-state - DP all-reduce + PP slot-ring path. - """ + DP all-reduce + PP slot-ring path.""" with ExitStack() as after: engine = AsyncLLM.from_engine_args(_engine_args(async_scheduling)) after.callback(engine.shutdown) @@ -114,8 +112,7 @@ async def test_pp_dp_v2_mid_concurrency(async_scheduling: bool): @pytest.mark.asyncio async def test_pp_dp_v2_abort_mid_decode(): """Cancel half the in-flight requests mid-stream and confirm the - engine survives the abort storm. - """ + engine survives the abort storm.""" with ExitStack() as after: engine = AsyncLLM.from_engine_args(_engine_args(async_scheduling=True)) after.callback(engine.shutdown) @@ -155,8 +152,7 @@ async def test_pp_dp_v2_abort_mid_decode(): @pytest.mark.asyncio async def test_pp_dp_v2_pause_resume(): """Pause an engine with a request in flight, then resume and confirm - new requests still work. - """ + new requests still work.""" with ExitStack() as after: engine = AsyncLLM.from_engine_args(_engine_args(async_scheduling=True)) after.callback(engine.shutdown) diff --git a/tests/v1/e2e/general/test_async_scheduling.py b/tests/v1/e2e/general/test_async_scheduling.py index 0610463484..8218f32529 100644 --- a/tests/v1/e2e/general/test_async_scheduling.py +++ b/tests/v1/e2e/general/test_async_scheduling.py @@ -48,8 +48,7 @@ def test_without_spec_decoding( monkeypatch: pytest.MonkeyPatch, ): """Test consistency of combos of async scheduling, preemption, - uni/multiproc executor, prefill chunking. - """ + uni/multiproc executor, prefill chunking.""" struct_outputs = StructuredOutputsParams(json=sample_json_schema) test_sampling_params: list[dict[str, Any]] = [ dict(), @@ -205,8 +204,7 @@ def run_tests( test_sampling_params: list[dict[str, Any]], ): """Test consistency of combos of async scheduling, preemption, - uni/multiproc executor with spec decoding. - """ + uni/multiproc executor with spec decoding.""" # Flex attention supports float32. attention_config = {"backend": "FLEX_ATTENTION"} diff --git a/tests/v1/e2e/general/test_attention_backend_per_kind.py b/tests/v1/e2e/general/test_attention_backend_per_kind.py index 42f2a72554..3281247b1c 100644 --- a/tests/v1/e2e/general/test_attention_backend_per_kind.py +++ b/tests/v1/e2e/general/test_attention_backend_per_kind.py @@ -72,8 +72,7 @@ def test_backend_per_kind_splits_groups(backend_per_kind, monkeypatch): ) def test_backend_per_kind_overrides_global_backend(monkeypatch): """A per-kind entry wins over the global ``backend`` for its kind; other - kinds fall back to the global backend. - """ + kinds fall back to the global backend.""" monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1") llm = LLM( model=MODEL, diff --git a/tests/v1/e2e/general/test_context_length.py b/tests/v1/e2e/general/test_context_length.py index 48f60747e8..91a450089f 100644 --- a/tests/v1/e2e/general/test_context_length.py +++ b/tests/v1/e2e/general/test_context_length.py @@ -34,8 +34,7 @@ def test_decoder_max_context_length_validation( max_tokens: int, ) -> None: """Check vLLM decoder model input validation for edge cases where - the prompt length is (almost) equal to the max model length. - """ + the prompt length is (almost) equal to the max model length.""" prompt_ids = [[43] * prompt_len] with vllm_runner( @@ -72,8 +71,7 @@ def test_auto_fit_max_model_len_rejects_oversized_input( """When max_model_len='auto' and KV cache memory is very limited, the engine auto-fits max_model_len to a small value. The frontend must see this reduced value and reject prompts that exceed it, - rather than accepting them and hanging. - """ + rather than accepting them and hanging.""" # Use a small KV cache budget to force auto-fit to a small # max_model_len. Pin block_size=16 so the budget is independent # of the platform's default block size. One block for this model is diff --git a/tests/v1/e2e/general/test_min_tokens.py b/tests/v1/e2e/general/test_min_tokens.py index 26a1770d39..c87339b768 100644 --- a/tests/v1/e2e/general/test_min_tokens.py +++ b/tests/v1/e2e/general/test_min_tokens.py @@ -172,8 +172,7 @@ def llm_v1(): def test_min_tokens_with_terminal_structured_output(llm_v1: LLM): """A grammar whose only legal continuation is EOS must stop under - min_tokens instead of sampling outside the grammar. - """ + min_tokens instead of sampling outside the grammar.""" params = SamplingParams( temperature=GREEDY, min_tokens=20, diff --git a/tests/v1/e2e/general/test_sharded_sampling.py b/tests/v1/e2e/general/test_sharded_sampling.py index 4db56337a8..a580605fb0 100644 --- a/tests/v1/e2e/general/test_sharded_sampling.py +++ b/tests/v1/e2e/general/test_sharded_sampling.py @@ -7,8 +7,7 @@ slightly different kernel/collective states (measured: same-state boots are bitwise identical across the two modes; cross-state boots differ by up to ~0.25 logprob and can flip a near-tie token). A real sharding bug — rows routed to the wrong request, misaligned gathers — produces many-nats -divergence and scrambled top-k sets, far outside these bounds. -""" +divergence and scrambled top-k sets, far outside these bounds.""" import pytest @@ -107,8 +106,7 @@ def _assert_logprob_dicts_close(ref_lps, out_lps, what: str) -> None: @multi_gpu_test(num_gpus=2) def test_sharded_sampling_outputs_match(monkeypatch: pytest.MonkeyPatch): """Generation, logprobs, and prompt logprobs match between batch-sharded - sampling and the replicated fallback, up to measured boot-state noise. - """ + sampling and the replicated fallback, up to measured boot-state noise.""" monkeypatch.setenv("VLLM_USE_V2_MODEL_RUNNER", "1") # Required for the collective_rpc mode check below. monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1") diff --git a/tests/v1/e2e/spec_decode/acceptance_rates/mtp_other/test_synthetic.py b/tests/v1/e2e/spec_decode/acceptance_rates/mtp_other/test_synthetic.py index 4fcaa2a59c..8714e4f56a 100644 --- a/tests/v1/e2e/spec_decode/acceptance_rates/mtp_other/test_synthetic.py +++ b/tests/v1/e2e/spec_decode/acceptance_rates/mtp_other/test_synthetic.py @@ -11,8 +11,7 @@ from ...utils import compute_acceptance_len, get_test_prompts @single_gpu_only def test_synthetic_acceptance_rate(vllm_runner): """Verify that synthetic rejection sampling produces an acceptance - length close to the requested mean acceptance length. - """ + length close to the requested mean acceptance length.""" num_spec_tokens = 3 expected_acceptance_len = 1.875 tolerance = 0.15 diff --git a/tests/v1/e2e/spec_decode/draft_model/test_draft_model.py b/tests/v1/e2e/spec_decode/draft_model/test_draft_model.py index f4cd06ca69..3a474ac203 100644 --- a/tests/v1/e2e/spec_decode/draft_model/test_draft_model.py +++ b/tests/v1/e2e/spec_decode/draft_model/test_draft_model.py @@ -167,8 +167,7 @@ def test_draft_model_tensor_parallelism(vllm_runner): @multi_gpu_only(num_gpus=2) def test_draft_model_engine_args_tensor_parallelism(): """Ensure the vllm_config for the draft model is created correctly, - and independently of the target model (quantization, TP, etc.) - """ + and independently of the target model (quantization, TP, etc.)""" engine_args = EngineArgs( model="Qwen/Qwen3-1.7B-FP8", # <<< tgt quantized tensor_parallel_size=2, @@ -199,8 +198,7 @@ def test_draft_model_engine_args_tensor_parallelism(): def _apply_draft_moe_backend(vllm_config: VllmConfig) -> VllmConfig: """Replicate SpecDecodeBaseProposer._create_draft_vllm_config logic - so we can test it without instantiating a full proposer. - """ + so we can test it without instantiating a full proposer.""" spec_cfg = vllm_config.speculative_config if spec_cfg.moe_backend is not None: return replace( @@ -225,8 +223,7 @@ def _platform_moe_backend(monkeypatch: pytest.MonkeyPatch) -> MoEBackend: def test_draft_model_moe_backend_override(monkeypatch: pytest.MonkeyPatch): """When moe_backend is set in speculative_config, the draft VllmConfig - should use it while the target keeps its own setting. - """ + should use it while the target keeps its own setting.""" target_moe_backend = _platform_moe_backend(monkeypatch) engine_args = EngineArgs( model="Qwen/Qwen3-1.7B", @@ -251,8 +248,7 @@ def test_draft_model_moe_backend_override(monkeypatch: pytest.MonkeyPatch): def test_draft_model_moe_backend_inherits_target(monkeypatch: pytest.MonkeyPatch): """When moe_backend is not set in speculative_config, the draft should - inherit the target's moe_backend. - """ + inherit the target's moe_backend.""" target_moe_backend = _platform_moe_backend(monkeypatch) engine_args = EngineArgs( model="Qwen/Qwen3-1.7B", @@ -275,8 +271,7 @@ def test_draft_model_moe_backend_inherits_target(monkeypatch: pytest.MonkeyPatch def test_draft_model_moe_backend_default_auto(): """When neither target nor draft set moe_backend explicitly, both should - default to 'auto'. - """ + default to 'auto'.""" engine_args = EngineArgs( model="Qwen/Qwen3-1.7B", tensor_parallel_size=1, @@ -297,8 +292,7 @@ def test_draft_model_moe_backend_default_auto(): def test_draft_model_engine_args_rejects_invalid_tp_argname(): """The user should pass "draft_tensor_parallel_size" rather than - "tensor_parallel_size". We enforce this with validation. - """ + "tensor_parallel_size". We enforce this with validation.""" engine_args = EngineArgs( model="Qwen/Qwen3-1.7B", tensor_parallel_size=1, @@ -315,8 +309,7 @@ def test_draft_model_engine_args_rejects_invalid_tp_argname(): def assert_draft_model_correctness(args: ArgsTest, vllm_runner): """Compare the outputs using and not using speculative decoding. - In the greedy decoding case, the outputs must match EXACTLY. - """ + In the greedy decoding case, the outputs must match EXACTLY.""" test_prompts: list[Messages] = get_messages( dataset=args.dataset, n=args.num_prompts ) diff --git a/tests/v1/e2e/spec_decode/test_sharded_sampling.py b/tests/v1/e2e/spec_decode/test_sharded_sampling.py index bcb39ad95a..cc9781ca9f 100644 --- a/tests/v1/e2e/spec_decode/test_sharded_sampling.py +++ b/tests/v1/e2e/spec_decode/test_sharded_sampling.py @@ -28,8 +28,7 @@ def test_mtp_sharded_sampling_equivalence(monkeypatch: pytest.MonkeyPatch): sampling under MTP spec decoding: the collectives move the same logits bytes, Gumbel keys derive from (request slot, position, seed), and slot assignment is rank-deterministic. Both runs here are spec decode with - identical math, so outputs must match exactly. - """ + identical math, so outputs must match exactly.""" tp_size = 2 _skip_if_insufficient_gpus_for_tp(tp_size) model_name = "Qwen/Qwen3.5-0.8B-Base" diff --git a/tests/v1/e2e/test_hybrid_chunked_prefill.py b/tests/v1/e2e/test_hybrid_chunked_prefill.py index 177c2f4bdb..66c8d5b9b7 100644 --- a/tests/v1/e2e/test_hybrid_chunked_prefill.py +++ b/tests/v1/e2e/test_hybrid_chunked_prefill.py @@ -67,8 +67,7 @@ def test_mtp_speculative_mixed_batch_short_prefill( vllm_runner, model_name, enable_prefix_caching ): """Test to ensure MTP speculative decoding correctly handles - short prefill chunks that fall below the reorder_batch_threshold. - """ + short prefill chunks that fall below the reorder_batch_threshold.""" # Set so large that both prefills will be classified as decodes in a mixed batch # note, with prefix caching we require chunk_size >= mamba_block_size chunk_size = 256 if not enable_prefix_caching else 2048 diff --git a/tests/v1/ec_connector/unit/cpu/scheduler/test_embedding_cache.py b/tests/v1/ec_connector/unit/cpu/scheduler/test_embedding_cache.py index df584d3dcb..8447532909 100644 --- a/tests/v1/ec_connector/unit/cpu/scheduler/test_embedding_cache.py +++ b/tests/v1/ec_connector/unit/cpu/scheduler/test_embedding_cache.py @@ -381,8 +381,7 @@ def test_pin_if_ready_none_when_absent(): def test_pin_if_ready_returns_unpinned_entry_when_not_ready(): """The producer needs "present but not ready" told apart from "absent": - the first is NACKed as retryable, the second as a miss. - """ + the first is NACKed as retryable, the second as a miss.""" cache = EmbeddingCache(num_blocks=4) cache.alloc("h", 1) # not-ready entry = cache.pin_if_ready("h") diff --git a/tests/v1/ec_connector/unit/cpu/scheduler/test_scheduler.py b/tests/v1/ec_connector/unit/cpu/scheduler/test_scheduler.py index 9b6338a773..24ea717cab 100644 --- a/tests/v1/ec_connector/unit/cpu/scheduler/test_scheduler.py +++ b/tests/v1/ec_connector/unit/cpu/scheduler/test_scheduler.py @@ -131,8 +131,7 @@ def test_has_cache_item_false_when_not_consumer(monkeypatch): def test_connector_keys_on_identifier_not_mm_hash(monkeypatch): """The connector must key the encoder cache on feature.identifier (what - has_cache_item is called with), NOT feature.mm_hash. - """ + has_cache_item is called with), NOT feature.mm_hash.""" s = _make_scheduler(monkeypatch) req = _Request([_Feature("PROC_KEY", length=1, identifier="ENC_KEY")]) s.update_state_after_alloc(req, 0) @@ -202,8 +201,7 @@ def test_loads_only_serves_hashes_touched_this_step(monkeypatch): def test_repeated_reload_same_step_loads_once(monkeypatch): """The same mm_hash requested twice in one step must appear in - meta.loads exactly once. - """ + meta.loads exactly once.""" s = _make_scheduler(monkeypatch) _seed_cached(s, "a", n_blocks=2) @@ -226,8 +224,7 @@ def test_load_not_emitted_for_uncached_entry(monkeypatch): def test_load_pin_protects_blocks_until_completion(monkeypatch): """Loaded blocks stay pinned until the worker reports the load memcpy complete. Observable: a save that needs eviction cannot reclaim a - still-pinned loaded entry, but can once the completion report arrives. - """ + still-pinned loaded entry, but can once the completion report arrives.""" # 2 blocks, both occupied by "a" (ready). s = _make_scheduler(monkeypatch, num_blocks=2) _seed_cached(s, "a", n_blocks=2) @@ -254,8 +251,7 @@ def test_load_pin_protects_blocks_until_completion(monkeypatch): def _can_evict(s: ECCPUScheduler, mm_hash: str, n_blocks: int) -> bool: """Whether a new save of `mm_hash` can claim `n_blocks`, i.e. whether the - blocks currently held by other entries are reclaimable. - """ + blocks currently held by other entries are reclaimable.""" s.update_state_after_alloc(_Request([_Feature(mm_hash, length=n_blocks)]), 0) meta = s.build_connector_meta(scheduler_output=None) return mm_hash in meta.saves @@ -315,8 +311,7 @@ def test_late_report_does_not_release_a_later_load_of_same_hash(monkeypatch): def test_region_full_skips_save_and_never_blocks(monkeypatch): """When the region is fully occupied by pinned entries, new saves are - silently skipped and ensure_cache_available never blocks. - """ + silently skipped and ensure_cache_available never blocks.""" s = _make_scheduler(monkeypatch, num_blocks=1) _seed_cached(s, "pinned", n_blocks=1) s._cache.pin("pinned") @@ -335,8 +330,7 @@ def test_region_full_skips_save_and_never_blocks(monkeypatch): def test_producer_only_never_emits_loads(monkeypatch): """A producer-only scheduler must never populate meta.loads, even when - entries are ready. - """ + entries are ready.""" s = _make_scheduler(monkeypatch, ec_role="ec_producer") req = _Request([_Feature("h1", length=1)]) @@ -378,8 +372,7 @@ def test_consumer_only_has_cache_item(monkeypatch): def test_save_not_emitted_for_already_cached_entry(monkeypatch): """An entry already in the cache (from a prior save) must not trigger - a second allocation or appear in meta.saves again. - """ + a second allocation or appear in meta.saves again.""" s = _make_scheduler(monkeypatch) req = _Request([_Feature("h1", length=1)]) @@ -400,8 +393,7 @@ def test_save_not_emitted_for_already_cached_entry(monkeypatch): def test_update_connector_output_ignores_foreign_meta(monkeypatch): """A worker output whose payload is not an ECCPUWorkerMetadata is a - no-op — no cache mutation, no crash. - """ + no-op — no cache mutation, no crash.""" s = _make_scheduler(monkeypatch) _seed_cached(s, "a", n_blocks=1) @@ -415,8 +407,7 @@ def test_update_connector_output_ignores_foreign_meta(monkeypatch): def test_update_connector_output_ignores_unknown_report(monkeypatch): """Reports for a never-seen save hash or a transfer id this scheduler never - dispatched are dropped rather than mutating unrelated state. - """ + dispatched are dropped rather than mutating unrelated state.""" s = _make_scheduler(monkeypatch) s.update_connector_output(_WorkerOutput(saves=["gone"], loads=[4242])) assert s.has_cache_item("gone") is False @@ -428,8 +419,7 @@ def test_update_connector_output_ignores_unknown_report(monkeypatch): def test_has_pending_push_work_tracks_inflight_save(monkeypatch): """A dispatched-but-unconfirmed save keeps push work pending until the - completion report marks it ready. - """ + completion report marks it ready.""" s = _make_scheduler(monkeypatch) assert s.has_pending_push_work() is False @@ -444,8 +434,7 @@ def test_has_pending_push_work_tracks_inflight_save(monkeypatch): def test_has_pending_push_work_tracks_inflight_load(monkeypatch): """A dispatched-but-unconfirmed load keeps push work pending until the - unpin completion report arrives. - """ + unpin completion report arrives.""" s = _make_scheduler(monkeypatch) _seed_cached(s, "a", n_blocks=1) assert s.has_pending_push_work() is False # ready + unpinned @@ -464,8 +453,7 @@ def test_has_pending_push_work_tracks_inflight_load(monkeypatch): def test_shutdown_disables_roles_and_cleans_region(monkeypatch): """After shutdown the scheduler serves no items and the region is - cleaned up. - """ + cleaned up.""" s = _make_scheduler(monkeypatch, num_blocks=2) _seed_cached(s, "a", n_blocks=2) assert s.has_cache_item("a") is True diff --git a/tests/v1/ec_connector/unit/cpu/test_ec_shared_region.py b/tests/v1/ec_connector/unit/cpu/test_ec_shared_region.py index fc5a8fc836..722c0d89fa 100644 --- a/tests/v1/ec_connector/unit/cpu/test_ec_shared_region.py +++ b/tests/v1/ec_connector/unit/cpu/test_ec_shared_region.py @@ -98,8 +98,7 @@ def test_second_instance_opens_existing_file_and_shares_memory(): def test_only_creator_unlinks_file_on_cleanup(): """Critical contract: if the non-creator unlinks, the creator's mmap path becomes a dangling backing file and a third opener would create a new one - out from under the creator. - """ + out from under the creator.""" instance_id = str(uuid.uuid4()) r1 = ECSharedRegion( engine_id=instance_id, @@ -216,8 +215,7 @@ def test_madvise_einval_selects_fallback_for_whole_region(monkeypatch): def test_non_creator_does_not_probe_or_populate(monkeypatch): """Only the creator pre-faults. A second opener must not probe the advice - nor re-touch pages the creator already populated. - """ + nor re-touch pages the creator already populated.""" from vllm.distributed.ec_transfer.ec_connector.cpu import ec_shared_region as esr instance_id = str(uuid.uuid4()) @@ -314,8 +312,7 @@ def test_madvise_unexpected_oserror_propagates(monkeypatch): def test_pin_memory_success_sets_flag(region): """When cudaHostRegister returns 0, _is_pinned flips to True - and cleanup will correspondingly call cudaHostUnregister. - """ + and cleanup will correspondingly call cudaHostUnregister.""" fake_cudart = MagicMock() success = MagicMock() success.value = 0 @@ -335,8 +332,7 @@ def test_pin_memory_success_sets_flag(region): def test_pin_memory_failure_leaves_flag_false(): """If cudaHostRegister fails (non-zero), don't pretend it succeeded — - cleanup must NOT call cudaHostUnregister on memory we never registered. - """ + cleanup must NOT call cudaHostUnregister on memory we never registered.""" r = _make_region() try: fake_cudart = MagicMock() diff --git a/tests/v1/ec_connector/unit/cpu/worker/test_worker.py b/tests/v1/ec_connector/unit/cpu/worker/test_worker.py index 317c714cca..f4f5f03f69 100644 --- a/tests/v1/ec_connector/unit/cpu/worker/test_worker.py +++ b/tests/v1/ec_connector/unit/cpu/worker/test_worker.py @@ -363,8 +363,7 @@ def test_save_caches_coalesces_only_adjacent_blocks( def test_save_caches_noop_when_mm_hash_not_in_saves(make_worker): """When the scheduler hasn't pre-allocated blocks for ``mm_hash``, - ``save_caches`` + ``flush_saves`` is a pure no-op. - """ + ``save_caches`` + ``flush_saves`` is a pure no-op.""" worker = make_worker() sentinel = 0x42 worker._region.blocks.fill_(sentinel) @@ -382,8 +381,7 @@ def test_save_caches_noop_when_mm_hash_not_in_saves(make_worker): ) def test_save_caches_noop_for_non_save_rank(make_worker, tp_rank, pcp_rank): """Only TP rank 0 + PCP rank 0 writes to mmap. All other combinations - must skip the save entirely. - """ + must skip the save entirely.""" worker = make_worker(tp_rank=tp_rank, pcp_rank=pcp_rank) sentinel = 0x42 worker._region.blocks.fill_(sentinel) @@ -398,8 +396,7 @@ def test_save_caches_noop_for_non_save_rank(make_worker, tp_rank, pcp_rank): def test_save_caches_raises_when_allocated_blocks_too_small(make_worker): """``save_caches`` must raise ``AssertionError`` when the encoder output - is larger than the allocated block space. - """ + is larger than the allocated block space.""" worker = make_worker() src = torch.zeros(3 * _HIDDEN_DIM, dtype=_DTYPE) with pytest.raises(AssertionError, match="exceeds allocated blocks"): @@ -552,8 +549,7 @@ def test_start_load_caches_noop_when_loads_is_empty(make_worker): def test_start_load_caches_skips_cached_and_loads_new_in_same_step(make_worker): """Every hash in ``meta.loads`` is copied from mmap, including one whose key is already resident in ``encoder_cache`` — there is no worker-side - skip. - """ + skip.""" worker = make_worker() n_blocks = 3 src_orig = torch.arange(n_blocks * _HIDDEN_DIM, dtype=_DTYPE).reshape( @@ -782,8 +778,7 @@ def test_buffer_pool_is_reused_across_save_steps(make_worker): @_requires_accelerator def test_buffer_pool_is_reused_across_load_steps(make_worker): """Once a load copy completes its descriptor buffers return to the pool and - are reused by the next call — no reallocation. - """ + are reused by the next call — no reallocation.""" worker = make_worker() worker._region.blocks[0].fill_(0x01) worker._region.blocks[1].fill_(0x02) @@ -854,8 +849,7 @@ def test_init_pins_memory_when_available(pin_available, expected_pinned): def test_shutdown_calls_region_cleanup_and_swallows_errors(caplog_vllm): """``shutdown`` must always call ``region.cleanup`` — and must never - raise. - """ + raise.""" worker = object.__new__(ECCPUWorker) mock_region = Mock(spec=ECSharedRegion) worker._region = mock_region diff --git a/tests/v1/ec_connector/unit/test_epd_proxy_round_robin.py b/tests/v1/ec_connector/unit/test_epd_proxy_round_robin.py index 1cceddb79c..558a80f9cf 100644 --- a/tests/v1/ec_connector/unit/test_epd_proxy_round_robin.py +++ b/tests/v1/ec_connector/unit/test_epd_proxy_round_robin.py @@ -43,8 +43,7 @@ def assign(proxy): def _drive(assign, e_urls, counts): """Feed a sequence of request item-counts through the cursor, as - fanout_encoder_primer does one request at a time. - """ + fanout_encoder_primer does one request at a time.""" cursor = 0 all_urls = [] for count in counts: diff --git a/tests/v1/ec_connector/unit/test_metadata.py b/tests/v1/ec_connector/unit/test_metadata.py index e9b78e09f2..65fdc6bbb3 100644 --- a/tests/v1/ec_connector/unit/test_metadata.py +++ b/tests/v1/ec_connector/unit/test_metadata.py @@ -40,8 +40,7 @@ def test_metadata_saves_dict_operations(): def test_metadata_loads_carry_a_transfer_id_and_blocks(): """Each load entry is a (transfer_id, block_ids) pair, so the worker can - report the transfer rather than the mm_hash. - """ + report the transfer rather than the mm_hash.""" meta = ECCPUConnectorMetadata() meta.loads["mm_hash_1"] = (0, [5, 6, 7]) diff --git a/tests/v1/ec_connector/unit/test_scheduler_nixl_producer.py b/tests/v1/ec_connector/unit/test_scheduler_nixl_producer.py index 462dcc80a9..156d98ae79 100644 --- a/tests/v1/ec_connector/unit/test_scheduler_nixl_producer.py +++ b/tests/v1/ec_connector/unit/test_scheduler_nixl_producer.py @@ -79,8 +79,7 @@ def test_request_finished_announces_not_ready_entry(monkeypatch): """A save whose GPU->mmap copy hasn't been confirmed complete yet is still announced: the entry can't be evicted before it's ready, and a read arriving too early is NACKed NACK_NOT_READY for the consumer to retry — - protecting it is not this method's job. - """ + protecting it is not this method's job.""" s = _sched_gate_off(monkeypatch) s._nixl_enabled = True s._peer_host, s._peer_port = "1.2.3.4", 5601 diff --git a/tests/v1/ec_connector/unit/test_session.py b/tests/v1/ec_connector/unit/test_session.py index fff7ba2ba7..5c25fdf228 100644 --- a/tests/v1/ec_connector/unit/test_session.py +++ b/tests/v1/ec_connector/unit/test_session.py @@ -129,8 +129,7 @@ def test_producer_session_grant_nacks_missing_entry(): def test_producer_session_grant_nacks_not_ready_entry_as_retryable(): """An announced entry whose save is still in flight is distinguished from a - miss, so the consumer retries instead of falling back to local compute. - """ + miss, so the consumer retries instead of falling back to local compute.""" cache = EmbeddingCache(num_blocks=8) cache.alloc("h1", 2) # not ready s = _make_producer_session(cache) @@ -438,8 +437,7 @@ def test_consumer_session_poll_nack_goes_to_tombstoned(): def test_consumer_session_poll_not_ready_nack_goes_to_retryable(): """A not-ready NACK must not tombstone: tombstoning admits the request with - no embedding, which is fatal once the media has been rewritten away. - """ + no embedding, which is fatal once the media has been rewritten away.""" import msgspec s = _make_consumer_session() diff --git a/tests/v1/engine/test_core_engine_actor_manager.py b/tests/v1/engine/test_core_engine_actor_manager.py index 49858f685c..69f52e2a7f 100644 --- a/tests/v1/engine/test_core_engine_actor_manager.py +++ b/tests/v1/engine/test_core_engine_actor_manager.py @@ -68,8 +68,7 @@ class _StubEngineCoreActor(EngineCoreActorMixin): # in ``tests/entrypoints/test_api_server_process_manager.py``. def _bind_and_report_worker(listen_address, sock, args, client_config): """Bind ROUTER/PULL with a kernel-assigned port, report the actual - endpoints back via ``actual_address_pipe``, then exit. - """ + endpoints back via ``actual_address_pipe``, then exit.""" ctx = zmq.Context() try: in_sock = make_zmq_socket( diff --git a/tests/v1/engine/test_engine_core.py b/tests/v1/engine/test_engine_core.py index 5843ce5f55..ba1e9a4d20 100644 --- a/tests/v1/engine/test_engine_core.py +++ b/tests/v1/engine/test_engine_core.py @@ -607,8 +607,7 @@ def _cadenced_dp_engine_core( monkeypatch, results: list[tuple[bool, bool]], dp_sync_interval: int = 32 ): """A bare DPEngineCoreProc whose all-reduce is scripted by `results`; - returns the core and the step numbers at which the all-reduce ran. - """ + returns the core and the step numbers at which the all-reduce ran.""" core = object.__new__(DPEngineCoreProc) core.dp_group = object() core.dp_sync_interval = dp_sync_interval @@ -627,8 +626,7 @@ def _cadenced_dp_engine_core( def test_dp_sync_interval_default_is_16(): """Regression pin: lowering the default narrows the mid-wave pause tail - for async RL, where the engine is rarely idle when pause lands. - """ + for async RL, where the engine is rarely idle when pause lands.""" assert ParallelConfig.dp_sync_interval == 16 @@ -646,8 +644,7 @@ def test_dp_sync_interval_normal_wave(monkeypatch, dp_sync_interval: int): def test_dp_sync_interval_idle_pause_consensus_on_first_step(monkeypatch): """A pause of an idle engine arms every rank before its kick-started first step, so the step-1 sync reaches consensus after one dummy batch - regardless of the configured cadence. - """ + regardless of the configured cadence.""" core, synced = _cadenced_dp_engine_core( monkeypatch, [(False, True)], dp_sync_interval=32 ) @@ -673,8 +670,7 @@ def _pausable_engine_core_proc() -> EngineCoreProc: @pytest.mark.parametrize("deferred", [False, True]) def test_pause_synchronizes_device_before_cache_reset(deferred: bool): """A resolved pause promises an idle device: the barrier must run before - caches are cleared and before the caller is unblocked. - """ + caches are cleared and before the caller is unblocked.""" core = _pausable_engine_core_proc() core.engines_running = deferred order: list[str] = [] diff --git a/tests/v1/engine/test_engine_core_client.py b/tests/v1/engine/test_engine_core_client.py index e6520bfadc..a23ae46b8f 100644 --- a/tests/v1/engine/test_engine_core_client.py +++ b/tests/v1/engine/test_engine_core_client.py @@ -249,8 +249,7 @@ def test_dplb_non_late_interaction_still_uses_lb(): def test_dplb_burst_round_robins_despite_snapshot_rebinds(): """A stats snapshot rebind wipes the optimistic lb_engines increments; - the exact in-flight floor must keep a burst spreading round-robin. - """ + the exact in-flight floor must keep a burst spreading round-robin.""" client = _make_dplb_client(num_engines=4) for _ in range(4): @@ -325,8 +324,7 @@ async def test_dplb_scale_down_routes_after_stale_stats_snapshot(): def test_dplb_snapshot_backpressure_overrides_inflight(): """An engine reported heavily loaded by the coordinator is avoided even - when this client has routed nothing to it. - """ + when this client has routed nothing to it.""" client = _make_dplb_client(num_engines=2) client.lb_engines = [[5, 10, 0.0], [0, 0, 0.0]] @@ -339,8 +337,7 @@ def test_dplb_snapshot_backpressure_overrides_inflight(): def test_dplb_kv_pressure_amplifies_waiting_penalty(): """A waiting queue on a KV-bound engine (slow drain) is penalized, while - the same queue with low KV usage is not (e.g. transient burst). - """ + the same queue with low KV usage is not (e.g. transient burst).""" client = _make_dplb_client(num_engines=2) # Engine 0 has a smaller total but is KV-bound with a queue. client.lb_engines = [[5, 10, 1.0], [0, 20, 0.2]] diff --git a/tests/v1/engine/test_logprobs_processor.py b/tests/v1/engine/test_logprobs_processor.py index 3a315c04d5..edb8cef518 100644 --- a/tests/v1/engine/test_logprobs_processor.py +++ b/tests/v1/engine/test_logprobs_processor.py @@ -30,8 +30,7 @@ def _make_processor(num_logprobs: int) -> LogprobsProcessor: def test_drops_trailing_sentinel_columns(): """A request that asked for 3 custom token logprobs but ended up in a - batch padded to width 5 must not surface the trailing -inf entries. - """ + batch padded to width 5 must not surface the trailing -inf entries.""" processor = _make_processor(num_logprobs=3) sampled = 42 diff --git a/tests/v1/engine/test_output_processor.py b/tests/v1/engine/test_output_processor.py index cdd61445bf..9df43088e6 100644 --- a/tests/v1/engine/test_output_processor.py +++ b/tests/v1/engine/test_output_processor.py @@ -229,8 +229,7 @@ def test_request_stream_interval_raises_but_not_below_engine_default( ): """A per-request stream_interval can raise the interval above the engine default but not below it (values under the default clamp up), without - altering the generated text. - """ + altering the generated text.""" engine_stream_interval = 5 # Request 0 (below the default) clamps up to 5; request 1 raises it to 10. request_stream_intervals = [1, 10] diff --git a/tests/v1/kv_connector/unit/offloading_connector/test_canonical_mapping.py b/tests/v1/kv_connector/unit/offloading_connector/test_canonical_mapping.py index 3c2f63c66a..9c3ba6d555 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/test_canonical_mapping.py +++ b/tests/v1/kv_connector/unit/offloading_connector/test_canonical_mapping.py @@ -80,8 +80,7 @@ def _split_hnd_cache(spec) -> torch.Tensor: def _packed_nhd_cache(spec) -> torch.Tensor: """Logical (num_blocks, heads, block_size, 2 * head_size) over an NHD - physical layout — the FlashAttention/FlashInfer/Triton/Flex form. - """ + physical layout — the FlashAttention/FlashInfer/Triton/Flex form.""" return torch.zeros( NUM_BLOCKS, spec.block_size, diff --git a/tests/v1/kv_connector/unit/offloading_connector/test_config.py b/tests/v1/kv_connector/unit/offloading_connector/test_config.py index 2d87431e31..f597c8fa27 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/test_config.py +++ b/tests/v1/kv_connector/unit/offloading_connector/test_config.py @@ -863,8 +863,7 @@ def test_parallelism_agnostic_excluded(kv_cache_groups: list[KVCacheGroupSpec]): ) def test_canonical_layout_gate(kv_cache_groups, certified): """The canonical layout certifies portability group by group; none of - these shapes are portable in the direct layout. - """ + these shapes are portable in the direct layout.""" assert not _parallelism_agnostic(kv_cache_groups) assert _parallelism_agnostic(kv_cache_groups, canonical=True) is certified @@ -872,8 +871,7 @@ def test_canonical_layout_gate(kv_cache_groups, certified): def test_canonical_layout_certifies_v2_model_runner(): """Canonical bytes are certified per layer against live tensor strides at registration, so the static gate must not depend on the model-runner - version — the v2 runner is the case the canonical layout exists for. - """ + version — the v2 runner is the case the canonical layout exists for.""" groups = _groups(_full_attention_spec()) assert _parallelism_agnostic(groups, canonical=True, v2=True) diff --git a/tests/v1/kv_connector/unit/offloading_connector/test_metrics.py b/tests/v1/kv_connector/unit/offloading_connector/test_metrics.py index 961ce1af12..b7d9d6c8ef 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/test_metrics.py +++ b/tests/v1/kv_connector/unit/offloading_connector/test_metrics.py @@ -117,8 +117,7 @@ def _spec_cls_with_metric_definitions( metric_definitions: dict[str, Any], ) -> type: """Build a fake offloading spec class reporting the given metric - definitions, so tests don't need to patch the real CPU spec. - """ + definitions, so tests don't need to patch the real CPU spec.""" class _FakeOffloadingSpec: @staticmethod @@ -188,8 +187,7 @@ def test_build_kv_connector_stats_with_empty_dict(): def test_build_kv_connector_stats_reconstructs_offload_stats(): """Test that OffloadingConnector stats are properly reconstructed with - correct data. - """ + correct data.""" serialized_data = { _StatsKey.TYPES: { LOAD_BYTES: _MetricType.COUNTER, diff --git a/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py b/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py index df69b9bb66..035fb6b005 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py +++ b/tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py @@ -1583,8 +1583,7 @@ _SCAN_BEHAVIOR = { @pytest.mark.parametrize("result", list(LookupResult)) def test_scan_behavior_declared_for_every_lookup_result(result: LookupResult): """Whether a result keeps a sliding-window streak alive decides how wide - the demanded chunk set gets, so every member needs deliberate behavior. - """ + the demanded chunk set gets, so every member needs deliberate behavior.""" assert result in _SCAN_BEHAVIOR, f"{result} has no declared scan behavior" expected_lookups, expected_end = _SCAN_BEHAVIOR[result] @@ -2035,8 +2034,7 @@ def test_request_level_policy_stores_all_blocks(request_runner, async_scheduling def test_loads_do_not_populate_fence_index(request_runner): """Loads don't populate _block_id_to_pending_jobs (protected by - delay_free_blocks while in flight). - """ + delay_free_blocks while in flight).""" runner = request_runner( blocks_per_chunk=3, block_size=4, @@ -2106,8 +2104,7 @@ def test_fence_at_update_state_after_alloc(request_runner): def test_fence_at_build_store_jobs(request_runner): """A new prefill (no load -> update_state_after_alloc returns early) reusing a finished request's pending-store block is flushed by - _build_store_jobs's fence. - """ + _build_store_jobs's fence.""" runner = request_runner( blocks_per_chunk=1, block_size=4, @@ -2157,8 +2154,7 @@ def test_fence_at_build_store_jobs(request_runner): @pytest.mark.parametrize("async_scheduling", [True, False]) def test_complete_store_called_per_job(request_runner, async_scheduling: bool): """complete_store fires per-job, not deferred to request finish. - Each call carries only that store's keys. - """ + Each call carries only that store's keys.""" tokens_per_block = 4 blocks_per_chunk = 3 tokens_per_chunk = tokens_per_block * blocks_per_chunk @@ -2387,8 +2383,7 @@ def test_offload_prompt_only(request_runner, async_scheduling: bool): @pytest.mark.parametrize("async_scheduling", [True, False]) def test_reset_cache(request_runner, async_scheduling: bool): """reset_cache flushes in-flight loads, calls manager.reset_cache(), resets - next_stored_chunk_idx for active requests and clears job tracking. - """ + next_stored_chunk_idx for active requests and clears job tracking.""" block_size = 4 blocks_per_chunk = 3 tokens_per_chunk = block_size * blocks_per_chunk @@ -2934,8 +2929,7 @@ def test_stale_sliding_window_block_after_prepare_store_failure( @pytest.mark.parametrize("async_scheduling", [True, False]) def test_skip_reading_prefix_cache(request_runner, async_scheduling: bool): """When skip_reading_prefix_cache=True, the offloading connector must not - load any blocks from CPU even if a matching prefix is cached there. - """ + load any blocks from CPU even if a matching prefix is cached there.""" block_size = 4 blocks_per_chunk = 3 tokens_per_chunk = block_size * blocks_per_chunk @@ -3029,8 +3023,7 @@ def test_max_load_tokens_limits_external_load(request_runner, async_scheduling: class TestEagle: """Tests for Eagle/MTP speculative decoding support in the offloading - connector scheduler — both _lookup() unit tests and integration tests. - """ + connector scheduler — both _lookup() unit tests and integration tests.""" # ------------------------------------------------------------------- # Helpers @@ -3572,8 +3565,7 @@ class TestEagle: self, request_runner, async_scheduling: bool ): """Eagle sliding-window group stores all prompt blocks but excludes - the trailing chunk while decoding. - """ + the trailing chunk while decoding.""" block_size = 4 sliding_window = 8 num_gpu_blocks = 100 @@ -3625,8 +3617,7 @@ class TestEagle: self, request_runner, async_scheduling: bool ): """An eagle group with a single-block prompt stores it at the end of - prefill: prompt blocks are stable, so no tail is held back. - """ + prefill: prompt blocks are stable, so no tail is held back.""" block_size = 4 blocks_per_chunk = 1 tokens_per_chunk = block_size * blocks_per_chunk @@ -4263,8 +4254,7 @@ def test_request_finished_mixed_full_attn_and_sliding_window( def test_chunked_local_attention_reports_its_chunk_window(): """Llama 4 uses chunked local attention, which used to trip the - FullAttentionSpec assert and kill the engine at startup. - """ + FullAttentionSpec assert and kill the engine at startup.""" spec = ChunkedLocalAttentionSpec( block_size=16, num_kv_heads=2, @@ -4503,8 +4493,7 @@ def test_retention_interval_zero_stores_only_replay_boundary( def _shared_kv_mtp_config(): """Speculative config for a shared-group MTP model: eagle-family method whose drafter layer merges into a target KV-cache group, so no group - self-identifies as a drafter group (issue #52735). - """ + self-identifies as a drafter group (issue #52735).""" spec = MagicMock(name="shared_kv_mtp_spec") spec.use_eagle.return_value = True spec.use_eagle_block_drop.return_value = True @@ -4518,14 +4507,12 @@ def _shared_kv_mtp_config(): class TestSharedGroupMTPOffload: """Regression tests for issue #52735: OffloadingConnector must keep serving when speculative decoding is enabled but no KV-cache group is - annotated as a drafter group (shared-group MTP models). - """ + annotated as a drafter group (shared-group MTP models).""" def test_no_annotation_marks_no_groups(self, request_runner): """Spec decode on + zero annotated groups must NOT mark every group as a drafter group; the full store->load roundtrip must match the - non-speculative behavior of test_two_groups_full_and_sliding_window. - """ + non-speculative behavior of test_two_groups_full_and_sliding_window.""" block_size = 4 kv_cache_groups = [ KVCacheGroupSpec( @@ -4582,8 +4569,7 @@ class TestSharedGroupMTPOffload: class TestMambaHybridOffloadServing: """Store->finish->lookup flows on a full-attention + mamba-align hybrid, with a manager that only HITs keys that were actually stored. Guards the - two collapse routes of issue #52735. - """ + two collapse routes of issue #52735.""" BLOCK = 4 MAMBA_BLOCK = 16 @@ -4712,8 +4698,7 @@ class TestMambaHybridOffloadServing: """Route 1 of #52735: with spec decode on and no drafter annotation, serving must equal the non-speculative baseline (was 0 before the fix: the all-groups fallback marked the mamba group as a drafter and - the volatile-tail pop consumed its only servable chunk). - """ + the volatile-tail pop consumed its only servable chunk).""" baseline = self._roundtrip_served_tokens(self._make_scheduler(None)) assert baseline == 16 served = self._roundtrip_served_tokens( @@ -4726,8 +4711,7 @@ class TestMambaHybridOffloadServing: group must not drag the confirmed boundary below a coarser sibling's chunk granularity. The widened query makes the volatile-tail pop land on an extra queried chunk, holding the boundary at 16 tokens - (was 0 before the fix: 4 hits -> pop -> 12 tokens < mamba chunk). - """ + (was 0 before the fix: 4 hits -> pop -> 12 tokens < mamba chunk).""" scheduler = self._make_scheduler(None, mamba_eagle=True) assert [c.is_eagle_group for c in scheduler.config.kv_group_configs] == [ True, diff --git a/tests/v1/kv_connector/unit/offloading_connector/test_worker.py b/tests/v1/kv_connector/unit/offloading_connector/test_worker.py index 9fdac58527..7a987fef3d 100644 --- a/tests/v1/kv_connector/unit/offloading_connector/test_worker.py +++ b/tests/v1/kv_connector/unit/offloading_connector/test_worker.py @@ -80,8 +80,7 @@ def _allocate_kv_caches( def _single_rank_vllm_config(total_kv_heads: int): """A one-rank (TP=1) parallel config, as canonical mappings are derived - from it. - """ + from it.""" vllm_config = MagicMock() parallel_config = vllm_config.parallel_config parallel_config.tensor_parallel_size = 1 diff --git a/tests/v1/kv_connector/unit/test_bidirectional_kv_transfer.py b/tests/v1/kv_connector/unit/test_bidirectional_kv_transfer.py index 006229b869..78a6d930f9 100644 --- a/tests/v1/kv_connector/unit/test_bidirectional_kv_transfer.py +++ b/tests/v1/kv_connector/unit/test_bidirectional_kv_transfer.py @@ -148,8 +148,7 @@ def test_multiturn_lifecycle(): (do_remote_decode=True). Finishes LENGTH_CAPPED with remote_block_ids. Turn 2: P receives remote_block_ids from D. P pulls KV from D because remote_block_ids is not None and external tokens > 0. Computes only - new tokens, finishes LENGTH_CAPPED. - """ + new tokens, finishes LENGTH_CAPPED.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -195,8 +194,7 @@ def test_multiturn_lifecycle(): def test_first_turn_no_remote_blocks(): """First turn: P has no remote_block_ids from D yet. - Standard local prefill, returns kv_transfer_params for future turns. - """ + Standard local prefill, returns kv_transfer_params for future turns.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -276,8 +274,7 @@ def test_abort_p_side_non_length_capped(): def test_remote_blocks_exceed_prompt_tokens(): """D provides more remote tokens than P's prompt needs. - P caps external tokens to prompt length. - """ + P caps external tokens to prompt length.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -313,8 +310,7 @@ def test_remote_blocks_exceed_prompt_tokens(): def test_p_node_pulls_partial_last_block_from_d(): """D sends remote_block_ids with partially filled last block. remote_num_tokens < len(remote_block_ids) * block_size. - P pulls only remote_num_tokens worth of external tokens. - """ + P pulls only remote_num_tokens worth of external tokens.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -359,8 +355,7 @@ def test_p_node_pulls_partial_last_block_from_d(): def test_add_new_req_to_recv_populates_remote_meta(): """add_new_req_to_recv correctly populates RemoteMeta for P-node - bi-directional KV pull from D. - """ + bi-directional KV pull from D.""" meta = NixlConnectorMetadata() kv_params = { "remote_block_ids": [[0, 1, 2]], @@ -388,8 +383,7 @@ def test_add_new_req_to_recv_populates_remote_meta(): def test_build_connector_meta_recv_entries(): """P-node scheduler: do_remote_decode=True + remote_block_ids → - _reqs_need_recv populated, build_connector_meta produces reqs_to_recv. - """ + _reqs_need_recv populated, build_connector_meta produces reqs_to_recv.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -463,8 +457,7 @@ def test_p_node_pull_kv_from_d(dist_init): ) def test_p_node_pull_then_send_kv(dist_init): """Full P-node bi-directional: pull KV from D → prefill → - send KV back to D via notification. - """ + send KV back to D via notification.""" connector, worker = _make_connector_with_fake_worker() meta = _make_p_node_recv_metadata("req-p2", [10, 11], [20, 21]) _do_load_kv(connector, meta) @@ -511,8 +504,7 @@ def test_p_node_deferred_pull_on_no_handshake(dist_init): def test_d_node_request_finished_returns_kv_params(): """D-node request_finished returns kv_transfer_params with do_remote_decode=True, remote_block_ids, remote_num_tokens - for P to pull. These params go directly to P node. - """ + for P to pull. These params go directly to P node.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -593,8 +585,7 @@ def test_d_node_request_finished_remote_num_tokens(): def test_d_node_partial_last_block_remote_num_tokens(): """D-node: remote_num_tokens < len(remote_block_ids) * block_size - when last block is partially filled. - """ + when last block is partially filled.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -628,8 +619,7 @@ def test_no_double_read_blocks_after_reschedule(): bidirectional request (once on initial schedule, once after WAITING_FOR_REMOTE_KVS → reschedule). The _remote_blocks_processed flag must prevent the request from being added to _reqs_need_recv - twice, which would cause P to read D's blocks twice. - """ + twice, which would cause P to read D's blocks twice.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -682,8 +672,7 @@ def test_remote_num_tokens_bounded_by_blocks(): """Edge case 2: D-node request_finished must return remote_num_tokens <= len(remote_block_ids) * block_size. request.num_tokens includes the last sampled token which has no KV - in the cache, so remote_num_tokens must use num_computed_tokens. - """ + in the cache, so remote_num_tokens must use num_computed_tokens.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -719,8 +708,7 @@ def test_remote_num_tokens_bounded_by_blocks(): def test_kv_recompute_threshold_skips_small_transfer(): """Edge case 3: When remote tokens are below kv_recompute_threshold, P should skip the remote pull and compute locally instead of - entering WAITING_FOR_REMOTE_KVS. - """ + entering WAITING_FOR_REMOTE_KVS.""" threshold = 256 vllm_config = create_vllm_config( kv_connector_extra_config={ @@ -762,8 +750,7 @@ def test_p_node_finished_holds_blocks_for_d(): """Edge case 4: P-node finishes with FINISHED_LENGTH_CAPPED and do_remote_decode=True. P must hold blocks (delay_free=True) and return kv_transfer_params with do_remote_prefill=True so D can - read P's blocks. - """ + read P's blocks.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -804,8 +791,7 @@ def test_p_node_finished_holds_blocks_for_d(): def test_cache_miss_first_turn_no_remote_pull(): """Edge case 5: First turn with do_remote_decode=True but no remote_block_ids (cache MISS). P should prefill locally with - num_external_tokens=0 and not enter WAITING_FOR_REMOTE_KVS. - """ + num_external_tokens=0 and not enter WAITING_FOR_REMOTE_KVS.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -840,8 +826,7 @@ def test_cache_miss_first_turn_no_remote_pull(): def test_partial_remote_tokens_less_than_prompt(): """Edge case 6: D's remote_num_tokens covers only part of P's prompt. P should pull remote_num_tokens worth of external tokens - and compute the rest locally. - """ + and compute the rest locally.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -886,8 +871,7 @@ def test_partial_remote_tokens_less_than_prompt(): def test_remote_blocks_processed_flag_persists(): """Edge case 7: After recv completes and request is rescheduled, the _remote_blocks_processed flag in kv_transfer_params prevents - the bidirectional path from re-entering _reqs_need_recv. - """ + the bidirectional path from re-entering _reqs_need_recv.""" vllm_config = create_vllm_config( kv_connector_extra_config=BIDIR_KV_EXTRA_CONFIG, ) @@ -959,8 +943,7 @@ _REMOTE = FakeNixlConnectorWorker.REMOTE_ENGINE_ID ) def test_turn2_deadline_gate(dist_init, offset, expiry_delta, expect_declined): """P declines on the turn-2 readback if the deadline is known, - near-expiry and a handshake clock offset is known - """ + near-expiry and a handshake clock offset is known""" connector, worker = _make_connector_with_fake_worker() worker._engine_clock_offset[_REMOTE] = offset expiry_time = None if expiry_delta is None else time.perf_counter() + expiry_delta @@ -996,8 +979,7 @@ def test_turn2_deadline_gate(dist_init, offset, expiry_delta, expect_declined): ) def test_turn2_full_prefix_hit_with_expired_deadline_skips_gate(dist_init): """A full local prefix hit issues no READ. The expiry gate must be skipped - even when D's deadline is expired. - """ + even when D's deadline is expired.""" connector, worker = _make_connector_with_fake_worker() worker._engine_clock_offset[_REMOTE] = 0.0 @@ -1050,8 +1032,7 @@ def test_d_node_request_finished_exports_blocks_expiry_time(): def test_handshake_listener_appends_perf_counter_frame(): """The handshake reply carries a 2nd frame with the listener's live - perf_counter. - """ + perf_counter.""" import threading import msgspec diff --git a/tests/v1/kv_connector/unit/test_config.py b/tests/v1/kv_connector/unit/test_config.py index d3dabe4fb4..019b8d1504 100644 --- a/tests/v1/kv_connector/unit/test_config.py +++ b/tests/v1/kv_connector/unit/test_config.py @@ -19,15 +19,13 @@ class _StubLMCacheMPConnector: test only asserts on the connector *name* and the ``extra_config`` dict produced by ``VllmConfig``, never instantiates the connector, so a bare placeholder class is sufficient. Not subclassing ``SupportsHMA`` mirrors - the real connector's HMA support (it does not support HMA either). - """ + the real connector's HMA support (it does not support HMA either).""" @pytest.fixture def stub_lmcache_mp_connector(monkeypatch): """Replace the lazy loader so VllmConfig.__post_init__ does not import - ``lmcache_mp_connector`` (and thus ``lmcache``) during config tests. - """ + ``lmcache_mp_connector`` (and thus ``lmcache``) during config tests.""" monkeypatch.setitem( KVConnectorFactory._registry, "LMCacheMPConnector", @@ -107,8 +105,7 @@ def _build_config( enable_cumem_allocator: bool = False, ) -> VllmConfig: """Build a VllmConfig that exercises _verify_kv_transfer_compat without - requiring a real model (avoids HF downloads in CI). - """ + requiring a real model (avoids HF downloads in CI).""" from types import SimpleNamespace kv_transfer_config = ( @@ -134,8 +131,7 @@ def test_kv_connector_rejects_expandable_segments(monkeypatch, kv_connector): invalidated when expandable_segments lets the CUDA VMM allocator remap the underlying physical pages. We can't enumerate every connector that does this (especially OOT ones), so reject the combination whenever any - connector is configured. - """ + connector is configured.""" monkeypatch.setenv("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True") with pytest.raises(ValueError, match="expandable_segments"): _build_config(kv_connector=kv_connector) @@ -143,8 +139,7 @@ def test_kv_connector_rejects_expandable_segments(monkeypatch, kv_connector): def test_kv_connector_allows_expandable_segments_with_sleep_mode(monkeypatch): """Sleep mode routes KV allocations through CuMemAllocator's pool, which - auto-disables expandable_segments (see #40812). - """ + auto-disables expandable_segments (see #40812).""" monkeypatch.setenv("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True") _build_config(kv_connector="NixlConnector", enable_sleep_mode=True) @@ -167,8 +162,7 @@ def test_kv_connector_allows_other_alloc_conf(monkeypatch): def test_no_kv_connector_ignores_expandable_segments(monkeypatch): """The expandable_segments check only applies when a KV connector is - configured. - """ + configured.""" monkeypatch.setenv("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True") _build_config(kv_connector=None) diff --git a/tests/v1/kv_connector/unit/test_flexkv_connector.py b/tests/v1/kv_connector/unit/test_flexkv_connector.py index a40e5f828c..8cb5736634 100644 --- a/tests/v1/kv_connector/unit/test_flexkv_connector.py +++ b/tests/v1/kv_connector/unit/test_flexkv_connector.py @@ -50,8 +50,7 @@ def _make_flexkv_module( impl_mock: MagicMock, ) -> tuple[types.ModuleType, types.ModuleType]: """Build a fake ``flexkv`` package hierarchy that returns *impl_mock* - when ``FlexKVConnectorV1Impl`` is instantiated. - """ + when ``FlexKVConnectorV1Impl`` is instantiated.""" flexkv_mod = types.ModuleType("flexkv") integration_mod = types.ModuleType("flexkv.integration") vllm_mod = types.ModuleType("flexkv.integration.vllm") @@ -72,8 +71,7 @@ def _make_flexkv_module( def _install_flexkv_mock(impl_mock: MagicMock): """Insert fake flexkv modules into sys.modules and return a context that - cleans them up afterwards. - """ + cleans them up afterwards.""" flexkv_mod, adapter_mod = _make_flexkv_module(impl_mock) mods = { "flexkv": flexkv_mod, @@ -106,8 +104,7 @@ def _build_connector(vllm_config: VllmConfig, impl_mock: MagicMock): class TestFlexKVConnectorImportError: """FlexKVConnectorV1 should fail with a helpful message when flexkv is - absent. - """ + absent.""" def test_import_error_message(self): from vllm.distributed.kv_transfer.kv_connector.v1.flexkv_connector import ( diff --git a/tests/v1/kv_connector/unit/test_handshake_pp_aggregation.py b/tests/v1/kv_connector/unit/test_handshake_pp_aggregation.py index b2cf0f0b64..e5cbd977b6 100644 --- a/tests/v1/kv_connector/unit/test_handshake_pp_aggregation.py +++ b/tests/v1/kv_connector/unit/test_handshake_pp_aggregation.py @@ -176,8 +176,7 @@ def test_engine_unwraps_handshake_metadata_for_legacy_connector( ) -> None: """Engine core always asks workers for `(pp_rank, tp_rank)`-keyed metadata, then unwraps to `{tp_rank: metadata}` for a connector that has not opted - into PP-aware handshake (single-PP producer, all `pp_rank == 0`). - """ + into PP-aware handshake (single-PP producer, all `pp_rank == 0`).""" metadata_0 = _Metadata() metadata_1 = _Metadata() connector = _LegacyConnector() @@ -200,8 +199,7 @@ def test_engine_rejects_pp_producer_for_legacy_connector( monkeypatch: pytest.MonkeyPatch, ) -> None: """A connector that has not opted into PP-aware handshake must not silently - drop metadata from `pp_rank > 0`; engine core init raises instead. - """ + drop metadata from `pp_rank > 0`; engine core init raises instead.""" connector = _LegacyConnector() with pytest.raises(ValueError, match="does not support PP-disaggregated"): @@ -216,8 +214,7 @@ def test_engine_passes_handshake_metadata_through_for_pp_aware_connector( monkeypatch: pytest.MonkeyPatch, ) -> None: """A PP-aware connector receives the full `(pp_rank, tp_rank)`-keyed dict - unchanged. - """ + unchanged.""" metadata_0 = _Metadata() metadata_1 = _Metadata() connector = _PPAwareConnector() diff --git a/tests/v1/kv_connector/unit/test_hf3fs_client.py b/tests/v1/kv_connector/unit/test_hf3fs_client.py index d0ae6c24ac..26a5de11c5 100644 --- a/tests/v1/kv_connector/unit/test_hf3fs_client.py +++ b/tests/v1/kv_connector/unit/test_hf3fs_client.py @@ -131,8 +131,7 @@ class TestHf3fsClientResourceManagement: def test_close_idempotent_and_handles_cleared(self, tmp_path): """Multiple close() calls must not raise; deregister_fd called exactly - once, all handles set to None, shm.close() invoked. - """ + once, all handles set to None, shm.close() invoked.""" client, shm_r, shm_w = self._make_client(tmp_path) with ( @@ -238,8 +237,7 @@ class TestHf3fsClientResourceManagement: def test_constructor_failure_does_not_close_unallocated_shm(self, tmp_path): """Failure before SharedMemory is created must not raise AttributeError - or TypeError from cleanup. - """ + or TypeError from cleanup.""" with ( patch(f"{self._MOD}.HF3FS_AVAILABLE", True), patch(f"{self._MOD}.register_fd"), diff --git a/tests/v1/kv_connector/unit/test_lmcache_connector.py b/tests/v1/kv_connector/unit/test_lmcache_connector.py index ad8ac0566e..a64f7f32d5 100644 --- a/tests/v1/kv_connector/unit/test_lmcache_connector.py +++ b/tests/v1/kv_connector/unit/test_lmcache_connector.py @@ -212,8 +212,7 @@ class TestUpdateConnectorOutput: self, mock_connector ): """Test that method returns early when kv_cache_events is not - LMCacheKVEvents. - """ + LMCacheKVEvents.""" # Create a mock object that is not LMCacheKVEvents fake_events = MagicMock() connector_output = KVConnectorOutput(kv_cache_events=fake_events) diff --git a/tests/v1/kv_connector/unit/test_mooncake_stats.py b/tests/v1/kv_connector/unit/test_mooncake_stats.py index 6e2bb59fa4..a20fcb5053 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_stats.py +++ b/tests/v1/kv_connector/unit/test_mooncake_stats.py @@ -199,8 +199,7 @@ def _bare_worker() -> MooncakeConnectorWorker: """Construct a MooncakeConnectorWorker skipping __init__ (full init requires a live TransferEngine). Only the attributes touched by the methods under test are populated; role flags and async_zmq_ctx keep __del__'s shutdown - path a no-op. - """ + path a no-op.""" worker = MooncakeConnectorWorker.__new__(MooncakeConnectorWorker) worker.xfer_stats = MooncakeKVConnectorStats() worker.engine = MagicMock() diff --git a/tests/v1/kv_connector/unit/test_mooncake_store_connector.py b/tests/v1/kv_connector/unit/test_mooncake_store_connector.py index 7e8e532fff..f3ffa55a54 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_store_connector.py +++ b/tests/v1/kv_connector/unit/test_mooncake_store_connector.py @@ -77,8 +77,7 @@ def test_store_tp_does_not_override_backend_kv_cache_layout(extra_config): def _make_kv_cache_config() -> KVCacheConfig: """Single-group full-attention KVCacheConfig — enough for the connector - constructor's validate() pass. - """ + constructor's validate() pass.""" spec = FullAttentionSpec(block_size=16, num_kv_heads=8, head_size=64, dtype=None) return KVCacheConfig( num_blocks=4, @@ -693,8 +692,7 @@ def _poll_lookup(client, req_id, num_tokens=128, block_hashes=(), timeout=5.0): def _gated_recv(gate: threading.Event, value: int): """Mock recv side-effect that blocks until ``gate`` is set, so the - executor's lookup can be held pending deterministically. - """ + executor's lookup can be held pending deterministically.""" def recv(): gate.wait() @@ -705,8 +703,7 @@ def _gated_recv(gate: threading.Event, value: int): def test_lookup_key_client_non_block_lookup_async(): """Non-blocking lookup defers to the executor: None first, hit once the - Future resolves. - """ + Future resolves.""" vllm_config = _make_vllm_config() with patch( diff --git a/tests/v1/kv_connector/unit/test_mooncake_store_coordinator.py b/tests/v1/kv_connector/unit/test_mooncake_store_coordinator.py index 583c249588..8767b1c0d9 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_store_coordinator.py +++ b/tests/v1/kv_connector/unit/test_mooncake_store_coordinator.py @@ -33,8 +33,7 @@ def _mamba_align(block_size=32): def _make_coord(groups, hash_block_size, use_eagle=False, retention_interval=None): """Construct a coordinator using the natural LCM of group block sizes as the scheduler block size — mirrors ``resolve_kv_cache_block_sizes`` for - the test fixtures. - """ + the test fixtures.""" block_sizes = [g.kv_cache_spec.block_size for g in groups] scheduler_block_size = lcm(*block_sizes) return MooncakeStoreCoordinator( @@ -144,8 +143,7 @@ def test_coordinator_single_full_attention_no_hits(): def test_coordinator_single_swa_tautological_pool_masks_pre_window(): """SWA tautological-pool: hit_length spans full prefix, mask is - tail-window only. - """ + tail-window only.""" groups = [KVCacheGroupSpec(["L0"], _swa(block_size=16, sliding_window=32))] coord = _make_coord(groups, hash_block_size=16) hs = _hashes(4) # 4 chunks * 16 tokens @@ -192,8 +190,7 @@ def test_coordinator_hybrid_hole_in_full_clips_both(): def test_coordinator_group_block_size_double_hash(): """Group block_size=32 over hash_block_size=16 hashes: adjacent - hashes merge before pool lookup. - """ + hashes merge before pool lookup.""" groups = [ KVCacheGroupSpec(["L0"], _full(16)), KVCacheGroupSpec(["L1"], _full(32)), @@ -217,8 +214,7 @@ def test_coordinator_group_block_size_double_hash(): def test_coordinator_fine_grained_partial_tail_hit(): """K3 shape: FA + mamba-align, block_size=32 over hash_block_size=16. When both groups have the sub-block boundary hash, the reconciled hit lands on - the hash boundary (48), not the block boundary (32). - """ + the hash boundary (48), not the block boundary (32).""" groups = [ KVCacheGroupSpec(["L0"], _full(32)), KVCacheGroupSpec(["L1"], _mamba_align(32)), @@ -238,8 +234,7 @@ def test_coordinator_fine_grained_partial_tail_hit(): def test_coordinator_fine_grained_clips_when_one_group_missing_tail(): """If only one group has the sub-block boundary, min-convergence clips the - reconciled hit back to the block boundary (32). - """ + reconciled hit back to the block boundary (32).""" groups = [ KVCacheGroupSpec(["L0"], _full(32)), KVCacheGroupSpec(["L1"], _mamba_align(32)), @@ -280,8 +275,7 @@ def test_store_mask_swa_only_window_around_each_lcm_boundary(): """Hybrid full-attn(block=32) + SWA(block=8, sw=8). lcm=32. With aligned=64 the SWA group should mark exactly the blocks ending at 32 and 64 (i.e. blocks 3 and 7 at block_size=8); the rest can never - participate in any future hit. - """ + participate in any future hit.""" full = _full(32) swa = _swa(block_size=8, sliding_window=8) groups = [KVCacheGroupSpec(["L0"], full), KVCacheGroupSpec(["L1"], swa)] @@ -327,8 +321,7 @@ def test_store_mask_swa_does_not_double_scale_under_dcp(): def test_store_mask_swa_wider_window_covers_more_blocks_per_lcm(): """Same hybrid layout but sliding_window=16 (= 2 SWA blocks). Each lcm - boundary should now span two SWA tail blocks. - """ + boundary should now span two SWA tail blocks.""" full = _full(32) swa = _swa(block_size=8, sliding_window=16) groups = [KVCacheGroupSpec(["L0"], full), KVCacheGroupSpec(["L1"], swa)] @@ -358,8 +351,7 @@ def test_store_mask_dsv4_5_groups_full_mla_plus_4_swa(): """DSV4-shaped: full-MLA(B=256) + 4 SWA groups with B in {64, 64, 4, 8} and varied sliding windows. lcm=256, hash_block_size=4. Two lcm segments (aligned_len=512). Validates that the tile-once strategy produces the - expected per-segment tail-window pattern, repeated. - """ + expected per-segment tail-window pattern, repeated.""" full_mla = _full(block_size=256) swa_64_sw128 = _swa(block_size=64, sliding_window=128) swa_64_sw512 = _swa(block_size=64, sliding_window=512) @@ -393,8 +385,7 @@ def test_store_mask_dsv4_5_groups_full_mla_plus_4_swa(): def test_store_mask_fast_path_all_block_sizes_equal_lcm(): """When every non-full-attn group already aligns to lcm_block_size, the - fast path returns all-True without invoking find_longest_cache_hit. - """ + fast path returns all-True without invoking find_longest_cache_hit.""" full = _full(block_size=64) swa = _swa(block_size=64, sliding_window=128) groups = [KVCacheGroupSpec(["L0"], full), KVCacheGroupSpec(["L1"], swa)] @@ -407,8 +398,7 @@ def test_store_mask_fast_path_all_block_sizes_equal_lcm(): def test_store_mask_fast_path_single_attention_group(): """Two groups sharing the same SWA spec collapse to one attention group; - no lcm filter applies, every chunk is True. - """ + no lcm filter applies, every chunk is True.""" swa = _swa(block_size=16, sliding_window=32) groups = [KVCacheGroupSpec(["L0"], swa), KVCacheGroupSpec(["L1"], swa)] coord = _make_coord(groups, hash_block_size=16) @@ -422,8 +412,7 @@ def test_store_mask_fast_path_single_attention_group(): def _retention_groups(): """Hybrid full-attn(block=32) + SWA(block=8, sw=8); lcm=32. The SWA group - densely keeps one tail block per 32-token boundary. - """ + densely keeps one tail block per 32-token boundary.""" full = _full(32) swa = _swa(block_size=8, sliding_window=8) return [KVCacheGroupSpec(["L0"], full), KVCacheGroupSpec(["L1"], swa)] @@ -431,8 +420,7 @@ def _retention_groups(): def test_store_mask_dense_default_matches_every_lcm_boundary(): """retention_interval=None (default) keeps the SWA tail at every lcm - boundary: tokens 32/64/96/128 -> chunks 3/7/11/15. - """ + boundary: tokens 32/64/96/128 -> chunks 3/7/11/15.""" coord = _make_coord(_retention_groups(), hash_block_size=8) masks = coord.store_mask(128) assert masks[0] is None @@ -442,8 +430,7 @@ def test_store_mask_dense_default_matches_every_lcm_boundary(): def test_store_mask_retention_interval_sparsifies_swa_tails(): """retention_interval=64 keeps an SWA tail once per 64-token segment (chunks 7 and 15) instead of every 32 tokens, dropping the mid-segment - boundaries at 32 and 96. - """ + boundaries at 32 and 96.""" coord = _make_coord(_retention_groups(), hash_block_size=8, retention_interval=64) masks = coord.store_mask(128) assert masks[0] is None # full attn unaffected @@ -452,8 +439,7 @@ def test_store_mask_retention_interval_sparsifies_swa_tails(): def test_store_mask_retention_interval_zero_keeps_only_replay_boundary(): """retention_interval=0 drops all segment tails; only the latest replay - boundary (capped at num_prompt-1, aligned down to lcm) is retained. - """ + boundary (capped at num_prompt-1, aligned down to lcm) is retained.""" coord = _make_coord(_retention_groups(), hash_block_size=8, retention_interval=0) # No replay info -> nothing reachable for the SWA group. assert coord.store_mask(128)[1] == [False] * 16 @@ -464,8 +450,7 @@ def test_store_mask_retention_interval_zero_keeps_only_replay_boundary(): def test_store_mask_retention_interval_keeps_segment_and_replay_tails(): """Sparse segment tails (interval=64 -> chunks 7,15) plus the replay - boundary tail (num_prompt=100 -> chunk 11) coexist. - """ + boundary tail (num_prompt=100 -> chunk 11) coexist.""" coord = _make_coord(_retention_groups(), hash_block_size=8, retention_interval=64) masks = coord.store_mask(128, num_prompt_tokens=100) assert masks[1] == [i in (7, 11, 15) for i in range(16)] @@ -503,8 +488,7 @@ def test_store_mask_excludes_mamba_groups_lookup_unaffected(): nulled/freed; speculative blocks relocate), so the positional normal save must never cover mamba chunks — regardless of retention. Lookups still probe mamba boundaries: their keys come from the pinned snapshot/CoW - hand-off path instead. - """ + hand-off path instead.""" groups = [ KVCacheGroupSpec(["L0"], _full(16)), KVCacheGroupSpec(["L1"], _mamba_align(16)), @@ -525,8 +509,7 @@ def test_store_mask_excludes_mamba_groups_lookup_unaffected(): def test_lookup_with_eagle_pops_last_full_attention_block(): """Sanity: with use_eagle, find_longest_cache_hit drops the last block. - Pairs with the load_mask test below to lock the round-trip contract. - """ + Pairs with the load_mask test below to lock the round-trip contract.""" groups = [KVCacheGroupSpec(["L0"], _full(16))] coord = _make_coord(groups, hash_block_size=16, use_eagle=True) hs = _hashes(4) @@ -567,8 +550,7 @@ def test_load_mask_with_eagle_does_not_double_prune_full_attention(): def test_load_mask_with_eagle_hybrid_full_plus_swa(): """Hybrid (FullAttn + SWA) with eagle: load_mask must cover every chunk in [0, token_len) for the FullAttn group; SWA group keeps its - tail-window mask. - """ + tail-window mask.""" groups = [ KVCacheGroupSpec(["L0"], _full(16)), KVCacheGroupSpec(["L1"], _swa(16, 32)), diff --git a/tests/v1/kv_connector/unit/test_mooncake_store_hma_e2e.py b/tests/v1/kv_connector/unit/test_mooncake_store_hma_e2e.py index 85d4970089..6c2cff0a54 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_store_hma_e2e.py +++ b/tests/v1/kv_connector/unit/test_mooncake_store_hma_e2e.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """End-to-end save->lookup test for MooncakeStoreConnector on a hybrid -(SWA + Full) attention config, using a dict-backed mock store. -""" +(SWA + Full) attention config, using a dict-backed mock store.""" import sys import threading @@ -283,8 +282,7 @@ def test_e2e_swa_plus_full_save_then_lookup_hits(): def test_recv_skips_swa_blocks_before_window(): """Producer stored every block for both groups; consumer must only fetch - SWA blocks within the sliding window, not the head. - """ + SWA blocks within the sliding window, not the head.""" full = FullAttentionSpec(block_size=16, num_kv_heads=8, head_size=64, dtype=None) # sliding_window=32, block_size=16 → 2 contiguous blocks within window. swa = SlidingWindowSpec( @@ -352,8 +350,7 @@ def test_recv_skips_swa_blocks_before_window(): def test_chunked_token_database_hash_block_size_smaller_than_block_size(): """DSv4-style: hash_block_size=4, group block_size=16 — process_tokens - keys each chunk by its ending fine hash, including a partial tail. - """ + keys each chunk by its ending fine hash, including a partial tail.""" md = KeyMetadata("m", 0, 0, 0, 0, group_id=3) db = ChunkedTokenDatabase(md, block_size=16, hash_block_size=4) db.set_kv_caches_base_addr([0]) @@ -386,8 +383,7 @@ def test_sub_block_partial_tail_offload_reads_cow_block(): """Sub-block prompt (the 900/128/1536 shape, scaled to 12/4/16): the partial tail is offloaded for both groups under the boundary sub-hash. The full-attention block is read from the request block table; the mamba block - is the core-provided CoW target, not block_ids. - """ + is the core-provided CoW target, not block_ids.""" full = FullAttentionSpec(block_size=16, num_kv_heads=8, head_size=64, dtype=None) mamba = MambaSpec( block_size=16, @@ -466,8 +462,7 @@ def test_sub_block_partial_tail_offload_reads_cow_block(): def test_offload_syncs_event_before_put(): """An offload-carrying meta synchronizes its CoW-fence event before the store put reads the blocks, then completes in one pass and drains the - completion counter. - """ + completion counter.""" full = FullAttentionSpec(block_size=16, num_kv_heads=8, head_size=64, dtype=None) mamba = MambaSpec( block_size=16, @@ -538,8 +533,7 @@ def test_sub_block_partial_tail_offload_covers_smaller_group_blocks(): offload must persist every FA block up to the boundary — the normal save floors to the lcm, so those blocks are otherwise never written and the consumer's per-group lookup would miss. The mamba boundary block still - reads the core-provided CoW target. - """ + reads the core-provided CoW target.""" full = FullAttentionSpec(block_size=4, num_kv_heads=8, head_size=64, dtype=None) mamba = MambaSpec( block_size=16, @@ -810,8 +804,7 @@ def test_ring_scratch_group_is_never_stored_and_does_not_block_hits(): """A per-request ring group (CircularBufferSpec, capacity as block_size) sits beside the paged group: worker setup tolerates its block size (the DeepSeek-V4.1 compressor ring is 8 rows), saving a request stores paged - blocks only, and lookup hits on the paged group alone. - """ + blocks only, and lookup hits on the paged group alone.""" full = FullAttentionSpec(block_size=16, num_kv_heads=8, head_size=64, dtype=None) ring = CircularBufferSpec( block_size=8, num_kv_heads=1, head_size=64, head_size_v=0, dtype=torch.uint8 diff --git a/tests/v1/kv_connector/unit/test_mooncake_store_scheduler.py b/tests/v1/kv_connector/unit/test_mooncake_store_scheduler.py index af2dfd6083..7ced38d65a 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_store_scheduler.py +++ b/tests/v1/kv_connector/unit/test_mooncake_store_scheduler.py @@ -536,8 +536,7 @@ def _make_pending_load_unfinished_request( def _make_pending_load_scheduler_output() -> SimpleNamespace: """scheduler_output for a step where req-0 is parked on a pending load - (not in scheduled_new_reqs or scheduled_cached_reqs). - """ + (not in scheduled_new_reqs or scheduled_cached_reqs).""" return SimpleNamespace( finished_req_ids=set(), preempted_req_ids=set(), @@ -713,8 +712,7 @@ def test_running_request_not_in_resumed_req_ids_appends_blocks(): def test_resumed_request_in_resumed_req_ids_replaces_blocks(): """A request the scheduler marks resumed gets the FULL block table in new_block_ids and must REPLACE the tracker's blocks (not append), even if - a stale tracker from before preemption is still present. - """ + a stale tracker from before preemption is still present.""" scheduler = _make_bare_scheduler() _make_resumed_unfinished_request( scheduler, diff --git a/tests/v1/kv_connector/unit/test_mooncake_store_worker.py b/tests/v1/kv_connector/unit/test_mooncake_store_worker.py index 9646331fe0..7dcce073a0 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_store_worker.py +++ b/tests/v1/kv_connector/unit/test_mooncake_store_worker.py @@ -432,8 +432,7 @@ def _patch_worker_runtime( def test_pool_key_to_string_without_prefix_is_unchanged(): """Default (empty) cache_prefix keeps keys byte-identical to the - historical unprefixed format so existing deployments keep their hits. - """ + historical unprefixed format so existing deployments keep their hits.""" key = PoolKey(KeyMetadata("test-model", 0, 0, 0, 0), "deadbeef") assert ( key.to_string() == "test-model@tp_rank:0@pcp0@dcp0@pp_rank:0@group:0@deadbeef" @@ -574,8 +573,7 @@ def test_tp_shared_receiving_reads_each_local_store_shard(): def test_pool_key_cache_prefix_namespaces_and_disambiguates(): """A non-empty cache_prefix is prepended, and two instances with - different prefixes never collide on identical block hashes. - """ + different prefixes never collide on identical block hashes.""" md_a = KeyMetadata("test-model", 0, 0, 0, 0, cache_prefix="depA") md_b = KeyMetadata("test-model", 0, 0, 0, 0, cache_prefix="depB") @@ -591,8 +589,7 @@ def test_pool_key_cache_prefix_namespaces_and_disambiguates(): def test_default_local_buffer_size_matches_pr40900(): """PR-40900 shipped a 4 GiB default for local_buffer_size; the dual-mode - patch preserves it (and the JSON key) so unchanged PR-40900 configs work. - """ + patch preserves it (and the JSON key) so unchanged PR-40900 configs work.""" assert worker.DEFAULT_LOCAL_BUFFER_SIZE == 4 * 1024**3 @@ -1014,8 +1011,7 @@ def test_store_sending_thread_skips_null_sparse_group_blocks(): def test_partial_tail_offload_skips_cap_omitted_mamba_group(): """A Mamba group omitted by the handoff cap must not fall back to the - connector's positional block table. - """ + connector's positional block table.""" from vllm.v1.kv_cache_interface import ( FullAttentionSpec, KVCacheGroupSpec, @@ -1143,8 +1139,7 @@ def test_partial_tail_put_failure_activates_pressure_gate(): def test_normal_save_excludes_mamba_group_and_null_blocks(): """The positional normal save must never cover mamba chunks (align-mode block tables are not append-only) and must skip chunks whose block is the - reserved null block, for any group. - """ + reserved null block, for any group.""" from vllm.v1.kv_cache_interface import ( FullAttentionSpec, KVCacheGroupSpec, @@ -1205,8 +1200,7 @@ def test_normal_save_excludes_mamba_group_and_null_blocks(): def test_block_aligned_snapshot_offload_uses_provided_block(): """A block-aligned hand-off (sparse-retention mamba checkpoint) uploads exactly the core-pinned block under the boundary-end hash key; the - positional block table entry for that chunk must be ignored. - """ + positional block table entry for that chunk must be ignored.""" store = MagicMock() store.batch_is_exist.side_effect = lambda keys: [0] * len(keys) store.batch_put_from_multi_buffers.side_effect = lambda keys, *a: [256] * len(keys) @@ -1234,8 +1228,7 @@ def test_block_aligned_snapshot_offload_uses_provided_block(): def test_mixed_snapshot_and_sub_block_offloads(): """A retention snapshot and the prompt-end sub-block CoW tail can arrive in one hand-off; the sub-block path covers FA gap blocks but reads the - mamba boundary only from the CoW block, never positionally. - """ + mamba boundary only from the CoW block, never positionally.""" store = MagicMock() store.batch_is_exist.side_effect = lambda keys: [0] * len(keys) store.batch_put_from_multi_buffers.side_effect = lambda keys, *a: [256] * len(keys) @@ -1275,8 +1268,7 @@ def test_mixed_snapshot_and_sub_block_offloads(): def test_snapshot_offload_skips_null_handoff_block(): """A hand-off the core could not materialize (null block) carries no - committed state; persisting it would poison the boundary key. - """ + committed state; persisting it would poison the boundary key.""" store = MagicMock() thread = _make_partial_tail_send_thread(store) @@ -1604,8 +1596,7 @@ def test_store_sending_thread_passes_replicate_config_when_preferred_segment_set def test_store_sending_thread_passes_default_replicate_config_when_no_preferred_segment(): # noqa: E501 """Without a preferred_segment the SendingThread still forwards a (default-constructed) ReplicateConfig so the C++ side always sees a - well-defined config object. - """ + well-defined config object.""" store = MagicMock() store.batch_is_exist.side_effect = lambda keys: [0] * len(keys) store.batch_put_from_multi_buffers.return_value = [256, 256] @@ -2115,8 +2106,7 @@ def test_recv_thread_stops_after_first_failing_disk_offload_sub_batch(): def test_recv_thread_skips_split_when_budget_holds_all_keys(): """PR-36 removed the count-based split trigger; with budget for 3 keys, - all three should be requested in a single call. - """ + all three should be requested in a single call.""" store = MagicMock() store.batch_get_into_multi_buffers.return_value = [256, 256, 256] thread = _make_store_recving_thread( @@ -2330,8 +2320,7 @@ def test_requester_worker_init_skips_disk_budget_when_offload_disabled( monkeypatch, ): """enable_offload=False zeroes out the disk budget so we don't generate - redundant owner GET-RPCs. - """ + redundant owner GET-RPCs.""" store = MagicMock() store.setup.return_value = 0 _install_fake_mooncake(monkeypatch, store) @@ -3006,8 +2995,7 @@ def test_requester_worker_group_semantics_string_true_enables( def test_store_sending_thread_clamps_token_len_to_lcm(): """Partial chunks past the last lcm boundary aren't stored — cache hits - are always lcm-aligned (mirrors HybridKVCacheCoordinator). - """ + are always lcm-aligned (mirrors HybridKVCacheCoordinator).""" store = MagicMock() store.batch_is_exist.return_value = [0, 0] store.batch_put_from_multi_buffers.return_value = [256, 256] @@ -3032,8 +3020,7 @@ def test_store_sending_thread_clamps_token_len_to_lcm(): def test_store_sending_thread_skips_when_token_len_below_lcm(): """Requests shorter than lcm_block_size cannot produce any aligned chunk, - so neither the existence check nor the put should be issued. - """ + so neither the existence check nor the put should be issued.""" from vllm.v1.kv_cache_interface import FullAttentionSpec, KVCacheGroupSpec store = MagicMock() @@ -3823,8 +3810,7 @@ def test_lookup_full_hit_with_eagle_pops_once_not_twice(): """Eagle already leaves the last block for the drafter, so a full-prompt re-derivation must never fire for eagle-governed hits: firing would anchor the search one block lower and pop a second - block, regressing the hit by an extra producer boundary. - """ + block, regressing the hit by an extra producer boundary.""" worker = _make_bare_worker(block_size=16) worker.coord = mooncake_store_worker.MooncakeStoreCoordinator( worker._kv_cache_groups, @@ -3981,8 +3967,7 @@ def test_lookup_full_hit_swa_degrades_when_no_stored_boundary_is_usable(): the full hit into 48, whose SWA window needs the never-written block 1, so every load failed and the recompute re-entered the same lookup. The re-derivation must report that no stored boundary below the request end - is usable. - """ + is usable.""" from vllm.v1.kv_cache_interface import KVCacheGroupSpec, SlidingWindowSpec worker = _make_bare_worker(block_size=16) @@ -4004,8 +3989,7 @@ def test_lookup_full_hit_swa_degrades_when_no_stored_boundary_is_usable(): def test_lookup_swa_single_group_returns_full_when_tail_window_present(): """Single-SWA, sliding_window=32 (= 2 blocks): producer stored only the tail. Coordinator-driven lookup returns full prefix even though the - pre-window blocks are absent. - """ + pre-window blocks are absent.""" from vllm.v1.kv_cache_interface import KVCacheGroupSpec, SlidingWindowSpec worker = _make_bare_worker(block_size=16) @@ -4401,8 +4385,7 @@ def test_config_defaults_to_embedded(): def test_config_pr40900_unchanged(tmp_path): """A literal PR-40900 config (no mode, no enable_offload, no preferred_segment) - parses without raising and resolves to embedded mode. - """ + parses without raising and resolves to embedded mode.""" config_path = _write_mooncake_config( tmp_path, { @@ -4510,8 +4493,7 @@ def test_config_zero_local_buffer(): def test_topology_standalone_store_with_disk_offload(tmp_path, monkeypatch): """standalone-store + disk: global_segment_size=0, enable_offload=True, preferred_segment set. Assert setup() positional args, ReplicateConfig - wiring, and that the disk-offload buffer budget is allocated. - """ + wiring, and that the disk-offload buffer budget is allocated.""" store = MagicMock() store.setup.return_value = 0 fake_replicate_config_cls = _install_fake_mooncake(monkeypatch, store) @@ -4560,8 +4542,7 @@ def test_topology_standalone_store_with_disk_offload(tmp_path, monkeypatch): def test_topology_embedded_cpu_only(tmp_path, monkeypatch): """Embedded + CPU-only: no mode key (defaults to embedded), global_segment_size>0, enable_offload absent, no preferred_segment. - This is the PR-40900 baseline recipe. - """ + This is the PR-40900 baseline recipe.""" store = MagicMock() store.setup.return_value = 0 fake_replicate_config_cls = _install_fake_mooncake(monkeypatch, store) @@ -4750,8 +4731,7 @@ def test_store_worker_close_swallows_store_errors(): def test_blob_block_hashes_wire_roundtrip(): """The lookup wire format sends a ``hash_len`` frame plus the raw hashes concatenated back-to-back; the server rebuilds them through a zero-copy - ``BlobBlockHashes`` view over the frame buffer. - """ + ``BlobBlockHashes`` view over the frame buffer.""" hashes = [BlockHash(bytes([i]) * 16) for i in range(5)] hash_len = len(hashes[0]) diff --git a/tests/v1/kv_connector/unit/test_moriio_connector.py b/tests/v1/kv_connector/unit/test_moriio_connector.py index eae9f71ee3..a30b5caf4b 100644 --- a/tests/v1/kv_connector/unit/test_moriio_connector.py +++ b/tests/v1/kv_connector/unit/test_moriio_connector.py @@ -692,8 +692,7 @@ def test_moriio_handshake_returns_metadata(mock_parallel_groups): def test_resolve_host_ip_prefers_extra_config(): """An explicit ``host_ip`` in kv_connector_extra_config overrides get_ip() (so an external router can advertise a routable/internal address); an - absent or empty value falls back to get_ip(). - """ + absent or empty value falls back to get_ip().""" assert resolve_host_ip({"host_ip": "10.0.0.7"}) == "10.0.0.7" fallback = get_ip() @@ -747,8 +746,7 @@ def _read_scheduler( def test_hma_blocks_per_sw_two_groups(): """A Full + SlidingWindow config runs with HMA and computes block budgets - correctly - """ + correctly""" scheduler = _read_scheduler(_make_hybrid_kv_cache_config()) assert scheduler._is_hma_required is True # cdiv(32, 16) + 1 == 3 for the sliding-window group, 0 for full attention. @@ -766,8 +764,7 @@ def test_hma_blocks_per_sw_two_groups(): def test_is_hma_required(swa_enabled, disable_hma, expected_is_hma): """_is_hma_required tracks both the KV cache groups and the --disable-hybrid-kv-cache-manager flag. When HMA is off, - get_exchange_clipped_blocks must be a no-op. - """ + get_exchange_clipped_blocks must be a no-op.""" config = ( _make_hybrid_kv_cache_config() if swa_enabled else _make_test_kv_cache_config() ) @@ -780,8 +777,7 @@ def test_is_hma_required(swa_enabled, disable_hma, expected_is_hma): def test_non_sliding_window_hybrid_is_rejected(): """A hybrid group that is not sliding-window (e.g. chunked-local - attention) must fail closed rather than be silently mistransferred. - """ + attention) must fail closed rather than be silently mistransferred.""" full_spec = FullAttentionSpec( block_size=16, num_kv_heads=4, head_size=64, dtype=torch.float16 ) @@ -815,8 +811,7 @@ def test_non_sliding_window_hybrid_is_rejected(): def test_token_count_basis_uses_full_attention_group(): """Chunked-prefill token counting must use an unclipped full-attention - group (blocks_per_sw == 0), not a clipped sliding-window group. - """ + group (blocks_per_sw == 0), not a clipped sliding-window group.""" scheduler = _read_scheduler(_make_hybrid_kv_cache_config()) # Group 0 is the full-attention group assert scheduler._full_attn_group_idx == 0 @@ -825,8 +820,7 @@ def test_token_count_basis_uses_full_attention_group(): def test_get_exchange_clipped_blocks_clips_only_sw_group(): """get_exchange_clipped_blocks keeps the full attn group intact and clips the - sliding-window group to its window tail. - """ + sliding-window group to its window tail.""" scheduler = _read_scheduler(_make_hybrid_kv_cache_config()) full = [10, 11, 12, 13, 14] sw = [20, 21, 22, 23, 24] @@ -837,8 +831,7 @@ def test_get_exchange_clipped_blocks_clips_only_sw_group(): def test_metadata_hma_block_ids_preserved_per_group(): """add_new_req stores per-group (BlockIds) block lists unchanged for both - read and write, so the hybrid group structure is retained. - """ + read and write, so the hybrid group structure is retained.""" metadata = MoRIIOConnectorMetadata() # Assume: diff --git a/tests/v1/kv_connector/unit/test_moriio_routing_fairness.py b/tests/v1/kv_connector/unit/test_moriio_routing_fairness.py index 76a33cff82..e38ec3f7e9 100644 --- a/tests/v1/kv_connector/unit/test_moriio_routing_fairness.py +++ b/tests/v1/kv_connector/unit/test_moriio_routing_fairness.py @@ -110,8 +110,7 @@ def make_meta(*, p_tp: int, p_dp: int, remote_dp_rank: int, host: str = "phost0" def build_decode_workers(cfg: PDConfig) -> list: """Decode workers that issue reads for one prefill instance. A TP decode instance reads from every tp rank; a DP decode instance from each dp-rank - worker. Reused across requests so per-worker round-robin state advances. - """ + worker. Reused across requests so per-worker round-robin state advances.""" if cfg.d_tp > 1: return [ make_decode_worker(world_size=cfg.d_tp, tp_rank=r, dp_rank=0) @@ -126,8 +125,7 @@ def prefill_target_multiset(cfg: PDConfig, rounds: int) -> Counter: """Drive the REAL _resolve_read_source over a fair input stream; tally which prefill GPU each read targets. The only modelled assumption is the proxy contract -- each owner dp-rank delivered equally (``for owner_dp in - range(p_dp)``); no proxy algorithm is reproduced. - """ + range(p_dp)``); no proxy algorithm is reproduced.""" workers = build_decode_workers(cfg) hits: Counter = Counter() for _ in range(rounds): diff --git a/tests/v1/kv_connector/unit/test_multi_connector.py b/tests/v1/kv_connector/unit/test_multi_connector.py index e6a78063be..fcda6232c6 100644 --- a/tests/v1/kv_connector/unit/test_multi_connector.py +++ b/tests/v1/kv_connector/unit/test_multi_connector.py @@ -555,8 +555,7 @@ class TestMultiConnectorStats: def test_build_kv_connector_stats_reconstructs_nixl_stats(self): """Test that NixlConnector stats are properly reconstructed with - correct data. - """ + correct data.""" serialized_data = { "NixlConnector": { "transfer_duration": [1.5, 2.3], diff --git a/tests/v1/kv_connector/unit/test_nixl_connector.py b/tests/v1/kv_connector/unit/test_nixl_connector.py index d02be5fd56..c9d2dcf5f1 100644 --- a/tests/v1/kv_connector/unit/test_nixl_connector.py +++ b/tests/v1/kv_connector/unit/test_nixl_connector.py @@ -318,8 +318,7 @@ def test_abort_immediately_remote_prefill_enqueues_empty_recv(): """A remote-prefill request added with abort_immediately=True should be added to the scheduler's waiting queue then immediately aborted, so the NIXL connector's request_finished hook enqueues an empty recv to notify - the prefill instance to free its blocks. - """ + the prefill instance to free its blocks.""" from vllm.v1.request import RequestStatus scheduler = create_scheduler(create_vllm_config()) @@ -3146,8 +3145,7 @@ def test_split_read_failure_defers_report_until_last_handle( request — nor invalidate its blocks — while the sibling xfer is still in flight: a posted READ cannot be aborted and would DMA into blocks the scheduler could free and reuse. The report happens exactly once, when the - last handle is terminal. - """ + last handle is terminal.""" request_id = "split_read_partial_failure" err_handle, live_handle = 11, 22 connector, worker, wrapper = _make_split_read_connector( diff --git a/tests/v1/kv_connector/unit/test_nixl_connector_hma.py b/tests/v1/kv_connector/unit/test_nixl_connector_hma.py index d79fcab698..3f1038ff65 100644 --- a/tests/v1/kv_connector/unit/test_nixl_connector_hma.py +++ b/tests/v1/kv_connector/unit/test_nixl_connector_hma.py @@ -281,8 +281,7 @@ def test_update_state_after_alloc_tracks_cached_blocks_per_group(): """Hybrid SWA+FA requests can have different prefix-cache-hit counts per KV cache group. Each group's count must be tracked independently rather than collapsed to a single scalar, or DCP read-phase alignment - (local_num_computed_blocks) would misalign one of the groups. - """ + (local_num_computed_blocks) would misalign one of the groups.""" from vllm.distributed.kv_transfer.kv_connector.v1.nixl.pull_scheduler import ( NixlPullConnectorScheduler, ) @@ -336,8 +335,7 @@ def test_full_local_hit_is_not_awaited_by_the_scheduler(): owed to the producer -- so the worker must not report it in finished_recving. Doing so trips `assert RequestStatus.is_finished` in _update_from_kv_xfer_finished, which only tolerates a finished recv for a - request that is parked or already done. - """ + request that is parked or already done.""" from vllm.distributed.kv_transfer.kv_connector.v1.nixl.pull_scheduler import ( NixlPullConnectorScheduler, ) @@ -442,8 +440,7 @@ def test_apply_dcp_prefix_caching_matches_global_logical_positions( """_apply_dcp_prefix_caching must operate on logical block IDs (DCP interleaves at logical-block granularity) and always return equal-length local/remote slices, so a later, unconditional _apply_prefix_caching - trim is a guaranteed no-op rather than double-processing the read. - """ + trim is a guaranteed no-op rather than double-processing the read.""" from vllm.distributed.kv_transfer.kv_connector.v1.nixl.worker import ( NixlConnectorWorker, ) @@ -842,8 +839,7 @@ def test_apply_prefix_caching_ssm_prefix_cache_hit( def test_apply_prefix_caching_ssm_unpairable_slots_rejected(): """Local SSM slots can only exceed the remote ones by the position D recomputes itself. A larger excess means the lists aren't - position-aligned: fail loudly rather than transfer into wrong slots. - """ + position-aligned: fail loudly rather than transfer into wrong slots.""" from vllm.distributed.kv_transfer.kv_connector.v1.nixl.worker import ( NixlConnectorWorker, ) @@ -1159,8 +1155,7 @@ def test_nixl_region_sort_preserves_pipeline_layer_order(): @pytest.mark.cpu_test def test_get_block_descs_ids_hybrid_ssm(): """Test _compute_desc_ids uses per-group strides for hybrid - FA+SSM when ratio=1 (no kernel block size mismatch). - """ + FA+SSM when ratio=1 (no kernel block size mismatch).""" from vllm.v1.kv_cache_interface import FullAttentionSpec, MambaSpec worker = _make_mock_worker_for_desc_ids( @@ -1244,8 +1239,7 @@ def test_get_block_descs_ids_uses_per_region_pool_capacity(): @pytest.mark.cpu_test def test_get_block_descs_ids_kernel_block_mismatch(): """Test _compute_desc_ids uses different strides for FA - (kernel blocks) vs SSM (logical blocks) when ratio > 1. - """ + (kernel blocks) vs SSM (logical blocks) when ratio > 1.""" from vllm.v1.kv_cache_interface import FullAttentionSpec, MambaSpec ratio = 4 @@ -1276,8 +1270,7 @@ def test_get_block_descs_ids_kernel_block_mismatch(): def test_get_block_descs_ids_hetero_block_size_hybrid(): """With a block-size ratio, FA desc ids are ratio-expanded while SSM desc ids keep the unexpanded logical stride (state blocks are never - sub-split). - """ + sub-split).""" from vllm.v1.kv_cache_interface import FullAttentionSpec, MambaSpec worker = _make_mock_worker_for_desc_ids( @@ -1316,8 +1309,7 @@ def _bind_worker_method(worker, name): @pytest.mark.cpu_test def test_map_block_ids_for_block_size_ratio_hybrid(): """Attention groups expand to remote granularity and clip to the remote - coverage; mamba state blocks pass through 1:1. - """ + coverage; mamba state blocks pass through 1:1.""" from unittest.mock import MagicMock from vllm.distributed.kv_transfer.kv_connector.v1.nixl.worker import ( @@ -1348,8 +1340,7 @@ def test_map_block_ids_for_block_size_ratio_hybrid(): @pytest.mark.cpu_test def test_post_process_zeroes_untransferred_tail(): """The untransferred sub-blocks of the last local block are zeroed on - receive; mamba state caches are untouched by the attention permute. - """ + receive; mamba state caches are untouched by the attention permute.""" from unittest.mock import MagicMock from vllm.distributed.kv_transfer.kv_connector.v1.nixl.worker import ( @@ -1392,8 +1383,7 @@ def test_post_process_zeroes_untransferred_tail(): @pytest.mark.cpu_test def test_nixl_metadata_hybrid_ssm_block_ids(): """Test NixlConnectorMetadata correctly stores block IDs for FA + SSM - groups with different block counts (kernel mismatch active). - """ + groups with different block counts (kernel mismatch active).""" from vllm.distributed.kv_transfer.kv_connector.v1.nixl.metadata import ( NixlConnectorMetadata, ) @@ -1474,8 +1464,7 @@ def _make_fake_kv_cache_manager(): @pytest.mark.cpu_test def test_zeroing_block_ids_cover_only_loaded_attention_blocks(): """Only zero-recorded (attention) groups contribute, sliced to the - externally-loaded token range; Mamba state blocks are never zeroed. - """ + externally-loaded token range; Mamba state blocks are never zeroed.""" manager = _make_fake_kv_cache_manager() # Tokens [0, 16) are locally cached; the load covers tokens [16, 56). @@ -1503,8 +1492,7 @@ def test_scheduler_filters_connector_loaded_blocks_from_zeroing(): @pytest.mark.cpu_test def test_failed_load_rezeroes_unwritten_skipped_blocks(): """A failed async load leaves zeroing-skipped blocks unwritten beyond - the valid prefix; they must be zeroed before local recompute. - """ + the valid prefix; they must be zeroed before local recompute.""" from unittest.mock import MagicMock from vllm.v1.core.sched.scheduler import Scheduler @@ -1964,8 +1952,7 @@ def test_logical_to_kernel_block_ids_with_remote_ratio( def test_exchange_clipped_blocks_ssm_single_state(): """In single-state cache modes, SSM lists are reduced to the running state slot: speculative scratch slots, null placeholders and the previous - step's state carry nothing. Attention groups pass through untouched. - """ + step's state carry nothing. Attention groups pass through untouched.""" sched = make_nixl_scheduler(has_mamba=True, is_hma_required=True) sched.blocks_per_sw = [0, 0] sched._ssm_spec_blocks = [None, 2] @@ -1992,8 +1979,7 @@ def test_exchange_clipped_blocks_ssm_single_state(): @pytest.mark.cpu_test def test_exchange_clipped_blocks_ssm_positional_states(): """In "all" mode every position holds a state, so only the speculative - slots go; placeholders stay to keep the list position-indexed. - """ + slots go; placeholders stay to keep the list position-indexed.""" sched = make_nixl_scheduler(has_mamba=True, is_hma_required=True) sched.blocks_per_sw = [0, 0] sched._ssm_spec_blocks = [None, 2] @@ -2010,8 +1996,7 @@ def _make_hybrid_mla_kv_cache_config(num_blocks: int = 4): """KimiLinear-shaped config: one MLA group and two KDA (GDN-typed MambaSpec) groups whose layers share the same HMA tensors, with a mamba-aligned unified page and an MLA kernel block smaller than the - logical block. - """ + logical block.""" from vllm.v1.attention.backends.registry import MambaAttentionBackendEnum from vllm.v1.kv_cache_interface import ( KVCacheConfig, @@ -2151,8 +2136,7 @@ def test_register_kv_caches_hybrid_mla_dual_purpose_regions(): """Hybrid MLA+KDA registration: HMA tensors shared by both layer types must be flagged as MLA regions even when a KDA layer registers them first, expose TP-independent kernel-granularity block lens, and build - FA + mamba descriptors for every region. - """ + FA + mamba descriptors for every region.""" from unittest.mock import MagicMock from vllm.config import set_current_vllm_config @@ -2253,8 +2237,7 @@ def test_register_kv_caches_hybrid_mla_dual_purpose_regions(): def test_push_write_hybrid_mla_replicates_attention(): """Hybrid MLA+SSM push with P_TP < D_TP: attention blocks must be written to every covered D rank (replicated MLA latent) while SSM state - is written per-rank through the split handles. - """ + is written per-rank through the split handles.""" import threading from collections import defaultdict from unittest.mock import MagicMock diff --git a/tests/v1/kv_connector/unit/test_nixl_desc_geometry.py b/tests/v1/kv_connector/unit/test_nixl_desc_geometry.py index dab6432b5c..a4bfa9ab83 100644 --- a/tests/v1/kv_connector/unit/test_nixl_desc_geometry.py +++ b/tests/v1/kv_connector/unit/test_nixl_desc_geometry.py @@ -24,8 +24,7 @@ from .utils import create_vllm_config class _RecordingNixl: """Minimal NIXL wrapper stand-in that records descriptor lists and - prepared transfers so tests can resolve desc ids to byte ranges. - """ + prepared transfers so tests can resolve desc ids to byte ranges.""" def __init__(self, *args, **kwargs): self.dlists: dict[int, np.ndarray] = {} @@ -594,8 +593,7 @@ def _register_remote_agents(worker, metadata, tp_size): def _owned_byte_ranges(worker, group_logical_ids): """Byte ranges owned by a request: for each HMA region tensor, every - logical block id of every group maps to one unified page. - """ + logical block id of every group maps to one unified page.""" unified_page = worker._test_unified_page bases = [t.data_ptr() for t in worker._test_tensors] owned = [] @@ -633,8 +631,7 @@ def test_hetero_ppl_multi_read_writes_stay_within_request_blocks(): (kernel 4, ppl=3) vs remote (P, TP2) logical blocks of 8 tokens (ppl=2), equal kernel pages, tp_ratio=-2 multi-read with replicated MLA and TP-sharded KDA state. Every local descriptor of the request's reads must - stay within its own blocks. - """ + stay within its own blocks.""" from vllm.distributed.kv_transfer.kv_connector.v1.nixl.metadata import ( NixlConnectorMetadata, ) @@ -701,8 +698,7 @@ def _resolve( """Resolve a desc id to (region, kind, token_start) where kind is 'attn' (desc-page sized, sub-block-aligned, in the request's attention blocks) or 'mamba'. token_start is the request-relative token offset, so local - and remote are comparable even when their kernel blocks differ in size. - """ + and remote are comparable even when their kernel blocks differ in size.""" addr, length, _ = (int(x) for x in desc_arr[int(idx)]) for region, base in enumerate(bases): off = addr - base @@ -896,8 +892,7 @@ def _run_hetero_case( def test_hetero_ppl_token_alignment_sweep(local_block, remote_block, num_tokens): """Sweep prompt lengths across block-boundary residues for several hetero-ppl geometries; assert neighbor-safety, token alignment, and - coverage of every transferred kernel block. - """ + coverage of every transferred kernel block.""" _run_hetero_case( local_block, kernel=4, remote_block=remote_block, num_tokens=num_tokens ) @@ -916,8 +911,7 @@ def test_hetero_ppl_with_block_size_ratio(num_tokens): 2). The transfer is clipped at remote sub-block granularity by the pairing and front-trimmed by _apply_prefix_caching, so the untransferred tail can span both a partial block and whole blocks — - the case each of the two former zeroing paths handled only half of. - """ + the case each of the two former zeroing paths handled only half of.""" _run_hetero_case( local_block=24, kernel=8, @@ -966,8 +960,7 @@ def test_mla_hybrid_large_ppl_geometry(num_tokens): """KimiLinear-scale MLA-hybrid geometry (TP8 prefill -> TP1 decode): decode (local) logical block 5760 / kernel 64 (ppl=90), prefill (remote) logical block 768 (ppl=12), tp_ratio=-8 multi-read with - replicated MLA and 8-way TP-sharded KDA state. - """ + replicated MLA and 8-way TP-sharded KDA state.""" _run_hetero_case( local_block=5760, kernel=64, @@ -981,8 +974,7 @@ def test_mla_hybrid_large_ppl_geometry(num_tokens): def test_mismatched_mla_kernel_page_rejected_for_mla_hybrid(): """The MLA per-token page is TP-independent, so kernel block lengths differing by anything other than the block-size ratio must fail the - handshake loudly rather than transfer at mismatched geometry. - """ + handshake loudly rather than transfer at mismatched geometry.""" worker = _make_mla_hybrid_worker( local_block_size=12, kernel_block_size=4, num_logical_blocks=8 ) @@ -1166,8 +1158,7 @@ def test_csa_linear_registration_discovers_shared_regions(): def test_csa_linear_scratch_descs_follow_the_pages_they_overlay(): """The scratch ring is addressed by the regions it actually registered in, not by inferring that it must sit on the MLA pages: overlaying the main KV - pages instead moves its descriptors with it. - """ + pages instead moves its descriptors with it.""" worker = _make_csa_linear_ple_worker(scratch_aliases="main_kv") # Same MLA regions as before, but the ring now lives in the non-MLA ones. @@ -1301,8 +1292,7 @@ def test_csa_linear_remote_ple_is_copied_whole(): def _make_ring_worker(): """Paged MLA group plus a per-layer ring group, no Mamba: the shape of a - model whose sliding-window KV lives in per-request rings. - """ + model whose sliding-window KV lives in per-request rings.""" from unittest.mock import MagicMock from vllm.config import set_current_vllm_config diff --git a/tests/v1/kv_connector/unit/test_nixl_push_connector.py b/tests/v1/kv_connector/unit/test_nixl_push_connector.py index 964cadc3ed..7ce84bf685 100644 --- a/tests/v1/kv_connector/unit/test_nixl_push_connector.py +++ b/tests/v1/kv_connector/unit/test_nixl_push_connector.py @@ -115,8 +115,7 @@ class _BlocksMock: def _stub_sw_clipping(scheduler) -> None: """Make ``get_exchange_clipped_blocks`` a passthrough so tests don't - need the full sliding-window machinery. - """ + need the full sliding-window machinery.""" scheduler.get_exchange_clipped_blocks = lambda block_ids, clip_ssm=True: block_ids @@ -174,8 +173,7 @@ class TestPushScheduler: def test_p_side_request_finished_stages_blocks(self): """P scheduler pushes blocks into both _finished_request_blocks (lease) - and _newly_finished_push_blocks (metadata for next step). - """ + and _newly_finished_push_blocks (metadata for next step).""" sched = make_nixl_push_scheduler() _stub_sw_clipping(sched) @@ -194,8 +192,7 @@ class TestPushScheduler: def test_build_connector_meta_drains_both_sides(self): """meta.push_registrations and meta.push_finished_blocks are filled - from the staging dicts and the staging dicts are cleared. - """ + from the staging dicts and the staging dicts are cleared.""" sched = make_nixl_push_scheduler() _stub_sw_clipping(sched) @@ -290,8 +287,7 @@ class TestPushScheduler: def test_registration_watchdog_expires(self, caplog): """Stale D registrations whose deadline has passed are dropped at - ``build_connector_meta`` time. - """ + ``build_connector_meta`` time.""" # Watchdog logs a WARNING when it drops the stale entry; that's # what this test is verifying, so silence it in the test report. caplog.set_level( @@ -332,8 +328,7 @@ class TestPushScheduler: class _StubWriterWorker(NixlPushConnectorWorker): """Construct a worker without invoking ``__init__`` so we can drive - the matching/notif logic without bringing up NIXL or torch. - """ + the matching/notif logic without bringing up NIXL or torch.""" @classmethod def fresh(cls) -> _StubWriterWorker: @@ -439,8 +434,7 @@ class TestPushWriterRegSend: """``_do_send_reg_notif``: the PUSH_REG goes to every handshaked agent of the P engine, and the agent map is read under ``_handshake_lock`` so the send can't race the handshake done-callback's insert or a concurrent - stale-engine eviction (X1). - """ + stale-engine eviction (X1).""" def _reg_send_worker(self) -> tuple[_StubWriterWorker, list]: w = _StubWriterWorker.fresh() @@ -485,8 +479,7 @@ class TestPushWriterRegSend: def test_agent_read_is_serialized_with_handshake_lock(self): """While another thread holds ``_handshake_lock`` (as the handshake done-callback does while writing ``_remote_agents``), the writer's - check-then-send must not run ahead of the critical section. - """ + check-then-send must not run ahead of the critical section.""" w, failures = self._reg_send_worker() w._remote_agents["prefill-engine"] = {(0, 0): "agent-0"} rd = _registration_data("req-1") @@ -596,8 +589,7 @@ class TestPushWriterMatching: class TestPushWriterStartLoadKv: def test_finished_blocks_inbox_matches_stashed_registration(self): """Run the writer-loop's finished-blocks drain against a - pre-populated _pending_d_registrations entry. - """ + pre-populated _pending_d_registrations entry.""" w = _StubWriterWorker.fresh() w._pending_d_registrations["req-C"] = _registration_data("req-C") @@ -622,8 +614,7 @@ class TestPushWriterStartLoadKv: def test_start_load_kv_enqueues_to_writer(self): """``start_load_kv`` should hand registrations + finished blocks - to the writer queues without doing matching itself. - """ + to the writer queues without doing matching itself.""" w = _StubWriterWorker.fresh() # Stub heartbeats to a no-op; tests don't exercise the heartbeat # path here. @@ -681,8 +672,7 @@ def test_do_start_push_kv_defers_then_writes_when_handshake_ready(): NIXL op from the writer or the executor callback); once it resolves the request is re-queued on ``_deferred_push_inbox`` with the wake set; and on re-drive with the handshake ready the WRITE is issued with a correct - ReqMeta. - """ + ReqMeta.""" w = _StubWriterWorker.fresh() w._logical_to_kernel_block_ids = lambda x, ratio: x xfer_calls: list[dict[str, Any]] = [] @@ -722,8 +712,7 @@ def test_do_start_push_kv_defers_then_writes_when_handshake_ready(): def test_do_start_push_kv_drops_request_on_handshake_failure(): """Handshake raises: the request is dropped (not re-queued, no WRITE) and the failure is logged. Blocks are reclaimed by the lease/watchdog, matching - the old blocking behaviour. - """ + the old blocking behaviour.""" w = _StubWriterWorker.fresh() w._logical_to_kernel_block_ids = lambda x, ratio: x xfer_calls: list[dict[str, Any]] = [] @@ -745,8 +734,7 @@ def test_do_start_push_kv_drops_request_on_handshake_failure(): def test_writer_loop_drains_deferred_push_inbox(): """The writer loop drains ``_deferred_push_inbox`` and re-drives - ``_do_start_push_kv`` for each entry (event-driven, no polling). - """ + ``_do_start_push_kv`` for each entry (event-driven, no polling).""" w = _StubWriterWorker.fresh() w.nixl_wrapper = MagicMock() w.nixl_wrapper.get_new_notifs.return_value = {} @@ -779,8 +767,7 @@ def test_writer_loop_drains_deferred_push_inbox(): def _eviction_worker(engine_ttl: float) -> NixlPushConnectorWorker: """A push worker wired to drive the base ``_ensure_handshake`` eviction - path (``_evict_stale_engines`` + ``_cleanup_remote_engine``). - """ + path (``_evict_stale_engines`` + ``_cleanup_remote_engine``).""" w = _StubWriterWorker.fresh() w._engine_ttl = engine_ttl w._engine_last_active = {} @@ -802,8 +789,7 @@ def _eviction_worker(engine_ttl: float) -> NixlPushConnectorWorker: def test_active_push_refreshes_engine_last_active(): """The base ``_ensure_handshake`` refreshes liveness only on a new handshake, so an active push to an already-connected engine must refresh - ``_engine_last_active`` itself or it is reaped mid-stream (S1). - """ + ``_engine_last_active`` itself or it is reaped mid-stream (S1).""" w = _eviction_worker(engine_ttl=3600.0) # Already-connected D -> _ensure_handshake returns None, WRITE runs inline. w._remote_agents["decode-engine"] = {(0, 0): "agent-decode"} @@ -819,8 +805,7 @@ def test_active_push_refreshes_engine_last_active(): def test_stale_engine_evicted_on_push(): """A push drives ``_ensure_handshake`` -> ``_evict_stale_engines``, so a D engine silent past its TTL is reaped -- no _remote_agents / NIXL agent leak - across D scale up/down (S1). - """ + across D scale up/down (S1).""" w = _eviction_worker(engine_ttl=30.0) w._remote_agents["D-old"] = {(0, 0): "agent-D-old"} w._engine_last_active["D-old"] = time.perf_counter() - 10_000.0 @@ -837,8 +822,7 @@ def test_stale_engine_evicted_on_push(): def test_cleanup_remote_engine_pops_under_handshake_lock(): """Regression (X1): eviction must not remove ``_remote_agents`` entries while another thread is inside the lock's critical section (e.g. the - push writer reading the map to send a registration). - """ + push writer reading the map to send a registration).""" w = _eviction_worker(engine_ttl=30.0) w._remote_agents["D-old"] = {(0, 0): "agent-D-old"} @@ -863,8 +847,7 @@ def test_cleanup_remote_engine_pops_under_handshake_lock(): class TestPushWriterNotifs: def test_get_new_notifs_processes_forwarded_completion_notif(self): """Non-PUSH_REG notifs forwarded by the writer thread are drained - on the engine main thread inside ``_get_new_notifs``. - """ + on the engine main thread inside ``_get_new_notifs``.""" w = _StubWriterWorker.fresh() # Pretend the writer thread already forwarded a completion notif # for a request whose KV is being received. @@ -910,8 +893,7 @@ class TestPushWriterNotifs: @staticmethod def _pollable_worker() -> _StubWriterWorker: """Stub worker with the extra base-worker state the real - ``get_transfer_results`` needs to poll ``_sending_transfers``. - """ + ``get_transfer_results`` needs to poll ``_sending_transfers``.""" w = _StubWriterWorker.fresh() w.transfer_topo = MagicMock() w.nixl_wrapper = MagicMock() @@ -953,8 +935,7 @@ class TestPushWriterNotifs: @pytest.mark.parametrize(("pp_size", "is_hma"), [(1, False), (2, True)]) def test_completed_push_send_waits_for_consumer_notif(self, pp_size, is_hma): """P-side sends are completed by consumer notifs / lease expiry, - not by local WRITE-handle completion. - """ + not by local WRITE-handle completion.""" w = self._pollable_worker() w.pp_size = pp_size w._is_hma_required = is_hma @@ -1025,8 +1006,7 @@ class TestPushSchedulerNegative: def test_request_finished_unfinished_status_does_not_stage(self): """If a request is still RUNNING, request_finished must not stash - blocks for the worker (no push needed). - """ + blocks for the worker (no push needed).""" sched = make_nixl_push_scheduler() _stub_sw_clipping(sched) @@ -1043,8 +1023,7 @@ class TestPushSchedulerNegative: def test_request_finished_empty_blocks_does_not_arm_lease(self): """Empty block-id groups should still complete cleanly without - arming the lease/finished maps. - """ + arming the lease/finished maps.""" sched = make_nixl_push_scheduler() _stub_sw_clipping(sched) @@ -1059,8 +1038,7 @@ class TestPushSchedulerNegative: def test_update_connector_output_unknown_request_is_noop(self): """Idempotent cleanup: clearing a request that was never staged - must not raise or mutate other state. - """ + must not raise or mutate other state.""" sched = make_nixl_push_scheduler() _stub_sw_clipping(sched) @@ -1093,8 +1071,7 @@ class TestPushWriterNegative: def test_pop_matching_registration_no_match_when_base_ids_differ(self): """A registration whose base id (after stripping the random suffix) - does NOT match the lookup request_id must not be popped. - """ + does NOT match the lookup request_id must not be popped.""" w = _StubWriterWorker.fresh() # Two unrelated requests: different base UUIDs, so stripping the # trailing ``-<8 hex>`` suffix still yields different base ids. @@ -1110,8 +1087,7 @@ class TestPushWriterNegative: def test_handle_push_reg_with_non_dict_payload_is_dropped(self, caplog): """msgpack-encoded non-dict payload (e.g. a list) should be - dropped without raising. - """ + dropped without raising.""" caplog.set_level( logging.CRITICAL, logger=("vllm.distributed.kv_transfer.kv_connector.v1.nixl.push_worker"), @@ -1139,8 +1115,7 @@ class TestPushWriterNegative: def test_handle_push_reg_idempotent_for_same_request_id(self): """Receiving the same PUSH_REG twice (e.g. P retries after a - flake) keeps the entry staged exactly once and never fires. - """ + flake) keeps the entry staged exactly once and never fires.""" w = _StubWriterWorker.fresh() notif = PUSH_REG_NOTIF_PREFIX + msgspec.msgpack.encode( _registration_data("req-dup") @@ -1155,8 +1130,7 @@ class TestPushWriterNegative: """``get_transfer_results`` must enqueue every completed request in ``done_sending`` so the writer can drop stale matching state. Unlike the happy-path test, this verifies the *cardinality*: N - completed requests -> N evictions, in order. - """ + completed requests -> N evictions, in order.""" w = _StubWriterWorker.fresh() with patch.object( NixlPushConnectorWorker.__mro__[1], @@ -1179,8 +1153,7 @@ class TestPushWriterNegative: def test_empty_transfer_results_do_not_enqueue_eviction(self): """If there's nothing newly done, no eviction should be enqueued. The wake event IS still set because ``get_finished`` always wakes - the writer to drain notifs. - """ + the writer to drain notifs.""" w = _StubWriterWorker.fresh() with patch.object( NixlPushConnectorWorker.__mro__[1], @@ -1221,8 +1194,7 @@ class TestPushWriterNegative: def test_get_new_notifs_unknown_request_is_logged_and_skipped(self, caplog): """A completion notif for a request the worker doesn't know - about should be logged but not crash. - """ + about should be logged but not crash.""" caplog.set_level( logging.CRITICAL, logger=("vllm.distributed.kv_transfer.kv_connector.v1.nixl.push_worker"), @@ -1254,8 +1226,7 @@ class TestPushWriterNegative: def test_get_new_notifs_extends_lease_on_heartbeat(self): """``HB:`` notifs forwarded by the writer thread must extend the leases of tracked P-side requests on the engine main thread, and - ignore request IDs that aren't being tracked. - """ + ignore request IDs that aren't being tracked.""" w = _StubWriterWorker.fresh() w.transfer_topo = MagicMock() # _handle_heartbeat reads ``self._lease_extension`` (set in the @@ -1291,13 +1262,11 @@ class TestPushWriterNegative: class TestPushPipelineParallel: """PP-sharded producer: per-stage completion counting, pp_size plumbing, - and remote-region slicing. - """ + and remote-region slicing.""" def test_completion_waits_for_one_notif_per_pp_stage(self): """Each PP stage WRITEs its own layers and sends one notif; D must - collect pp_size notifs before reporting the recv done. - """ + collect pp_size notifs before reporting the recv done.""" w = _StubWriterWorker.fresh() w.transfer_topo = MagicMock() request_id = "req-pp-2" @@ -1318,8 +1287,7 @@ class TestPushPipelineParallel: def test_req_meta_reads_pp_size_from_kv_transfer_params(self): """D learns the producer's pp_size from kv_transfer_params (forwarded - by the proxy) and defaults to 1 when absent. - """ + by the proxy) and defaults to 1 when absent.""" metadata = NixlConnectorMetadata() params = { "remote_block_ids": ([0],), @@ -1342,8 +1310,7 @@ class TestPushPipelineParallel: this worker holds only a contiguous layer slice; add_remote_agent trims the remote region list to [offset : offset + num_local_regions] before building descriptors. We stop right after the slice via a - sentinel on the next collaborator call. - """ + sentinel on the next collaborator call.""" block_len = 4096 * 16 w = _StubWriterWorker.fresh() # seeds writer-thread state for teardown w.pp_size = 2 @@ -1385,8 +1352,7 @@ class TestPushWriterMlaReplication: """MLA latent KV is replicated across D's TP ranks, so when D_TP > P_TP (``tp_ratio < 0``) the producer must *WRITE* the latent into every D rank it handshook -- not write one and merely notify the rest, which would - leave the un-written ranks decoding against stale KV. - """ + leave the un-written ranks decoding against stale KV.""" @staticmethod def _mla_worker_writing_to(d_ranks): @@ -1611,8 +1577,7 @@ class TestPushPrefixCaching: def test_partial_prefix_hit_end_trims_producer_blocks(self): """D registered only its 2 uncomputed suffix blocks; P finished the - full 5-block sequence. P must WRITE its LAST 2 blocks into D's slots. - """ + full 5-block sequence. P must WRITE its LAST 2 blocks into D's slots.""" w, _ = self._worker_driving_xfer() reg = _registration_data("req-pc", local_block_ids=([500, 501],)) diff --git a/tests/v1/kv_connector/unit/test_nixl_rocm_gpu_mem_diag.py b/tests/v1/kv_connector/unit/test_nixl_rocm_gpu_mem_diag.py index bab9ed6e0f..da8be07157 100644 --- a/tests/v1/kv_connector/unit/test_nixl_rocm_gpu_mem_diag.py +++ b/tests/v1/kv_connector/unit/test_nixl_rocm_gpu_mem_diag.py @@ -171,8 +171,7 @@ def test_gpu_memory_nixl_hma(model_name, sw_size): @pytest.mark.parametrize("model_name", ["google/gemma-3-1b-it"]) def test_gpu_memory_no_nixl_baseline(model_name): """Same workload without NixlConnector. Comparing driver-level memory - between this and test_gpu_memory_nixl_hma isolates UCX/NIXL impact. - """ + between this and test_gpu_memory_nixl_hma isolates UCX/NIXL impact.""" from vllm import LLM, SamplingParams from vllm.distributed.parallel_state import cleanup_dist_env_and_memory diff --git a/tests/v1/kv_connector/unit/test_nixl_simple_cpu_offload.py b/tests/v1/kv_connector/unit/test_nixl_simple_cpu_offload.py index 7044f9f0be..bdab91a21f 100644 --- a/tests/v1/kv_connector/unit/test_nixl_simple_cpu_offload.py +++ b/tests/v1/kv_connector/unit/test_nixl_simple_cpu_offload.py @@ -213,8 +213,7 @@ def _multi_connector_config(swa_enabled: bool = False): def test_nixl_wins_load_over_cpu_offload(): """When NixlConnector (index 0) has matched tokens from a remote prefill, it should win the load: Nixl metadata tracks the recv while CPU offload metadata has no load - scheduled. - """ + scheduled.""" vllm_config, kv_cache_config = _multi_connector_config() scheduler = create_scheduler(vllm_config, kv_cache_config=kv_cache_config) mc = scheduler.connector @@ -251,8 +250,7 @@ def test_nixl_wins_load_over_cpu_offload(): @patch(NIXL_WRAPPER_PATCH, FakeNixlWrapper) def test_cpu_offload_wins_when_nixl_has_no_match(): """When NixlConnector returns 0 matched tokens and SimpleCPUOffloadConnector has a - CPU cache hit, the CPU offload connector (index 1) wins the load. - """ + CPU cache hit, the CPU offload connector (index 1) wins the load.""" vllm_config, kv_cache_config = _multi_connector_config() scheduler = create_scheduler(vllm_config, kv_cache_config=kv_cache_config) mc = scheduler.connector @@ -311,8 +309,7 @@ def test_cpu_offload_wins_when_nixl_has_no_match(): def test_request_finished_no_async_save(swa_enabled: bool): """A normal request (no P/D) produces no async save from either connector. MultiConnector returns (False, None) via both request_finished and - request_finished_all_groups, and cleans up _requests_to_connector. - """ + request_finished_all_groups, and cleans up _requests_to_connector.""" from vllm.v1.request import RequestStatus vllm_config, kv_cache_config = _multi_connector_config(swa_enabled=swa_enabled) diff --git a/tests/v1/kv_connector/unit/test_offloading_connector.py b/tests/v1/kv_connector/unit/test_offloading_connector.py index 1d99ac0d11..db7ecca621 100644 --- a/tests/v1/kv_connector/unit/test_offloading_connector.py +++ b/tests/v1/kv_connector/unit/test_offloading_connector.py @@ -321,8 +321,7 @@ def test_cpu_offloading( @pytest.mark.skipif(not current_platform.is_cuda(), reason="Requires CUDA") def test_cpu_offloading_metrics() -> None: """Verify that offloading Prometheus metrics (new flat and deprecated - labeled) are emitted after stores and loads. - """ + labeled) are emitted after stores and loads.""" extra_config: dict = { "cpu_bytes_to_use": 500 << 20, "block_size": CPU_BLOCK_SIZES, @@ -511,8 +510,7 @@ def test_tiering_offloading() -> None: def test_fs_tiering_offloading(tmp_path) -> None: """Tests OffloadingConnector with TieringOffloadingSpec - + fs secondary tier. - """ + + fs secondary tier.""" extra_config: dict = { "cpu_bytes_to_use": 1 << 30, "block_size": CPU_BLOCK_SIZES, diff --git a/tests/v1/kv_connector/unit/test_remote_prefill_lifecycle.py b/tests/v1/kv_connector/unit/test_remote_prefill_lifecycle.py index 9ee93c8894..4f82e828d3 100644 --- a/tests/v1/kv_connector/unit/test_remote_prefill_lifecycle.py +++ b/tests/v1/kv_connector/unit/test_remote_prefill_lifecycle.py @@ -704,8 +704,7 @@ def test_async_load_reserves_blocks_for_inflight(): def test_async_loads_both_admitted_when_pool_fits(): """Sanity: with a pool large enough, the reservation gate admits both async - loads (it is not over-conservative). - """ + loads (it is not over-conservative).""" vllm_config = create_vllm_config() BLOCK_SIZE = vllm_config.cache_config.block_size scheduler = create_scheduler(vllm_config, num_blocks=64) diff --git a/tests/v1/kv_connector/unit/test_simple_cpu_offload_connector.py b/tests/v1/kv_connector/unit/test_simple_cpu_offload_connector.py index f9f7902329..af4c7858fc 100644 --- a/tests/v1/kv_connector/unit/test_simple_cpu_offload_connector.py +++ b/tests/v1/kv_connector/unit/test_simple_cpu_offload_connector.py @@ -129,8 +129,7 @@ def _make_ring_kv_cache_config(num_blocks: int = 16) -> KVCacheConfig: def test_ring_scratch_group_is_accepted_and_never_offloaded() -> None: """The ring group's capacity is not a token granularity, it holds no - hashed blocks, and it never participates in CPU hits. - """ + hashed blocks, and it never participates in CPU hits.""" vllm_config = create_vllm_config( kv_connector="SimpleCPUOffloadConnector", kv_role="kv_both", diff --git a/tests/v1/kv_connector/unit/test_tp_mapping.py b/tests/v1/kv_connector/unit/test_tp_mapping.py index 201950705a..3ddc568a52 100644 --- a/tests/v1/kv_connector/unit/test_tp_mapping.py +++ b/tests/v1/kv_connector/unit/test_tp_mapping.py @@ -235,8 +235,7 @@ class TestMambaPlanSplitHandles: def test_hetero_block_size_splits(self): """With a block-size ratio, single-source FA sub-block descs pass - through whole; SSM descs are unexpanded and split per source. - """ + through whole; SSM descs are unexpanded and split per source.""" plan = TPMapping( source_ranks_per_group=((0,), (0, 1)), all_source_ranks=(0, 1), @@ -271,8 +270,7 @@ class TestMambaPlanSplitHandles: def test_hetero_block_size_head_sharded_asserts(self): """Head-sharded FA reads (multiple FA sources) are incompatible with - a block-size mismatch and must fail loudly. - """ + a block-size mismatch and must fail loudly.""" plan = TPMapping( source_ranks_per_group=((0, 1), (0, 1)), all_source_ranks=(0, 1), diff --git a/tests/v1/kv_offload/cpu/policies/test_factory.py b/tests/v1/kv_offload/cpu/policies/test_factory.py index 35897a9236..338ec18d0e 100644 --- a/tests/v1/kv_offload/cpu/policies/test_factory.py +++ b/tests/v1/kv_offload/cpu/policies/test_factory.py @@ -15,8 +15,7 @@ from vllm.v1.kv_offload.cpu.policies.lru import LRUCachePolicy class _DummyCachePolicy(CachePolicy): """Minimal CachePolicy for CachePolicyFactory registration tests. Loaded by module path, so it must be importable at module scope (mirrors - tests/v1/kv_offload/test_factory.py's SingleArgExternalOffloadingSpec). - """ + tests/v1/kv_offload/test_factory.py's SingleArgExternalOffloadingSpec).""" def __init__(self, cache_capacity: int) -> None: self.cache_capacity = cache_capacity @@ -55,8 +54,7 @@ class TestCachePolicyFactory: def test_pre_registered_policies_can_be_imported(self): """If someone moves a policy module but forgets to update - factory.py, CI fails. - """ + factory.py, CI fails.""" for name in CachePolicyFactory._registry: cls = CachePolicyFactory._registry[name]() assert issubclass(cls, CachePolicy) @@ -90,8 +88,7 @@ class TestCachePolicyFactory: register_cache_policy() call -- this is how external projects integrate a custom CachePolicy without forking/patching vLLM. Mirrors tests/v1/kv_offload/test_factory.py's - test_dynamic_load_via_spec_module_path. - """ + test_dynamic_load_via_spec_module_path.""" policy_cls = CachePolicyFactory.get_cache_policy_cls( "_DummyCachePolicy", "tests.v1.kv_offload.cpu.policies.test_factory" ) @@ -99,8 +96,7 @@ class TestCachePolicyFactory: def test_manager_resolves_policy_via_module_path(self): """End-to-end: CPUOffloadingManager resolves an unregistered policy - purely from cache_policy_module_path. - """ + purely from cache_policy_module_path.""" manager = CPUOffloadingManager( num_chunks=4, cache_policy="_DummyCachePolicy", @@ -110,7 +106,6 @@ class TestCachePolicyFactory: def test_unregistered_policy_without_module_path_raises(self): """eviction_policy not in registry + no cache_policy_module_path -> - ValueError, same shape as the OffloadingSpecFactory error path. - """ + ValueError, same shape as the OffloadingSpecFactory error path.""" with pytest.raises(ValueError, match="Unknown cache policy"): CachePolicyFactory.get_cache_policy_cls("nonexistent", None) diff --git a/tests/v1/kv_offload/cpu/test_canonical_layout.py b/tests/v1/kv_offload/cpu/test_canonical_layout.py index d4e383801c..4594e1eb09 100644 --- a/tests/v1/kv_offload/cpu/test_canonical_layout.py +++ b/tests/v1/kv_offload/cpu/test_canonical_layout.py @@ -126,8 +126,7 @@ def _canonical_handler(gpu_tensor, cpu_tensor, mapping, gpu_to_cpu): def test_gpu_roundtrip_assembles_canonical_page_across_ranks(): """Two TP2-style rank handlers must scatter into one shared canonical CPU page such that each rank reloads bit-exact and a whole-page (TP1) - reader sees both shards — the cross-topology contract. - """ + reader sees both shards — the cross-topology contract.""" torch.manual_seed(0) num_blocks = 4 gpu_rank = [ @@ -204,8 +203,7 @@ def _nhd_shard_mapping(tp: int, rank: int) -> CanonicalPageMapping: def _head_shard(full_kv: torch.Tensor, tp: int, rank: int) -> torch.Tensor: """This rank's local page rows out of the (blocks, 2, tokens, heads, - head_bytes) ground truth. - """ + head_bytes) ground truth.""" local_heads = _TOTAL_HEADS // tp shard = full_kv[:, :, :, rank * local_heads : (rank + 1) * local_heads, :] return shard.reshape(full_kv.shape[0], -1).contiguous() @@ -216,8 +214,7 @@ def _head_shard(full_kv: torch.Tensor, tp: int, rank: int) -> torch.Tensor: def test_cross_topology_roundtrip(writer_tp: int, reader_tp: int): """KV written at one tp must be readable at another: writer ranks scatter head shards into a shared canonical region, reader ranks gather their own - shards, and every reader must see the writers' ground-truth bytes. - """ + shards, and every reader must see the writers' ground-truth bytes.""" torch.manual_seed(0) num_blocks = 3 full_kv = torch.randint( diff --git a/tests/v1/kv_offload/cpu/test_shared_offload_region.py b/tests/v1/kv_offload/cpu/test_shared_offload_region.py index 1d6a78f9e7..4f22d122db 100644 --- a/tests/v1/kv_offload/cpu/test_shared_offload_region.py +++ b/tests/v1/kv_offload/cpu/test_shared_offload_region.py @@ -167,8 +167,7 @@ def _mp_race_construct_and_write( ) -> None: """Race to construct a SharedOffloadRegion, write fill_value, then wait for the parent's cleanup signal before tearing down. The wait gives the - parent a window to read the raw mmap before the creator removes the file. - """ + parent a window to read the raw mmap before the creator removes the file.""" try: region = SharedOffloadRegion( engine_id=engine_id, @@ -197,8 +196,7 @@ def _mp_barrier_construct_and_hold( replicated: bool = False, ) -> None: """Construct with a real cross-process barrier, write, then hold the - mapping (no cleanup) until the parent SIGKILLs this process. - """ + mapping (no cleanup) until the parent SIGKILLs this process.""" try: populate_calls = 0 get_populate_write_fn = region_module._get_populate_write_fn @@ -252,8 +250,7 @@ def iid(): def test_create_next_worker_view_shape_and_stride(iid): """Returned tensor must have shape (num_chunks, tensor_page_size) and - stride (row_stride, 1) where row_stride = cpu_page_size * num_workers. - """ + stride (row_stride, 1) where row_stride = cpu_page_size * num_workers.""" with _region(iid, num_chunks=4, cpu_page_size=2 * PAGE_SIZE) as r: t = r.create_next_worker_view(PAGE_SIZE) assert t.shape == (4, PAGE_SIZE) @@ -293,8 +290,7 @@ def test_create_next_worker_view_row_stride_with_multiple_workers(iid): def test_create_next_worker_view_cursor_advances(iid): """Each create_next_worker_view call must advance _worker_offset by - tensor_page_size. - """ + tensor_page_size.""" with _region(iid, cpu_page_size=3 * PAGE_SIZE) as r: assert r._worker_offset == 0 r.create_next_worker_view(PAGE_SIZE) @@ -351,8 +347,7 @@ def test_create_next_worker_view_overflow_does_not_mutate_cursor(iid): def test_create_next_worker_view_write_visible_in_raw_mmap(iid): """Writes into a create_next_worker_view view must appear at the correct - raw mmap offset - """ + raw mmap offset""" with _region(iid, num_chunks=4) as r: t = r.create_next_worker_view(PAGE_SIZE) t[2, :] = 42 # write to chunk row 2 @@ -385,8 +380,7 @@ def test_create_next_worker_view_multi_tensor_layout(iid): def test_create_next_worker_view_multiprocess_slots(iid): """Each worker process calls create_next_worker_view and writes distinct data; - the parent verifies each slot lands at the correct interleaved offset. - """ + the parent verifies each slot lands at the correct interleaved offset.""" num_workers = 2 num_chunks = 4 @@ -671,8 +665,7 @@ def test_multi_worker_race_shared_memory_visible(iid): def test_multiprocess_race_construct_and_write(iid): """N processes race to construct the same SharedOffloadRegion, each writes - fill_value = rank+1 into their slot; parent verifies interleaved layout. - """ + fill_value = rank+1 into their slot; parent verifies interleaved layout.""" num_workers = 4 num_chunks = 3 @@ -798,8 +791,7 @@ def test_cleanup_unregisters_every_pinned_chunk(iid, monkeypatch): def test_cleanup_after_create_next_worker_view_releases_mmap(iid): """cleanup() must close the mmap even after create_next_worker_view was called. create_next_worker_view returns a view that shares storage with _base; both must be - released before mmap.close() can succeed. - """ + released before mmap.close() can succeed.""" r = _make_region(iid) mmap_obj = r.mmap_obj @@ -978,8 +970,7 @@ def test_ftruncate_failure_cleans_up_creator(monkeypatch): def test_backing_file_unlinked_after_barrier(iid): """The file must exist until the barrier releases (late joiners need the - name) and be gone right after, so no exit path can leak it. - """ + name) and be gone right after, so no exit path can leak it.""" path = f"/dev/shm/vllm_offload_{iid}.mmap" seen_at_barrier = [] @@ -1001,8 +992,7 @@ def test_backing_file_unlinked_after_barrier(iid): def test_barrier_failure_unlinks_creator_and_raises(iid): """A failed rendezvous must remove the creator's file and re-raise, not - leave a stub that wedges the next start in _wait_for_file_size. - """ + leave a stub that wedges the next start in _wait_for_file_size.""" path = f"/dev/shm/vllm_offload_{iid}.mmap" with pytest.raises(RuntimeError, match="peer died"): _make_region(iid, barrier=MagicMock(side_effect=RuntimeError("peer died"))) @@ -1012,8 +1002,7 @@ def test_barrier_failure_unlinks_creator_and_raises(iid): @pytest.mark.parametrize("replicated", [False, True]) def test_mp_barrier_unlinks_file_and_survives_sigkill(iid, replicated): """With a real cross-process barrier every worker maps one shared inode, - the name is gone while they run, and SIGKILL leaks nothing. - """ + the name is gone while they run, and SIGKILL leaks nothing.""" num_workers = 2 path = f"/dev/shm/vllm_offload_{iid}.mmap" ctx = get_mp_context() @@ -1052,8 +1041,7 @@ def test_mp_barrier_unlinks_file_and_survives_sigkill(iid, replicated): @pytest.mark.parametrize("failure_phase", ["shm", "memory", "population"]) def test_setup_failure_before_barrier_releases_peers(iid, monkeypatch, failure_phase): """A worker that dies before the rendezvous must still arrive at the - barrier, or its peers block in the collective until it times out. - """ + barrier, or its peers block in the collective until it times out.""" failure = MagicMock(side_effect=ValueError("Insufficient space")) memory_check = failure if failure_phase == "memory" else None if failure_phase == "shm": @@ -1084,8 +1072,7 @@ def test_setup_failure_before_barrier_releases_peers(iid, monkeypatch, failure_p def test_mmap_failure_unlinks_creator_before_releasing_peers(iid, monkeypatch): """A creator that fails after sizing the file must drop it before arriving - at the barrier, so the next start does not land on a stale file. - """ + at the barrier, so the next start does not land on a stale file.""" path = f"/dev/shm/vllm_offload_{iid}.mmap" monkeypatch.setattr("mmap.mmap", MagicMock(side_effect=OSError("mmap"))) seen_at_barrier = [] @@ -1098,8 +1085,7 @@ def test_mmap_failure_unlinks_creator_before_releasing_peers(iid, monkeypatch): def test_barrier_release_failure_keeps_original_error(iid, monkeypatch): """When releasing the peers fails too, the setup error that explains the - failure must be the one that propagates. - """ + failure must be the one that propagates.""" import vllm.v1.kv_offload.cpu.shared_offload_region as region monkeypatch.setattr( diff --git a/tests/v1/kv_offload/tiering/p2p/test_manager.py b/tests/v1/kv_offload/tiering/p2p/test_manager.py index 2e8e9ff4be..aceec1cd8f 100644 --- a/tests/v1/kv_offload/tiering/p2p/test_manager.py +++ b/tests/v1/kv_offload/tiering/p2p/test_manager.py @@ -48,8 +48,7 @@ def _remote_prefiller_kv_params( kv_request_id: str = "req-1", ) -> dict: """Decoder-side kv_transfer_params: ``remote_prefiller`` sub-dict carries - kv_request_id + remote_host + remote_port. - """ + kv_request_id + remote_host + remote_port.""" return { "remote_prefiller": { "kv_request_id": kv_request_id, @@ -65,8 +64,7 @@ def _remote_kv_source_kv_params( kv_request_id: str = "req-1", ) -> dict: """Symmetric-P2P consumer kv_transfer_params: ``remote_kv_source`` sub-dict has - the same shape as ``remote_prefiller`` (kv_request_id + remote_host + port). - """ + the same shape as ``remote_prefiller`` (kv_request_id + remote_host + port).""" return { "remote_kv_source": { "kv_request_id": kv_request_id, @@ -78,8 +76,7 @@ def _remote_kv_source_kv_params( def _remote_decoder_kv_params(kv_request_id: str = "req-1") -> dict: """Prefiller-side kv_transfer_params: ``remote_decoder`` sub-dict carries - kv_request_id only. - """ + kv_request_id only.""" return {"remote_decoder": {"kv_request_id": kv_request_id}} @@ -244,8 +241,7 @@ class TestLookup: def test_lookup_returns_miss_without_prefill_key(self): """No ``remote_prefiller`` sub-dict means the request was not routed for remote prefill — local prefill should run instead, so lookup() - returns MISS even when a stale ``remote_decoder`` block is present. - """ + returns MISS even when a stale ``remote_decoder`` block is present.""" mgr = _make_manager() ctx = _req_context(kv_params=_remote_decoder_kv_params()) assert mgr.lookup(b"key", ctx) is LookupResult.MISS @@ -313,8 +309,7 @@ class TestServeExternalRequests: def test_flushes_failed_serve_ctxs_then_serves_each_session(self): """serve_external_requests releases the failed serves left by reaped sessions via parent.on_request_finished (clearing the - queue), then delegates to every live session with the same parent. - """ + queue), then delegates to every live session with the same parent.""" mgr = _make_manager() ctx = ReqContext(req_id="p2p:peer:req-1:lu1") mgr._failed_serve_ctxs = [ctx] @@ -368,8 +363,7 @@ class TestSubmitStore: def test_no_binding_yet_parks_in_unbound_stores(self): """submit_store without a bound session buffers the batch keyed by kv_request_id; no session is pre-created (peer_id is unknown - to the producer at store time). - """ + to the producer at store time).""" mgr = _make_manager() job = _job_metadata( job_id=1, @@ -396,8 +390,7 @@ class TestSubmitStore: def test_routes_to_bound_session(self): """If a session has already received FetchMsg for this kv_request_id (so _kv_to_session is populated), submit_store - forwards directly to that session rather than re-buffering. - """ + forwards directly to that session rather than re-buffering.""" mgr = _make_manager() bound = _FakeSession(peer_id="10.0.0.1:8000", connected=True) mgr._kv_to_session["req-1"] = bound # type: ignore[assignment] @@ -420,8 +413,7 @@ class TestSubmitStore: def test_extra_top_level_keys_are_ignored(self): """Producer-side kv_transfer_params should not pre-create a session even when a stale caller still passes a top-level - ``remote_host``/``remote_port`` next to ``remote_decoder``. - """ + ``remote_host``/``remote_port`` next to ``remote_decoder``.""" mgr = _make_manager() params = _remote_decoder_kv_params() params["remote_host"] = "stale" @@ -465,8 +457,7 @@ class TestSubmitLoad: def test_happy_path_with_active_session(self): """When the peer's session exists, submit_load forwards to - session.request_blocks and does NOT add a finished result yet. - """ + session.request_blocks and does NOT add a finished result yet.""" mgr = _make_manager() peer_id = "10.0.0.1:8000" existing = _FakeSession(peer_id=peer_id, connected=True) @@ -486,8 +477,7 @@ class TestSubmitLoad: def test_missing_consumer_flag_fails(self): """Peer fields present but neither do_remote_prefill nor do_p2p_fetch is set — submit_load fails the job rather than - emit a stray FetchMsg. - """ + emit a stray FetchMsg.""" mgr = _make_manager() params = { "remote_host": "10.0.0.1", @@ -531,8 +521,7 @@ class TestOnRequestFinished: def test_decoder_side_calls_session_finish_request(self): """Decoder-side finish (``remote_prefiller`` set) still routes via peer_id because the consumer addresses the producer it loaded from. The - session's finish_request cancels the client-role load. - """ + session's finish_request cancels the client-role load.""" mgr = _make_manager() peer_id = "10.0.0.1:8000" session = _FakeSession(peer_id=peer_id) @@ -544,8 +533,7 @@ class TestOnRequestFinished: def test_p2p_consumer_side_calls_session_finish_request(self): """Symmetric-P2P consumer finish (``remote_kv_source`` set) routes via peer_id so the session drops any pending lookups (cancel_lookups) and - cancels any inbound load. - """ + cancels any inbound load.""" mgr = _make_manager() peer_id = "10.0.0.1:8000" session = _FakeSession(peer_id=peer_id) @@ -556,8 +544,7 @@ class TestOnRequestFinished: def test_prefiller_bound_id_routes_via_kv_to_session(self): """Prefiller-side finish for an id whose session is already bound - (FetchMsg received) routes via _kv_to_session and pops the entry. - """ + (FetchMsg received) routes via _kv_to_session and pops the entry.""" mgr = _make_manager() bound = _FakeSession(peer_id="some-peer:1", connected=True) mgr._kv_to_session["req-1"] = bound # type: ignore[assignment] @@ -571,8 +558,7 @@ class TestOnRequestFinished: and no session binding is a no-op on `_unbound_stores`. The parked batches survive until a peer fetches them or the `_reap_unbound_stores` timeout fires — `on_request_finished` - must not evict them. - """ + must not evict them.""" from vllm.v1.kv_offload.tiering.p2p.manager import _UnboundStoreBatch mgr = _make_manager() @@ -742,8 +728,7 @@ class TestGetFinished: def test_reap_fails_probes(self): """A reaped session's in-flight lookups land in _failed_req_ids so - the consumer's lookup() returns MISS instead of RETRY forever. - """ + the consumer's lookup() returns MISS instead of RETRY forever.""" class FakeData: def remove_remote_peer(self, pid): @@ -778,8 +763,7 @@ class TestGetFinished: def test_unbound_store_reaped_after_timeout(self): """Unbound stores past the reap deadline surface as failed and their kv_request_id lands in _reaped_stores so a late FetchMsg is rejected - instead of parking demand nothing can satisfy. - """ + instead of parking demand nothing can satisfy.""" from vllm.v1.kv_offload.tiering.p2p.manager import _UnboundStoreBatch mgr = self._make() @@ -801,8 +785,7 @@ class TestGetFinished: def test_submit_store_parks_unbound_batch(self): """submit_store on an unbound id appends a batch with a fresh - submitted_at stamp so the unbound-store sweep can age it out. - """ + submitted_at stamp so the unbound-store sweep can age it out.""" mgr = _make_manager() job = _job_metadata( job_id=1, kv_params=_remote_decoder_kv_params(kv_request_id="req-1") @@ -824,21 +807,18 @@ class TestHasPendingWork: """has_pending_work() must always return True so the engine keeps ticking the offload pipeline — that's the only thread driving _control.poll() (incoming peer connects) and session.poll() - (incoming fetch messages on existing sessions). - """ + (incoming fetch messages on existing sessions).""" def test_returns_true_unconditionally_to_keep_engine_ticking(self): """Even with no sessions and no jobs, has_pending_work() returns True so the engine keeps calling get_finished_jobs(), which is - what drives _control.poll() for inbound peer connects. - """ + what drives _control.poll() for inbound peer connects.""" mgr = _make_manager() assert mgr.has_pending_work() is True def test_returns_true_even_when_sessions_present(self): """The result is the same regardless of session state — there is - no 'idle' branch. - """ + no 'idle' branch.""" mgr = _make_manager() mgr._sessions["peer:1"] = _FakeSession(peer_id="peer:1") # type: ignore[assignment] assert mgr.has_pending_work() is True @@ -851,8 +831,7 @@ class TestHasPendingWork: class _ShutdownFakeData: """Fake DataTransport that records cancel/poll/close calls and - drives the wait-cancel loop with a scriptable `still` queue. - """ + drives the wait-cancel loop with a scriptable `still` queue.""" def __init__(self, still_queue: list[list[int]] | None = None) -> None: # Each list in still_queue is the set of ids the next @@ -896,8 +875,7 @@ class _ShutdownFakeControl: class TestShutdownDrain: """shutdown() drains inflight transfers via cancel(mode='wait') before calling _data.close(), with a 3s deadline fallback to - cancel(mode='immediate'). - """ + cancel(mode='immediate').""" def _prep( self, @@ -1316,8 +1294,7 @@ class _RecordingConn: class TestAcceptNewPeers: """A second inbound from an already-connected peer is rejected and the - new conn is closed; the existing session is left untouched. - """ + new conn is closed; the existing session is left untouched.""" def test_duplicate_connection_is_closed_and_existing_session_untouched(self): mgr = _make_manager() @@ -1339,8 +1316,7 @@ class TestAcceptNewPeers: """An inbound conn from a peer with no existing session creates a fresh connected session and registers it under conn.peer_id. The prefiller has no pre-created pending session anymore — the - first signal of a peer's existence is its inbound connection. - """ + first signal of a peer's existence is its inbound connection.""" class FakeData: block_len = 4096 @@ -1387,8 +1363,7 @@ class TestAcceptNewPeers: class TestPollOnce: """_poll_once must drain control, accept new peers, poll every session, - surface results, and reap dead sessions — in that order. - """ + surface results, and reap dead sessions — in that order.""" def test_orchestrates_accept_poll_and_reap(self): mgr = _make_manager() @@ -1444,8 +1419,7 @@ class TestPollOnce: def test_new_fetch_id_binds_and_replays_unbound_batches(self): """When session.poll() reports a kv_request_id whose FetchMsg arrived this tick, the manager binds it to that session and - replays every parked submit_store batch via add_stored_blocks. - """ + replays every parked submit_store batch via add_stored_blocks.""" from vllm.v1.kv_offload.tiering.p2p.manager import _UnboundStoreBatch mgr = _make_manager() @@ -1479,8 +1453,7 @@ class TestPollOnce: def test_new_fetch_id_with_no_unbound_still_binds(self): """A FetchMsg for a kv_request_id with no parked batches still - records the binding so subsequent submit_stores route fast. - """ + records the binding so subsequent submit_stores route fast.""" mgr = _make_manager() peer = "10.0.0.1:8000" sess = _FakeSession( @@ -1503,8 +1476,7 @@ class TestPollOnce: def test_failed_load_records_kv_request_id(self): """A LoadResult(success=False) from session.poll() must add its - kv_request_id to _failed_req_ids so future lookups return MISS. - """ + kv_request_id to _failed_req_ids so future lookups return MISS.""" mgr = _make_manager() peer = "10.0.0.1:8000" sess = _FakeSession( @@ -1568,8 +1540,7 @@ class TestDrainJobs: def test_logs_warning_after_5s_then_completes(self, monkeypatch): """A session that stays inflight past 5s triggers the warning, and - once it clears the loop returns. - """ + once it clears the loop returns.""" mgr = _make_manager() mgr._control = _DrainCtrl() # type: ignore[assignment] sess = _FakeSession(peer_id="peer:1") @@ -1627,8 +1598,7 @@ class TestDrainJobs: class TestOnScheduleEnd: def test_is_noop(self): """on_schedule_end is a documented no-op; just confirm it doesn't - raise and doesn't mutate state. - """ + raise and doesn't mutate state.""" mgr = _make_manager() before_sessions = dict(mgr._sessions) before_jobs = list(mgr._finished_jobs) @@ -1654,8 +1624,7 @@ class TestConnectionDeathMidTransfer: prefiller-side store no longer travels through the session at store time (it's parked in _unbound_stores keyed by kv_request_id), so its cleanup on connection death is via on_request_finished or the - unbound-store timeout — covered separately below. - """ + unbound-store timeout — covered separately below.""" def test_dead_connection_with_pending_work_surfaces_failures(self): mgr_a, mgr_b = _build_paired_managers() diff --git a/tests/v1/kv_offload/tiering/p2p/test_sessions.py b/tests/v1/kv_offload/tiering/p2p/test_sessions.py index ff5641134e..a09445668f 100644 --- a/tests/v1/kv_offload/tiering/p2p/test_sessions.py +++ b/tests/v1/kv_offload/tiering/p2p/test_sessions.py @@ -626,8 +626,7 @@ class TestClientFlows: """collect_results / has_active_loads use the _active_loads work-list, armed when a fetch is issued and discarded exactly when its load clears — a probe-only request never enters it, and completion empties - it while the entry may briefly linger for GC. - """ + it while the entry may briefly linger for GC.""" session, conn, _ = _make_session() _activate(session, conn) client = session._client @@ -704,8 +703,7 @@ class TestClientFlows: def test_load_abort_ack_clears_request(self): """After load timeout sends AbortFetch, an arriving AbortAckMsg from the peer surfaces the failure cleanly and removes the request from - _requests — covers the on_abort_ack arrival path. - """ + _requests — covers the on_abort_ack arrival path.""" session, conn, _ = _make_session() _activate(session, conn) session.request_blocks( @@ -742,8 +740,7 @@ class TestLookupFlow: def test_aggregate_flush_resolve_round_trip(self): """register_lookup → flush sends one LookupMsg → response resolves entries → register_lookup returns the cached bool on - every call, and repeat probes never re-issue a LookupMsg. - """ + every call, and repeat probes never re-issue a LookupMsg.""" session, conn, _ = _make_session() _activate(session, conn) @@ -796,8 +793,7 @@ class TestLookupFlow: def test_request_blocks_clears_probe_cache(self): """A resolved HIT probe is popped when its fetch is issued, so a re-scheduled request re-probes instead of trusting the stale True - (the served block is unpinned and may have been evicted). - """ + (the served block is unpinned and may have been evicted).""" session, conn, _ = _make_session() _activate(session, conn) @@ -883,8 +879,7 @@ class TestLookupFlow: def test_multiple_lookup_msgs_across_steps(self): """A request's block set may be discovered across scheduler steps: each step that registers new keys flushes its own LookupMsg for - the same kv_request_id, carrying only the newly-probed keys. - """ + the same kv_request_id, carrying only the newly-probed keys.""" session, conn, _ = _make_session() _activate(session, conn) @@ -912,8 +907,7 @@ class TestLookupFlow: def test_split_response_resolves_across_messages(self): """Producer may answer one LookupMsg's keys across multiple - LookupRespMsgs — pairs are self-describing so each lands. - """ + LookupRespMsgs — pairs are self-describing so each lands.""" session, conn, _ = _make_session() _activate(session, conn) @@ -960,8 +954,7 @@ class TestLookupFlow: def test_finish_after_flushed_lookup_sends_empty_fetch(self): """LookupMsg flushed but no FetchMsg sent (all-miss case) → finish_request emits an empty FetchMsg so the peer can drop its - lookup state and call parent.on_request_finished. - """ + lookup state and call parent.on_request_finished.""" session, conn, _ = _make_session() _activate(session, conn) @@ -979,8 +972,7 @@ class TestLookupFlow: def test_finish_without_flushed_lookup_sends_no_fetch(self): """No LookupMsg was ever sent → finish_request must not emit an - empty FetchMsg (the peer has no state to release). - """ + empty FetchMsg (the peer has no state to release).""" session, conn, _ = _make_session() _activate(session, conn) @@ -995,8 +987,7 @@ class TestLookupFlow: def test_finish_after_real_fetch_sends_no_second_fetch(self): """A real FetchMsg was already sent for the id → finish_request - must not emit a second (empty) FetchMsg. - """ + must not emit a second (empty) FetchMsg.""" session, conn, _ = _make_session() _activate(session, conn) @@ -1027,8 +1018,7 @@ class TestLookupFlow: """``poll()`` only enqueues an inbound LookupMsg — no response is sent until ``serve_external_requests``. With an all-miss parent the aggregated LookupRespMsg carries the same keys and - ``hits=[False, ...]``. - """ + ``hits=[False, ...]``.""" session, conn, _ = _make_session() _activate(session, conn) @@ -1088,8 +1078,7 @@ class TestServerLookupHandling: def test_immediate_hits_create_one_store_job(self): """All-HIT batch: one create_store_job call with all keys, one LookupRespMsg with hits=[True]*N, on_request_finished fires at the - end of serve, and `available` is populated for the eventual fetch. - """ + end of serve, and `available` is populated for the eventual fetch.""" cb = FakeParent(stored={b"hA": 1, b"hB": 2, b"hC": 3}) session, conn, _ = _make_session() _activate(session, conn) @@ -1119,8 +1108,7 @@ class TestServerLookupHandling: def test_all_misses_no_store_job_finish_fires(self): """All-MISS batch: no create_store_job call; one LookupRespMsg - with hits=[False]*N; on_request_finished fires at end of serve. - """ + with hits=[False]*N; on_request_finished fires at end of serve.""" cb = FakeParent() session, conn, _ = _make_session() _activate(session, conn) @@ -1140,8 +1128,7 @@ class TestServerLookupHandling: """HIT/MISS resolutions do not go out on first sight when any key is still HIT_PENDING / RETRY. The lookup parks until every key has settled (or the deadline fires), then one - LookupRespMsg carries all keys in wire order. - """ + LookupRespMsg carries all keys in wire order.""" cb = FakeParent( stored={b"hA": 1}, pending={b"hB"}, @@ -1170,8 +1157,7 @@ class TestServerLookupHandling: the deferred aggregate response: one LookupRespMsg carrying both keys in wire order, and one create_store_job call per HIT (the second HIT is pinned when it resolves, not when the - response goes out). - """ + response goes out).""" cb = FakeParent(stored={b"hA": 1}, pending={b"hB"}) session, conn, _ = _make_session() _activate(session, conn) @@ -1207,8 +1193,7 @@ class TestServerLookupHandling: def test_pending_timeout_replies_miss_no_store_job(self): """A HIT_PENDING key that stays pending past the batch ``deadline`` is force-MISS and never pinned; the deferred - aggregate response fires with hits=[False]. - """ + aggregate response fires with hits=[False].""" cb = FakeParent(pending={b"hA"}) session, conn, _ = _make_session() _activate(session, conn) @@ -1235,8 +1220,7 @@ class TestServerLookupHandling: def test_finish_request_called_per_lookup_msg_not_per_kv_request_id(self): """Two LookupMsgs for the same kv_request_id get distinct ctxs - and two on_request_finished calls (one per batch). - """ + and two on_request_finished calls (one per batch).""" cb = FakeParent(stored={b"hA": 1, b"hB": 2}) session, conn, _ = _make_session() _activate(session, conn) @@ -1260,8 +1244,7 @@ class TestServerLookupHandling: """Tearing the session down with a parked batch returns the synthetic ctx as a failed serve (no parent handle at teardown) so the manager can release the TieringManager's state on its next - serve. - """ + serve.""" cb = FakeParent(pending={b"hA"}) session, conn, _ = _make_session() _activate(session, conn) @@ -1282,8 +1265,7 @@ class TestServerLookupHandling: def test_wire_finish_drops_pending_batches_for_kv_request_id(self): """``ServerRole.finish(kv_request_id)`` drops every parked batch whose kv_request_id matches and queues its ctx for the next - serve's on_request_finished. - """ + serve's on_request_finished.""" cb = FakeParent(pending={b"hA", b"hB"}) session, conn, _ = _make_session() _activate(session, conn) @@ -1314,8 +1296,7 @@ class TestServerLookupHandling: def test_incoming_fetch_drops_pending_lookups_for_kv_request_id(self): """A peer FetchMsg terminates the lookup phase for its id: parked lookups with matching kv_request_id are dropped and their - ctx queued for on_request_finished; other kv_request_ids untouched. - """ + ctx queued for on_request_finished; other kv_request_ids untouched.""" cb = FakeParent(pending={b"hA", b"hB"}) session, conn, _ = _make_session() _activate(session, conn) @@ -1357,8 +1338,7 @@ class TestServerLookupHandling: def test_lookup_then_fetch_round_trip_emits_store_result(self): """End-to-end: lookup pins primary slots → fetch matches them → NIXL transfer completes → StoreResult surfaces with the - create_store_job's job_id (the engine releases the pin). - """ + create_store_job's job_id (the engine releases the pin).""" cb = FakeParent(stored={b"hA": 7, b"hB": 8}) session, conn, transport = _make_session() _activate(session, conn) @@ -1480,8 +1460,7 @@ class TestServerFlows: def test_abort_fetch_defers_ack_when_cancel_pending(self): """If cancel(mode='wait') reports still-inflight tids, the ack is - deferred and the abort is parked (abort_started_at set). - """ + deferred and the abort is parked (abort_started_at set).""" session, conn, transport = _make_session() _activate(session, conn) # Seed an inflight transfer for req-1 that the transport pretends @@ -1516,8 +1495,7 @@ class TestServerFlows: def test_abort_fetch_acks_after_drain(self): """Once the transport reports the tid as DONE the parked abort - completes and AbortAckMsg is sent. - """ + completes and AbortAckMsg is sent.""" session, conn, transport = _make_session() _activate(session, conn) tid = 42 @@ -1556,8 +1534,7 @@ class TestServerFlows: def test_abort_fetch_force_cancels_after_timeout(self): """If wait-mode never drains, the deadline forces immediate - cancel and an ack is still sent. - """ + cancel and an ack is still sent.""" session, conn, transport = _make_session() _activate(session, conn) tid = 42 @@ -1599,8 +1576,7 @@ class TestServerFlows: def test_abort_fetch_idempotent_while_draining(self): """Receiving AbortFetchMsg twice for the same kv_request_id - keeps a single pending entry and produces a single ack. - """ + keeps a single pending entry and produces a single ack.""" session, conn, transport = _make_session() _activate(session, conn) tid = 42 @@ -1658,8 +1634,7 @@ class TestServerFlows: def test_store_timeout_then_late_completion_no_duplicate(self): """A job timed out by _timeout_pending_store_jobs must not also emit a contradictory StoreResult(success=True) when the transport - later reports the same transfer as done. - """ + later reports the same transfer as done.""" session, conn, transport = _make_session() _activate(session, conn) session.add_stored_blocks("req-1", [b"k1"], [0], job_id=1) @@ -1692,8 +1667,7 @@ class TestServerFlows: def test_store_timeout_then_late_failure_no_duplicate(self): """Symmetric guard: a timed-out job must not also emit a second StoreResult(success=False) when the transport later reports the - same transfer as failed. - """ + same transfer as failed.""" session, conn, transport = _make_session() _activate(session, conn) session.add_stored_blocks("req-1", [b"k1"], [0], job_id=1) @@ -1736,8 +1710,7 @@ class TestFinishRequestServerSide: def test_no_inflight_unmatched_demand_sends_failure(self): """finish_request with unmatched demand and no inflight -> - immediate TransferDoneMsg(success=False); _outbound cleared. - """ + immediate TransferDoneMsg(success=False); _outbound cleared.""" session, conn, _ = _make_session() _activate(session, conn) # Decoder demanded a block we never stored. @@ -1763,8 +1736,7 @@ class TestFinishRequestServerSide: def test_with_inflight_defers_then_fires_on_last_transfer(self): """finish_request with inflight defers; last transfer fires the - early-fail message and clears _outbound. - """ + early-fail message and clears _outbound.""" session, conn, transport = _make_session() _activate(session, conn) # Demand 2 blocks; we store 1 (kicks one inflight transfer). @@ -1801,8 +1773,7 @@ class TestFinishRequestServerSide: def test_full_demand_satisfied_still_sends_success(self): """finish_request must not override a fully-satisfied transfer: - when remaining hits 0, success=True still fires. - """ + when remaining hits 0, success=True still fires.""" session, conn, transport = _make_session() _activate(session, conn) conn.enqueue( @@ -1831,8 +1802,7 @@ class TestFinishRequestServerSide: """Prefiller-first: finish_request runs before the decoder's fetch arrives. State is held until fetch, then finalized — success=True if all demand was matched against - available blocks, else success=False. - """ + available blocks, else success=False.""" # Case A: all demand satisfied by available blocks. session, conn, transport = _make_session() _activate(session, conn) @@ -1893,8 +1863,7 @@ class TestFinishRequestServerSide: """finish_request with a stored-but-unmatched job and no inflight -> TransferDoneMsg(success=False) AND deferred StoreResult(success=False) for the submit_store'd job, instead of - the 30s _STORE_TIMEOUT_S path. - """ + the 30s _STORE_TIMEOUT_S path.""" session, conn, _ = _make_session() _activate(session, conn) # Decoder demanded b"demand"; we never stored it. @@ -1930,8 +1899,7 @@ class TestFinishRequestServerSide: def test_finish_request_remaining_zero_emits_success_via_inflight(self): """Deferred-via-inflight path: finish_request with inflight, last transfer drains remaining to 0 -> TransferDoneMsg(success=True) - AND StoreResult(success=True). - """ + AND StoreResult(success=True).""" session, conn, transport = _make_session() _activate(session, conn) conn.enqueue( @@ -2279,8 +2247,7 @@ class TestDisconnect: def test_send_failure_marks_connection_dead(self): """A raising send must mark the connection dead, not silently drop the message — otherwise the session lingers alive, is never reaped, - and in-flight lookups/loads toward the dead peer hang forever. - """ + and in-flight lookups/loads toward the dead peer hang forever.""" session, conn, _ = _make_session() _activate(session, conn) assert session.alive @@ -2293,8 +2260,7 @@ class TestDisconnect: def test_close_surfaces_inflight_lookups(self): """close() reports kv_request_ids whose symmetric-P2P probe is still - unresolved; resolved probes are not reported (their answer is in). - """ + unresolved; resolved probes are not reported (their answer is in).""" session, conn, _ = _make_session() _activate(session, conn) @@ -2402,8 +2368,7 @@ class TestDispatchErrorHandling: def test_value_error_disconnects_on_first_occurrence(self): """A FetchMsg that fails validate() raises ValueError and must - terminate the session immediately, with a DisconnectMsg sent. - """ + terminate the session immediately, with a DisconnectMsg sent.""" session, conn, _ = _make_session() _activate(session, conn) # length mismatch → FetchMsg.validate raises ValueError @@ -2430,8 +2395,7 @@ class TestDispatchErrorHandling: def test_internal_error_does_not_disconnect_once(self): """A non-ValueError raised by a handler is treated as an internal - bug: counter increments, session stays alive on a single hit. - """ + bug: counter increments, session stays alive on a single hit.""" session, conn, _ = _make_session() _activate(session, conn) @@ -2454,8 +2418,7 @@ class TestDispatchErrorHandling: def test_internal_error_threshold_disconnects(self): """Once consecutive non-protocol errors hit the threshold, the - session tears down via _protocol_error. - """ + session tears down via _protocol_error.""" session, conn, _ = _make_session() _activate(session, conn) @@ -2479,8 +2442,7 @@ class TestDispatchErrorHandling: def test_internal_error_counter_resets_on_success(self): """A successful dispatch between errors prevents the threshold - from being reached. - """ + from being reached.""" session, conn, _ = _make_session() _activate(session, conn) @@ -2523,8 +2485,7 @@ class TestInflightPerReqInvariant: def test_invariant_holds_through_lifecycle(self): """Run a full submit→complete sequence for two concurrent kv_request_ids and assert the counter matches `_inflight` at - every observable step, including the empty-after-finish case. - """ + every observable step, including the empty-after-finish case.""" session, conn, transport = _make_session() _activate(session, conn) @@ -2589,8 +2550,7 @@ class TestInflightPerReqInvariant: """Populate many inflight xfers across many ids; lookup must match the actual presence in `_inflight` for both hits and misses. The whole point of the counter is that this lookup is - constant-time, but we assert correctness, not timing. - """ + constant-time, but we assert correctness, not timing.""" session, _, _ = _make_session() for kv_id_idx in range(100): kv_id = f"req-{kv_id_idx}" diff --git a/tests/v1/kv_offload/tiering/test_async_lookup.py b/tests/v1/kv_offload/tiering/test_async_lookup.py index 616c6efa94..3649c8df04 100644 --- a/tests/v1/kv_offload/tiering/test_async_lookup.py +++ b/tests/v1/kv_offload/tiering/test_async_lookup.py @@ -264,8 +264,7 @@ class TestAsyncLookupManager: subsequent lookup then returns False (MISS) directly, WITHOUT enqueuing a fresh batch_lookup — that is what makes the request unable to loop. The entry is retained (as False) not dropped, so cleanup()'s reverse - index stays consistent; an unknown key is a no-op. - """ + index stays consistent; an unknown key is a no-op.""" mgr = InMemoryLookupManager(existing_keys={_key(1), _key(2)}) ctx = _ctx("reqA") assert mgr.lookup(_key(1), ctx) is None @@ -305,8 +304,7 @@ class TestAsyncLookupManager: receive at most one result per key. Normal operation resolves a key a single time; a second result for an already-decided key trips the assert that guards the invariant (a silent overwrite could flip a corrected - miss back to True and reopen the failed-load livelock). - """ + miss back to True and reopen the failed-load livelock).""" mgr = InMemoryLookupManager(existing_keys={_key(1)}) ctx = _ctx("reqA") diff --git a/tests/v1/kv_offload/tiering/test_fs_tier.py b/tests/v1/kv_offload/tiering/test_fs_tier.py index 13621fb4c4..9c3a64d22a 100644 --- a/tests/v1/kv_offload/tiering/test_fs_tier.py +++ b/tests/v1/kv_offload/tiering/test_fs_tier.py @@ -369,8 +369,7 @@ def test_shutdown_discards_pending_tasks(fs_tier): @pytest.mark.parametrize("use_c_ext", [True, False]) def test_store_load_data_integrity(fs_tier, monkeypatch, use_c_ext, batch_size): """Data written by store must be exactly recovered by load, for batches - of any size -- including the empty batch. - """ + of any size -- including the empty batch.""" import vllm.v1.kv_offload.tiering.fs.io as io_mod if use_c_ext and not io_mod._HAS_FSIO_C: @@ -467,8 +466,7 @@ def test_wait_idle_blocks_until_tasks_complete(): def test_batch_lookup_c_extension(tmp_path): """Validates batch_lookup_C: empty, single, all-existing, all-missing, - mixed ordering, and input type validation. - """ + mixed ordering, and input type validation.""" try: from vllm.fs_io_C import batch_lookup as batch_lookup_C except ImportError: @@ -532,8 +530,7 @@ def test_batch_lookup_dispatch(fs_tier, monkeypatch, use_c_ext): @pytest.mark.parametrize("use_c_ext", [True, False]) def test_out_of_bounds_block_id_smoke(fs_tier, monkeypatch, use_c_ext): """Smoke test: a block id beyond the primary tensor's block count must - fail the job, for both the C extension and the Python fallback. - """ + fail the job, for both the C extension and the Python fallback.""" import vllm.v1.kv_offload.tiering.fs.io as io_mod if use_c_ext and not io_mod._HAS_FSIO_C: @@ -615,8 +612,7 @@ def test_batched_partial_load_failure_keeps_loaded_blocks( loaded before it (#50321). Corrupt the LAST block: the earlier blocks load fine, so the job reports successful_keys for them and marks only the failed tail a miss. The earlier keys stay HIT — including for the same request — - while the corrupt block stays a MISS (its file was removed). - """ + while the corrupt block stays a MISS (its file was removed).""" import vllm.v1.kv_offload.tiering.fs.io as io_mod if use_c_ext and not io_mod._HAS_FSIO_C: @@ -668,8 +664,7 @@ def test_batched_load_first_block_fails_marks_whole_batch( ): """When the FIRST block fails, nothing loaded before it: the job reports no successful_keys (None) and the whole batch is marked a miss for the - request. - """ + request.""" import vllm.v1.kv_offload.tiering.fs.io as io_mod if use_c_ext and not io_mod._HAS_FSIO_C: @@ -700,8 +695,7 @@ def test_transient_load_failure_leaves_file(fs_tier, monkeypatch, use_c_ext): """A transient host error (here ELOOP on open) is NOT a short read: the job fails but the block file must survive untouched, on both the C and Python paths. Deleting on a transient error would turn a passing hiccup into - permanent data loss. - """ + permanent data loss.""" import vllm.v1.kv_offload.tiering.fs.io as io_mod if use_c_ext and not io_mod._HAS_FSIO_C: @@ -805,8 +799,7 @@ def test_mixed_job_results_emit_event_only_for_successful_job( fs_tier_with_events, monkeypatch ): """With a failed and a successful store job in flight, exactly one event - is emitted and its keys belong to the successful job. - """ + is emitted and its keys belong to the successful job.""" import vllm.v1.kv_offload.tiering.fs.manager as mgr_mod tier = fs_tier_with_events @@ -891,8 +884,7 @@ def test_events_require_global_kv_events_flag(tmp_path): def test_cascade_store_emits_fs_event_through_tiering_manager(tmp_path): """A GPU->CPU->fs cascade surfaces the tier-owned FS stored event via the - TieringOffloadingManager's aggregated take_events(). - """ + TieringOffloadingManager's aggregated take_events().""" from vllm.v1.kv_offload.tiering.manager import ( CPUPrimaryTierOffloadingManager, TieringOffloadingManager, diff --git a/tests/v1/kv_offload/tiering/test_obj_tier.py b/tests/v1/kv_offload/tiering/test_obj_tier.py index 0b3168ec3d..bf8afca424 100644 --- a/tests/v1/kv_offload/tiering/test_obj_tier.py +++ b/tests/v1/kv_offload/tiering/test_obj_tier.py @@ -346,8 +346,7 @@ class TestMockObjTierBasic: the scheduler would re-issue the same doomed promotion every step for the life of the request. The mark is served from cache with no re-probe, so even though the mock object is still 'present' the SAME - request now resolves to MISS. - """ + request now resolves to MISS.""" ctx = ReqContext(req_id="obj-livelock") self.tier.submit_store(make_job(1, [key(1)], [0])) assert all(r.success for r in drain(self.tier)) @@ -651,8 +650,7 @@ class TestObjTierKVEvents: def test_mixed_job_results_emit_event_only_for_successful_job(self): """With a failed and a successful store job resolving in the same poll, exactly one event is emitted and its keys belong to the - successful job. - """ + successful job.""" original = self.agent.check_xfer_state self.agent.check_xfer_state = lambda h: "ERR" if h._id == 0 else original(h) self.tier.submit_store(make_job(1, [key(1)], [0])) # handle 0: fails diff --git a/tests/v1/kv_offload/tiering/test_tiering_offloading.py b/tests/v1/kv_offload/tiering/test_tiering_offloading.py index 5cc5f48e3a..63b4c2c4d0 100644 --- a/tests/v1/kv_offload/tiering/test_tiering_offloading.py +++ b/tests/v1/kv_offload/tiering/test_tiering_offloading.py @@ -273,8 +273,7 @@ _CASCADE_SUPPLY_BEHAVIOR = { def test_every_lookup_result_has_a_declared_cascade_behavior(): """A new LookupResult must state what the cascade does with it, rather - than falling into whichever branch happens to catch it. - """ + than falling into whichever branch happens to catch it.""" assert set(_CASCADE_SUPPLY_BEHAVIOR) == set(LookupResult) @@ -321,8 +320,7 @@ class TestTieringOffloadingManager: def test_failed_promotion_finalizes_primary_with_failure(self, manager_setup): """A failed promotion still finalizes the primary slots with - success=False; the tier corrects its own verdict. - """ + success=False; the tier corrects its own verdict.""" from unittest.mock import patch from vllm.v1.kv_offload.tiering.base import JobResult @@ -1093,8 +1091,7 @@ class TestTieringOffloadingManager: def test_on_new_request_lifecycle(self, manager_setup): """Policy defaults to CHUNK_LEVEL, escalates when a tier requests it, - and is cleaned up on on_request_finished. - """ + and is cleaned up on on_request_finished.""" # Default: all tiers return CHUNK_LEVEL ctx = ReqContext(req_id="req_policy_lifecycle") result = self.manager.on_new_request(ctx) @@ -1171,8 +1168,7 @@ class TestTieringOffloadingManager: def _make_request_level_request(self, req_id: str) -> ReqContext: """Start a request for which tier1 asks for request-level offloading, - with tier1's submit_store wrapped so the cascade can be observed. - """ + with tier1's submit_store wrapped so the cascade can be observed.""" self.secondary_tier1.on_new_request = lambda req_context: ( RequestOffloadingContext(policy=OffloadPolicy.REQUEST_LEVEL) ) @@ -1194,8 +1190,7 @@ class TestTieringOffloadingManager: def test_cascade_rejects_retry_from_primary(self, manager_setup): """RETRY would be parked with no guarantee of ever draining, so the cascade refuses it. No real primary tier returns it, so this is the one - disposition that has to be forced. - """ + disposition that has to be forced.""" keys = to_keys(range(3)) self._start_request() assert self.manager.prepare_store(keys, _CTX) is not None @@ -1210,8 +1205,7 @@ class TestTieringOffloadingManager: def _start_in_flight_primary_write(self, keys: list[OffloadKey]) -> ReqContext: """Leave a GPU->primary write for `keys` open, so they look present to - prepare_store but are not yet readable. - """ + prepare_store but are not yet readable.""" writer_ctx = ReqContext(req_id="req_writer") self._start_request(writer_ctx) assert self.manager.prepare_store(keys, writer_ctx) is not None @@ -1220,8 +1214,7 @@ class TestTieringOffloadingManager: def test_cascade_defers_keys_whose_primary_write_is_in_flight(self, manager_setup): """A key another request is still writing must reach the peer once the write lands, not be dropped: prepare_store already counts it as stored - and the scheduler advances past its chunk, so nothing re-offers it. - """ + and the scheduler advances past its chunk, so nothing re-offers it.""" keys = to_keys(range(3)) writer_ctx = self._start_in_flight_primary_write(keys) @@ -1238,8 +1231,7 @@ class TestTieringOffloadingManager: def test_deferred_cascade_holds_request_from_finalization(self, manager_setup): """A request that finishes with keys still deferred must stay alive, or - its tiers are torn down before the peer is ever served. - """ + its tiers are torn down before the peer is ever served.""" keys = to_keys(range(3)) writer_ctx = self._start_in_flight_primary_write(keys) @@ -1262,8 +1254,7 @@ class TestTieringOffloadingManager: self, manager_setup ): """A failed write frees the chunk, so the deferred key resolves to MISS - and the request finalizes instead of parking forever. - """ + and the request finalizes instead of parking forever.""" keys = to_keys(range(3)) writer_ctx = self._start_in_flight_primary_write(keys) @@ -1283,8 +1274,7 @@ class TestTieringOffloadingManager: def test_reset_cache_clears_orchestrator_state(self, manager_setup): """reset_cache wipes every kind of orchestrator state and resets primary tier; pending submissions are dropped without being sent - to the secondary tier. Active request state is retained. - """ + to the secondary tier. Active request state is retained.""" # Cascade — populates primary chunks and leaves cascade jobs # in _jobs (the synchronous example tier has already # queued completions); reset_cache's drain loop will pick them up. @@ -1376,8 +1366,7 @@ class TestTieringOffloadingManager: self, manager_setup, load_tier_filter ): """Filter excluding secondary medium returns MISS from secondaries - even when they hold the chunk; primary is unaffected. - """ + even when they hold the chunk; primary is unaffected.""" chunks = to_keys(range(2)) # Put one chunk in primary, one only in secondary self._start_request() diff --git a/tests/v1/logits_processors/test_correctness.py b/tests/v1/logits_processors/test_correctness.py index fccdf56409..9b12e7412e 100644 --- a/tests/v1/logits_processors/test_correctness.py +++ b/tests/v1/logits_processors/test_correctness.py @@ -1344,8 +1344,7 @@ 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 ) diff --git a/tests/v1/logits_processors/utils.py b/tests/v1/logits_processors/utils.py index 85ad2032cd..76877b655b 100644 --- a/tests/v1/logits_processors/utils.py +++ b/tests/v1/logits_processors/utils.py @@ -138,8 +138,7 @@ 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`.""" @@ -158,8 +157,7 @@ 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 diff --git a/tests/v1/metrics/test_perf_metrics.py b/tests/v1/metrics/test_perf_metrics.py index 32c203705c..3868cc772e 100644 --- a/tests/v1/metrics/test_perf_metrics.py +++ b/tests/v1/metrics/test_perf_metrics.py @@ -1241,8 +1241,7 @@ def test_mla_per_gpu_with_pipeline_parallelism(): def test_mla_model_metrics_excludes_standard_attention(): """Test that ModelMetrics uses MLAAttentionMetrics, not AttentionMetrics, - for DeepSeek MLA models. - """ + for DeepSeek MLA models.""" hf_config = DeepseekV3Config( hidden_size=7168, num_attention_heads=128, diff --git a/tests/v1/metrics/test_ray_metrics.py b/tests/v1/metrics/test_ray_metrics.py index 7bc49aae6e..ce4ebcbfdb 100644 --- a/tests/v1/metrics/test_ray_metrics.py +++ b/tests/v1/metrics/test_ray_metrics.py @@ -45,8 +45,7 @@ def test_engine_log_metrics_ray( max_tokens: int, ) -> None: """Simple smoke test, verifying this can be used without exceptions. - Need to start a Ray cluster in order to verify outputs. - """ + Need to start a Ray cluster in order to verify outputs.""" @ray.remote(num_gpus=1) class EngineTestActor: @@ -120,8 +119,7 @@ def test_sanitized_opentelemetry_name(): def _install_mock_metric(wrapper: RayPrometheusMetric) -> MagicMock: """Swap the wrapper's underlying Ray metric for a MagicMock while preserving the real metric's ``_tag_keys`` (labels() reads them to - validate arity). - """ + validate arity).""" real_metric = wrapper.metric mock = MagicMock() mock._tag_keys = real_metric._tag_keys @@ -131,8 +129,7 @@ def _install_mock_metric(wrapper: RayPrometheusMetric) -> MagicMock: def test_ray_counter_labels_returns_independent_children(): """RayCounterWrapper.labels() must return distinct labeled children that - each carry their own tag set. - """ + each carry their own tag set.""" base = RayCounterWrapper( name="vllm_test_finish_reason", documentation="", @@ -152,8 +149,7 @@ def test_ray_counter_labels_returns_independent_children(): def test_ray_counter_inc_forwards_per_child_tags(): """.inc() on a labeled counter must forward that child's tags to the - underlying Ray metric (not rely on a shared set_default_tags). - """ + underlying Ray metric (not rely on a shared set_default_tags).""" wrapper = RayCounterWrapper( name="vllm_test_counter_tag_forward", documentation="", @@ -218,8 +214,7 @@ def test_ray_histogram_labels_returns_independent_children_and_forwards_tags(): def test_ray_counter_labels_accepts_non_string_label_values(): """RayPrometheusStatLogger passes ``str(idx)`` for engine indexes; this covers the coercion path for any caller that passes a non-string label - value positionally. - """ + value positionally.""" wrapper = RayCounterWrapper( name="vllm_test_nonstr_label", documentation="", @@ -242,8 +237,7 @@ def test_ray_counter_labels_arity_validation(): def test_unlabeled_inc_carries_replica_id(): """Recording on an unlabeled metric must still pass ReplicaId — it's a - declared tag_key and Ray rejects updates that omit any declared key. - """ + declared tag_key and Ray rejects updates that omit any declared key.""" wrapper = RayCounterWrapper( name="vllm_test_unlabeled_replica_id", documentation="", @@ -256,8 +250,7 @@ def test_unlabeled_inc_carries_replica_id(): def test_double_labels_raises(): """labels() on an already-labeled child should raise, mirroring the - prometheus_client contract. - """ + prometheus_client contract.""" wrapper = RayCounterWrapper( name="vllm_test_double_labels", documentation="", diff --git a/tests/v1/sample/test_batched_count_greater_than.py b/tests/v1/sample/test_batched_count_greater_than.py index 0e2d192882..c9ace93c69 100644 --- a/tests/v1/sample/test_batched_count_greater_than.py +++ b/tests/v1/sample/test_batched_count_greater_than.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Test that batched_count_greater_than does not trigger 0/1 specialization -recompiles when batch_size varies. -""" +recompiles when batch_size varies.""" import torch diff --git a/tests/v1/sample/test_logprobs.py b/tests/v1/sample/test_logprobs.py index 372e1c8156..d2cb99bc26 100644 --- a/tests/v1/sample/test_logprobs.py +++ b/tests/v1/sample/test_logprobs.py @@ -573,8 +573,7 @@ def test_logprobs_mode(logprobs_mode: LogprobsMode): def test_prompt_logprobs_mode(): """prompt_logprobs must respect logprobs_mode: *_logits and *_logprobs must return different values. Prompt tokens skip sampling processors, - so processed_* == raw_* on the prompt side. - """ + so processed_* == raw_* on the prompt side.""" from vllm import LLM values: dict[str, float] = {} diff --git a/tests/v1/sample/test_rejection_sampler.py b/tests/v1/sample/test_rejection_sampler.py index abb069a26a..231f6adbb2 100644 --- a/tests/v1/sample/test_rejection_sampler.py +++ b/tests/v1/sample/test_rejection_sampler.py @@ -54,8 +54,7 @@ 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) diff --git a/tests/v1/sample/test_topk_topp_sampler.py b/tests/v1/sample/test_topk_topp_sampler.py index 9f53a8c287..0b570f49d9 100644 --- a/tests/v1/sample/test_topk_topp_sampler.py +++ b/tests/v1/sample/test_topk_topp_sampler.py @@ -884,8 +884,7 @@ class TestFlashInferTopkToppRobustness: def _make_logits(self, pattern: str) -> torch.Tensor: """Build (BATCH, VOCAB) logits with `pattern` applied to row 0 - (rows 1..B-1 stay clean so we can detect cross-row corruption). - """ + (rows 1..B-1 stay clean so we can detect cross-row corruption).""" logits = ( torch.randn( self.BATCH, diff --git a/tests/v1/sample/utils.py b/tests/v1/sample/utils.py index 19c50f79b1..e4e9f21092 100644 --- a/tests/v1/sample/utils.py +++ b/tests/v1/sample/utils.py @@ -204,8 +204,7 @@ def fake_update_logitsprocs_state( batch_update: BatchUpdate | None, ) -> None: """Imitate logits processors persistent batch state update - in engine core - """ + in engine core""" for logitproc in test_fakes.get_logitsprocs(): logitproc.update_state(batch_update) holder = test_fakes.sampling_metadata.thinking_budget_state_holder diff --git a/tests/v1/simple_kv_offload/test_kv_events.py b/tests/v1/simple_kv_offload/test_kv_events.py index 5f5b63c93e..f21dae7e0b 100644 --- a/tests/v1/simple_kv_offload/test_kv_events.py +++ b/tests/v1/simple_kv_offload/test_kv_events.py @@ -67,8 +67,7 @@ def _make_mixed_kv_cache_config( mamba_block_size: int = BLOCK_SIZE, ) -> KVCacheConfig: """Build a KVCacheConfig with a FullAttention group plus optional - SlidingWindow and Mamba groups for per-group metadata tests. - """ + SlidingWindow and Mamba groups for per-group metadata tests.""" register_all_kvcache_specs(vllm_config=None) groups = [] tensors = [] @@ -239,8 +238,7 @@ def test_events_disabled_no_events() -> None: # --------------------------------------------------------------------------- def test_block_stored_per_group_metadata_full_attention() -> None: """BlockStored carries medium, group_idx, kind, sliding_window, block_size, - and the correct block hash. - """ + and the correct block hash.""" fix = make_events_scheduler() sched = fix.scheduler assert sched.kv_event_medium == MEDIUM_CPU @@ -640,8 +638,7 @@ def test_mamba_block_size_not_scaled() -> None: def test_multi_group_fa_block_stored_group_idx() -> None: """Two distinct groups (FA + SW): each BlockStored carries its group_idx and kind. HybridKVCacheCoordinator requires >=2 distinct spec groups, so - we use FA (group 0) + SlidingWindow (group 1). - """ + we use FA (group 0) + SlidingWindow (group 1).""" kv_cfg = _make_mixed_kv_cache_config(num_blocks=16, sliding_window=32) fix = make_events_scheduler( num_cpu_blocks=8, diff --git a/tests/v1/simple_kv_offload/test_scheduler.py b/tests/v1/simple_kv_offload/test_scheduler.py index c87a5f7c95..ffc8b20478 100644 --- a/tests/v1/simple_kv_offload/test_scheduler.py +++ b/tests/v1/simple_kv_offload/test_scheduler.py @@ -1170,8 +1170,7 @@ def test_touched_blocks_survive_eviction() -> None: # --------------------------------------------------------------------------- def test_preemption_no_cpu_block_leak() -> None: """request_finished during in-flight load defers cleanup; - completes after load done. - """ + completes after load done.""" fix = make_scheduler(num_cpu_blocks=8, num_gpu_blocks=16, lazy=False) sched = fix.scheduler @@ -1266,8 +1265,7 @@ def test_eager_store_preemption_cleanup() -> None: # --------------------------------------------------------------------------- def test_inflight_finish_deferred_cleanup() -> None: """Store, then start a load, request_finished defers, - load completion fires cleanup. - """ + load completion fires cleanup.""" fix = make_scheduler(num_cpu_blocks=8, num_gpu_blocks=16, lazy=False) sched = fix.scheduler @@ -1401,8 +1399,7 @@ def test_chunked_prefill_reads_live_block_ids() -> None: """With chunked prefill, block IDs accumulate across scheduler steps. _prepare_eager_store_specs reads block IDs from scheduler_output via yield_req_data, so the store should reflect the updated (larger) block - list, not a stale snapshot. - """ + list, not a stale snapshot.""" fix = make_scheduler(num_cpu_blocks=8, num_gpu_blocks=16, lazy=False) sched = fix.scheduler @@ -1973,8 +1970,7 @@ def test_cp_eager_store_and_load_roundtrip( ) -> None: """With CP enabled, store blocks to CPU and reload them for a new request with matching tokens. Verifies that hash matching and transfer-pair - construction work with the virtual block size. - """ + construction work with the virtual block size.""" fix = _make_cp_scheduler( dcp_world_size=dcp_world_size, pcp_world_size=pcp_world_size, @@ -2118,8 +2114,7 @@ def test_cp_effective_block_size_store_and_load( @pytest.mark.parametrize("cp_world_size", [1, 2, 4]) def test_cp_lazy_target_blocks_scaling(cp_world_size: int) -> None: """_estimate_lazy_target_blocks returns fewer blocks when cp_world_size > 1 - because each virtual block covers more tokens. - """ + because each virtual block covers more tokens.""" kv_cache_config = _make_kv_cache_config(num_blocks=16) max_batched = 64 @@ -2811,8 +2806,7 @@ def test_finished_eager_store_recovers_nulled_window_tail() -> None: """A sliding-window group nulls pages that left the window before the connector sees the finished request's block table, while the GPU keeps them hashed in its free queue. The eager store must copy those pages, or - the CPU lookup (which needs the whole window) misses every time. - """ + the CPU lookup (which needs the whole window) misses every time.""" fix = make_scheduler(num_cpu_blocks=16, num_gpu_blocks=32, num_groups=2, lazy=False) sched = fix.scheduler gpu_pool = fix.gpu_block_pool diff --git a/tests/v1/spec_decode/test_backup_token_async_spec.py b/tests/v1/spec_decode/test_backup_token_async_spec.py index 3f99a5de06..9340503ea4 100644 --- a/tests/v1/spec_decode/test_backup_token_async_spec.py +++ b/tests/v1/spec_decode/test_backup_token_async_spec.py @@ -131,8 +131,7 @@ class TestBackupTokenAsyncSpec: def test_buggy_code_was_always_off_by_one(self): """The original code used seq_len as index, which is always one past - the end of output_token_ids even without async inflation. - """ + the end of output_token_ids even without async inflation.""" req_ids = ["r0"] requests = {"r0": _FakeRequest([0, 1, 2], [1000, 1001])} batch = _FakeInputBatch(req_ids, [5]) diff --git a/tests/v1/spec_decode/test_eagle_draft_attn_metadata.py b/tests/v1/spec_decode/test_eagle_draft_attn_metadata.py index 19166ee193..0cc78f3371 100644 --- a/tests/v1/spec_decode/test_eagle_draft_attn_metadata.py +++ b/tests/v1/spec_decode/test_eagle_draft_attn_metadata.py @@ -105,8 +105,7 @@ def test_build_draft_attn_metadata_sets_seq_lens_cpu_upper_bound(): """The fix: every per-step ``CommonAttentionMetadata`` carries a non-None ``seq_lens_cpu_upper_bound`` derived from the target-side upper bound plus the current draft-step offset. Padded entries are zeroed (matching the - main model runner's convention). - """ + main model runner's convention).""" fake = _make_fake_speculator() base = torch.tensor([100, 200, 300, 0], dtype=torch.int32) @@ -127,8 +126,7 @@ def test_build_draft_attn_metadata_sets_seq_lens_cpu_upper_bound(): def test_build_draft_attn_metadata_zeroes_padded_upper_bound_tail(): """The padded tail of the upper-bound tensor is zeroed, so it stays a - valid tensor of length ``num_reqs_padded`` regardless of padding. - """ + valid tensor of length ``num_reqs_padded`` regardless of padding.""" fake = _make_fake_speculator() base = torch.zeros(2, dtype=torch.int32) @@ -143,8 +141,7 @@ def test_build_draft_attn_metadata_zeroes_padded_upper_bound_tail(): def test_build_draft_attn_metadata_clamps_to_max_model_len(): """The per-request upper bound (target bound + step) is clamped to the - model length so it never exceeds the allocated KV range. - """ + model length so it never exceeds the allocated KV range.""" fake = _make_fake_speculator(max_model_len=1024) base = torch.tensor([1023, 500], dtype=torch.int32) diff --git a/tests/v1/spec_decode/test_eagle_step_kernel.py b/tests/v1/spec_decode/test_eagle_step_kernel.py index 4d6244eb77..83a29bc046 100644 --- a/tests/v1/spec_decode/test_eagle_step_kernel.py +++ b/tests/v1/spec_decode/test_eagle_step_kernel.py @@ -132,8 +132,7 @@ def test_eagle_step_slot_mapping_kernel_exceeds_max(): def test_eagle_step_slot_mapping_kernel_cudagraph_padding(): """Test that padding threads write PADDING_SLOT_ID when - input_batch_size > batch_size (cudagraph padding). - """ + input_batch_size > batch_size (cudagraph padding).""" device = torch.device(DEVICE_TYPE) batch_size = 4 input_batch_size = 8 diff --git a/tests/v1/spec_decode/test_llm_base_proposer.py b/tests/v1/spec_decode/test_llm_base_proposer.py index 622d425065..5510c36e60 100644 --- a/tests/v1/spec_decode/test_llm_base_proposer.py +++ b/tests/v1/spec_decode/test_llm_base_proposer.py @@ -69,8 +69,7 @@ def _make_kv_cache_config(layer_names: set[str]) -> SimpleNamespace: def test_block_size_uses_kernel_block_size(monkeypatch: pytest.MonkeyPatch): """The proposer's slot-mapping math runs against the kernel-granularity - block table, so block_size must come from kernel_block_sizes. - """ + block table, so block_size must come from kernel_block_sizes.""" layer_names = {"draft.0.self_attn.attn"} proposer = _make_proposer(monkeypatch, layer_names) @@ -98,8 +97,7 @@ def test_block_size_falls_back_to_kv_cache_spec(monkeypatch: pytest.MonkeyPatch) def test_draft_layer_iteration_is_deterministic(monkeypatch: pytest.MonkeyPatch): """_draft_attn_layer_names is a set; the attention groups built from it - must not depend on its (process-random) iteration order. - """ + must not depend on its (process-random) iteration order.""" layer_names = {"draft.c.attn", "draft.a.attn", "draft.b.attn"} expected_order = sorted(layer_names) diff --git a/tests/v1/spec_decode/test_max_len.py b/tests/v1/spec_decode/test_max_len.py index 3644f0528f..81f8424193 100644 --- a/tests/v1/spec_decode/test_max_len.py +++ b/tests/v1/spec_decode/test_max_len.py @@ -93,8 +93,7 @@ def test_eagle_max_len( @pytest.mark.parametrize("spec_max_model_len", [80, 150]) def test_mtp_speculative_config_max_model_len(spec_max_model_len: int): """Regression test for #41456: max_model_len in speculative config - should be respected for the draft model. - """ + should be respected for the draft model.""" model_config = ModelConfig( model="XiaomiMiMo/MiMo-7B-Base", runner="generate", diff --git a/tests/v1/structured_output/test_validation.py b/tests/v1/structured_output/test_validation.py index ea44292702..a231894384 100644 --- a/tests/v1/structured_output/test_validation.py +++ b/tests/v1/structured_output/test_validation.py @@ -29,8 +29,7 @@ class _StubModelConfig: def test_structured_outputs_rejected_for_diffusion_models(): """Diffusion LLMs denoise the canvas in parallel, which is incompatible with the token-by-token grammar FSM. The request must fail with a clear - validation error instead of an FSM rejection mid-generation (#45436). - """ + validation error instead of an FSM rejection mid-generation (#45436).""" params = SamplingParams( structured_outputs=StructuredOutputsParams(json=JSON_SCHEMA) ) @@ -63,8 +62,7 @@ def test_degenerate_structured_outputs_rejected(structured_outputs, match): """json_object=False and an empty json schema pass the `is not None` exclusivity check but resolve to no structured-output key, so they must be rejected at request validation (-> 400) instead of reaching and crashing - the engine. - """ + the engine.""" params = SamplingParams(structured_outputs=structured_outputs) with pytest.raises(VLLMValidationError, match=match): params._validate_structured_outputs( @@ -87,8 +85,7 @@ def test_regex_with_nul_byte_rejected(regex): handled by xgrammar's native regex converter. It must be rejected at request validation in every backend mode (a clean 400), instead of reaching that native code or silently falling back to another backend in the default - 'auto' mode. - """ + 'auto' mode.""" params = SamplingParams(structured_outputs=StructuredOutputsParams(regex=regex)) # Rejected before backend selection, so it is a 400 even in 'auto' mode @@ -127,8 +124,7 @@ INVALID_JSON_SCHEMA = {"type": "object", "properties": {"name": {"type": "str"}} ) def test_unsupported_grammar_is_a_client_error(backend, structured_outputs): """Only `VLLMClientError` survives `AsyncLLM.generate` untouched; anything else - is wrapped in `EngineGenerateError` and served as a 500 instead of a 400. - """ + is wrapped in `EngineGenerateError` and served as a 500 instead of a 400.""" params = SamplingParams(structured_outputs=structured_outputs) with pytest.raises(VLLMClientError): params._validate_structured_outputs( diff --git a/tests/v1/test_outputs.py b/tests/v1/test_outputs.py index b5f180710e..5d52c86374 100644 --- a/tests/v1/test_outputs.py +++ b/tests/v1/test_outputs.py @@ -46,8 +46,7 @@ def test_logprobs_tensors_cat(): def test_logprobs_tensors_tolists_with_tensor_boundaries(): """Adaptive verification hands over the request boundaries as a tensor (they only exist on device); tolists() must materialize it as a plain - list so slice_request splits requests correctly. - """ + list so slice_request splits requests correctly.""" tensors = LogprobsTensors( torch.tensor([[1, 2], [3, 4], [5, 6]]), torch.tensor([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]]), @@ -86,8 +85,7 @@ def test_sampling_mask_lists_to_nested_list(): def test_sampling_mask_tensors_match_finite_support(max_num_kept): """Whatever its size (empty, one, around the compact width, beyond the cap, the whole vocab), a sampled row's mask is exactly the ascending set - of its finite logits; rows that sampled nothing are empty. - """ + of its finite logits; rows that sampled nothing are empty.""" from vllm.v1.worker.gpu.sample.output import MAX_COMPACT_SUPPORT vocab_size = 20_001 @@ -114,8 +112,7 @@ def test_sampling_mask_tensors_match_finite_support(max_num_kept): def test_sampling_mask_matches_processed_top_k_top_p_support(): """The mask must exactly mirror whatever support `apply_top_k_top_p` (the real logits-processing function used by the sampler) actually - produces, whatever backend implements it. - """ + produces, whatever backend implements it.""" processed_logits = apply_top_k_top_p( logits=torch.tensor( [[6.0, 5.0, 4.0, 4.0, 4.0, 2.0, 1.0, 0.0]], device=DEVICE_TYPE @@ -141,8 +138,7 @@ def test_sampling_mask_matches_processed_top_k_top_p_support(): def test_sampling_mask_preserves_top_k_boundary_ties(): """When the kept support is wider than `max_num_kept` (e.g. a top-k boundary tie keeps more than k logits), the mask must fall back to the - exact bitmask instead of silently truncating to `max_num_kept` ids. - """ + exact bitmask instead of silently truncating to `max_num_kept` ids.""" processed_logits = torch.tensor( [[6.0, 5.0, 4.0, 4.0, 4.0, float("-inf"), float("-inf"), float("-inf")]], device=DEVICE_TYPE, diff --git a/tests/v1/test_serial_utils.py b/tests/v1/test_serial_utils.py index 8a1af4e468..db0d7e6822 100644 --- a/tests/v1/test_serial_utils.py +++ b/tests/v1/test_serial_utils.py @@ -427,8 +427,7 @@ def _logprobs_outputs(num_reqs: int, num_prompt_tokens: int): """An EngineCoreOutputs carrying prompt logprobs, as the engine core sends it: many requests, each with per-token tensors small enough that pyzmq copies their frames, while the accumulated payload frame is large enough - that pyzmq sends it zero-copy. - """ + that pyzmq sends it zero-copy.""" from vllm.v1.engine import EngineCoreOutput, EngineCoreOutputs from vllm.v1.outputs import LogprobsTensors diff --git a/tests/v1/worker/test_dsv4_packed_zeroer_geometry.py b/tests/v1/worker/test_dsv4_packed_zeroer_geometry.py index 299ef7695f..4cc8f9ffe2 100644 --- a/tests/v1/worker/test_dsv4_packed_zeroer_geometry.py +++ b/tests/v1/worker/test_dsv4_packed_zeroer_geometry.py @@ -101,8 +101,7 @@ def test_packed_dsv4_zeroer_zeroes_only_each_layers_page(): def test_overlaid_zeroer_dedups_segments_with_max_span(): """Two groups overlay one allocation; the zeroer must emit one segment per distinct byte offset, spanning the widest overlaid page, so a newly allocated block is fully - zeroed no matter which group owns it. - """ + zeroed no matter which group owns it.""" from unittest.mock import MagicMock from vllm.v1.core.kv_cache_utils import get_kv_cache_config_from_groups diff --git a/tests/v1/worker/test_encoder_runner.py b/tests/v1/worker/test_encoder_runner.py index 28df60f49d..f8bd50c6d9 100644 --- a/tests/v1/worker/test_encoder_runner.py +++ b/tests/v1/worker/test_encoder_runner.py @@ -97,8 +97,7 @@ def test_draft_lookahead_uses_boundary_feature_when_cached(): """The drafter's +1 look-ahead can reach the feature at offset == processed_end (the next chunk). When its encoder output is already cached (the scheduler encoded it ahead), it is used for the look-ahead position - rather than ignored. - """ + rather than ignored.""" f0 = _feature("h0", offset=0, length=8) f1 = _feature("h1", offset=8, length=8) # starts exactly at processed_end runner = _make_runner([f0, f1], cached=[f0, f1]) @@ -115,8 +114,7 @@ def test_draft_lookahead_uses_boundary_feature_when_cached(): def test_draft_lookahead_tolerates_missing_boundary_feature(): """When the +1 look-ahead feature past the processed boundary is not yet encoded, fall back to the token embedding (the draft token is verified by - the target) instead of raising. - """ + the target) instead of raising.""" f0 = _feature("h0", offset=0, length=8) f1 = _feature("h1", offset=8, length=8) # boundary feature, not cached runner = _make_runner([f0, f1], cached=[f0]) @@ -133,8 +131,7 @@ def test_draft_lookahead_tolerates_missing_boundary_feature(): def test_draft_lookahead_raises_on_interior_miss(): """A miss for a feature within the processed range (not the look-ahead boundary) is a real invariant violation and must fail loudly, even on the - drafter path. - """ + drafter path.""" f0 = _feature("h0", offset=0, length=8) # interior, within processed range runner = _make_runner([f0], cached=[]) @@ -144,8 +141,7 @@ def test_draft_lookahead_raises_on_interior_miss(): def test_target_path_raises_on_encoder_cache_miss(): """On the target path (no look-ahead) a miss is a real invariant - violation and must fail loudly. - """ + violation and must fail loudly.""" f0 = _feature("h0", offset=0, length=8) runner = _make_runner([f0], cached=[]) @@ -156,8 +152,7 @@ def test_target_path_raises_on_encoder_cache_miss(): @pytest.mark.parametrize("draft_lookahead", [0, 1]) def test_multi_request_batch_gathers_per_request(draft_lookahead): """Two prefilling requests in one batch: per-request query bounds must be - indexed by request, not applied as whole arrays. - """ + indexed by request, not applied as whole arrays.""" a0 = _feature("a0", offset=0, length=8) b0 = _feature("b0", offset=0, length=8) cache = EncoderCache() diff --git a/tests/v1/worker/test_gpu_bad_words.py b/tests/v1/worker/test_gpu_bad_words.py index 6081163c4b..150c4ed007 100644 --- a/tests/v1/worker/test_gpu_bad_words.py +++ b/tests/v1/worker/test_gpu_bad_words.py @@ -73,8 +73,7 @@ def _apply(bad_words_token_ids: list[list[int]]) -> torch.Tensor: def test_v2_bad_words_prefix_inside_draft_tokens(): """A prefix matching entirely within the draft tokens must mask the bad - word's last token at the draft position that completes the prefix. - """ + word's last token at the draft position that completes the prefix.""" out = _apply([[12, 13, 40]]) expected = torch.zeros_like(out) expected[2, 40] = -float("inf") @@ -83,8 +82,7 @@ def test_v2_bad_words_prefix_inside_draft_tokens(): def test_v2_bad_words_prefix_spanning_committed_and_draft_tokens(): """A prefix spanning the committed/draft boundary must mask at the row - where the prefix completes, not one draft position later. - """ + where the prefix completes, not one draft position later.""" out = _apply([[11, 12, 30]]) expected = torch.zeros_like(out) expected[1, 30] = -float("inf") @@ -93,8 +91,7 @@ def test_v2_bad_words_prefix_spanning_committed_and_draft_tokens(): def test_v2_bad_words_no_spurious_match_from_last_committed_token(): """The last committed token must not be double-counted as the first draft - token; [11, 11] never occurs in output [10, 11] + drafts [12, 13]. - """ + token; [11, 11] never occurs in output [10, 11] + drafts [12, 13].""" out = _apply([[11, 11, 50]]) expected = torch.zeros_like(out) torch.testing.assert_close(out, expected) diff --git a/tests/v1/worker/test_gpu_batch_shard.py b/tests/v1/worker/test_gpu_batch_shard.py index 9f0b6da218..1309686d53 100644 --- a/tests/v1/worker/test_gpu_batch_shard.py +++ b/tests/v1/worker/test_gpu_batch_shard.py @@ -43,8 +43,7 @@ def _make_batch( slot_pool: np.ndarray | None = None, ) -> InputBatch: """Consistent batch with random unique request slots, 1 + k_i logits - rows per request at the tail of each query segment. - """ + rows per request at the tail of each query segment.""" if slot_pool is None: slot_pool = np.arange(max_num_reqs) slots = rng.choice(slot_pool, size=num_reqs, replace=False) @@ -142,8 +141,7 @@ def _owned_rows(cu: np.ndarray, owned: np.ndarray) -> np.ndarray: def test_local_batch_partition(tp_size: int, seed: int): """Local sub-batches partition the batch by owner, preserve batch order within an owner, and carry exactly the owned requests' entries of every - per-request and per-row array. - """ + per-request and per-row array.""" rng = np.random.default_rng(seed) max_num_reqs = 64 batch = _make_batch(rng, num_reqs=23, max_num_reqs=max_num_reqs, max_spec=3) @@ -225,8 +223,7 @@ def test_local_batch_partition(tp_size: int, seed: int): def test_all_to_all_reassembly_simulated(tp_size: int): """Vocab shards computed from owner-sorted hidden states and routed through the simulated all-to-all reassemble into exactly the full-vocab - logits of each rank's owned rows. - """ + logits of each rank's owned rows.""" rng = np.random.default_rng(7) max_num_reqs = 32 batch = _make_batch(rng, num_reqs=11, max_num_reqs=max_num_reqs, max_spec=4) @@ -264,8 +261,7 @@ def test_all_to_all_reassembly_simulated(tp_size: int): @requires_cuda def test_shard_no_spec(): """Batches without draft tokens (one logits row per request) degenerate - cleanly: rows mirror requests. - """ + cleanly: rows mirror requests.""" rng = np.random.default_rng(11) tp_size = 4 max_num_reqs = 32 @@ -284,8 +280,7 @@ def test_shard_no_spec(): @pytest.mark.parametrize("tp_size", [2, 4]) def test_shard_grammar_output(tp_size: int): """The grammar filter keeps exactly the owned requests' bitmask rows, in - grammar order, and the per-rank pieces partition the global bitmask. - """ + grammar order, and the per-rank pieces partition the global bitmask.""" rng = np.random.default_rng(5) max_num_reqs = 32 num_reqs = 12 @@ -340,8 +335,7 @@ def test_shard_grammar_output(tp_size: int): @pytest.mark.parametrize("tp_size", [2, 4]) def test_gather_src_indices_round_trip(tp_size: int): """Padded per-rank result blocks indexed by gathered_src_indices restore - batch order, including when some rank owns zero requests. - """ + batch order, including when some rank owns zero requests.""" rng = np.random.default_rng(3) max_num_reqs = 40 all_slots = np.arange(max_num_reqs) @@ -376,8 +370,7 @@ def test_gather_src_indices_round_trip(tp_size: int): def test_gather_sampler_output_kernels(tp_size: int): """The fused pack/unpack kernels round-trip per-rank sampler results into batch order: token ids zero-filled past the local width, counts - cast back to int32, identical on every rank. - """ + cast back to int32, identical on every rank.""" from dataclasses import replace as dc_replace from vllm.v1.worker.gpu.sample.output import SamplerOutput @@ -472,8 +465,7 @@ def test_gather_sampler_output_kernels(tp_size: int): def test_gather_sampler_output_logprobs_and_nans(): """num_nans is reduced per request and gathered; LogprobsTensors are packed into fixed per-request blocks, width-aligned across ranks (pad - and truncate paths), and restored to global row order. - """ + and truncate paths), and restored to global row order.""" from dataclasses import replace as dc_replace from vllm.v1.outputs import LogprobsTensors @@ -606,8 +598,7 @@ def test_gather_sampler_output_logprobs_and_nans(): def test_finish_requests_frees_slots_in_sorted_order(): """Request slots must be freed in the same order on every TP rank: ownership derives from slot indices, and `finished_req_ids` is a set - whose iteration order is per-process hash-randomized. - """ + whose iteration order is per-process hash-randomized.""" from vllm.v1.worker.gpu.model_runner import GPUModelRunner removed: list[str] = [] diff --git a/tests/v1/worker/test_gpu_block_table.py b/tests/v1/worker/test_gpu_block_table.py index f44edabea4..e77156eef9 100644 --- a/tests/v1/worker/test_gpu_block_table.py +++ b/tests/v1/worker/test_gpu_block_table.py @@ -217,8 +217,7 @@ def test_v1_block_table_move_row_clears_vacated_row(): not keep stale block ids. Padded dummy-run batches dereference stale rows as mamba state slots (bypassing the NULL_BLOCK_ID fill of real decode padding) and write state in place there — corrupting the blocks' new - owner once they are reallocated, e.g. to an in-flight NIXL load. - """ + owner once they are reallocated, e.g. to an in-flight NIXL load.""" from vllm.v1.worker.block_table import BlockTable block_table = BlockTable( @@ -250,8 +249,7 @@ def test_get_dummy_block_tables_returns_zeroed_rows(): PAD-filled, state indices are not), so stale rows would direct dummy state writes at freed — possibly reallocated — blocks. get_dummy_block_tables must hand out zeroed (null block) rows while - preserving the persistent storage address for CUDA graphs. - """ + preserving the persistent storage address for CUDA graphs.""" device = torch.device("cuda") block_tables = BlockTables( block_sizes=[16], diff --git a/tests/v1/worker/test_gpu_logit_bias.py b/tests/v1/worker/test_gpu_logit_bias.py index 8e7148575b..3bf62380bb 100644 --- a/tests/v1/worker/test_gpu_logit_bias.py +++ b/tests/v1/worker/test_gpu_logit_bias.py @@ -85,8 +85,7 @@ def test_v2_min_tokens_keeps_masking_when_other_candidates_remain(): def test_v2_min_tokens_mixed_batch_gates_restore_per_request(): """CHECK_ALL_MASKED_ROWS is a batch-wide constexpr, so a mixed batch must - still consult the per-request flag. - """ + still consult the per-request flag.""" out = _apply(_only_stop_token_left(2), structured=[True, False]) assert out[0, STOP_TOKEN] == 1.0 diff --git a/tests/v1/worker/test_gpu_model_runner.py b/tests/v1/worker/test_gpu_model_runner.py index 2dae086889..80e8318fa1 100644 --- a/tests/v1/worker/test_gpu_model_runner.py +++ b/tests/v1/worker/test_gpu_model_runner.py @@ -73,8 +73,7 @@ DEVICE_TYPE = current_platform.device_type def _restore_default_dtype(): """Several tests here set the process-wide default dtype to float16 and previously leaked it, corrupting later float-sensitive tests in the same - pytest process (torch.randn silently produced fp16). - """ + pytest process (torch.randn silently produced fp16).""" old = torch.get_default_dtype() yield torch.set_default_dtype(old) @@ -1454,8 +1453,7 @@ def test_v2_runner_snapshots_late_interleave_adjustment(monkeypatch): def test_hybrid_block_table_initialization(): """Test hybrid block table with different kernel and kvcache_manager block - sizes. - """ + sizes.""" from vllm.v1.worker.block_table import BlockTable # Test configuration: kvcache_manager block size = 32, diff --git a/tests/v1/worker/test_gpu_model_runner_mm_gather.py b/tests/v1/worker/test_gpu_model_runner_mm_gather.py index dcf754fcae..a86e77c8f5 100644 --- a/tests/v1/worker/test_gpu_model_runner_mm_gather.py +++ b/tests/v1/worker/test_gpu_model_runner_mm_gather.py @@ -62,8 +62,7 @@ def _gather(features, cached, *, num_scheduled, shift, num_computed=0): def test_draft_shift_uses_boundary_feature_when_cached(): """The drafter's +1 look-ahead reaches the feature at offset == processed_end; when it is already cached it is used for the look-ahead - position rather than ignored. - """ + position rather than ignored.""" f0 = _feature("h0", offset=0, length=8) f1 = _feature("h1", offset=8, length=8) # starts exactly at processed_end mm_embeds, is_mm_embed = _gather([f0, f1], [f0, f1], num_scheduled=8, shift=1) @@ -76,8 +75,7 @@ def test_draft_shift_uses_boundary_feature_when_cached(): def test_draft_shift_tolerates_missing_boundary_feature(): """When the +1 look-ahead feature past the processed boundary is not yet - encoded, fall back to the token embedding instead of raising. - """ + encoded, fall back to the token embedding instead of raising.""" f0 = _feature("h0", offset=0, length=8) f1 = _feature("h1", offset=8, length=8) # boundary feature, not cached mm_embeds, is_mm_embed = _gather([f0, f1], [f0], num_scheduled=8, shift=1) @@ -89,8 +87,7 @@ def test_draft_shift_tolerates_missing_boundary_feature(): def test_draft_shift_raises_on_interior_miss(): """A miss for a feature within the processed range (not the look-ahead - boundary) is a real invariant violation, even on the drafter path. - """ + boundary) is a real invariant violation, even on the drafter path.""" f0 = _feature("h0", offset=0, length=8) # interior, within processed range with pytest.raises(RuntimeError, match="Encoder cache miss"): _gather([f0], [], num_scheduled=8, shift=1) diff --git a/tests/v1/worker/test_gpu_model_runner_v2.py b/tests/v1/worker/test_gpu_model_runner_v2.py index 891778678b..308c9fe9ea 100644 --- a/tests/v1/worker/test_gpu_model_runner_v2.py +++ b/tests/v1/worker/test_gpu_model_runner_v2.py @@ -219,8 +219,7 @@ def test_append_block_ids_rejects_write_past_row_capacity(): def _make_capture_runner(captured: bool) -> GPUModelRunner: """Minimal V2 runner for capture_model: fakes everything except the - cudagraph_manager's needs_capture decision. - """ + cudagraph_manager's needs_capture decision.""" runner = GPUModelRunner.__new__(GPUModelRunner) runner.model_state = SimpleNamespace(supports_mm_inputs=False) runner.cudagraph_manager = SimpleNamespace( @@ -246,8 +245,7 @@ def _make_capture_runner(captured: bool) -> GPUModelRunner: def test_capture_model_locks_workspace_after_capture(monkeypatch): """A workspace resize after capture frees the buffer the captured graphs baked in, so capture_model must lock the workspace before returning - (https://github.com/vllm-project/vllm/issues/55336). - """ + (https://github.com/vllm-project/vllm/issues/55336).""" runner = _make_capture_runner(captured=True) monkeypatch.setattr( model_runner_module, "freeze_gc_for_cudagraph_capture", contextlib.nullcontext @@ -268,8 +266,7 @@ def test_capture_model_locks_workspace_after_capture(monkeypatch): def test_capture_model_skips_lock_when_nothing_captured(monkeypatch): """With no graphs to capture (e.g. enforce_eager) there is nothing baked - into the workspace, so the early return must not lock it. - """ + into the workspace, so the early return must not lock it.""" runner = _make_capture_runner(captured=False) lock_calls = [] monkeypatch.setattr( @@ -283,8 +280,7 @@ def test_capture_model_skips_lock_when_nothing_captured(monkeypatch): def test_capture_model_profile_only_skips_lock(monkeypatch): """The memory-profiling capture pass runs before kernel warmup and the real capture; locking there would stop the warmup from growing the - workspace to its scheduler-realistic size. - """ + workspace to its scheduler-realistic size.""" runner = _make_capture_runner(captured=True) monkeypatch.setattr( model_runner_module, "freeze_gc_for_cudagraph_capture", contextlib.nullcontext diff --git a/tests/v1/worker/test_gpu_model_runner_v2_cudagraph_profiling.py b/tests/v1/worker/test_gpu_model_runner_v2_cudagraph_profiling.py index 0230ff9b83..74191206d3 100644 --- a/tests/v1/worker/test_gpu_model_runner_v2_cudagraph_profiling.py +++ b/tests/v1/worker/test_gpu_model_runner_v2_cudagraph_profiling.py @@ -82,8 +82,7 @@ def _make_profiling_runner( class _FakePlatform: """Stands in for current_platform; the global graph pool is a class attr, - matching vllm.platforms.Platform's lazy singleton. - """ + matching vllm.platforms.Platform's lazy singleton.""" _global_graph_pool: Any = GLOBAL_POOL diff --git a/tests/v1/worker/test_gpu_profiler.py b/tests/v1/worker/test_gpu_profiler.py index fce0f93077..a283b6d932 100644 --- a/tests/v1/worker/test_gpu_profiler.py +++ b/tests/v1/worker/test_gpu_profiler.py @@ -120,8 +120,7 @@ def test_max_iterations(default_profiler_config): def test_restart_after_max_iterations(default_profiler_config): """A start_profile after an auto-stop must actually restart, not be silently ignored (regression test: auto-stop used to leave _active - True forever, so start() always bailed out early). - """ + True forever, so start() always bailed out early).""" default_profiler_config.max_iterations = 2 profiler = ConcreteWorkerProfiler(default_profiler_config) @@ -332,8 +331,7 @@ class TestAnnotateProfile: def test_profiler_entered_during_capture(): """Profiler is used as a context manager in _warmup_and_capture, - confirming it is active during the actual graph capture run. - """ + confirming it is active during the actual graph capture run.""" runner = MagicMock() runner.compilation_config.cudagraph_num_of_warmups = 0 mock_profiler = MagicMock() diff --git a/tests/v1/worker/test_gpu_rejection_sampler_i64.py b/tests/v1/worker/test_gpu_rejection_sampler_i64.py index b69732c8e1..769444ed64 100644 --- a/tests/v1/worker/test_gpu_rejection_sampler_i64.py +++ b/tests/v1/worker/test_gpu_rejection_sampler_i64.py @@ -34,8 +34,7 @@ def _run( ) -> tuple[torch.Tensor, torch.Tensor]: """Run rejection_sample on a batch of uniform k=2 requests, with the request under test at request index `roi_req` and draft-logits row - `req_state_idx`. Returns that request's (sampled, num_sampled). - """ + `req_state_idx`. Returns that request's (sampled, num_sampled).""" num_logits = num_reqs * LOGITS_PER_REQ roi_row = roi_req * LOGITS_PER_REQ diff --git a/tests/v1/worker/test_gpu_thinking_budget.py b/tests/v1/worker/test_gpu_thinking_budget.py index a7fe0608a7..2bc697b084 100644 --- a/tests/v1/worker/test_gpu_thinking_budget.py +++ b/tests/v1/worker/test_gpu_thinking_budget.py @@ -288,8 +288,7 @@ def test_v2_thinking_budget_clamps_oversized_budget(): def test_v2_thinking_budget_continues_end_prefix_from_prompt(): """A resumed prompt ending with a partial forced-end marker must not - restart the marker sequence and duplicate its first token. - """ + restart the marker sequence and duplicate its first token.""" req_states = _make_req_states([1, START, 10, 11, END_A], prompt_len=5) state = ThinkingBudgetState(req_states, MockMultiTokenEndReasoningConfig()) state.add_request(3, SamplingParams(thinking_token_budget=3)) diff --git a/tests/v1/worker/test_gpu_ubatch_slicing.py b/tests/v1/worker/test_gpu_ubatch_slicing.py index 13f1bbe45e..e735953d8b 100644 --- a/tests/v1/worker/test_gpu_ubatch_slicing.py +++ b/tests/v1/worker/test_gpu_ubatch_slicing.py @@ -701,8 +701,7 @@ def test_microbatches_recompute_dcp_lens_from_truncated_seq_lens(dcp_rank: int): @pytest.mark.skipif(not torch.cuda.is_available(), reason="triton kernel needs CUDA") def test_each_microbatch_owns_its_dcp_buffer(): """Microbatch DCP lengths live in per-microbatch persistent buffers so - CPU-visible shapes stay valid under CUDA graph capture and replay. - """ + CPU-visible shapes stay valid under CUDA graph capture and replay.""" input_batch, _ = _make_cuda_input_batch([4, 4, 4, 4], [8, 9, 10, 11]) ubatches, dcp_buffers = _slice_with_dcp(input_batch, dcp_rank=0) diff --git a/tests/v1/worker/test_gpu_worker.py b/tests/v1/worker/test_gpu_worker.py index f780b2f78f..88cbee6802 100644 --- a/tests/v1/worker/test_gpu_worker.py +++ b/tests/v1/worker/test_gpu_worker.py @@ -49,8 +49,7 @@ def plan_env(monkeypatch: pytest.MonkeyPatch, tmp_path): def test_startup_plan_fingerprint_sensitivity(plan_env): """The fingerprint is the OOM-safety key: stable for identical inputs, - different for anything the profiled value depends on. - """ + different for anything the profiled value depends on.""" fp = startup_plan.compute_plan_fingerprint base = fp(_plan_worker().vllm_config, 0, 1) assert base == fp(_plan_worker().vllm_config, 0, 1) @@ -98,8 +97,7 @@ def _snapshot(free_memory, torch_memory=0): def _profile_result(consumed, reserved_before=0, reserved_after=0): """A result whose free-memory readings agree with `consumed`, which - `memory_profiling` derives as the drop in free memory, negative when it grew. - """ + `memory_profiling` derives as the drop in free memory, negative when it grew.""" return SimpleNamespace( total_consumed=consumed, transient_peak_headroom=0, @@ -127,8 +125,7 @@ def test_profiling_fallback_declines_when_free_memory_dropped(rocm): @pytest.mark.parametrize("rocm", [True], indirect=True) def test_profiling_fallback_replaces_a_released_measurement(rocm): """A negative measurement describes the rest of the device, so it is replaced - by this process's reservation, which the rest of the device cannot move. - """ + by this process's reservation, which the rest of the device cannot move.""" result = _profile_result( consumed=-RELEASED_BY_OTHERS, reserved_after=TORCH_RESERVED, @@ -152,8 +149,7 @@ def test_profiling_fallback_never_returns_a_negative_amount(rocm): @pytest.mark.parametrize("rocm", [False], indirect=True) def test_profiling_fallback_declines_off_rocm(rocm): """Platforms that account frees eagerly keep reporting the error, so the - caller's assertion stays reachable there. - """ + caller's assertion stays reachable there.""" result = _profile_result(consumed=-RELEASED_BY_OTHERS) assert maybe_rocm_profiling_fallback(result) is None @@ -177,8 +173,7 @@ def test_execute_model_waits_previous_pp_send_before_forward( monkeypatch: pytest.MonkeyPatch, ): """Previous device handles are waited before the forward pass; the - metadata handle is left to the GroupCoordinator's reaper. - """ + metadata handle is left to the GroupCoordinator's reaper.""" import torch from vllm.sequence import IntermediateTensors diff --git a/tests/v1/worker/test_kv_block_zeroer.py b/tests/v1/worker/test_kv_block_zeroer.py index de541c9df6..64a81771dd 100644 --- a/tests/v1/worker/test_kv_block_zeroer.py +++ b/tests/v1/worker/test_kv_block_zeroer.py @@ -358,8 +358,7 @@ def test_warmup_respects_available_block_count(): def test_zeroes_exactly_one_block_per_layer(layout: KVCacheLayout): """The zeroer must zero every byte of the target block in every layer and nothing outside it — per head-group region under LHBNC, and never past the target block's - tile under block-major layouts (no out-of-bounds writes, no clobbering). - """ + tile under block-major layouts (no out-of-bounds writes, no clobbering).""" device = torch.device("cuda") num_blocks, num_layers = 4, 2 spec = FullAttentionSpec( diff --git a/tests/v1/worker/test_mamba_utils.py b/tests/v1/worker/test_mamba_utils.py index bce4c8c358..47a27795ca 100644 --- a/tests/v1/worker/test_mamba_utils.py +++ b/tests/v1/worker/test_mamba_utils.py @@ -645,8 +645,7 @@ def test_mamba_groups_support_mixed_specs_in_uniform_group(): def _make_staging_ctx(max_num_reqs: int, device: torch.device) -> MagicMock: """Build a MambaSpecDecodeGPUContext stand-in exposing only the four - per-request staging buffers touched by stage_postprocess_inputs_to_gpu. - """ + per-request staging buffers touched by stage_postprocess_inputs_to_gpu.""" ctx = MagicMock() ctx.mamba_state_idx_buf = _MockCpuGpuBuffer(max_num_reqs, torch.int32, device) ctx.num_scheduled_tokens_buf = _MockCpuGpuBuffer(max_num_reqs, torch.int32, device) @@ -658,8 +657,7 @@ def _make_staging_ctx(max_num_reqs: int, device: torch.device) -> MagicMock: def test_stage_postprocess_inputs_to_gpu_fills_pinned_views(): """stage_postprocess_inputs_to_gpu writes each request's state_idx and scheduled/computed/draft counts into slot `i` for `req_ids[i]`, leaves - slots past `num_reqs` untouched, and mirrors the values to the GPU buffers. - """ + slots past `num_reqs` untouched, and mirrors the values to the GPU buffers.""" device = torch.device("cpu") max_num_reqs = 8 ctx = _make_staging_ctx(max_num_reqs, device) @@ -731,8 +729,7 @@ def test_stage_postprocess_inputs_to_gpu_fills_pinned_views(): def test_stage_postprocess_inputs_to_gpu_asserts_on_missing_state_idx(): """If preprocess_mamba didn't populate mamba_state_idx for a req in the - batch, staging must fail loudly rather than silently writing a stale index. - """ + batch, staging must fail loudly rather than silently writing a stale index.""" device = torch.device("cpu") ctx = _make_staging_ctx(max_num_reqs=4, device=device) scheduler_output = _make_postprocess_scheduler_output( @@ -810,8 +807,7 @@ def _run_gpu_postprocess( device: torch.device, ) -> None: """Initialize the GPU context against `block_table`, run the fused - postprocess kernel for `req_ids`, and synchronize. - """ + postprocess kernel for `req_ids`, and synchronize.""" def t(values): return torch.tensor(values, dtype=torch.int32, device=device) diff --git a/tests/v1/worker/test_mixed_warmup_gate.py b/tests/v1/worker/test_mixed_warmup_gate.py index d4123269a9..04f456a7c9 100644 --- a/tests/v1/worker/test_mixed_warmup_gate.py +++ b/tests/v1/worker/test_mixed_warmup_gate.py @@ -17,8 +17,7 @@ def _fail(*args, **kwargs): @pytest.mark.parametrize("max_num_reqs", [1, 0]) def test_mixed_warmup_skipped_for_single_seq(max_num_reqs): """A mixed prefill+decode step needs >=2 requests; with max_num_reqs < 2 - the warmup must be skipped without touching the worker callbacks. - """ + the warmup must be skipped without touching the worker callbacks.""" runner = SimpleNamespace(is_pooling_model=False, max_num_reqs=max_num_reqs) assert ( diff --git a/tests/v1/worker/test_prompt_embeds_state.py b/tests/v1/worker/test_prompt_embeds_state.py index f28c6d2e01..1893d0f347 100644 --- a/tests/v1/worker/test_prompt_embeds_state.py +++ b/tests/v1/worker/test_prompt_embeds_state.py @@ -78,8 +78,7 @@ def _apply( def test_overlay_chunked_prefill_and_decode(): """Rows within the embeds range come from prompt_embeds at the num_computed offset; requests without embeds and requests past their - embeds length (decode) keep the base embedding. - """ + embeds length (decode) keep the base embedding.""" state = _make_state() embeds_a = torch.randn(6, HIDDEN, dtype=torch.float32) embeds_b = torch.randn(5, HIDDEN, dtype=torch.float32) @@ -98,8 +97,7 @@ def test_overlay_chunked_prefill_and_decode(): def test_overlay_clamps_to_embeds_length(): """A window straddling the end of the prompt embeds writes only the - in-range rows (e.g. final prefill chunk + sampled token). - """ + in-range rows (e.g. final prefill chunk + sampled token).""" state = _make_state() embeds = torch.randn(4, HIDDEN, dtype=torch.float32) state.add_request(3, _NewReqData("a", embeds)) @@ -114,8 +112,7 @@ def test_overlay_clamps_to_embeds_length(): def test_overlay_respects_is_token_ids_mask(): """Mixed mode: positions marked as real token ids keep the base - embedding; only embed positions are overwritten. - """ + embedding; only embed positions are overwritten.""" state = _make_state() embeds = torch.randn(5, HIDDEN, dtype=torch.float32) is_token_ids = [True, False, False, True, False] @@ -133,8 +130,7 @@ def test_overlay_respects_is_token_ids_mask(): def test_index_reuse_clears_stale_entry(): """A request added at a previously-used index without embeds must not - inherit the prior occupant's pointer-table entry. - """ + inherit the prior occupant's pointer-table entry.""" state = _make_state() state.add_request(0, _NewReqData("a", torch.randn(4, HIDDEN, dtype=torch.float32))) # A second live embeds request so the kernel actually launches (the diff --git a/tests/v1/worker/test_workspace.py b/tests/v1/worker/test_workspace.py index cc52f28e4b..7824c8000d 100644 --- a/tests/v1/worker/test_workspace.py +++ b/tests/v1/worker/test_workspace.py @@ -84,8 +84,7 @@ def test_workspace_lanes_compose_with_ubatches(monkeypatch) -> None: def test_workspace_lock_blocks_growth_and_unlock_restores(monkeypatch) -> None: """Once locked, oversized requests fail loudly instead of reallocating the - buffer that captured CUDA graphs point at; unlock restores growth. - """ + buffer that captured CUDA graphs point at; unlock restores growth.""" monkeypatch.setattr(workspace, "dbo_current_ubatch_id", lambda: 0) manager = workspace.WorkspaceManager(torch.device("cpu"), num_lanes=1) diff --git a/tools/report_build_time_ninja.py b/tools/report_build_time_ninja.py index 916e29a35f..3b43fc988e 100644 --- a/tools/report_build_time_ninja.py +++ b/tools/report_build_time_ninja.py @@ -56,8 +56,7 @@ class Target: def __init__(self, start, end): """Creates a target object by passing in the start/end times in seconds - as a float. - """ + as a float.""" self.start = start self.end = end # A list of targets, appended to by the owner of this object. @@ -105,8 +104,7 @@ class Target: def ReadTargets(log, show_all): """Reads all targets from .ninja_log file |log_file|, sorted by duration. - The result is a list of Target objects. - """ + The result is a list of Target objects.""" header = log.readline() assert header == "# ninja log v5\n", "unrecognized ninja log version {!r}".format( header @@ -155,8 +153,7 @@ def GetExtension(target, extra_patterns): For targets that generate multiple outputs it is important to return a consistent 'canonical' extension. Ultimately the goal is to group build steps - by type. - """ + by type.""" for output in target.targets: if extra_patterns: for fn_pattern in extra_patterns.split(";"): diff --git a/vllm/_aiter_ops.py b/vllm/_aiter_ops.py index dfcba987d6..da4bc310d7 100644 --- a/vllm/_aiter_ops.py +++ b/vllm/_aiter_ops.py @@ -1974,8 +1974,7 @@ class rocm_aiter_ops: enabled aiter. Only aiter's Triton kernels exist on gfx12 (no CK build), so this deliberately stays off the gfx9/CK `@if_aiter_supported` umbrella and gates only the Triton paths rdna4 uses. The gfx12 analog of - `is_enabled()`. - """ + `is_enabled()`.""" if not current_platform.is_rocm() or not IS_AITER_FOUND: return False from vllm.platforms.rocm import on_rdna4 diff --git a/vllm/benchmarks/datasets/create_txt_slices_dataset.py b/vllm/benchmarks/datasets/create_txt_slices_dataset.py index e4555bce9a..1bcd93c8ae 100644 --- a/vllm/benchmarks/datasets/create_txt_slices_dataset.py +++ b/vllm/benchmarks/datasets/create_txt_slices_dataset.py @@ -65,8 +65,7 @@ def create_txt_slices_jsonl( trust_remote_code: bool = False, ) -> None: """Read *input_path*, slice it into prompts, and write JSONL to - *output_path*. - """ + *output_path*.""" tokenizer = AutoTokenizer.from_pretrained( tokenizer_name, trust_remote_code=trust_remote_code ) diff --git a/vllm/benchmarks/datasets/datasets.py b/vllm/benchmarks/datasets/datasets.py index 3456fc6337..8f9e87cf83 100644 --- a/vllm/benchmarks/datasets/datasets.py +++ b/vllm/benchmarks/datasets/datasets.py @@ -4383,8 +4383,7 @@ class PrefixRepetitionRandomDataset(BenchmarkDataset): def _generate_exact_length_tokens(target_length: int) -> tuple[list[int], int]: """Generate tokens that decode and re-encode to exactly - target_length. - """ + target_length.""" # Generate random tokens tokens = np.random.randint(0, vocab_size, size=target_length).tolist() diff --git a/vllm/benchmarks/lib/endpoint_request_func.py b/vllm/benchmarks/lib/endpoint_request_func.py index 5adb54c47f..2b4027b502 100644 --- a/vllm/benchmarks/lib/endpoint_request_func.py +++ b/vllm/benchmarks/lib/endpoint_request_func.py @@ -22,8 +22,7 @@ AIOHTTP_TIMEOUT = aiohttp.ClientTimeout(total=6 * 60 * 60) class StreamedResponseHandler: """Handles streaming HTTP responses by accumulating chunks until complete - messages are available. - """ + messages are available.""" def __init__(self): self.buffer = "" @@ -31,8 +30,7 @@ class StreamedResponseHandler: def add_chunk(self, chunk_bytes: bytes) -> list[str]: """Add a chunk of bytes to the buffer and return any complete - messages. - """ + messages.""" chunk_str = self._decoder.decode(chunk_bytes) self.buffer += chunk_str diff --git a/vllm/compilation/backends.py b/vllm/compilation/backends.py index fb981a3600..4ac6949316 100644 --- a/vllm/compilation/backends.py +++ b/vllm/compilation/backends.py @@ -150,8 +150,7 @@ class CompilerManager: def compile_context(self, compile_range: Range) -> Generator[None, None, None]: """Provide compilation context for the duration of compilation to set any torch global properties we want to scope to a single Inductor - compilation (e.g. partition rules, pass context). - """ + compilation (e.g. partition rules, pass context).""" with pass_context(compile_range): if self.compilation_config.use_inductor_graph_partition: with inductor_partition_rule_context( diff --git a/vllm/compilation/compiler_interface.py b/vllm/compilation/compiler_interface.py index 0195a08799..67aff0fe1e 100644 --- a/vllm/compilation/compiler_interface.py +++ b/vllm/compilation/compiler_interface.py @@ -153,8 +153,7 @@ def _get_vllm_functorch_config() -> dict[str, Any]: """Return the functorch config overrides that vLLM applies at compile time. Used by both set_functorch_config() and get_inductor_factors() to ensure - the compile-time config and cache key are always consistent. - """ + the compile-time config and cache key are always consistent.""" cfg: dict[str, Any] = {} if not envs.VLLM_USE_MEGA_AOT_ARTIFACT: cfg["bundled_autograd_cache"] = False diff --git a/vllm/compilation/passes/fusion/allreduce_rms_fusion.py b/vllm/compilation/passes/fusion/allreduce_rms_fusion.py index bb41c9550d..b2961debce 100644 --- a/vllm/compilation/passes/fusion/allreduce_rms_fusion.py +++ b/vllm/compilation/passes/fusion/allreduce_rms_fusion.py @@ -66,8 +66,7 @@ def _view_flashinfer_nvfp4_scale_out_as_int32( def _norm_input_weight_dtype_match(match: pm.Match) -> bool: """Prevent fusion when the norm input and weight dtypes differ (e.g. a Gemma - fp32 weight.float()+1 gamma), covering rms_norm and fused_add_rms_norm. - """ + fp32 weight.float()+1 gamma), covering rms_norm and fused_add_rms_norm.""" for node in match.nodes: if node.target == _IR_RMS_NORM_OP: x, weight = node.args[0], node.args[1] diff --git a/vllm/compilation/passes/utility/split_coalescing.py b/vllm/compilation/passes/utility/split_coalescing.py index 9b60d10fba..f16623a1aa 100644 --- a/vllm/compilation/passes/utility/split_coalescing.py +++ b/vllm/compilation/passes/utility/split_coalescing.py @@ -30,8 +30,7 @@ logger = init_logger(__name__) class SplitCoalescingPass(VllmInductorPass): """Replace duplicate ``split_with_sizes`` nodes with a single canonical - node when they share the same input tensor and split sizes. - """ + node when they share the same input tensor and split sizes.""" @VllmInductorPass.time_and_log def __call__(self, graph: fx.Graph) -> None: diff --git a/vllm/config/compilation.py b/vllm/config/compilation.py index f1b5e90f2a..8ccc7332bd 100644 --- a/vllm/config/compilation.py +++ b/vllm/config/compilation.py @@ -36,8 +36,7 @@ logger = init_logger(__name__) class CompilationMode(enum.IntEnum): """The compilation approach used for torch.compile-based compilation of the - model. - """ + model.""" NONE = 0 """No torch.compile compilation is applied, model runs in fully eager pytorch mode. @@ -337,8 +336,7 @@ class PassConfig: class DynamicShapesType(str, enum.Enum): """Types of dynamic shapes handling in torch.compile(). see Dynamic shapes and vllm guard dropping in torch_compile.md - for more details. - """ + for more details.""" BACKED = "backed" """Use backed dynamic shapes. torch.compile() guards on backed dynamic diff --git a/vllm/config/model.py b/vllm/config/model.py index a07fbbc7a2..9ee35069da 100644 --- a/vllm/config/model.py +++ b/vllm/config/model.py @@ -1005,8 +1005,7 @@ class ModelConfig: def _get_transformers_backend_cls(self) -> str: """Determine which Transformers modeling backend class will be used if - `model_impl` is set to `transformers` or `auto`. - """ + `model_impl` is set to `transformers` or `auto`.""" cls = "Transformers" # If 'hf_config is not hf_text_config' it's a nested config, i.e. multimodal cls += "MultiModal" if self.hf_config is not self.hf_text_config else "" diff --git a/vllm/config/multimodal.py b/vllm/config/multimodal.py index 5f93fce0aa..09e184b8ce 100644 --- a/vllm/config/multimodal.py +++ b/vllm/config/multimodal.py @@ -524,8 +524,7 @@ class MultiModalConfig: def get_video_pruning_spec(self) -> tuple[VideoPruningMethod, float] | None: """Return `(method, rate)` when video pruning is enabled, else None. - `rate` is the fraction of video tokens to prune. - """ + `rate` is the fraction of video tokens to prune.""" if self.video_pruning_rate is not None and self.video_pruning_rate > 0: return (self.video_pruning_method, float(self.video_pruning_rate)) return None diff --git a/vllm/config/observability.py b/vllm/config/observability.py index c964fe904d..e24668b1a6 100644 --- a/vllm/config/observability.py +++ b/vllm/config/observability.py @@ -156,8 +156,7 @@ class ObservabilityConfig: cls, value: list[DetailedTraceModules] | None ) -> list[DetailedTraceModules] | None: """Handle the legacy case where users might provide a comma-separated - string instead of a list of strings. - """ + string instead of a list of strings.""" if value is not None and len(value) == 1 and "," in value[0]: value = cast(list[DetailedTraceModules], value[0].split(",")) return value diff --git a/vllm/config/reasoning.py b/vllm/config/reasoning.py index e00d9adc27..0ac93be082 100644 --- a/vllm/config/reasoning.py +++ b/vllm/config/reasoning.py @@ -47,15 +47,13 @@ class ReasoningConfig: @property def enabled(self) -> bool: """Returns True if reasoning is enabled (i.e. if token IDs have been - initialized), False otherwise. - """ + initialized), False otherwise.""" return self._enabled @property def reasoning_start_token_ids(self) -> list[int] | None: """Token IDs derived from `reasoning_start_str`. Set automatically by - `initialize_token_ids`. Not intended to be configured directly. - """ + `initialize_token_ids`. Not intended to be configured directly.""" return self._reasoning_start_token_ids @property diff --git a/vllm/config/speculative.py b/vllm/config/speculative.py index 96340df591..63f729a832 100644 --- a/vllm/config/speculative.py +++ b/vllm/config/speculative.py @@ -543,8 +543,7 @@ class SpeculativeConfig: @staticmethod def _acceptance_length_to_rates(length: float, n: int) -> list[float]: """Mean acceptance length to unconditional per-position rates, using - the minimum-variance schedule. - """ + the minimum-variance schedule.""" num_drafts = length - 1 # expected number of accepted draft tokens num_full = int(num_drafts) return ( @@ -558,8 +557,7 @@ class SpeculativeConfig: length: float | None, ) -> list[float]: """Return per-position unconditional acceptance rates from exactly one - of `rates` or `length` (validates range, length, and monotonicity). - """ + of `rates` or `length` (validates range, length, and monotonicity).""" if (rates is None) == (length is None): raise ValueError( "rejection_sample_method='synthetic' requires exactly one of " diff --git a/vllm/config/utils.py b/vllm/config/utils.py index 192b8bc870..ed72474619 100644 --- a/vllm/config/utils.py +++ b/vllm/config/utils.py @@ -84,8 +84,7 @@ def config( def get_field(cls: ConfigType, name: str) -> Any: """Get the default factory field of a dataclass by name. Used for getting - default factory fields in `EngineArgs`. - """ + default factory fields in `EngineArgs`.""" if not is_dataclass(cls): raise TypeError("The given class is not a dataclass.") try: @@ -122,8 +121,7 @@ def is_init_field(cls: ConfigType, name: str) -> bool: def replace(dataclass_instance: ConfigT, /, **kwargs) -> ConfigT: """Like [`dataclasses.replace`](https://docs.python.org/3/library/dataclasses.html#dataclasses.replace), but compatible with Pydantic dataclasses which use `pydantic.fields.Field` instead - of `dataclasses.field` - """ + of `dataclasses.field`""" cls = type(dataclass_instance) dataclass_dict = dataclass_instance.__dict__ dataclass_dict = {k: v for k, v in dataclass_dict.items() if is_init_field(cls, k)} diff --git a/vllm/config/vllm.py b/vllm/config/vllm.py index 174e184c53..e5710dced3 100644 --- a/vllm/config/vllm.py +++ b/vllm/config/vllm.py @@ -153,8 +153,7 @@ IS_DENSE = False def enable_norm_fusion(cfg: "VllmConfig") -> bool: """Enable if either RMS norm or quant FP8 custom op is active; - otherwise Inductor handles fusion. - """ + otherwise Inductor handles fusion.""" return ( cfg.compilation_config.is_custom_op_enabled("rms_norm") or cfg.compilation_config.is_custom_op_enabled("quant_fp8") @@ -744,8 +743,7 @@ class VllmConfig: def _is_dflash2_draft(self) -> bool: """Whether the DFlash draft is a DFlash2 one, by the architecture the - speculator selects on (v1/worker/gpu/spec_decode/__init__.py). - """ + speculator selects on (v1/worker/gpu/spec_decode/__init__.py).""" spec = self.speculative_config if spec is None or spec.method != "dflash": return False diff --git a/vllm/device_allocator/sleep_mode_backend.py b/vllm/device_allocator/sleep_mode_backend.py index bf28278f7c..45a635d613 100644 --- a/vllm/device_allocator/sleep_mode_backend.py +++ b/vllm/device_allocator/sleep_mode_backend.py @@ -70,8 +70,7 @@ class SleepModeBackend(ABC): def state(self) -> SleepModeState: """Current lifecycle state. Lets ``/health`` distinguish a healthy-idle - (suspended) engine from a healthy-serving one (see RFC #34303). - """ + (suspended) engine from a healthy-serving one (see RFC #34303).""" return self._state # -- Capability introspection (no instance required) -- @@ -84,30 +83,26 @@ class SleepModeBackend(ABC): @classmethod def preserves_communicators(cls) -> bool: """If False, collective communicators (e.g. NCCL) are destroyed by - ``suspend`` and the executor must re-initialize them on ``resume``. - """ + ``suspend`` and the executor must re-initialize them on ``resume``.""" return False @classmethod def preserves_compiled_artifacts(cls) -> bool: """If True, torch.compile / JIT kernels survive suspend/resume and need - not be recompiled on resume. - """ + not be recompiled on resume.""" return False @classmethod def preserves_graphs_with_communicators(cls) -> bool: """If True, CUDA graphs containing collective communicators (e.g. NCCL) stay valid after resume. False when communicators are rebuilt (embedded - comm handles go stale). - """ + comm handles go stale).""" return False @classmethod def supports_durable_storage(cls) -> bool: """If True, suspended state can be persisted beyond the process - lifetime (disk or object storage) and restored in a new process. - """ + lifetime (disk or object storage) and restored in a new process.""" return False diff --git a/vllm/distributed/device_communicators/all_reduce_utils.py b/vllm/distributed/device_communicators/all_reduce_utils.py index 43e615a398..a8298a459f 100644 --- a/vllm/distributed/device_communicators/all_reduce_utils.py +++ b/vllm/distributed/device_communicators/all_reduce_utils.py @@ -156,8 +156,7 @@ def should_nccl_symm_mem_allreduce(world_size: int, input_tensor: torch.Tensor) def should_nccl_symm_mem_ag_rs() -> bool: """Check whether NCCL symmetric memory should be used for - AllGather / ReduceScatter collectives. - """ + AllGather / ReduceScatter collectives.""" from vllm.distributed.device_communicators.pynccl_allocator import ( is_symmetric_memory_enabled, ) diff --git a/vllm/distributed/device_communicators/shm_broadcast.py b/vllm/distributed/device_communicators/shm_broadcast.py index f457cf61e8..bafc5728b8 100644 --- a/vllm/distributed/device_communicators/shm_broadcast.py +++ b/vllm/distributed/device_communicators/shm_broadcast.py @@ -650,8 +650,7 @@ class MessageQueue: def shutdown(self): """If this is an idle reader, wakes it up so it can clean up and shut - down - """ + down""" self.shutting_down = True if self._spin_condition is not None: self._spin_condition.cancel() @@ -761,8 +760,7 @@ class MessageQueue: def should_warn(self) -> bool: """Returns true if it's time to log a warning for a timeout that is not - indefinite - """ + indefinite""" if self._should_warn: elapsed = time.monotonic() - self.started if elapsed >= VLLM_RINGBUFFER_WARNING_INTERVAL * self.n_warning: diff --git a/vllm/distributed/ec_transfer/ec_connector/cpu/scheduler/embedding_cache.py b/vllm/distributed/ec_transfer/ec_connector/cpu/scheduler/embedding_cache.py index afadcfd42f..2fd4b01059 100644 --- a/vllm/distributed/ec_transfer/ec_connector/cpu/scheduler/embedding_cache.py +++ b/vllm/distributed/ec_transfer/ec_connector/cpu/scheduler/embedding_cache.py @@ -15,8 +15,7 @@ from collections import OrderedDict class CacheEntry: """A single cache entry. Read `.block_ids` and `.ready` freely; - mutations only through EmbeddingCache methods. - """ + mutations only through EmbeddingCache methods.""" __slots__ = ("block_ids", "_pin_count") diff --git a/vllm/distributed/eplb/eplb_communicator.py b/vllm/distributed/eplb/eplb_communicator.py index d05ca8e00c..61fef468d3 100644 --- a/vllm/distributed/eplb/eplb_communicator.py +++ b/vllm/distributed/eplb/eplb_communicator.py @@ -84,8 +84,7 @@ class EplbCommunicator(ABC): @property def needs_profile_buffer_reservation(self) -> bool: """Whether the profile path must run a dummy collective operation to reserve - communication buffers. - """ + communication buffers.""" return True def set_stream(self, cuda_stream: torch.cuda.Stream | None) -> None: @@ -443,8 +442,7 @@ class NixlEplbCommunicator(EplbCommunicator): def _exchange_remote_send_meta(self) -> None: """Exchange per-layer per-tensor metadata so receivers can compute - remote RDMA addresses at transfer time. - """ + remote RDMA addresses at transfer time.""" local_meta: dict[tuple[int, int], tuple[int, int, int]] = {} for layer_idx, layer_tensors in enumerate(self._all_expert_weights): for t_idx, t in enumerate(layer_tensors): diff --git a/vllm/distributed/kv_transfer/kv_connector/utils.py b/vllm/distributed/kv_transfer/kv_connector/utils.py index 9821f912b2..b645e97c4d 100644 --- a/vllm/distributed/kv_transfer/kv_connector/utils.py +++ b/vllm/distributed/kv_transfer/kv_connector/utils.py @@ -51,8 +51,7 @@ def get_kv_connector_cache_layout(vllm_config: VllmConfig | None = None): class KVOutputAggregator: """Utility class to aggregate the output of all workers into a single - output corresponding to Rank 0 for scheduler. - """ + output corresponding to Rank 0 for scheduler.""" def __init__(self, expected_finished_count: int): # Complete transfer tracker. Used to track finished requests diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/example_hidden_states_connector.py b/vllm/distributed/kv_transfer/kv_connector/v1/example_hidden_states_connector.py index 320d9ce804..e9a3e5d99a 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/example_hidden_states_connector.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/example_hidden_states_connector.py @@ -278,8 +278,7 @@ class ExampleHiddenStatesConnector(KVConnectorBase_V1, SupportsHMA): def _on_write_done(self, req_id: str, future: Future) -> None: """Surface any exception from the disk-write thread and drop the - completed future from the in-flight tracking dict. - """ + completed future from the in-flight tracking dict.""" self._req_futures.pop(req_id, None) exc = future.exception() if exc is not None: diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/lmcache_mp_connector.py b/vllm/distributed/kv_transfer/kv_connector/v1/lmcache_mp_connector.py index 31b20f0ed7..51f4ddf349 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/lmcache_mp_connector.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/lmcache_mp_connector.py @@ -231,8 +231,7 @@ class LMCacheMPRequestTracker: #### def needs_retrieve(self) -> bool: """Check whether the current request needs retrieve, will be used - update_stage_after_alloc - """ + update_stage_after_alloc""" return ( self.num_lmcache_hit_blocks > self.num_vllm_hit_blocks and self.state != LMCacheMPRequestState.READY @@ -240,8 +239,7 @@ class LMCacheMPRequestTracker: def is_ready_for_retrieving(self) -> bool: """Check whether the current request is ready for retrieving, - will be used in process_loading_requests - """ + will be used in process_loading_requests""" return ( self.state == LMCacheMPRequestState.WAITING_FOR_LOAD and self.needs_retrieve() diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/mooncake_connector.py b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/mooncake_connector.py index 4e6844034c..b22387e98b 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/mooncake_connector.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/mooncake_connector.py @@ -718,8 +718,7 @@ class MooncakeConnectorScheduler: def _get_remote_prefill_token_count(self, num_prompt_tokens: int) -> int: """D-side only. Returns N-1 for Mamba models since the decoder - always recomputes the last token and must start from h(N-1). - """ + always recomputes the last token and must start from h(N-1).""" if self._has_mamba and num_prompt_tokens > 1: return num_prompt_tokens - 1 return num_prompt_tokens @@ -730,8 +729,7 @@ class MooncakeConnectorScheduler: derive h(N) correctly. Guarded by ``_p_side_truncated`` to avoid repeated truncation if the - request is preempted and rescheduled. - """ + request is preempted and rescheduled.""" params = request.kv_transfer_params if ( params is not None @@ -1677,8 +1675,7 @@ class MooncakeConnectorWorker: def _bind_sender_thread_device(self) -> None: """ThreadPoolExecutor initializer — binds each pool thread to the correct CUDA device. CUDA device selection is thread-local, so - without this, NVLink transfers fail for TP ranks > 0. - """ + without this, NVLink transfers fail for TP ranks > 0.""" current_platform.set_device(self.device_id) def _send_blocks( @@ -1904,8 +1901,7 @@ class MooncakeConnectorWorker: def get_kv_connector_stats(self) -> KVConnectorStats | None: """Return transfer stats collected since the last call, or None - if nothing has been recorded in this interval. - """ + if nothing has been recorded in this interval.""" if self.xfer_stats.is_empty(): return None return self.xfer_stats.clone_and_reset() diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/coordinator.py b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/coordinator.py index 9e75c880d5..d05b553b64 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/coordinator.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/coordinator.py @@ -73,8 +73,7 @@ class ExternalCachedBlockPool: class MooncakeStoreCoordinator: """Mirror of ``HybridKVCacheCoordinator.find_longest_cache_hit`` over an - ``ExternalCachedBlockPool``. - """ + ``ExternalCachedBlockPool``.""" def __init__( self, diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py index fca59a12e0..762749987b 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py @@ -2629,8 +2629,7 @@ class LookupKeyClient: non_block: bool = False, ) -> MooncakeLookupResult | None: """If non_block is True, will return None until the result is ready, - so the caller retries on a later step. - """ + so the caller retries on a later step.""" future = self.futures.get(req_id) if future is None: future = self.executor.submit(self._lookup, num_tokens, list(block_hashes)) diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_connector.py b/vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_connector.py index ea6c363df3..f15eee9bd5 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_connector.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_connector.py @@ -548,8 +548,7 @@ class MoRIIOConnectorScheduler: self, request_id: ReqId, transfer_id: TransferId | None = None ): """Unmap request_id/transfer_id. Uses transfer_id for lookup if - exact request_id match fails (handles input_processor mutation). - """ + exact request_id match fails (handles input_processor mutation).""" if request_id in self.request_id_to_transfer_id: tid = self.request_id_to_transfer_id[request_id] del self.request_id_to_transfer_id[request_id] diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_scheduler.py b/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_scheduler.py index ed9123fc6a..e264a94aaf 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_scheduler.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_scheduler.py @@ -400,8 +400,7 @@ class NixlBaseConnectorScheduler: def _get_remote_prefill_token_count(self, num_prompt_tokens: int) -> int: """D-side only. The number of prompt tokens to load from the prefiller. Stops short of the trailing ``_prefill_backoff()`` tokens that the decoder - will recompute locally. - """ + will recompute locally.""" backoff = self._prefill_backoff() if backoff and num_prompt_tokens > backoff: return num_prompt_tokens - backoff @@ -414,8 +413,7 @@ class NixlBaseConnectorScheduler: multi-module MTP it is the drafter's whole lookahead window. Guarded by ``_p_side_truncated`` to avoid repeated truncation if the - request is preempted and rescheduled. - """ + request is preempted and rescheduled.""" backoff = self._prefill_backoff() params = request.kv_transfer_params if ( diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_worker.py b/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_worker.py index b261a13883..7bcdd2531b 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_worker.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/nixl/base_worker.py @@ -1873,8 +1873,7 @@ class NixlBaseConnectorWorker: ) -> np.ndarray: """Build remote desc regions (conv sub-projections + ssm) per layer. For hetero-TP, each D rank reads only its sub-projection slice from - the P rank. Returns an Nx3 uint64 array. - """ + the P rank. Returns an Nx3 uint64 array.""" assert nixl_agent_meta.kv_caches_base_addr, ( "Remote KV cache base addresses must not be empty." ) @@ -2657,8 +2656,7 @@ class NixlBaseConnectorWorker: @cached_property def _attention_kv_caches(self) -> list[torch.Tensor]: """Device KV caches of attention layers (mamba states excluded), - as consumed by the receive post-process. - """ + as consumed by the receive post-process.""" assert self.device_kv_caches, ( "_attention_kv_caches accessed before register_kv_caches" ) diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/nixl/push_worker.py b/vllm/distributed/kv_transfer/kv_connector/v1/nixl/push_worker.py index a61e5f8f78..01c956a525 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/nixl/push_worker.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/nixl/push_worker.py @@ -315,8 +315,7 @@ class NixlPushConnectorWorker(NixlBaseConnectorWorker): executes on the writer; the handshake runs on the background executor and the request is re-queued onto ``_reg_send_inbox`` once it completes (at which point ``_ensure_handshake`` returns ``None`` and we - send directly). - """ + send directly).""" remote_pp_size = reg_data.get("remote_pp_size", 1) fut = self._ensure_handshake( reg_data["remote_engine_id"], @@ -508,8 +507,7 @@ class NixlPushConnectorWorker(NixlBaseConnectorWorker): ``BlockIds`` is canonically a tuple of per-group lists, but some registration payloads collapse a single-group case to a flat list. Re-wrap that case so downstream group-aware helpers see a - consistent shape. - """ + consistent shape.""" if block_ids and not isinstance(block_ids[0], (list, tuple)): return (list(block_ids),) return block_ids diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/canonical_mapping.py b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/canonical_mapping.py index 3c51fa277f..27f08c1fd8 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/canonical_mapping.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/canonical_mapping.py @@ -37,8 +37,7 @@ def canonical_format_id(kv_cache_layout: str) -> str: Canonical pages keep the worker's KV layout family, so the id couples the format version with that family; consumers must match it exactly. The family keeps its historical NHD/HND spelling so ids stay stable for KV persisted - before the layout enum existed. - """ + before the layout enum existed.""" layout = KVCacheLayout[kv_cache_layout] legacy = {KVCacheLayout.LBNHC: "nhd", KVCacheLayout.LBHNC: "hnd"} family = legacy.get(layout, layout.name.lower()) @@ -122,8 +121,7 @@ def _interleave_cp_tokens( ctx: _RankContext, ) -> tuple[CopyRun, ...]: """Place each region's num_tokens rows at their canonical token positions, - one run per chunk of interleaved tokens. - """ + one run per chunk of interleaved tokens.""" runs: list[CopyRun] = [] for region in regions: if ctx.cp_size == 1: @@ -258,8 +256,7 @@ def _attention_byte_regions( cp_size: int, ) -> list[ByteRegion] | None: """Byte regions of an attention page, given this rank's head shard. - None when the physical layout is not recognized (fail closed). - """ + None when the physical layout is not recognized (fail closed).""" bs, heads, head_size = spec.block_size, spec.num_kv_heads, spec.head_size if tuple(kv_cache.shape) == (num_blocks, heads, bs, 2 * head_size): return _packed_kv_regions(kv_cache, spec, head_shard, num_head_shards, cp_size) @@ -373,8 +370,7 @@ def _is_exact_partition(intervals: list[tuple[int, int]], size: int) -> bool: def _verify_tiling(layer_name: str, per_rank: list[CanonicalPageMapping]) -> None: """Whichever ranks a block elects as writers must tile the canonical page - exactly once, and each rank's runs must cover exactly its local page. - """ + exactly once, and each rank's runs must cover exactly its local page.""" size = per_rank[0].canonical_page_size_bytes num_writers = per_rank[0].num_writers for mapping in per_rank: diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/events.py b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/events.py index a8789d81c4..6dcfcb5ec0 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/events.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/events.py @@ -79,8 +79,7 @@ def get_offloading_event_group_spec( class _OffloadEventMetadata: """BlockStored payload snapshot for one OffloadKey, captured while the Request is available and kept until the final matching removal event. - ``medium`` and ``ownership`` are forwarded from the OffloadingEvent. - """ + ``medium`` and ``ownership`` are forwarded from the OffloadingEvent.""" # The chunk's constituent block hashes; the last one is the OffloadKey. block_hashes: tuple[BlockHash, ...] @@ -256,8 +255,7 @@ class OffloadingEventsTracker: def reset(self) -> None: """Drop all tracked state; pending payloads are stale after a - manager cache reset. - """ + manager cache reset.""" self._pending_event_metadata.clear() def _build_event_metadata( @@ -268,8 +266,7 @@ class OffloadingEventsTracker: ) -> _OffloadEventMetadata: """Build the payload snapshot for one offloaded chunk: its constituent per-block hashes, the whole chunk's tokens, and the - per-block ``block_size``. - """ + per-block ``block_size``.""" hashes_per_chunk = group_config.hashes_per_chunk assert hashes_per_chunk > 0 assert chunk_idx >= 0 diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py index 961980ee89..d6c210a6f9 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/offloading/scheduler.py @@ -676,8 +676,7 @@ class OffloadingConnectorScheduler: start_chunk_idx: int, ) -> int | None: """Return the number of consecutive offloaded chunks from the start, - or None if the backend deferred a lookup. - """ + or None if the backend deferred a lookup.""" hit_count = 0 defer_lookup = False for local_idx, key in enumerate(keys): @@ -712,8 +711,7 @@ class OffloadingConnectorScheduler: """Return the end index (in `keys`) of the last run of `sliding_window_size` consecutive hits, scanning from the end. The first run may need a larger window for a partial rightmost chunk. - Returns 0 on miss, None if the backend deferred a lookup. - """ + Returns 0 on miss, None if the backend deferred a lookup.""" defer_lookup = False pending_in_window = False consecutive_hits = 0 diff --git a/vllm/distributed/utils.py b/vllm/distributed/utils.py index f830420074..b32269ec2b 100644 --- a/vllm/distributed/utils.py +++ b/vllm/distributed/utils.py @@ -59,8 +59,7 @@ def ensure_divisibility(numerator, denominator): def divide(numerator, denominator): """Ensure that numerator is divisible by the denominator and return - the division value. - """ + the division value.""" ensure_divisibility(numerator, denominator) return numerator // denominator diff --git a/vllm/distributed/weight_transfer/factory.py b/vllm/distributed/weight_transfer/factory.py index 74a04cc9d8..48f9e4f212 100644 --- a/vllm/distributed/weight_transfer/factory.py +++ b/vllm/distributed/weight_transfer/factory.py @@ -141,8 +141,7 @@ class WeightTransferTrainerFactory: class_name: str | None = None, ) -> None: """Register a trainer engine. Same conventions as - `WeightTransferEngineFactory.register_engine`. - """ + `WeightTransferEngineFactory.register_engine`.""" if name in cls._registry: raise ValueError( f"Weight transfer trainer engine '{name}' is already registered." diff --git a/vllm/distributed/weight_transfer/ipc_engine.py b/vllm/distributed/weight_transfer/ipc_engine.py index 83b5d15f58..15864811e9 100644 --- a/vllm/distributed/weight_transfer/ipc_engine.py +++ b/vllm/distributed/weight_transfer/ipc_engine.py @@ -40,8 +40,7 @@ class IPCWeightTransferInitInfo(WeightTransferInitInfo): `packed` is a must-agree wire param: the trainer ships it here at the init handshake so the worker decodes with the same setting the trainer encoded with. The consumer rebuilds from the IPC handle + `tensor_sizes`, so it does - not need the buffer size (producer-only). - """ + not need the buffer size (producer-only).""" packed: bool = False @@ -54,8 +53,7 @@ class IPCTrainerInitInfo(TrainerInitInfo): `packed` / `packed_buffer_size_bytes` are the transfer's wire params. The trainer propagates `packed` to the worker at `trainer_init` so the two sides - cannot disagree. `backend` is the factory dispatch key. - """ + cannot disagree. `backend` is the factory dispatch key.""" backend: ClassVar[str] = "ipc" packed: bool = False diff --git a/vllm/distributed/weight_transfer/nccl_common.py b/vllm/distributed/weight_transfer/nccl_common.py index 09e31f0291..57a17b9830 100644 --- a/vllm/distributed/weight_transfer/nccl_common.py +++ b/vllm/distributed/weight_transfer/nccl_common.py @@ -118,8 +118,7 @@ def worker_init_payload(init_info: NCCLWeightTransferInitInfo) -> dict: """Serialize a worker init info for `init_weight_transfer_engine`, dropping the unset rendezvous field (the UID in TCP mode) so the wire payload carries only the mode actually in use. Shared by the dense and sparse trainer - engines so the two cannot drift. - """ + engines so the two cannot drift.""" return {key: value for key, value in asdict(init_info).items() if value is not None} diff --git a/vllm/distributed/weight_transfer/nccl_engine.py b/vllm/distributed/weight_transfer/nccl_engine.py index 91298777a9..5b98845870 100644 --- a/vllm/distributed/weight_transfer/nccl_engine.py +++ b/vllm/distributed/weight_transfer/nccl_engine.py @@ -69,8 +69,7 @@ class NCCLTrainerInitInfo(TrainerInitInfo): propagates them to the worker at `trainer_init` so the two sides cannot disagree. Note this defaults to packed, unlike the worker-side `NCCLWeightTransferInitInfo`, whose default only applies when no trainer - ships a value. `backend` is the factory dispatch key. - """ + ships a value. `backend` is the factory dispatch key.""" backend: ClassVar[str] = "nccl" @@ -365,8 +364,7 @@ class NCCLTrainerWeightTransferEngine(TrainerWeightTransferEngine[NCCLTrainerIni def _broadcast(self, source: WeightSource, meta: list[ParamMeta]) -> None: """Iterate the source (materializing each tensor — a collective on all ranks) and, on the sender, broadcast from rank 0, packed or one-by-one. - Non-sender ranks only replay the iteration to stay in the collective. - """ + Non-sender ranks only replay the iteration to stay in the collective.""" if not self.is_sender: for _ in source: pass diff --git a/vllm/distributed/weight_transfer/sharded_rdt_common.py b/vllm/distributed/weight_transfer/sharded_rdt_common.py index eeda365965..0d91362817 100644 --- a/vllm/distributed/weight_transfer/sharded_rdt_common.py +++ b/vllm/distributed/weight_transfer/sharded_rdt_common.py @@ -214,8 +214,7 @@ class RdtRouter: def class_of(self, name: str) -> int: """The name's owner class — the planner's bucketing key, since all names - of a chunk must share one producer. - """ + of a chunk must share one producer.""" return self._class_of.get(name, 0) def owners(self, name: str) -> list[int]: @@ -286,8 +285,7 @@ class RdtRouter: def bind(self, actors: list, produce_methods: list, consumer_id: int) -> None: """Attach this consumer's producer handles. Rebuilt wholesale per init, never appended to: every owner index is a position in these lists, so a - rejoining engine that re-inits must not shift them. - """ + rejoining engine that re-inits must not shift them.""" if len(actors) != len(produce_methods): raise ValueError("actors and produce_methods must be parallel") self._actors = list(actors) @@ -350,6 +348,5 @@ def buffer_alloc_bytes(nbytes: int, presize: int = 0) -> int: optional ``presize`` floor, and a coarse 256MB round-up, so the buffer is allocated ONCE and never regrows. Regrowth is a correctness hazard, not just a perf one -- see ``buffer_presize_gb``. Shared by the consumer's receive buffers - and the producer's serve rings. - """ + and the producer's serve rings.""" return max(nbytes, presize, -(-nbytes // (256 << 20)) * (256 << 20)) diff --git a/vllm/distributed/weight_transfer/sharded_rdt_engine.py b/vllm/distributed/weight_transfer/sharded_rdt_engine.py index cfe84d2dd0..96dd53f0fd 100644 --- a/vllm/distributed/weight_transfer/sharded_rdt_engine.py +++ b/vllm/distributed/weight_transfer/sharded_rdt_engine.py @@ -134,8 +134,7 @@ class _PendingPull: ``targets``/``blob`` must stay strongly referenced until it completes: ``set_target_for_ref`` stores WEAKREFS, so dropping them silently reroutes the - transfer into a fallback buffer. - """ + transfer into a fallback buffer.""" ref: "Any" keys: "list[FetchKey]" @@ -562,8 +561,7 @@ class ShardedRDTWeightTransferEngine( def _build_static_plan(self, init_info: ShardedRDTWeightTransferInitInfo) -> None: """Build the chunk/free plan once. It never changes across syncs, so - ``update_weights`` needs no per-sync names. - """ + ``update_weights`` needs no per-sync names.""" if not init_info.group_lens: raise ValueError( "Sharded RDT engine requires init_info.group_lens (the gather-" @@ -587,8 +585,7 @@ class ShardedRDTWeightTransferEngine( Both sides are sized from the static plan: receive buffers are ``ring_depth`` slots at the largest chunk's ``pack_bytes``, and each bound producer is asked to pre-register a serve ring at the max bytes this - consumer will pull from it. A no-op when this worker has no chunks. - """ + consumer will pull from it. A no-op when this worker has no chunks.""" plan = self._cached_plan if plan is None or not plan.chunks: return @@ -633,8 +630,7 @@ class ShardedRDTWeightTransferEngine( ``data_parallel_index``, not ``data_parallel_rank``: vLLM resets the latter to 0 in a dense worker but keeps the former as the distinct global DP rank. Same formula as the sibling ``nccl_engine``, so dense-via-TP and - MoE-via-DP+EP both yield distinct 0..C-1. - """ + MoE-via-DP+EP both yield distinct 0..C-1.""" pc = self.parallel_config return pc.data_parallel_index * pc.world_size + pc.rank # world_size = TP*PP @@ -642,16 +638,14 @@ class ShardedRDTWeightTransferEngine( """Total inference-worker count. Prefers the driver-supplied ``init_info.num_consumers`` (authoritative -- the driver knows the whole fleet); else ``world_size_across_dp``, the same stride - ``_global_worker_index`` indexes with, so the two agree at any pp. - """ + ``_global_worker_index`` indexes with, so the two agree at any pp.""" if self._num_consumers_override > 0: return self._num_consumers_override return self.parallel_config.world_size_across_dp def start_weight_update(self) -> None: """Put the model's params on meta so layerwise reload streams them in - as each layer's slices land. Baked replay uses checkpoint format. - """ + as each layer's slices land. Baked replay uses checkpoint format.""" from vllm.model_executor.model_loader.reload import ( initialize_layerwise_reload, ) @@ -660,8 +654,7 @@ class ShardedRDTWeightTransferEngine( def finish_weight_update(self) -> None: """Drain the deferred pull/process pipeline (so every layer is fully - loaded) before finalizing the layerwise reload. - """ + loaded) before finalizing the layerwise reload.""" from vllm.model_executor.model_loader.reload import ( finalize_layerwise_reload, ) @@ -674,8 +667,7 @@ class ShardedRDTWeightTransferEngine( device sync: post-processing is deferred to background threads and a sync here would block on them and serialize the pull/process pipeline. Completion is guaranteed by ``drain_pending`` in - ``finish_weight_update``. - """ + ``finish_weight_update``.""" self.receive_weights(self.parse_update_info(update_info)) def receive_weights( @@ -717,8 +709,7 @@ class ShardedRDTWeightTransferEngine( device: torch.device, ) -> list[tuple[str, torch.Tensor]]: """Zero-storage lazies for ``names``, dtype/shape from the init metadata, - all feeding the bake's recording sink. - """ + all feeding the bake's recording sink.""" return [ ( name, @@ -986,8 +977,7 @@ class ShardedRDTWeightTransferEngine( def _ensure_proc_worker(self) -> None: """Lazily create the per-slot events, the background CUDA stream, the work - queue, and the single processing thread. Idempotent. - """ + queue, and the single processing thread. Idempotent.""" if self._proc_thread is not None: return import queue @@ -1046,8 +1036,7 @@ class ShardedRDTWeightTransferEngine( def _mark_slot_done(self, slot: int) -> None: """Publish that a queued item's read-done event has been recorded (or the item failed) so a pull waiting to reuse ``slot`` can proceed to its - CUDA-event synchronize. - """ + CUDA-event synchronize.""" with self._slot_cv: self._slot_done[slot] += 1 self._slot_cv.notify_all() @@ -1063,8 +1052,7 @@ class ShardedRDTWeightTransferEngine( """Block until the background thread has processed every queued item and its stream work is complete, then re-raise any error it hit. Called from the worker's ``finish_weight_update`` before ``finalize_layerwise_reload`` - so every baked layer is fully loaded (and ``info.reset()``-ed) first. - """ + so every baked layer is fully loaded (and ``info.reset()``-ed) first.""" if self._proc_queue is not None: self._proc_queue.join() # every put() item task_done()'d # The scatter thread feeds the quant thread, so join it SECOND (all @@ -1116,8 +1104,7 @@ class ShardedRDTWeightTransferEngine( which is exactly what an owner class is. The cut is a pure function of the bake and the ownership table. Copy order within a chunk is bake order, and a module's copies may span chunks (materialize/quant fire on - its first/last chunk; see ``_build_call_plan``). - """ + its first/last chunk; see ``_build_call_plan``).""" assert self._router is not None by_class: dict[int, list[_Scatter]] = {} for copies in modules: @@ -1248,8 +1235,7 @@ class ShardedRDTWeightTransferEngine( pulls nothing from. Refs are held and drained in ``drain_pending`` so every signal has EXECUTED before the sync ends: ``begin_sync`` resets the counters, and a straggler landing in the next sync would credit a - group it does not belong to. - """ + group it does not belong to.""" assert self._router is not None self._pending_frees.extend(self._router.free_group(group_idx)) @@ -1384,8 +1370,7 @@ class ShardedRDTWeightTransferEngine( the modules' scatters via ``ready``; touches only the scattered params (never a receive slot), so it can overlap subsequent chunks' RDMA and scatters. ``info.reset()`` is what makes finalize skip the layer — - drain_pending joins the quant queue before finalize runs. - """ + drain_pending joins the quant queue before finalize runs.""" from vllm.model_executor.layers.quantization.base_config import ( QuantizeMethodBase, ) @@ -1418,8 +1403,7 @@ class ShardedRDTWeightTransferEngine( def _quant_worker_loop(self) -> None: """Dedicated quant thread: drains (completed_modules, scatter-done event) - batches. Errors surface via _proc_error like the scatter thread's. - """ + batches. Errors surface via _proc_error like the scatter thread's.""" torch.cuda.set_device(self.device) q = self._quant_queue assert q is not None diff --git a/vllm/distributed/weight_transfer/sharded_rdt_fake.py b/vllm/distributed/weight_transfer/sharded_rdt_fake.py index 536329922b..5e3613e9d5 100644 --- a/vllm/distributed/weight_transfer/sharded_rdt_fake.py +++ b/vllm/distributed/weight_transfer/sharded_rdt_fake.py @@ -206,8 +206,7 @@ class FakeRDTTensor(torch.Tensor): def _meta(self) -> torch.Tensor: """A zero-storage meta tensor of this fake's shape/dtype, so PyTorch - itself computes post-op geometry rather than us reimplementing it. - """ + itself computes post-op geometry rather than us reimplementing it.""" return torch.empty(self.shape, dtype=self.dtype, device="meta") @classmethod @@ -251,8 +250,7 @@ class FakeRDTTensor(torch.Tensor): ): """Append the op and return a child, or a tuple of children for multi-return ops. Each child's geometry comes from running the op on a - meta tensor. - """ + meta tensor.""" meta = self_._meta() with torch._C.DisableTorchFunctionSubclass(): meta_result = func(meta, *args, **kwargs) diff --git a/vllm/distributed/weight_transfer/sharded_rdt_trainer.py b/vllm/distributed/weight_transfer/sharded_rdt_trainer.py index 4b16fece8f..6b755e772e 100644 --- a/vllm/distributed/weight_transfer/sharded_rdt_trainer.py +++ b/vllm/distributed/weight_transfer/sharded_rdt_trainer.py @@ -132,8 +132,7 @@ PRODUCE_METHOD_NAME = "rdt_produce_weights_batched" @dataclass class _SharedPack: """One generation of one slot-sharing group: the rendezvous state for a - single chunk, identified by the consumers' issue index. - """ + single chunk, identified by the consumers' issue index.""" group: int slot: int @@ -467,8 +466,7 @@ class _RDTProducerServer: def end_sync(self) -> list[int]: """Block until every published group has been freed by its consumers; - return the remaining freed keys so the engine drops its last refs. - """ + return the remaining freed keys so the engine drops its last refs.""" with self._cache_cond: self._wait_for( lambda: bool(self._inflight_groups), @@ -481,8 +479,7 @@ class _RDTProducerServer: def set_gather_error(self, message: str) -> None: """Record a trainer-side gather failure so blocked serves / publishes - stop waiting and surface it. - """ + stop waiting and surface it.""" with self._cache_cond: self._gather_error = RuntimeError(message) self._cache_cond.notify_all() @@ -511,8 +508,7 @@ class _RDTProducerServer: def _new_serve_buffer(self, nbytes: int) -> torch.Tensor: """Allocate + NIXL-register one serve slot: the single allocation seam, so registration cannot be skipped on either of the two paths that make - buffers (the init-time reservation and the serve-path backstop). - """ + buffers (the init-time reservation and the serve-path backstop).""" t = torch.empty(nbytes, dtype=torch.uint8, device=self._serve_device) with self._reg_lock: register_nixl_memory(t) @@ -584,15 +580,13 @@ class _RDTProducerServer: def _share_group(self, consumer_id: int) -> int: """The slot-sharing group ``consumer_id`` belongs to: its index within its own deployment, since that is what fixes the plan. Without a width - the group is the consumer itself and nothing is shared. - """ + the group is the consumer itself and nothing is shared.""" return consumer_id % self._share_width if self._share_width > 0 else consumer_id def _sharers_of(self, sg: int) -> frozenset: """The LIVE consumers of group ``sg``: the rendezvous width. Derived from ``begin_sync``'s live set, so a degraded sync narrows the barrier instead - of waiting forever on a dead deployment. Caller holds ``_cache_cond``. - """ + of waiting forever on a dead deployment. Caller holds ``_cache_cond``.""" cached = self._sharers.get(sg) if cached is None: if not self._sharing_active or self._live_ids is None: @@ -628,8 +622,7 @@ class _RDTProducerServer: def _await_shared_pack(self, gen: _SharedPack) -> torch.Tensor: """Block until this generation's packer published its blob, and return it. A failed pack is re-raised here, so every sharer of a bad pack fails - instead of reading a half-written slot. - """ + instead of reading a half-written slot.""" with self._cache_cond: self._wait_for( lambda: not gen.done and gen.error is None, @@ -650,8 +643,7 @@ class _RDTProducerServer: """Group ``sg``'s ring slot ``idx``, grown if this chunk outgrew the reservation. Growing registers memory while the fabric is busy, the hazard ``reserve_serve_buffer`` exists to avoid, so it is a backstop: the - reservation is sized from the same static plan as this pack. - """ + reservation is sized from the same static plan as this pack.""" with self._serve_lock: buffer = self._serve_rings.setdefault(sg, [None] * self._nring)[idx] if buffer is not None and buffer.numel() >= need: @@ -663,8 +655,7 @@ class _RDTProducerServer: def _fail_shared_pack(self, gen: _SharedPack, exc: BaseException) -> None: """Publish a pack failure so waiting sharers raise instead of hanging on - a generation that will never complete. - """ + a generation that will never complete.""" with self._cache_cond: gen.error = exc self._cache_cond.notify_all() @@ -866,8 +857,7 @@ class ShardedRDTTrainerWeightTransferEngine( def _rpc(self, method: str, *args: Any) -> Any: """Call one of the server actor's methods and block for the result. The single seam through which the engine talks to its server, so tests - can inject a local (non-Ray) fake server. - """ + can inject a local (non-Ray) fake server.""" import ray return ray.get(getattr(self._server, method).remote(*args)) @@ -944,8 +934,7 @@ class ShardedRDTTrainerWeightTransferEngine( """Fire publish_group WITHOUT waiting on the RPC (the gather loop overlaps the publish's server-side rebuild with the next group's gather) and return a handle that ``_await_publish`` resolves. Ray actor - handle in production; a plain (non-Ray) fake server runs inline. - """ + handle in production; a plain (non-Ray) fake server runs inline.""" method = self._server.publish_group remote = getattr(method, "remote", None) if remote is not None: @@ -956,8 +945,7 @@ class ShardedRDTTrainerWeightTransferEngine( """Resolve one async publish so a server-side rebuild error surfaces at window depth instead of at end_sync. Publishes carry nothing back — freed groups flow only through wait_freed/end_sync (one channel; see - publish_group). - """ + publish_group).""" import ray if isinstance(ref, ray.ObjectRef): @@ -1144,8 +1132,7 @@ class ShardedRDTTrainerWeightTransferEngine( by stall watchdog 300s later: consumers route pulls here, the pull passes the served-names guard, and the cache wait never completes. With it, that is an immediate error naming the weight. One set lookup per - name per sync. - """ + name per sync.""" if self._held_names is None: return for name, tensor in zip(names, tensors): @@ -1346,8 +1333,7 @@ class ShardedRDTTrainerWeightTransferEngine( credit releases when every live consumer has signaled the group). So the loop self-paces to the consumers' pull rate with at most `gather_lookahead + 1` groups resident. Runs on every rank; only the - sender has an `update_future` to fail fast on. - """ + sender has an `update_future` to fail fast on.""" assert self.source is not None # guaranteed by trainer_init # The live IDS ride along with the count: the free barrier needs only # the count, but the slot-sharing rendezvous needs to know WHICH diff --git a/vllm/distributed/weight_transfer/sparse_nccl_engine.py b/vllm/distributed/weight_transfer/sparse_nccl_engine.py index 3441f8febc..9c704ab344 100644 --- a/vllm/distributed/weight_transfer/sparse_nccl_engine.py +++ b/vllm/distributed/weight_transfer/sparse_nccl_engine.py @@ -68,8 +68,7 @@ class SparseNCCLTrainerInitInfo(TrainerInitInfo): Same rendezvous shape as the dense NCCL backend (the sender opens its endpoint as NCCL rank 0), but with no packed wire params: sparse transfers - are never packed. `backend` is the factory dispatch key. - """ + are never packed. `backend` is the factory dispatch key.""" backend: ClassVar[str] = "sparse_nccl" @@ -368,8 +367,7 @@ class SparseNCCLTrainerWeightTransferEngine( rebuild or free the patch tensors as soon as a send method returns rather than relying on same-stream ordering. See `NCCLTrainerWeightTransferEngine._post_send_sync` for why there is no - cross-rank barrier. - """ + cross-rank barrier.""" if torch.cuda.is_available(): torch.cuda.current_stream().synchronize() diff --git a/vllm/entrypoints/cli/main.py b/vllm/entrypoints/cli/main.py index 21a185b3c1..4ac960d8cb 100644 --- a/vllm/entrypoints/cli/main.py +++ b/vllm/entrypoints/cli/main.py @@ -3,8 +3,7 @@ """The CLI entrypoints of vLLM. Note that all future modules must be lazily loaded within main -to avoid certain eager import breakage. -""" +to avoid certain eager import breakage.""" import importlib.metadata import sys diff --git a/vllm/entrypoints/generate/base/serving.py b/vllm/entrypoints/generate/base/serving.py index 247e968d43..5142346df6 100644 --- a/vllm/entrypoints/generate/base/serving.py +++ b/vllm/entrypoints/generate/base/serving.py @@ -295,8 +295,7 @@ class GenerateBaseServing(BaseServing, BeamSearchOnlineMixin): ) -> _T: """Wrap a `create_*` coroutine so that, if it raises or returns an ErrorResponse (i.e. the request never reached the engine), the KV - connector is notified to free any pinned remote-prefill blocks. - """ + connector is notified to free any pinned remote-prefill blocks.""" kv_transfer_params = self.has_kv_connector and request.kv_transfer_params if not kv_transfer_params or not kv_transfer_params.get("do_remote_prefill"): return await awaitable diff --git a/vllm/entrypoints/openai/models/serving.py b/vllm/entrypoints/openai/models/serving.py index dc78cc3963..1e13311dce 100644 --- a/vllm/entrypoints/openai/models/serving.py +++ b/vllm/entrypoints/openai/models/serving.py @@ -123,8 +123,7 @@ class OpenAIServingModels: async def init_static_loras(self): """Loads all static LoRA modules. - Raises if any fail to load - """ + Raises if any fail to load""" if self.static_lora_modules is None: return for lora in self.static_lora_modules: @@ -149,8 +148,7 @@ class OpenAIServingModels: async def show_available_models(self) -> ModelList: """Show available models. This includes the base model and all - adapters. - """ + adapters.""" model_list = await self.registry.show_available_models() lora_cards = [ ModelCard( diff --git a/vllm/entrypoints/openai/responses/context.py b/vllm/entrypoints/openai/responses/context.py index 167f006ba0..077f78c02b 100644 --- a/vllm/entrypoints/openai/responses/context.py +++ b/vllm/entrypoints/openai/responses/context.py @@ -408,8 +408,7 @@ class ParsableContext(ConversationContext): def need_builtin_tool_call(self) -> bool: """Return true if the last message is a builtin tool call - that the request has enabled. - """ + that the request has enabled.""" last_message = self.response_messages[-1] if last_message.type != "function_call": return False diff --git a/vllm/entrypoints/openai/responses/harmony.py b/vllm/entrypoints/openai/responses/harmony.py index c1f3f1b716..1aae70a381 100644 --- a/vllm/entrypoints/openai/responses/harmony.py +++ b/vllm/entrypoints/openai/responses/harmony.py @@ -52,8 +52,7 @@ logger = init_logger(__name__) def _parse_harmony_format_message(chat_msg: dict) -> Message: """Reconstruct a Message from Harmony-format dict, - preserving channel, recipient, and content_type. - """ + preserving channel, recipient, and content_type.""" author_dict = chat_msg["author"] role = author_dict.get("role") name = author_dict.get("name") diff --git a/vllm/entrypoints/openai/responses/protocol.py b/vllm/entrypoints/openai/responses/protocol.py index f826c932a4..201e46ed04 100644 --- a/vllm/entrypoints/openai/responses/protocol.py +++ b/vllm/entrypoints/openai/responses/protocol.py @@ -117,8 +117,7 @@ def serialize_messages(msgs): class ResponseRawMessageAndToken(OpenAIBaseModel): """Class to show the raw message. - If message / tokens diverge, tokens is the source of truth - """ + If message / tokens diverge, tokens is the source of truth""" message: str tokens: list[int] diff --git a/vllm/entrypoints/pooling/pooling/io_processor.py b/vllm/entrypoints/pooling/pooling/io_processor.py index 51ce9ba0ef..4b18cfc9e1 100644 --- a/vllm/entrypoints/pooling/pooling/io_processor.py +++ b/vllm/entrypoints/pooling/pooling/io_processor.py @@ -44,8 +44,7 @@ class PluginWithoutIOProcessorPlugins(PoolingIOProcessor): class PluginWithIOProcessorPlugins(PoolingIOProcessor): """IO Processor plugins are a feature that allows pre- and post-processing - of the model input and output for pooling models. - """ + of the model input and output for pooling models.""" name = "plugin" diff --git a/vllm/entrypoints/scale_out/token_in_token_out/mm_serde.py b/vllm/entrypoints/scale_out/token_in_token_out/mm_serde.py index b754fcc42e..60a3560ad7 100644 --- a/vllm/entrypoints/scale_out/token_in_token_out/mm_serde.py +++ b/vllm/entrypoints/scale_out/token_in_token_out/mm_serde.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Encode/decode utilities for multimodal tensors and field metadata -over JSON/HTTP, used by the disaggregated generate endpoint. -""" +over JSON/HTTP, used by the disaggregated generate endpoint.""" from __future__ import annotations diff --git a/vllm/entrypoints/serve/exception_handling/handlers/validation.py b/vllm/entrypoints/serve/exception_handling/handlers/validation.py index acf2e57f3b..7cdcb3970e 100644 --- a/vllm/entrypoints/serve/exception_handling/handlers/validation.py +++ b/vllm/entrypoints/serve/exception_handling/handlers/validation.py @@ -126,8 +126,7 @@ def _format_error(err: object) -> str: def _is_internal_loc_segment(segment: str) -> bool: """True if `segment` is a Pydantic-internal wrapper/union-branch - marker rather than a user-meaningful field name or list index. - """ + marker rather than a user-meaningful field name or list index.""" if _BRACKETED_INTERNAL_RE.search(segment): return True return segment.lower() in _INTERNAL_LOC_MARKERS diff --git a/vllm/entrypoints/serve/lora/api_router.py b/vllm/entrypoints/serve/lora/api_router.py index cd7e5bc99e..61436371c2 100644 --- a/vllm/entrypoints/serve/lora/api_router.py +++ b/vllm/entrypoints/serve/lora/api_router.py @@ -63,8 +63,7 @@ def _attach_router(app: FastAPI): @router.post("/v1/load_lora_adapter", dependencies=[Depends(validate_json_request)]) async def load_lora_adapter(request: LoadLoRAAdapterRequest, raw_request: Request): """Handle POST /v1/load_lora_adapter: load a LoRA adapter into the - serving engine. - """ + serving engine.""" handler: OpenAIServingModels = models(raw_request) response = await handler.load_lora_adapter(request) if isinstance(response, ErrorResponse): @@ -86,8 +85,7 @@ def _attach_router(app: FastAPI): request: UnloadLoRAAdapterRequest, raw_request: Request ): """Handle POST /v1/unload_lora_adapter: unload a LoRA adapter from - the serving engine. - """ + the serving engine.""" handler: OpenAIServingModels = models(raw_request) response = await handler.unload_lora_adapter(request) if isinstance(response, ErrorResponse): diff --git a/vllm/entrypoints/serve/sagemaker/api_router.py b/vllm/entrypoints/serve/sagemaker/api_router.py index 5c4e3de740..f2fb255cee 100644 --- a/vllm/entrypoints/serve/sagemaker/api_router.py +++ b/vllm/entrypoints/serve/sagemaker/api_router.py @@ -30,8 +30,7 @@ EndpointFn = Callable[[RequestType, Request], Awaitable[Any]] def _snapshot_handler_levels() -> list[tuple[logging.Handler, int]]: """Snapshot handler levels for loggers that may be affected by third-party logging configuration side effects (e.g. model_hosting_container_standards - calling configure_root_logger() at import time). - """ + calling configure_root_logger() at import time).""" loggers = [logging.getLogger(), logging.getLogger("vllm")] seen: set[int] = set() snapshot: list[tuple[logging.Handler, int]] = [] @@ -74,8 +73,7 @@ def _attach_router( model_config: ModelConfig | None = None, ): """Register the SageMaker hosting routes (/ping, /invocations) on the - app. - """ + app.""" import model_hosting_container_standards.sagemaker as sagemaker_standards router = APIRouter() diff --git a/vllm/entrypoints/serve/utils/fingerprint.py b/vllm/entrypoints/serve/utils/fingerprint.py index 5203d1003b..e858e667d0 100644 --- a/vllm/entrypoints/serve/utils/fingerprint.py +++ b/vllm/entrypoints/serve/utils/fingerprint.py @@ -33,8 +33,7 @@ def set_default_fingerprint_mode( custom_value: str | None = None, ) -> None: """Configure the fingerprint mode for subsequent ``get_system_fingerprint`` - calls. Called once at server startup. - """ + calls. Called once at server startup.""" global _DEFAULT_MODE, _CUSTOM_VALUE _DEFAULT_MODE = mode _CUSTOM_VALUE = custom_value @@ -42,8 +41,7 @@ def set_default_fingerprint_mode( def get_system_fingerprint(vllm_config: Any) -> str | None: """Return the fingerprint for ``vllm_config`` using the mode configured by - ``set_default_fingerprint_mode``. - """ + ``set_default_fingerprint_mode``.""" return build_system_fingerprint(vllm_config, _DEFAULT_MODE, _CUSTOM_VALUE) diff --git a/vllm/entrypoints/speech_to_text/base/serving.py b/vllm/entrypoints/speech_to_text/base/serving.py index 2e77ceffef..34b7e9c249 100644 --- a/vllm/entrypoints/speech_to_text/base/serving.py +++ b/vllm/entrypoints/speech_to_text/base/serving.py @@ -92,8 +92,7 @@ def asr_inter_chunk_separator( class SpeechToTextBaseServing(GenerateBaseServing): """Base class for speech-to-text operations like transcription and - translation. - """ + translation.""" def __init__( self, @@ -427,8 +426,7 @@ class SpeechToTextBaseServing(GenerateBaseServing): stream_generator_method: Callable[..., AsyncGenerator[str, None]], ) -> T | V | AsyncGenerator[str, None] | ErrorResponse: """Base method for speech-to-text operations like transcription and - translation. - """ + translation.""" if request.stream and request.use_beam_search: return self.create_error_response( "Streaming is not currently supported with beam search" diff --git a/vllm/env_override.py b/vllm/env_override.py index 35431cccb6..87501eb469 100644 --- a/vllm/env_override.py +++ b/vllm/env_override.py @@ -581,8 +581,7 @@ _constrain_to_fx_strides_patched = False def _apply_constrain_to_fx_strides_patch(): """Patch lowering.constrain_to_fx_strides globally. Safe to call multiple times; only the first call does anything. - Only applies for torch >= 2.11 and < 2.12. - """ + Only applies for torch >= 2.11 and < 2.12.""" global _constrain_to_fx_strides_patched if _constrain_to_fx_strides_patched: return diff --git a/vllm/envs.py b/vllm/envs.py index 8d836ffc4e..0a3f6d3c67 100755 --- a/vllm/envs.py +++ b/vllm/envs.py @@ -2249,8 +2249,7 @@ def compile_factors() -> dict[str, object]: """Return env vars used for torch.compile cache keys. Start with every known vLLM env var; drop entries in `ignored_factors`; - hash everything else. This keeps the cache key aligned across workers. - """ + hash everything else. This keeps the cache key aligned across workers.""" ignored_factors: set[str] = { "MAX_JOBS", "VLLM_RPC_BASE_PATH", diff --git a/vllm/forward_context.py b/vllm/forward_context.py index dc025175a3..6a31b3faff 100644 --- a/vllm/forward_context.py +++ b/vllm/forward_context.py @@ -209,8 +209,7 @@ def is_forward_context_available() -> bool: def in_piecewise_cudagraph() -> bool: """Whether the current forward runs in piecewise cudagraph mode (graph - segments separated by eager breaks), at capture or replay time. - """ + segments separated by eager breaks), at capture or replay time.""" return ( is_forward_context_available() and get_forward_context().cudagraph_runtime_mode == CUDAGraphMode.PIECEWISE diff --git a/vllm/logger.py b/vllm/logger.py index 4f528a1301..cdce7748f2 100644 --- a/vllm/logger.py +++ b/vllm/logger.py @@ -216,8 +216,7 @@ def _configure_vllm_root_logger() -> None: def init_logger(name: str) -> _VllmLogger: """The main purpose of this function is to ensure that loggers are retrieved in such a way that we can be sure the root vllm logger has - already been configured. - """ + already been configured.""" logger = logging.getLogger(name) for method_name, method in _METHODS_TO_PATCH.items(): diff --git a/vllm/lora/layers/column_parallel_linear.py b/vllm/lora/layers/column_parallel_linear.py index 6075629c45..d015fd53ce 100644 --- a/vllm/lora/layers/column_parallel_linear.py +++ b/vllm/lora/layers/column_parallel_linear.py @@ -733,8 +733,7 @@ class MergedColumnParallelLinearVariableSliceWithLoRA( lora_b: torch.Tensor | list[torch.Tensor], ): """Override to handle single tensor weights - that need to be split into slices. - """ + that need to be split into slices.""" self.reset_lora(index) # Handle case where checkpoint has single tensor weights diff --git a/vllm/lora/lora_model.py b/vllm/lora/lora_model.py index 6286533a0f..593f859936 100644 --- a/vllm/lora/lora_model.py +++ b/vllm/lora/lora_model.py @@ -90,8 +90,7 @@ class LoRAModel: def clone(self, lora_model_id: int) -> "LoRAModel": """Return a copy of the object with different ids. - Will share the underlying tensors. - """ + Will share the underlying tensors.""" return self.__class__( lora_model_id, rank=self.rank, diff --git a/vllm/lora/worker_manager.py b/vllm/lora/worker_manager.py index 1fab524e6d..93624523e2 100644 --- a/vllm/lora/worker_manager.py +++ b/vllm/lora/worker_manager.py @@ -28,8 +28,7 @@ class WorkerLoRAManager: """WorkerLoRAManager that manages LoRA models on the worker side. Every request, the requested LoRAs will be loaded (unless they are already - loaded), and every other LoRA will be unloaded. - """ + loaded), and every other LoRA will be unloaded.""" _manager_cls: type[LoRAModelManager] = LoRAModelManager @@ -75,8 +74,7 @@ class WorkerLoRAManager: @contextmanager def dummy_lora_cache(self): """Use this context manager to reuse the dummy lora model - to avoid creating it repeatedly. - """ + to avoid creating it repeatedly.""" self._cached_dummy_lora = None yield self._cached_dummy_lora = False @@ -251,8 +249,7 @@ class LRUCacheWorkerLoRAManager(WorkerLoRAManager): Uses an LRU Cache. Every request, the requested LoRAs will be loaded (unless they are already loaded) and least recently used LoRAs will - be unloaded if the cache is above capacity. - """ + be unloaded if the cache is above capacity.""" _manager_cls: type[LRUCacheLoRAModelManager] = LRUCacheLoRAModelManager diff --git a/vllm/model_executor/hw_agnostic/custom_op.py b/vllm/model_executor/hw_agnostic/custom_op.py index e9c1e24820..ecb37681f2 100644 --- a/vllm/model_executor/hw_agnostic/custom_op.py +++ b/vllm/model_executor/hw_agnostic/custom_op.py @@ -135,8 +135,7 @@ class CustomOp(nn.Module): def forward_native(self, *args, **kwargs): """PyTorch-native implementation; OOT plugins override via - :meth:`forward_oot`. - """ + :meth:`forward_oot`.""" raise NotImplementedError def forward_oot(self, *args, **kwargs): diff --git a/vllm/model_executor/hw_agnostic/layers/layernorm.py b/vllm/model_executor/hw_agnostic/layers/layernorm.py index 1461e20eb4..d2c854afd3 100644 --- a/vllm/model_executor/hw_agnostic/layers/layernorm.py +++ b/vllm/model_executor/hw_agnostic/layers/layernorm.py @@ -10,8 +10,7 @@ from vllm.model_executor.hw_agnostic.custom_op import CustomOp @CustomOp.register("rms_norm") class RMSNorm(CustomOp): """``x -> w * x / sqrt(E[x^2] + eps)``. With ``residual``, fuses - ``residual += x`` then RMSNorm and returns ``(normalized, residual)``. - """ + ``residual += x`` then RMSNorm and returns ``(normalized, residual)``.""" def __init__( self, diff --git a/vllm/model_executor/kernels/linear/__init__.py b/vllm/model_executor/kernels/linear/__init__.py index 37c73868f7..26ad557c67 100644 --- a/vllm/model_executor/kernels/linear/__init__.py +++ b/vllm/model_executor/kernels/linear/__init__.py @@ -881,8 +881,7 @@ def choose_mp_linear_kernel( def init_mxfp8_linear_kernel(*, bmm_batch_size: int | None = None) -> Mxfp8LinearKernel: """Select and instantiate the best MXFP8 linear kernel for the - current platform. - """ + current platform.""" config = Mxfp8LinearLayerConfig(bmm_batch_size=bmm_batch_size) platform = current_platform._enum @@ -934,8 +933,7 @@ def init_mxfp4_linear_kernel( activation_quant_key: QuantKey | None = None, ) -> MxFp4LinearKernel: """Select and instantiate the best MXFP4 linear kernel for the - current platform. - """ + current platform.""" config = MxFp4LinearLayerConfig( activation_quant_key=activation_quant_key, ) @@ -982,8 +980,7 @@ def init_mxfp6_linear_kernel( activation_quant_key: QuantKey | None = None, ) -> MxFp6LinearKernel: """Select and instantiate the best MXFP6 linear kernel for the - current platform. - """ + current platform.""" config = MxFp6LinearLayerConfig( weight_quant_key=weight_quant_key, activation_quant_key=activation_quant_key, @@ -1071,8 +1068,7 @@ def init_wfp8_a16_linear_kernel( def init_nvfp4_linear_kernel(use_a16: bool = False) -> NvFp4LinearKernel: """Select and instantiate the best NVFP4 linear kernel for the - current platform. - """ + current platform.""" config = NvFp4LinearLayerConfig() a16_kernels = ( FlashInferCuteDslNvFp4W4A16LinearKernel, diff --git a/vllm/model_executor/kernels/linear/nvfp4/flashinfer.py b/vllm/model_executor/kernels/linear/nvfp4/flashinfer.py index c5ec08ec8a..a555ca17bf 100644 --- a/vllm/model_executor/kernels/linear/nvfp4/flashinfer.py +++ b/vllm/model_executor/kernels/linear/nvfp4/flashinfer.py @@ -177,8 +177,7 @@ class FlashInferCutlassNvFp4LinearKernel(NvFp4LinearKernel): def input_quant_key(self) -> QuantKey | None: """This kernel supports dynamic quantization of the input. By - convention, pre-quantized blockscales must use the swizzled layout. - """ + convention, pre-quantized blockscales must use the swizzled layout.""" return kNvfp4Dynamic @classmethod diff --git a/vllm/model_executor/kernels/linear/scaled_mm/BlockScaledMMLinearKernel.py b/vllm/model_executor/kernels/linear/scaled_mm/BlockScaledMMLinearKernel.py index 7a38c69647..3a053412f3 100644 --- a/vllm/model_executor/kernels/linear/scaled_mm/BlockScaledMMLinearKernel.py +++ b/vllm/model_executor/kernels/linear/scaled_mm/BlockScaledMMLinearKernel.py @@ -41,8 +41,7 @@ class FP8BlockParams(FP8Params): @property def block_scale_attr(self) -> str: """Fp8LinearMethod registers the block scale as ``weight_scale_inv``, - compressed-tensors as ``weight_scale``. - """ + compressed-tensors as ``weight_scale``.""" return ( self.WEIGHT_SCALE if self.weight_scale_inv is None diff --git a/vllm/model_executor/kernels/linear/scaled_mm/cutlass.py b/vllm/model_executor/kernels/linear/scaled_mm/cutlass.py index 7df7331f41..9f69ab0c73 100644 --- a/vllm/model_executor/kernels/linear/scaled_mm/cutlass.py +++ b/vllm/model_executor/kernels/linear/scaled_mm/cutlass.py @@ -174,8 +174,7 @@ class CutlassFP8ScaledMMLinearKernel(FP8ScaledMMLinearKernel): def input_quant_key(self) -> QuantKey | None: """Only static per-tensor activation quantization is supported for external - quantization. - """ + quantization.""" if self.config.activation_quant_key == kFp8StaticTensorSym: return kFp8StaticTensorSym return None @@ -185,8 +184,7 @@ class CutlassFP8ScaledMMLinearKernel(FP8ScaledMMLinearKernel): x: torch.Tensor, dim: int, alignment: int, value: float = 0.0 ) -> torch.Tensor: """Pad tensor ``x`` along ``dim`` to the next multiple of - ``alignment``. - """ + ``alignment``.""" remainder = x.shape[dim] % alignment if remainder == 0: return x diff --git a/vllm/model_executor/layers/activation.py b/vllm/model_executor/layers/activation.py index f730026d4a..7166d3f8fe 100644 --- a/vllm/model_executor/layers/activation.py +++ b/vllm/model_executor/layers/activation.py @@ -804,8 +804,7 @@ _ACTIVATION_REGISTRY = LazyDict( def _get_gelu_pytorch_tanh() -> nn.Module: """Get PyTorch GELU with tanh approximation, with ROCm fallback - and fast GELU for ARM. - """ + and fast GELU for ARM.""" if current_platform.is_rocm(): # TODO:[ROCm] PyTorch native GELU with tanh is unstable with torch.compile logger.warning_once( diff --git a/vllm/model_executor/layers/attention/mla_attention.py b/vllm/model_executor/layers/attention/mla_attention.py index caa58eefae..4cbc380bb1 100644 --- a/vllm/model_executor/layers/attention/mla_attention.py +++ b/vllm/model_executor/layers/attention/mla_attention.py @@ -1568,8 +1568,7 @@ class MLACommonBackend(AttentionBackend): @classmethod def customize_spec(cls, spec: "AttentionSpec") -> "AttentionSpec": """Per-token-head modes pack an inline fp32 scale pair after the - latent data (single-sided: ``head_size_v == 0`` for MLA). - """ + latent data (single-sided: ``head_size_v == 0`` for MLA).""" spec = super().customize_spec(spec) mode = spec.kv_quant_mode if spec.state_content_bytes is not None or not mode.is_per_token_head: diff --git a/vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py b/vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py index 4f2d5c1783..7046bfc991 100644 --- a/vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py +++ b/vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py @@ -55,8 +55,7 @@ _FI_SUPPORTED_DTYPES = (torch.bfloat16, torch.float16) def _max_token_num(tp_size: int, hidden_size: int, dtype: torch.dtype) -> int | None: """Workspace token budget for flashinfer fused all-reduce, or None if the - current world size / device is unsupported. Mirrors ``FlashInferAllReduce``. - """ + current world size / device is unsupported. Mirrors ``FlashInferAllReduce``.""" from vllm.config.compilation import PassConfig max_size_mb = PassConfig.default_fi_allreduce_fusion_max_size_mb().get(tp_size) diff --git a/vllm/model_executor/layers/fused_embed_norm.py b/vllm/model_executor/layers/fused_embed_norm.py index 876585ad32..ddeb5156ae 100644 --- a/vllm/model_executor/layers/fused_embed_norm.py +++ b/vllm/model_executor/layers/fused_embed_norm.py @@ -170,8 +170,7 @@ def _fused_embed_eh_norm_kernel( ``table[ids]``, zero it at position 0, RMSNorm(embed) with enorm and RMSNorm(prev_hidden) with hnorm, written side-by-side into ``out`` ([N, 2H]) ready for the eh_proj GEMM. Replaces embedding lookup + where + 2x RMSNorm + - cat. Requires the full table on-rank (replicated embedding). - """ + cat. Requires the full table on-rank (replicated embedding).""" tok = tl.program_id(0) off = tl.arange(0, BLOCK) mask = off < H diff --git a/vllm/model_executor/layers/fused_moe/activation.py b/vllm/model_executor/layers/fused_moe/activation.py index 18f97be332..46a9bd1b4c 100644 --- a/vllm/model_executor/layers/fused_moe/activation.py +++ b/vllm/model_executor/layers/fused_moe/activation.py @@ -56,8 +56,7 @@ class MoEActivation(Enum): @property def custom_op_name(self) -> str: """Maps to the CustomOp name of activations - in vllm/model_executor/layers/activation.py. - """ + in vllm/model_executor/layers/activation.py.""" return _CUSTOM_OP_NAMES[self] def without_mul(self) -> "MoEActivation": diff --git a/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp8_moe.py b/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp8_moe.py index dcd9b8b543..93a4088fc4 100644 --- a/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp8_moe.py +++ b/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp8_moe.py @@ -36,8 +36,7 @@ def is_aiter_mxfp8_moe_available() -> bool: nightly lacking #3811 would wrongly select FlyDSL instead of falling back to the native Triton dot_scaled path. #3811 added no probe-able public symbol, so detect the ``minimax_m3_mxfp8`` tuned config it shipped. Every check fails - closed (returns False -> triton dot_scaled), which is always safe. - """ + closed (returns False -> triton dot_scaled), which is always safe.""" if not (current_platform.is_rocm() and current_platform.supports_mx()): return False try: diff --git a/vllm/model_executor/layers/fused_moe/experts/cpu_moe.py b/vllm/model_executor/layers/fused_moe/experts/cpu_moe.py index b9a96b2804..7b3193fb5f 100644 --- a/vllm/model_executor/layers/fused_moe/experts/cpu_moe.py +++ b/vllm/model_executor/layers/fused_moe/experts/cpu_moe.py @@ -192,8 +192,7 @@ class CPUUnquantizedExperts(mk.FusedMoEExpertsModular): def _pad_moe_intermediate(self, layer: torch.nn.Module) -> None: """Zero-pad the per-partition MoE intermediate dim of both weights and - the expert bias, see `_padded_intermediate_size`. - """ + the expert bias, see `_padded_intermediate_size`.""" intermediate_size = self.moe_config.intermediate_size_per_partition padded_size = self._padded_intermediate_size(self.moe_config) if padded_size == intermediate_size: @@ -953,8 +952,7 @@ class CPUExpertsInt4(mk.FusedMoEExpertsModular): class CPUExpertsInt8(mk.FusedMoEExpertsModular): """CPU INT8 W8A8 per-channel weight / dynamic per-token activation - modular MoE experts. - """ + modular MoE experts.""" def __init__( self, @@ -1287,8 +1285,7 @@ class ArmCPUExpertsInt8(mk.FusedMoEExpertsModular): class ZenCPUExpertsInt8(mk.FusedMoEExpertsModular): """AMD Zen INT8 MoE with per-token activation and channelwise weight - quantization, dispatched through zentorch. - """ + quantization, dispatched through zentorch.""" def __init__( self, diff --git a/vllm/model_executor/layers/fused_moe/experts/mxfp8_native_moe.py b/vllm/model_executor/layers/fused_moe/experts/mxfp8_native_moe.py index d5217706e1..c8063ffb4d 100644 --- a/vllm/model_executor/layers/fused_moe/experts/mxfp8_native_moe.py +++ b/vllm/model_executor/layers/fused_moe/experts/mxfp8_native_moe.py @@ -34,8 +34,7 @@ from vllm.triton_utils import tl, triton def _select_cfg(M, N, K, block_m): """Pick the launch config from host constants only (M=num_valid_tokens, N, K, - block_m) — graph-capture safe (no GPU-scalar branch). - """ + block_m) — graph-capture safe (no GPU-scalar branch).""" # Per-regime winners (measured, isolated cuda-event A/B on gfx950, GPU 3): # BLOCK_K=256 (fewer K-iters + bigger MX scale-load coalesced with the dot), # num_stages=2 (software-pipeline overlaps the E8M0 scale-load with the scaled diff --git a/vllm/model_executor/layers/fused_moe/oracle/base.py b/vllm/model_executor/layers/fused_moe/oracle/base.py index 87c540409f..06be6becf8 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/base.py +++ b/vllm/model_executor/layers/fused_moe/oracle/base.py @@ -55,28 +55,24 @@ class MoEKernelOracle(ABC, Generic[BackendT]): @abstractmethod def backend_enum_cls(self) -> type[BackendT]: """Return the concrete `Enum` class enumerating this oracle's - backends (e.g. `UnquantizedMoeBackend`, `Fp8MoeBackend`). - """ + backends (e.g. `UnquantizedMoeBackend`, `Fp8MoeBackend`).""" @abstractmethod def get_priority_backends(self, moe_config: FusedMoEConfig) -> list[BackendT]: """Return platform-appropriate backends in priority order for - this `moe_config`. - """ + this `moe_config`.""" @abstractmethod def backend_to_kernel_cls( self, backend: BackendT ) -> list[type[mk.FusedMoEExperts]]: """Map a backend enum value to its concrete `FusedMoEExperts` - subclasses, in selection priority order. - """ + subclasses, in selection priority order.""" @abstractmethod def map_backend(self, runner_backend: MoEBackend) -> BackendT: """Map a user-facing `MoEBackend` (from the runner config) to - this oracle's enum. - """ + this oracle's enum.""" @abstractmethod def select_backend( @@ -108,8 +104,7 @@ class MoEKernelOracle(ABC, Generic[BackendT]): routing_tables: tuple[torch.Tensor, torch.Tensor, torch.Tensor] | None = None, ) -> mk.FusedMoEKernel: """Construct the `FusedMoEKernel` (Prepare/Finalize + Experts - combinator) for the chosen backend. - """ + combinator) for the chosen backend.""" def convert_to_kernel_format( self, diff --git a/vllm/model_executor/layers/fused_moe/oracle/fp8.py b/vllm/model_executor/layers/fused_moe/oracle/fp8.py index 72e83cda42..7c57e2e5c2 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/fp8.py +++ b/vllm/model_executor/layers/fused_moe/oracle/fp8.py @@ -451,8 +451,7 @@ def _humming_fp8_weight_schema( layer: RoutedExperts, weight: torch.Tensor, weight_scale: torch.Tensor ) -> dict[str, Any]: """Build the humming weight schema from the canonical on-device fp8/mxfp8 - tensors (scale dtype/shape, block size), not the producing quant method. - """ + tensors (scale dtype/shape, block size), not the producing quant method.""" # mxfp8: e8m0 group-32 scales (stored as uint8 bytes or e8m0). humming has # no compressed-tensors mxfp8 loader; its modelopt schema fits both sources. if weight_scale.dtype in (torch.uint8, torch.float8_e8m0fnu): diff --git a/vllm/model_executor/layers/fused_moe/oracle/int8.py b/vllm/model_executor/layers/fused_moe/oracle/int8.py index 3fdd3ae0a8..3b8a3c4f87 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/int8.py +++ b/vllm/model_executor/layers/fused_moe/oracle/int8.py @@ -224,8 +224,7 @@ def _humming_int8_weight_schema( weight: torch.Tensor, weight_scale: torch.Tensor ) -> dict[str, Any]: """Build the humming compressed-tensors int8 schema from the canonical - on-device tensors; humming does the signed-int8 -> native conversion. - """ + on-device tensors; humming does the signed-int8 -> native conversion.""" config: dict[str, Any] = { "quant_method": "compressed-tensors", "format": "int-quantized", diff --git a/vllm/model_executor/layers/fused_moe/oracle/int_wna16.py b/vllm/model_executor/layers/fused_moe/oracle/int_wna16.py index f449513741..c70bea9aa3 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/int_wna16.py +++ b/vllm/model_executor/layers/fused_moe/oracle/int_wna16.py @@ -512,8 +512,7 @@ def _process_weights_flashinfer( def _pad_w13_shard_cols(x: torch.Tensor, unit: int, padded_unit: int) -> torch.Tensor: """Zero-pad each of the two gate/up shards of a ``(E, rows, 2 * unit)`` - tensor along its last dim, from ``unit`` to ``padded_unit`` columns. - """ + tensor along its last dim, from ``unit`` to ``padded_unit`` columns.""" if padded_unit == unit: return x e, rows, _ = x.shape @@ -1081,8 +1080,7 @@ def _humming_wna16_weight_schema( quant_config: QuantizationConfig | QuantizationArgs | None, ) -> dict[str, Any]: """Humming weight schema for a WNA16 checkpoint, derived from the quant - config rather than the running kernel. - """ + config rather than the running kernel.""" from vllm.model_executor.layers.quantization.auto_awq import AutoAWQConfig from vllm.model_executor.layers.quantization.auto_gptq import AutoGPTQConfig diff --git a/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py b/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py index c0ce181949..912b713918 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py +++ b/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py @@ -331,8 +331,7 @@ def map_mxfp4_backend(runner_backend: MoEBackend) -> list[Mxfp4MoeBackend]: def _get_priority_backends_for_gpt_oss() -> list[Mxfp4MoeBackend]: """Available backends in priority order, BF16-act variant before - activation-quantized variant within each vendor family. - """ + activation-quantized variant within each vendor family.""" _AVAILABLE_BACKENDS = [ Mxfp4MoeBackend.FLASHINFER_TRTLLM_MXFP4_BF16, Mxfp4MoeBackend.FLASHINFER_TRTLLM_MXFP4_MXFP8, @@ -411,8 +410,7 @@ def _resolve_activation_key( model_activation_key: QuantKey | None, ) -> QuantKey | None: """Combine the model-supplied activation key with the user override. - Raises on conflict (both set and disagreeing). - """ + Raises on conflict (both set and disagreeing).""" user_override = _user_moe_activation_override() if user_override is None: return model_activation_key @@ -462,8 +460,7 @@ def _filter_by_activation( ) -> list[Mxfp4MoeBackend]: """Pick variants matching ``requested_activation_key``; without one, prefer BF16 if the list has any, else keep the list as-is so explicit - non-BF16 picks (e.g. the ``_afp8`` aliases) still land. - """ + non-BF16 picks (e.g. the ``_afp8`` aliases) still land.""" if requested_activation_key is not None: return [ b diff --git a/vllm/model_executor/layers/fused_moe/router/zero_expert_router.py b/vllm/model_executor/layers/fused_moe/router/zero_expert_router.py index c2dc86dd7c..0107f88156 100644 --- a/vllm/model_executor/layers/fused_moe/router/zero_expert_router.py +++ b/vllm/model_executor/layers/fused_moe/router/zero_expert_router.py @@ -71,8 +71,7 @@ class ZeroExpertRouter(BaseRouter): input_ids: torch.Tensor | None = None, ) -> tuple[torch.Tensor, torch.Tensor]: """Compute routing with full bias, compute zero expert output, - mask zero expert IDs. - """ + mask zero expert IDs.""" topk_weights, topk_ids = fused_topk_bias( hidden_states=hidden_states, gating_output=router_logits, diff --git a/vllm/model_executor/layers/indexer_topk.py b/vllm/model_executor/layers/indexer_topk.py index c6e027afb5..2ddf710703 100644 --- a/vllm/model_executor/layers/indexer_topk.py +++ b/vllm/model_executor/layers/indexer_topk.py @@ -163,8 +163,7 @@ class SparseIndexerTopk(torch.nn.Module): ) -> str: """Resolve the decode top-k implementation from the configured backend ("auto" = the pre-existing chain, or a validated explicit - value). - """ + value).""" if self._backend == "auto": return self._resolve_auto(logits, topk_tokens, num_rows) @@ -211,8 +210,7 @@ class SparseIndexerTopk(torch.nn.Module): self, logits: torch.Tensor, topk_tokens: int, num_rows: int ) -> str: """The pre-existing priority chain: cooperative -> persistent -> - per_row. deep_select/flashinfer/torch are opt-in only. - """ + per_row. deep_select/flashinfer/torch are opt-in only.""" if not self._cooperative_constraints(logits, topk_tokens, num_rows): return "cooperative" if self._is_cuda and topk_tokens in (512, 1024, 2048): @@ -274,8 +272,7 @@ class SparseIndexerTopk(torch.nn.Module): max_seq_len: int, ) -> None: """Run the resolved decode top-k implementation, writing into - topk_indices (int32, -1 fill for rows shorter than topk_tokens). - """ + topk_indices (int32, -1 fill for rows shorter than topk_tokens).""" backend = self.resolve_backend(logits, topk_tokens, logits.shape[0]) if backend == "deep_select": row_ends = self._row_ends(seq_lens, next_n, logits.shape[0]) diff --git a/vllm/model_executor/layers/linear.py b/vllm/model_executor/layers/linear.py index c8d52a6a10..9d2e31cfe1 100644 --- a/vllm/model_executor/layers/linear.py +++ b/vllm/model_executor/layers/linear.py @@ -158,8 +158,7 @@ class LinearMethodBase(QuantizeMethodBase): bias: torch.Tensor | None = None, ) -> torch.Tensor: """Apply the weights in layer to the input tensor. - Expects create_weights to have been called before on the layer. - """ + Expects create_weights to have been called before on the layer.""" raise NotImplementedError diff --git a/vllm/model_executor/layers/mamba/gdn/qwen_gdn_linear_attn.py b/vllm/model_executor/layers/mamba/gdn/qwen_gdn_linear_attn.py index 0cb6ba5160..807a5b9b1a 100644 --- a/vllm/model_executor/layers/mamba/gdn/qwen_gdn_linear_attn.py +++ b/vllm/model_executor/layers/mamba/gdn/qwen_gdn_linear_attn.py @@ -861,8 +861,7 @@ class QwenGatedDeltaNetAttention(GatedDeltaNetAttention): hidden_states: torch.Tensor, ) -> torch.Tensor: """ROCm forward using AITER Triton fused projection+attention when - available, otherwise falling back to the generic CUDA path. - """ + available, otherwise falling back to the generic CUDA path.""" if GDN_AITER_TRITON_AVAILABLE: num_tokens = hidden_states.size(0) projected_states_qkvz, _ = self.in_proj_qkvz(hidden_states) diff --git a/vllm/model_executor/layers/mamba/mamba_utils.py b/vllm/model_executor/layers/mamba/mamba_utils.py index 630c27ad2d..db7e119560 100644 --- a/vllm/model_executor/layers/mamba/mamba_utils.py +++ b/vllm/model_executor/layers/mamba/mamba_utils.py @@ -261,8 +261,7 @@ class MambaStateShapeCalculator: @classmethod def extra_groups_for_head_shards(cls, ngroups: int, tp_size: int): """Compute the increase in group numbers to account for - replication in order to accompany the head shards. - """ + replication in order to accompany the head shards.""" # in the case ngoups % tp_size == 0, this will be zero if ngroups % tp_size == 0: return 0 diff --git a/vllm/model_executor/layers/mamba/ops/mamba_ssm.py b/vllm/model_executor/layers/mamba/ops/mamba_ssm.py index f69368e273..0f2041d226 100644 --- a/vllm/model_executor/layers/mamba/ops/mamba_ssm.py +++ b/vllm/model_executor/layers/mamba/ops/mamba_ssm.py @@ -59,8 +59,7 @@ def get_ssm_device_name() -> str: def _canonical_cache_dtype(cache_dtype: str) -> str: """Canonical key for config lookup. bf16 and fp16 share the same tuned - configs because the kernel only sees bit width when accessing state. - """ + configs because the kernel only sees bit width when accessing state.""" return "float16" if cache_dtype == "bfloat16" else cache_dtype @@ -161,8 +160,7 @@ _ssm_config_override: tuple[int, int] | None = None @contextmanager def override_ssm_config(config: tuple[int, int]): """Pin ``try_get_optimal_ssm_config`` to ``config`` for the duration of - the context. Used by the tuning benchmark to time specific configs. - """ + the context. Used by the tuning benchmark to time specific configs.""" global _ssm_config_override prev = _ssm_config_override _ssm_config_override = config diff --git a/vllm/model_executor/layers/minimax_rms_norm/lamport_workspace.py b/vllm/model_executor/layers/minimax_rms_norm/lamport_workspace.py index 7f8900fa89..0b2ef3a6aa 100644 --- a/vllm/model_executor/layers/minimax_rms_norm/lamport_workspace.py +++ b/vllm/model_executor/layers/minimax_rms_norm/lamport_workspace.py @@ -210,8 +210,7 @@ class LamportWorkspace: @property def workspace(self) -> torch.Tensor: """Device tensor (int64) that can be passed to the kernel - as ``void** workspace``. - """ + as ``void** workspace``.""" return self._workspace # ------------------------------------------------------------------ diff --git a/vllm/model_executor/layers/quantization/base_config.py b/vllm/model_executor/layers/quantization/base_config.py index 1492997caa..a2c6eb2a45 100644 --- a/vllm/model_executor/layers/quantization/base_config.py +++ b/vllm/model_executor/layers/quantization/base_config.py @@ -46,24 +46,21 @@ class QuantizeMethodBase(ABC): ): """Create weights for a layer. - The weights will be set as attributes of the layer. - """ + The weights will be set as attributes of the layer.""" raise NotImplementedError @abstractmethod def apply(self, layer: torch.nn.Module, *args, **kwargs) -> torch.Tensor: """Apply the weights in layer to the input tensor. - Expects create_weights to have been called before on the layer. - """ + Expects create_weights to have been called before on the layer.""" raise NotImplementedError # Not required functions def embedding(self, layer: torch.nn.Module, *args, **kwargs) -> torch.Tensor: """Gather embeddings in the layer based on indices in the input tensor. - Expects create_weights to have been called before on the layer. - """ + Expects create_weights to have been called before on the layer.""" raise NotImplementedError # Not required functions @@ -76,8 +73,7 @@ class QuantizeMethodBase(ABC): Quantization methods that need special weight handling (e.g. repacked weights) override this. - Expects create_weights to have been called before on the layer. - """ + Expects create_weights to have been called before on the layer.""" layer.weight = embed_tokens.weight return layer diff --git a/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py b/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py index 8f134da1df..3603fd8bde 100644 --- a/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py +++ b/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py @@ -665,8 +665,7 @@ class CompressedTensorsConfig(QuantizationConfig): ) -> bool: """Weight N-bit INT (pack-quantized for sub-byte, int-quantized for 8-bit) with static per-tensor INT8 input/output activation quant, applied as a float - fake-quant around a weight-only matmul. - """ + fake-quant around a weight-only matmul.""" is_int_pack_format = format in ( CompressionFormat.pack_quantized.value, CompressionFormat.int_quantized.value, @@ -702,8 +701,7 @@ class CompressedTensorsConfig(QuantizationConfig): format: str | None, ) -> bool: """Weight N-bit INT with symmetric dynamic INT activation quant - via Humming kernel. - """ + via Humming kernel.""" if input_quant is None: return False is_pack_format = format == CompressionFormat.pack_quantized.value diff --git a/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_embedding.py b/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_embedding.py index d8ee32b0fa..23d2526130 100644 --- a/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_embedding.py +++ b/vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_embedding.py @@ -37,8 +37,7 @@ def _dequant_gather_kernel( BLOCK: tl.constexpr, ): """Gather embedding rows by token id, unpack int32-packed INT weights, and - dequantize to ``out`` dtype in one pass (no int8 intermediate). - """ + dequantize to ``out`` dtype in one pass (no int8 intermediate).""" row = tl.program_id(0) col = tl.program_id(1) * BLOCK + tl.arange(0, BLOCK) col_mask = col < hidden diff --git a/vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa8o8.py b/vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa8o8.py index 3aa1aac45d..187b6438ab 100644 --- a/vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa8o8.py +++ b/vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_wNa8o8.py @@ -211,8 +211,7 @@ class CompressedTensorsWNA8O8Int(CompressedTensorsScheme): def _pack_int_quantized_weight(self, layer: torch.nn.Module) -> None: """Normalize an int-quantized (plain int8) weight to the canonical - ``weight_packed`` int32 + ``weight_shape`` layout the MP kernels expect. - """ + ``weight_packed`` int32 + ``weight_shape`` layout the MP kernels expect.""" weight = layer.weight out_features, in_features = weight.shape packed = pack_to_int32(weight.data.contiguous(), self.num_bits) diff --git a/vllm/model_executor/layers/quantization/inc/config_parser.py b/vllm/model_executor/layers/quantization/inc/config_parser.py index e854c582eb..ce3e99bb8d 100644 --- a/vllm/model_executor/layers/quantization/inc/config_parser.py +++ b/vllm/model_executor/layers/quantization/inc/config_parser.py @@ -86,8 +86,7 @@ class INCConfigParser: def is_explicitly_configured(name: str) -> bool: """Return True if *name* has an explicit entry in extra_config, - either via exact key match or via a regex pattern key. - """ + either via exact key match or via a regex pattern key.""" if not self._config.extra_config: return False if name in self._config.extra_config: diff --git a/vllm/model_executor/layers/quantization/inc/schemes/inc_scheme.py b/vllm/model_executor/layers/quantization/inc/schemes/inc_scheme.py index 98c8c982f7..8672972aa1 100644 --- a/vllm/model_executor/layers/quantization/inc/schemes/inc_scheme.py +++ b/vllm/model_executor/layers/quantization/inc/schemes/inc_scheme.py @@ -48,8 +48,7 @@ class INCScheme(ABC): layer_config: "INCLayerConfig", ) -> "FusedMoEMethodBase | None": """Optional. Override if this scheme supports MoE. - Default raises NotImplementedError. - """ + Default raises NotImplementedError.""" raise NotImplementedError( f"{type(self).__name__} does not support MoE layers. " f"Layer config: {layer_config}" diff --git a/vllm/model_executor/layers/quantization/modelopt.py b/vllm/model_executor/layers/quantization/modelopt.py index f4ea599456..c649061f33 100644 --- a/vllm/model_executor/layers/quantization/modelopt.py +++ b/vllm/model_executor/layers/quantization/modelopt.py @@ -1988,8 +1988,7 @@ class KNvfp4Static(QuantKeyScheme): class KNvfp4Dynamic(QuantKeyScheme): """NVFP4 activation scheme (W4A4). Has a static global input scale on disk; - the per-group scale is computed at runtime inside the kernel. - """ + the per-group scale is computed at runtime inside the kernel.""" key = kNvfp4Dynamic @@ -2026,8 +2025,7 @@ class KNvfp4Dynamic(QuantKeyScheme): class KFp8StaticTensor(QuantKeyScheme): """Plain per-tensor static FP8 — bivalent: serves BOTH the weight slot and - the activation slot (W8A8). One key in both QuantSpec slots. - """ + the activation slot (W8A8). One key in both QuantSpec slots.""" key = kFp8StaticTensorSym @@ -2097,8 +2095,7 @@ class KFp8StaticTensor(QuantKeyScheme): class KFp8StaticChannel(QuantKeyScheme): """Per-channel static FP8 weight (the 'PcPt' weight). Weight-role only — - there is no static per-channel *activation* today. - """ + there is no static per-channel *activation* today.""" key = kFp8StaticTokenSym @@ -2139,8 +2136,7 @@ class KFp8StaticChannel(QuantKeyScheme): class KFp8Block128(QuantKeyScheme): """128x128 block-static FP8 weight ('PbWo'). Weight-role only. ModelOpt exports the scale 4-D [out_blk,1,in_blk,1]; process squeezes to 2-D. - No transpose (block kernel keeps [out,in]). - """ + No transpose (block kernel keeps [out,in]).""" key = kFp8Static128BlockSym @@ -2196,8 +2192,7 @@ class KFp8Block128(QuantKeyScheme): class KMxfp8Static(QuantKeyScheme): """MXFP8 weight: fp8-e4m3 values + per-32-block e8m0 (uint8) scale. - Weight-role only. process is validate-only plus an idempotency guard. - """ + Weight-role only. process is validate-only plus an idempotency guard.""" key = kMxfp8Static @@ -2272,8 +2267,7 @@ class KDynamicNoParam(QuantKeyScheme): """Dynamic activation with no stored scale (W8A8): quantized at runtime in the kernel. NOT the same as activation=None (weight-only) — init_fp8 needs a non-None activation key. Activation-role only. Serves the fp8 per-token, fp8 - per-block, and mxfp8 dynamic activation keys. - """ + per-block, and mxfp8 dynamic activation keys.""" def create_weights(self, layer, role, ctx, shapes, wl) -> None: if role is not ACT: diff --git a/vllm/model_executor/layers/quantization/mxfp4.py b/vllm/model_executor/layers/quantization/mxfp4.py index a4f689f2c1..33f6afac80 100644 --- a/vllm/model_executor/layers/quantization/mxfp4.py +++ b/vllm/model_executor/layers/quantization/mxfp4.py @@ -79,8 +79,7 @@ class Mxfp4Config(QuantizationConfig): def _make_moe_method(self, moe: FusedMoEConfig) -> FusedMoEMethodBase: """MoE method for RoutedExperts. Subclasses override to pick a - checkpoint-specific kernel family. - """ + checkpoint-specific kernel family.""" return Mxfp4MoEMethod(moe) def get_quant_method( diff --git a/vllm/model_executor/layers/quantization/online/base.py b/vllm/model_executor/layers/quantization/online/base.py index 125ec4f2e3..41bca8d29d 100644 --- a/vllm/model_executor/layers/quantization/online/base.py +++ b/vllm/model_executor/layers/quantization/online/base.py @@ -139,8 +139,7 @@ def _find_matching_targets( class OnlineQuantizationConfig(QuantizationConfig): """Model-level config for online quantization (quantize fp16/bf16 weights - during model loading, without requiring a pre-quantized checkpoint). - """ + during model loading, without requiring a pre-quantized checkpoint).""" def __init__( self, diff --git a/vllm/model_executor/layers/quantization/online/fp8.py b/vllm/model_executor/layers/quantization/online/fp8.py index 0e12799304..2a8ef0b69f 100644 --- a/vllm/model_executor/layers/quantization/online/fp8.py +++ b/vllm/model_executor/layers/quantization/online/fp8.py @@ -118,8 +118,7 @@ def _is_tp_sharded(layer: Module, *, reduces_output_dim: bool = True) -> bool: class OnlineLinearBase(LinearMethodBase): """Shared base for online FP8 linear methods. Loads fp16/bf16 checkpoint - weights onto meta device and materializes them just-in-time. - """ + weights onto meta device and materializes them just-in-time.""" uses_meta_device: bool = True @@ -163,8 +162,7 @@ class OnlineLinearBase(LinearMethodBase): class Fp8PerTensorOnlineLinearMethod(OnlineLinearBase): """Online tensorwise FP8 linear quantization. - Loads fp16/bf16 weights and quantizes them per-tensor during loading. - """ + Loads fp16/bf16 weights and quantizes them per-tensor during loading.""" def __init__(self): super().__init__() @@ -265,8 +263,7 @@ class Fp8PerTensorOnlineLinearMethod(OnlineLinearBase): class Fp8PerBlockOnlineLinearMethod(OnlineLinearBase): """Online blockwise FP8 linear quantization. - Loads fp16/bf16 weights and quantizes them per-block during loading. - """ + Loads fp16/bf16 weights and quantizes them per-block during loading.""" def __init__(self): super().__init__() @@ -440,8 +437,7 @@ class Fp8PtpcOnlineLinearMethod(OnlineLinearBase): class _Fp8OnlineMoEBase(OnlineMoEMethodBase): """Shared base for online FP8 MoE methods. Loads fp16/bf16 checkpoint - weights onto meta device and materializes them just-in-time. - """ + weights onto meta device and materializes them just-in-time.""" # Declared here for mypy; actual values are set in __init__. fp8_backend: "Fp8MoeBackend" @@ -562,8 +558,7 @@ class _Fp8OnlineMoEBase(OnlineMoEMethodBase): class Fp8PerTensorOnlineMoEMethod(_Fp8OnlineMoEBase): """Online tensorwise FP8 MoE quantization. - Loads fp16/bf16 weights and quantizes them per-tensor during loading. - """ + Loads fp16/bf16 weights and quantizes them per-tensor during loading.""" def __init__( self, @@ -620,8 +615,7 @@ class Fp8PerTensorOnlineMoEMethod(_Fp8OnlineMoEBase): class Fp8PerBlockOnlineMoEMethod(_Fp8OnlineMoEBase): """Online blockwise FP8 MoE quantization. - Loads fp16/bf16 weights and quantizes them per-block during loading. - """ + Loads fp16/bf16 weights and quantizes them per-block during loading.""" def __init__( self, diff --git a/vllm/model_executor/layers/quantization/utils/fp8_utils.py b/vllm/model_executor/layers/quantization/utils/fp8_utils.py index edf92fb264..79859a69d4 100644 --- a/vllm/model_executor/layers/quantization/utils/fp8_utils.py +++ b/vllm/model_executor/layers/quantization/utils/fp8_utils.py @@ -69,8 +69,7 @@ def input_to_float8( x: torch.Tensor, dtype: torch.dtype | None = None ) -> tuple[torch.Tensor, torch.Tensor]: """This function quantizes input values to float8 values " - "with tensor-wise quantization. - """ + "with tensor-wise quantization.""" dtype = current_platform.fp8_dtype() if dtype is None else dtype finfo = torch.finfo(dtype) min_val, max_val = x.aminmax() @@ -1195,8 +1194,7 @@ def prepare_fp8_moe_layer_for_deepgemm( def _maybe_pad_fp8_weight(weight: torch.Tensor) -> torch.Tensor: """Pad the weight tensor. This is an optimization on ROCm platform, which - can benefit from tensors located far enough from one another in memory - """ + can benefit from tensors located far enough from one another in memory""" if ( envs.VLLM_ROCM_FP8_PADDING and current_platform.is_rocm() diff --git a/vllm/model_executor/layers/quantization/utils/humming_utils.py b/vllm/model_executor/layers/quantization/utils/humming_utils.py index f03b1dc7b4..f48c33d4cd 100644 --- a/vllm/model_executor/layers/quantization/utils/humming_utils.py +++ b/vllm/model_executor/layers/quantization/utils/humming_utils.py @@ -297,8 +297,7 @@ def _humming_input_schema_to_quant_key( schema: "HummingInputSchema", ) -> QuantKey | None: """Convert a HummingInputSchema to a QuantKey. Returns None if - the schema represents unquantized (bf16/fp16) inputs. - """ + the schema represents unquantized (bf16/fp16) inputs.""" if schema.a_dtype is None or schema.a_dtype.num_bits >= 16: return None @@ -427,8 +426,7 @@ def convert_linear_layer_to_humming_standard( ): """Rename/reshape a linear layer's quantized params (the canonical MPLinear layout: ``weight_packed`` int32 + ``weight_scale``) into the parameter names - and layout humming's weight schema expects (``weight`` / ``weight_scale``). - """ + and layout humming's weight schema expects (``weight`` / ``weight_scale``).""" for name, checkpoint_name in name_map.items(): tensor = getattr(layer, checkpoint_name) delattr(layer, checkpoint_name) diff --git a/vllm/model_executor/layers/quantization/utils/marlin_utils.py b/vllm/model_executor/layers/quantization/utils/marlin_utils.py index 8e0e4bba1c..82201dff3b 100644 --- a/vllm/model_executor/layers/quantization/utils/marlin_utils.py +++ b/vllm/model_executor/layers/quantization/utils/marlin_utils.py @@ -245,8 +245,7 @@ def marlin_padded_nk(size_n: int, size_k: int, group_size: int = -1) -> tuple[in def marlin_repacked_nk(qweight: torch.Tensor, num_bits: int) -> tuple[int, int]: """Recover the (size_n, size_k) a Marlin weight was repacked with - (including any tile padding) from its packed shape. - """ + (including any tile padding) from its packed shape.""" pack_factor = 32 // num_bits size_k = qweight.size(0) * GPTQ_MARLIN_TILE size_n = qweight.size(1) * pack_factor // GPTQ_MARLIN_TILE @@ -257,8 +256,7 @@ def marlin_pad_qweight( qweight: torch.Tensor, size_n: int, size_k: int, padded_n: int, padded_k: int ) -> torch.Tensor: """Zero-pad a GPTQ-layout packed weight (size_k / pack, size_n) for - gptq_marlin_repack. - """ + gptq_marlin_repack.""" if (padded_n, padded_k) == (size_n, size_k): return qweight pack_factor = size_k // qweight.size(0) @@ -276,8 +274,7 @@ def marlin_pad_scales( group_size: int, ) -> torch.Tensor: """Zero-pad weight scales (num_groups, size_n); call before - marlin_permute_scales and pass the padded extents to it. - """ + marlin_permute_scales and pass the padded extents to it.""" if (padded_n, padded_k) == (size_n, size_k): return scales pad_rows = padded_k // group_size - scales.size(0) if group_size > 0 else 0 diff --git a/vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py b/vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py index 1a550576b6..a12d8b87e9 100644 --- a/vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py +++ b/vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py @@ -41,8 +41,7 @@ def _nvfp4_compute_scale_factor( ) -> float: """Compute the power-of-2 scale_factor needed so that all non-zero values in marlin_scales * 2^7 are >= 2 after rescaling. - Returns a Python float (power of 2, >= 1.0). - """ + Returns a Python float (power of 2, >= 1.0).""" # Since half has a smaller dynamic range compared to bfloat16, # no rescaling is applied here if active dtype is half. if a_dtype is not None and a_dtype == torch.half: @@ -376,8 +375,7 @@ def prepare_nvfp4_moe_layer_for_marlin( def pad_w13(x: torch.Tensor) -> torch.Tensor: """Zero-pad each gate/up shard of a (E, num_shards * N, cols) - tensor to padded_N rows. - """ + tensor to padded_N rows.""" if padded_N == N: return x x = x.view(E, num_shards, N, x.size(-1)) @@ -386,8 +384,7 @@ def prepare_nvfp4_moe_layer_for_marlin( def pad_w2(x: torch.Tensor, packing: int) -> torch.Tensor: """Zero-pad the packed N (last) dim of a (E, K, N / packing) - tensor. - """ + tensor.""" if padded_N == N: return x return torch.nn.functional.pad(x, (0, (padded_N - N) // packing)) diff --git a/vllm/model_executor/layers/quantization/utils/marlin_utils_fp8.py b/vllm/model_executor/layers/quantization/utils/marlin_utils_fp8.py index 251207a973..4a5f5ee59a 100644 --- a/vllm/model_executor/layers/quantization/utils/marlin_utils_fp8.py +++ b/vllm/model_executor/layers/quantization/utils/marlin_utils_fp8.py @@ -217,8 +217,7 @@ def prepare_fp8_layer_for_marlin( def _moe_pad_shard_rows(x: torch.Tensor, n: int, padded_n: int) -> torch.Tensor: """Zero-pad each gate/up shard of a ``(E, 2 * n, ...)`` tensor to padded_n - rows. FP8 zero decodes to 0.0, so the padded rows contribute nothing. - """ + rows. FP8 zero decodes to 0.0, so the padded rows contribute nothing.""" if padded_n == n: return x e = x.size(0) diff --git a/vllm/model_executor/layers/rotary_embedding/ntk_scaling_rope.py b/vllm/model_executor/layers/rotary_embedding/ntk_scaling_rope.py index b92dc8e7fd..031a12fceb 100644 --- a/vllm/model_executor/layers/rotary_embedding/ntk_scaling_rope.py +++ b/vllm/model_executor/layers/rotary_embedding/ntk_scaling_rope.py @@ -9,8 +9,7 @@ from .base import RotaryEmbedding class NTKScalingRotaryEmbedding(RotaryEmbedding): """RotaryEmbedding extended with fixed and mixed NTK scaling. - https://kexue.fm/archives/9706 - """ + https://kexue.fm/archives/9706""" def __init__( self, diff --git a/vllm/model_executor/layers/sparse_attn_indexer.py b/vllm/model_executor/layers/sparse_attn_indexer.py index e7a9382396..7dde4db00f 100644 --- a/vllm/model_executor/layers/sparse_attn_indexer.py +++ b/vllm/model_executor/layers/sparse_attn_indexer.py @@ -285,8 +285,7 @@ def _gather_workspace_shapes( """Return ((values_shape, values_dtype), (scales_shape, scales_dtype)) for the K-gather workspace. FP8 path: (T, head_dim) fp8 + (T, 4) uint8 fp32 scales. MXFP4 path: (T, head_dim // 2) uint8 packed mxfp4 + - (T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales. - """ + (T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales.""" if use_fp4_cache: return ( ((total_seq_lens, head_dim // 2), torch.uint8), @@ -304,8 +303,7 @@ def kv_cache_as_quant_view( use_fp4_cache: bool, ) -> torch.Tensor: """4D ``[num_blocks, block_size, 1, head_width]`` view expected by - DeepGEMM, from the 3D indexer kv-cache allocation. - """ + DeepGEMM, from the 3D indexer kv-cache allocation.""" if use_fp4_cache: assert kv_cache.ndim == 3 and kv_cache.dtype == torch.uint8 num_blocks, block_size, _ = kv_cache.shape diff --git a/vllm/model_executor/layers/sparse_mqa_indexer.py b/vllm/model_executor/layers/sparse_mqa_indexer.py index a019f9ec73..78db1b3df5 100644 --- a/vllm/model_executor/layers/sparse_mqa_indexer.py +++ b/vllm/model_executor/layers/sparse_mqa_indexer.py @@ -41,8 +41,7 @@ def _prefill_k_workspaces( total_seq_lens: int, head_dim: int ) -> tuple[torch.Tensor, torch.Tensor]: """The packed MXFP4 K-gather workspace ``(values, scales)``, shared with - the dense indexer layers of the same model. - """ + the dense indexer layers of the same model.""" values_spec, scales_spec = _gather_workspace_shapes( total_seq_lens, head_dim, current_platform.fp8_dtype(), use_fp4_cache=True ) @@ -120,8 +119,7 @@ class SparseMQAIndexer(nn.Module): def _reserve_workspaces(self, device: torch.device) -> None: """Profiling run: claim the K-gather workspace and the peak sparse - logits allocation so the memory estimate covers them. - """ + logits allocation so the memory estimate covers them.""" _prefill_k_workspaces(self.max_total_seq_len, self.head_dim) max_logits_bytes = envs.VLLM_SPARSE_INDEXER_MAX_LOGITS_MB * 1024 * 1024 torch.empty(max_logits_bytes, dtype=torch.uint8, device=device) diff --git a/vllm/model_executor/layers/vocab_parallel_embedding.py b/vllm/model_executor/layers/vocab_parallel_embedding.py index 688b4bf197..72cafceb25 100644 --- a/vllm/model_executor/layers/vocab_parallel_embedding.py +++ b/vllm/model_executor/layers/vocab_parallel_embedding.py @@ -376,8 +376,7 @@ class VocabParallelEmbedding(PluggableLayer): ) -> VocabParallelEmbeddingShardIndices: """Get start and end indices for vocab parallel embedding, following the layout outlined in the class docstring, based on the given tp_rank and - tp_size. - """ + tp_size.""" num_added_embeddings_padded = vocab_size_padded - org_vocab_size_padded padded_org_vocab_start_index, padded_org_vocab_end_index = ( vocab_range_from_global_vocab_size(org_vocab_size_padded, tp_rank, tp_size) diff --git a/vllm/model_executor/model_loader/base_loader.py b/vllm/model_executor/model_loader/base_loader.py index bbda4a33fd..6f35646458 100644 --- a/vllm/model_executor/model_loader/base_loader.py +++ b/vllm/model_executor/model_loader/base_loader.py @@ -36,8 +36,7 @@ class BaseModelLoader(ABC): @abstractmethod def load_weights(self, model: nn.Module, model_config: ModelConfig) -> None: """Load weights into a model. This standalone API allows - inplace weights loading for an already-initialized model - """ + inplace weights loading for an already-initialized model""" raise NotImplementedError def create_model( diff --git a/vllm/model_executor/model_loader/default_loader.py b/vllm/model_executor/model_loader/default_loader.py index e48c5a380e..039a577f80 100644 --- a/vllm/model_executor/model_loader/default_loader.py +++ b/vllm/model_executor/model_loader/default_loader.py @@ -135,8 +135,7 @@ class DefaultModelLoader(BaseModelLoader): ) -> tuple[str, list[str], bool]: """Prepare weights for the model. - If the model is not local, it will be downloaded. - """ + If the model is not local, it will be downloaded.""" model_name_or_path = ( maybe_download_from_modelscope(model_name_or_path, revision) or model_name_or_path diff --git a/vllm/model_executor/model_loader/ep_weight_filter.py b/vllm/model_executor/model_loader/ep_weight_filter.py index 4b2f92a18d..0e23dfc113 100644 --- a/vllm/model_executor/model_loader/ep_weight_filter.py +++ b/vllm/model_executor/model_loader/ep_weight_filter.py @@ -23,8 +23,7 @@ def parse_expert_id(weight_name: str) -> int | None: Returns ``None`` for dense weights (attention, layernorm, embedding), shared experts, and 3D fused-expert tensors where all experts are stored - in a single tensor without a numeric expert id in the name. - """ + in a single tensor without a numeric expert id in the name.""" m = _EXPERT_ID_RE.search(weight_name) return int(m.group(1)) if m else None @@ -71,8 +70,7 @@ def should_skip_weight( local_expert_ids: set[int] | None, ) -> bool: """Return ``True`` if *weight_name* is an expert weight that does not - belong to the local rank and should be skipped during loading. - """ + belong to the local rank and should be skipped during loading.""" if local_expert_ids is None: return False eid = parse_expert_id(weight_name) diff --git a/vllm/model_executor/model_loader/reload/layerwise.py b/vllm/model_executor/model_loader/reload/layerwise.py index c52fad985b..062bfa6090 100644 --- a/vllm/model_executor/model_loader/reload/layerwise.py +++ b/vllm/model_executor/model_loader/reload/layerwise.py @@ -308,8 +308,7 @@ def _reload_attention_scales(layer: torch.nn.Module, info: LayerReloadingInfo) - Assumes dtype/shapes of attention tensors do not change during processing, since we use .data.copy_() to preserve kernel tensor - references. - """ + references.""" quant_method = getattr(layer, "quant_method", None) if quant_method is not None: # Re-create scale Parameters with sentinel values so unloaded scales @@ -388,8 +387,7 @@ def _get_weight_loader(tensor: torch.Tensor): def _copy_and_restore_kernel_tensors(layer: torch.nn.Module, info: LayerReloadingInfo): """Copy processed values into original kernel tensor storage and restore - kernel tensor references on the layer. Preserves cudagraph references. - """ + kernel tensor references on the layer. Preserves cudagraph references.""" assert info.kernel_tensors is not None parameters, buffers = info.kernel_tensors non_persistent = info.kernel_non_persistent_buffers diff --git a/vllm/model_executor/model_loader/runai_streamer_loader.py b/vllm/model_executor/model_loader/runai_streamer_loader.py index b38729d283..e07330ae57 100644 --- a/vllm/model_executor/model_loader/runai_streamer_loader.py +++ b/vllm/model_executor/model_loader/runai_streamer_loader.py @@ -81,8 +81,7 @@ class RunaiModelStreamerLoader(BaseModelLoader): ) -> list[str]: """Prepare weights for the model. - If the model is not local, it will be downloaded. - """ + If the model is not local, it will be downloaded.""" is_object_storage_path = is_runai_obj_uri(model_name_or_path) is_local = os.path.isdir(model_name_or_path) safetensors_pattern = "*.safetensors" diff --git a/vllm/model_executor/model_loader/tensorizer.py b/vllm/model_executor/model_loader/tensorizer.py index 582ee0ea3e..3f865c3f39 100644 --- a/vllm/model_executor/model_loader/tensorizer.py +++ b/vllm/model_executor/model_loader/tensorizer.py @@ -497,8 +497,7 @@ def _check_tensors_on_meta_device(model: nn.Module) -> None: def _resize_lora_embeddings(model: nn.Module): """Modify LoRA embedding layers to use bigger tensors - to allow for adapter added tokens. - """ + to allow for adapter added tokens.""" for child in model.modules(): if ( isinstance(child, VocabParallelEmbedding) diff --git a/vllm/model_executor/model_loader/tensorizer_loader.py b/vllm/model_executor/model_loader/tensorizer_loader.py index e231eea20b..338f9eac07 100644 --- a/vllm/model_executor/model_loader/tensorizer_loader.py +++ b/vllm/model_executor/model_loader/tensorizer_loader.py @@ -105,8 +105,7 @@ class TensorizerLoader(BaseModelLoader): Expects a vLLM-tensorized model. See the examples/features/tensorize_vllm_model.py example script - for serializing vLLM models. - """ + for serializing vLLM models.""" if is_vllm_tensorized(self.tensorizer_config): tensorizer_config = self._patch_tensorizer_config(model_config) deserialize_tensorizer_model(model, tensorizer_config) diff --git a/vllm/model_executor/model_loader/weight_cache/ipc_loader.py b/vllm/model_executor/model_loader/weight_cache/ipc_loader.py index 52d770f5d1..6c3fb742cd 100644 --- a/vllm/model_executor/model_loader/weight_cache/ipc_loader.py +++ b/vllm/model_executor/model_loader/weight_cache/ipc_loader.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """IPC model loader: maps post-quantized weights from a local weight cache -daemon via CUDA IPC instead of loading from disk. -""" +daemon via CUDA IPC instead of loading from disk.""" import dataclasses import socket diff --git a/vllm/model_executor/model_loader/weight_tying.py b/vllm/model_executor/model_loader/weight_tying.py index bd0bfa4b80..d0c309d2c4 100644 --- a/vllm/model_executor/model_loader/weight_tying.py +++ b/vllm/model_executor/model_loader/weight_tying.py @@ -78,8 +78,7 @@ def maybe_retie_word_embeddings(model: nn.Module, model_config: ModelConfig) -> Checkpoints produced by quantization or fine-tuning tooling often keep a redundant copy of the tied `lm_head`. Sharing the storage again reclaims the memory it would - otherwise cost. - """ + otherwise cost.""" if not model_config.word_embeddings_untied_by_checkpoint: return if (untied := _get_untied_lm_head(model)) is None: diff --git a/vllm/model_executor/model_loader/weight_utils.py b/vllm/model_executor/model_loader/weight_utils.py index 2a9937bcd4..c781a8bf87 100644 --- a/vllm/model_executor/model_loader/weight_utils.py +++ b/vllm/model_executor/model_loader/weight_utils.py @@ -144,8 +144,7 @@ def atomic_writer( def _natural_sort_key(filepath: str) -> list: """Natural sort key for filenames with numeric components, such as - model-00001-of-00005.safetensors -> ['model-', 1, '-of-', 5, '.safetensors'] - """ + model-00001-of-00005.safetensors -> ['model-', 1, '-of-', 5, '.safetensors']""" return [ int(s) if s.isdigit() else s for s in re.split(r"(\d+)", os.path.basename(filepath)) @@ -162,8 +161,7 @@ def maybe_download_from_modelscope( """Download model from ModelScope hub if VLLM_USE_MODELSCOPE is True. Returns the path to the downloaded model, or None if the model is not - downloaded from ModelScope. - """ + downloaded from ModelScope.""" if envs.VLLM_USE_MODELSCOPE: # download model from ModelScope hub, # lazy import so that modelscope is not required for normal use. @@ -1148,8 +1146,7 @@ def instanttensor_weights_iterator( use_tqdm_on_load: bool, ) -> Generator[tuple[str, torch.Tensor], None, None]: """Iterate over the weights in the model safetensor files - using instanttensor library. - """ + using instanttensor library.""" try: import instanttensor except ImportError as e: diff --git a/vllm/model_executor/models/arcee.py b/vllm/model_executor/models/arcee.py index a75bdaee5a..32ad19a8e7 100644 --- a/vllm/model_executor/models/arcee.py +++ b/vllm/model_executor/models/arcee.py @@ -47,8 +47,7 @@ from .utils import ( class ArceeMLP(nn.Module): """Feed-forward layer for Arcee using ReLU^2 activation - (no gating as in LLaMA). - """ + (no gating as in LLaMA).""" def __init__( self, @@ -96,8 +95,7 @@ class ArceeMLP(nn.Module): class ArceeDecoderLayer(nn.Module): """Transformer decoder block for Arcee, with self-attention and - ReLU^2 MLP. - """ + ReLU^2 MLP.""" def __init__( self, @@ -177,8 +175,7 @@ class ArceeDecoderLayer(nn.Module): @support_torch_compile class ArceeModel(nn.Module, EagleModelMixin): """The transformer model backbone for Arcee (embedding layer + stacked - decoder blocks + final norm). - """ + decoder blocks + final norm).""" def __init__( self, @@ -280,8 +277,7 @@ class ArceeForCausalLM( nn.Module, SupportsLoRA, SupportsPP, SupportsEagle, SupportsEagle3 ): """Arcee Model for causal language modeling, integrated with vLLM - runtime. - """ + runtime.""" hf_to_vllm_mapper = WeightsMapper( orig_to_new_stacked={ @@ -362,8 +358,7 @@ class ArceeForCausalLM( def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: """Load weights into the model (delegates to inner model and handles - tied embeddings). - """ + tied embeddings).""" loader = AutoWeightsLoader(self) # AutoWeightLoader handles weight name remapping, including fusing # separate q_proj, k_proj, v_proj into qkv_proj diff --git a/vllm/model_executor/models/blip.py b/vllm/model_executor/models/blip.py index 09f0973a5c..a4e821ec6b 100644 --- a/vllm/model_executor/models/blip.py +++ b/vllm/model_executor/models/blip.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Minimal implementation of BlipVisionModel intended to be only used -within a vision language model. -""" +within a vision language model.""" from collections.abc import Iterable diff --git a/vllm/model_executor/models/cohere2_moe.py b/vllm/model_executor/models/cohere2_moe.py index ebfd93e857..d657b78a5d 100644 --- a/vllm/model_executor/models/cohere2_moe.py +++ b/vllm/model_executor/models/cohere2_moe.py @@ -96,8 +96,7 @@ class RMSNorm(nn.Module): def select_norm_impl(config: CohereConfig) -> tuple[type[nn.Module], float]: """Returns (norm_class, eps). Uses RMSNorm when config.rms_norm_eps is set, - otherwise falls back to LayerNorm with config.layer_norm_eps. - """ + otherwise falls back to LayerNorm with config.layer_norm_eps.""" rms_eps = getattr(config, "rms_norm_eps", None) if rms_eps is not None: return RMSNorm, rms_eps diff --git a/vllm/model_executor/models/cohere_asr.py b/vllm/model_executor/models/cohere_asr.py index 5020cadc99..844e8c5e0e 100644 --- a/vllm/model_executor/models/cohere_asr.py +++ b/vllm/model_executor/models/cohere_asr.py @@ -667,8 +667,7 @@ class ConvSubsampling(nn.Module): repeat_num: int = 1, ) -> torch.Tensor: """Calculates the output length of a Tensor passed - through a convolution or max pooling layer - """ + through a convolution or max pooling layer""" add_pad: float = all_paddings - kernel_size one: float = 1.0 for i in range(repeat_num): diff --git a/vllm/model_executor/models/deepencoder.py b/vllm/model_executor/models/deepencoder.py index 824813eadb..fa972ca615 100644 --- a/vllm/model_executor/models/deepencoder.py +++ b/vllm/model_executor/models/deepencoder.py @@ -363,8 +363,7 @@ class ImageEncoderViT(nn.Module): class Block(nn.Module): """Transformer blocks with support of window attention and residual propagation - blocks - """ + blocks""" def __init__( self, diff --git a/vllm/model_executor/models/deepseek_ocr.py b/vllm/model_executor/models/deepseek_ocr.py index 3ead25f173..3d1921dc2b 100644 --- a/vllm/model_executor/models/deepseek_ocr.py +++ b/vllm/model_executor/models/deepseek_ocr.py @@ -139,8 +139,7 @@ class NoRepeatNGramLogitsProcessor: class NGramPerReqLogitsProcessor(AdapterLogitsProcessor): """Example of overriding the wrapper class `__init__()` in order to utilize - info about the device type - """ + info about the device type""" @classmethod def validate_params(cls, params: SamplingParams): diff --git a/vllm/model_executor/models/diffusion_gemma.py b/vllm/model_executor/models/diffusion_gemma.py index 7df3f744ce..bd1d14b6f6 100644 --- a/vllm/model_executor/models/diffusion_gemma.py +++ b/vllm/model_executor/models/diffusion_gemma.py @@ -511,8 +511,7 @@ def _compiled_sample_step( accept/renoise → convergence, all as vectorized PyTorch ops. Returns the temperature-scaled logits ``[num_decode, CL, vocab]`` so the - caller can compute logprobs outside the compiled region. - """ + caller can compute logprobs outside the compiled region.""" num_decode = decode_slots.shape[0] device = decode_slots.device diff --git a/vllm/model_executor/models/gemma3n.py b/vllm/model_executor/models/gemma3n.py index 87d72c18c1..3c9df39e67 100644 --- a/vllm/model_executor/models/gemma3n.py +++ b/vllm/model_executor/models/gemma3n.py @@ -814,8 +814,7 @@ class Gemma3nCrossDecoder(nn.Module): def _kv_sharing_weights_mapper(config: Gemma3nTextConfig) -> WeightsMapper: """KV-shared layers only have q_proj, so qkv_proj packing applies to the other layers. Original checkpoints still ship K/V tensors for the shared - layers (fine-tuned ones omit them); those are dropped. - """ + layers (fine-tuned ones omit them); those are dropped.""" first_kv_shared_layer_idx = config.num_hidden_layers - config.num_kv_shared_layers return WeightsMapper( orig_to_new_substr={ diff --git a/vllm/model_executor/models/gemma3n_mm.py b/vllm/model_executor/models/gemma3n_mm.py index dfde046fec..d0f536afe8 100644 --- a/vllm/model_executor/models/gemma3n_mm.py +++ b/vllm/model_executor/models/gemma3n_mm.py @@ -499,8 +499,7 @@ class Gemma3nMultiModalProcessor(BaseMultiModalProcessor[Gemma3nProcessingInfo]) class Gemma3nMultimodalEmbedder(nn.Module): """Embeds token ids or soft tokens for multimodal content into language - model space. - """ + model space.""" def __init__( self, diff --git a/vllm/model_executor/models/glm4_1v.py b/vllm/model_executor/models/glm4_1v.py index c0f77e770d..8f3db8a3d1 100644 --- a/vllm/model_executor/models/glm4_1v.py +++ b/vllm/model_executor/models/glm4_1v.py @@ -25,8 +25,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Inference-only GLM-4.1V & GLM-4.6V-Flash, AutoGLM-Phone-9B model -compatible with HuggingFace weights. -""" +compatible with HuggingFace weights.""" import math from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, Sequence diff --git a/vllm/model_executor/models/glm4_moe.py b/vllm/model_executor/models/glm4_moe.py index 18256e9c13..3c72a148d5 100644 --- a/vllm/model_executor/models/glm4_moe.py +++ b/vllm/model_executor/models/glm4_moe.py @@ -22,8 +22,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Inference-only GLM-4.5, GLM-4.6, GLM-4.7 model -compatible with HuggingFace weights. -""" +compatible with HuggingFace weights.""" from collections.abc import Iterable from itertools import islice diff --git a/vllm/model_executor/models/glm4_moe_mtp.py b/vllm/model_executor/models/glm4_moe_mtp.py index 12592af4a7..6d951e04ac 100644 --- a/vllm/model_executor/models/glm4_moe_mtp.py +++ b/vllm/model_executor/models/glm4_moe_mtp.py @@ -22,8 +22,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Inference-only GLM-4.5, GLM-4.6, GLM-4.7 MTP -model compatible with HuggingFace weights. -""" +model compatible with HuggingFace weights.""" import typing from collections.abc import Callable, Iterable diff --git a/vllm/model_executor/models/granite_speech.py b/vllm/model_executor/models/granite_speech.py index 529befd21d..1c1e98be04 100644 --- a/vllm/model_executor/models/granite_speech.py +++ b/vllm/model_executor/models/granite_speech.py @@ -462,8 +462,7 @@ class GraniteSpeechConformerConvModule(nn.Module): class GraniteSpeechConformerBlock(nn.Module): """Conformer block, consisting largely of linear layers, - attention, and convolutional layers. - """ + attention, and convolutional layers.""" def __init__(self, config: PretrainedConfig, prefix: str = ""): super().__init__() diff --git a/vllm/model_executor/models/interfaces.py b/vllm/model_executor/models/interfaces.py index e0121f9533..1cefd63dd6 100644 --- a/vllm/model_executor/models/interfaces.py +++ b/vllm/model_executor/models/interfaces.py @@ -892,8 +892,7 @@ def has_inner_state( @runtime_checkable class IsAttentionFree(Protocol): """The interface required for all models like Mamba that lack attention, - but do have state whose size is constant wrt the number of tokens. - """ + but do have state whose size is constant wrt the number of tokens.""" is_attention_free: ClassVar[Literal[True]] = True """ @@ -921,8 +920,7 @@ def is_attention_free( class IsHybrid(Protocol): """The interface required for all models like Jamba that have both attention and mamba blocks, indicates that - hf_config has 'layers_block_type' - """ + hf_config has 'layers_block_type'""" is_hybrid: ClassVar[Literal[True]] = True """ @@ -1338,8 +1336,7 @@ class SupportsTranscription(Protocol): ) -> "PromptType": """Get the prompt for the ASR model. The model has control over the construction, as long as it - returns a valid PromptType. - """ + returns a valid PromptType.""" ... @classmethod @@ -1631,8 +1628,7 @@ class EagleModelMixin: @runtime_checkable class SupportsEagle(SupportsEagleBase, Protocol): """The interface required for models that support - EAGLE-1 and EAGLE-2 speculative decoding. - """ + EAGLE-1 and EAGLE-2 speculative decoding.""" supports_eagle: ClassVar[Literal[True]] = True """ @@ -1662,8 +1658,7 @@ def supports_eagle( @runtime_checkable class SupportsEagle3(SupportsEagleBase, Protocol): """The interface required for models that support - EAGLE-3 speculative decoding. - """ + EAGLE-3 speculative decoding.""" supports_eagle3: ClassVar[Literal[True]] = True """ diff --git a/vllm/model_executor/models/keye.py b/vllm/model_executor/models/keye.py index b11adfa499..1322920900 100644 --- a/vllm/model_executor/models/keye.py +++ b/vllm/model_executor/models/keye.py @@ -345,8 +345,7 @@ def apply_rotary_pos_emb_flashatt( class KeyeSiglipAttention(nn.Module): """Multi-headed attention from 'Attention Is All You - Need' paper. - """ + Need' paper.""" def __init__( self, diff --git a/vllm/model_executor/models/lfm2_siglip2.py b/vllm/model_executor/models/lfm2_siglip2.py index 57a3d4a8d7..b3c7ee28ae 100644 --- a/vllm/model_executor/models/lfm2_siglip2.py +++ b/vllm/model_executor/models/lfm2_siglip2.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Implementation of Siglip2VisionModel intended to be only used -within a vision language model. -""" +within a vision language model.""" from collections.abc import Iterable diff --git a/vllm/model_executor/models/medusa.py b/vllm/model_executor/models/medusa.py index bf43f85d36..6adf3b7669 100644 --- a/vllm/model_executor/models/medusa.py +++ b/vllm/model_executor/models/medusa.py @@ -51,8 +51,7 @@ class Medusa(nn.Module): truncated_vocab_size < vocab_size. To use this technique, one has to find the top-k most frequent tokens in target dataset and add that as a tensor in the draft checkpoint (using key token_map). Also, the draft config - needs to have truncated_vocab_size (=k) as an attribute. - """ + needs to have truncated_vocab_size (=k) as an attribute.""" def __init__(self, *, vllm_config: VllmConfig, prefix: str = "") -> None: speculative_config = vllm_config.speculative_config diff --git a/vllm/model_executor/models/minicpmv4_6.py b/vllm/model_executor/models/minicpmv4_6.py index c8a2fe4bcd..0a96c2d847 100644 --- a/vllm/model_executor/models/minicpmv4_6.py +++ b/vllm/model_executor/models/minicpmv4_6.py @@ -858,8 +858,7 @@ class MiniCPMV4_6ViTWindowAttentionMerger(nn.Module): class MiniCPMV4_6DownsampleMLP(nn.Module): """Match HF (transformers v5.7+) parameter naming: pre_norm/linear_1/ - act/linear_2 (instead of pre_norm + Sequential(mlp.0/mlp.2)). - """ + act/linear_2 (instead of pre_norm + Sequential(mlp.0/mlp.2)).""" def __init__( self, diff --git a/vllm/model_executor/models/mllama4.py b/vllm/model_executor/models/mllama4.py index 5c5c272871..797c06d180 100644 --- a/vllm/model_executor/models/mllama4.py +++ b/vllm/model_executor/models/mllama4.py @@ -1090,8 +1090,7 @@ class Llama4ForConditionalGeneration( def _rename_weight_for_modelopt_checkpoint(self, name: str) -> str: """Rename weights from ModelOpt llama4 fp8 checkpoints to vLLM - format. - """ + format.""" if name.startswith("model.") or name.startswith("language_model.model."): renamed = ( name.replace("model.", "language_model.model.", 1) diff --git a/vllm/model_executor/models/muse_glimmer.py b/vllm/model_executor/models/muse_glimmer.py index 38cc475be2..ed8064542b 100644 --- a/vllm/model_executor/models/muse_glimmer.py +++ b/vllm/model_executor/models/muse_glimmer.py @@ -114,8 +114,7 @@ logger = init_logger(__name__) def _text_config(config): """MuseGlimmer checkpoints may nest the text config under ``text_config`` (multimodal ``MuseGlimmerConfig``) or expose it directly - (``MuseGlimmerTextConfig``). - """ + (``MuseGlimmerTextConfig``).""" return getattr(config, "text_config", config) @@ -489,8 +488,7 @@ class MuseGlimmerMultiModalProcessor( def _muse_glimmer_use_qk_norm(config) -> bool: """Whether QK-norm is applied. MuseGlimmer ALWAYS applies QK-norm; the modular HF ``text_config`` schema simply omits ``use_qk_norm`` (reads as ``None``). - Treat a missing/None flag as True — only an explicit ``False`` disables it. - """ + Treat a missing/None flag as True — only an explicit ``False`` disables it.""" val = getattr(config, "use_qk_norm", None) return True if val is None else bool(val) @@ -498,8 +496,7 @@ def _muse_glimmer_use_qk_norm(config) -> bool: def _muse_glimmer_use_attn_output_gate(config) -> bool: """Whether the per-head sigmoid attention output gate is applied. MuseGlimmer ALWAYS applies it; the modular HF ``text_config`` omits ``use_attn_output_gate`` - (reads as ``None``). Missing/None -> True; only explicit ``False`` disables. - """ + (reads as ``None``). Missing/None -> True; only explicit ``False`` disables.""" val = getattr(config, "use_attn_output_gate", None) return True if val is None else bool(val) diff --git a/vllm/model_executor/models/nano_nemotron_vl.py b/vllm/model_executor/models/nano_nemotron_vl.py index eb5e9f06ca..6e500c0c2c 100644 --- a/vllm/model_executor/models/nano_nemotron_vl.py +++ b/vllm/model_executor/models/nano_nemotron_vl.py @@ -1188,8 +1188,7 @@ class NemotronH_Nano_VL_V2( self, video_input: NanoNemotronVLVideoPixelInputs ) -> tuple[torch.Tensor, ...]: """Process video input and create final embeddings with video content - and indicator tokens. - """ + and indicator tokens.""" T = self.video_temporal_patch_size if T > 1: diff --git a/vllm/model_executor/models/phi4mm_utils.py b/vllm/model_executor/models/phi4mm_utils.py index bd7ec9c344..af54defd3f 100644 --- a/vllm/model_executor/models/phi4mm_utils.py +++ b/vllm/model_executor/models/phi4mm_utils.py @@ -1462,8 +1462,7 @@ class NemoConvSubsampling(torch.nn.Module): def conv_split_by_channel(self, x: Tensor) -> Tensor: """For dw convs, tries to split input by time, run conv and concat - results - """ + results""" x = self.conv[0](x) # full conv2D x = self.conv[1](x) # activation diff --git a/vllm/model_executor/models/qwen3_dflash.py b/vllm/model_executor/models/qwen3_dflash.py index a807f2d4b5..ce3884a10e 100644 --- a/vllm/model_executor/models/qwen3_dflash.py +++ b/vllm/model_executor/models/qwen3_dflash.py @@ -69,8 +69,7 @@ def _dflash_layer_causal(config: Qwen3Config, layer_idx: int) -> bool: def dflash_has_any_non_causal(config: Qwen3Config) -> bool: """Whether the draft needs a non-causal-capable backend, resolved from config - (config mirror of the model's ``get_draft_attn_causal``, usable pre-build). - """ + (config mirror of the model's ``get_draft_attn_causal``, usable pre-build).""" return not all( _dflash_layer_causal(config, i) for i in range(config.num_hidden_layers) ) @@ -155,8 +154,7 @@ class DFlashQwen3Attention(nn.Module): Context KVs are pre-inserted into the KV cache before the forward pass. This layer handles only query tokens via standard attention. - Adapted from Qwen3Attention. - """ + Adapted from Qwen3Attention.""" def __init__( self, @@ -250,8 +248,7 @@ class DFlashQwen3Attention(nn.Module): """DFlash attention assumes that the KV cache is already populated with the context K/V from the target model's hidden states. This forward op computes attention for the query tokens only. - See also: precompute_and_store_context_kv - """ + See also: precompute_and_store_context_kv""" qkv, _ = self.qkv_proj(hidden_states) q, k, v = qkv.split([self.q_size, self.kv_size, self.kv_size], dim=-1) @@ -743,8 +740,7 @@ class DFlashQwen3ForCausalLM(Qwen3ForCausalLM): def get_draft_attn_causal(self) -> list[bool]: """Per-layer attention causality, aligned with - get_draft_kv_cache_layer_names. - """ + get_draft_kv_cache_layer_names.""" return [layer.self_attn.causal for layer in self.model.layers] def compute_logits( diff --git a/vllm/model_executor/models/qwen3_vl.py b/vllm/model_executor/models/qwen3_vl.py index 78dda9c815..dc2baa1c5e 100644 --- a/vllm/model_executor/models/qwen3_vl.py +++ b/vllm/model_executor/models/qwen3_vl.py @@ -1321,8 +1321,7 @@ class Qwen3VLMultiModalProcessor(BaseMultiModalProcessor[Qwen3VLProcessingInfo]) def _expands_only_video_token(hf_processor: ProcessorMixin) -> bool: """Transformers>=5.10 processors override `replace_video_token` to expand only the bare video token, keeping the prompt's outer - `<|vision_start|>`/`<|vision_end|>` markers. - """ + `<|vision_start|>`/`<|vision_end|>` markers.""" mixin_impl = getattr(ProcessorMixin, "replace_video_token", None) proc_impl = getattr(type(hf_processor), "replace_video_token", None) return proc_impl is not None and proc_impl is not mixin_impl diff --git a/vllm/model_executor/models/radio.py b/vllm/model_executor/models/radio.py index 9f8ff5ed2b..bc89591324 100644 --- a/vllm/model_executor/models/radio.py +++ b/vllm/model_executor/models/radio.py @@ -599,8 +599,7 @@ class RadioInternVisionModel(nn.Module): self, imgs_sizes: list[tuple[int, int]], device: torch.device ) -> MaskMetadata: """Build mask metadata from image pixel sizes. Adds num_skip to each - sequence length (cls/register tokens) to match patch generator output. - """ + sequence length (cls/register tokens) to match patch generator output.""" patch_size = self.patch_generator.patch_size num_skip = self.patch_generator.num_skip @@ -613,8 +612,7 @@ class RadioInternVisionModel(nn.Module): ) -> MaskMetadata: """Build mask metadata from actual sequence lengths (already including cls/register tokens, i.e. patch_count + num_skip per item). - Use inter_image_mask_metadata() when you only have imgs_sizes. - """ + Use inter_image_mask_metadata() when you only have imgs_sizes.""" assert len(seq_lens) > 0 cu_seqlens = torch.tensor( list(accumulate(seq_lens, initial=0)), dtype=torch.int32, device=device diff --git a/vllm/model_executor/models/siglip2navit.py b/vllm/model_executor/models/siglip2navit.py index aabb62f4ab..1d0c3c8d96 100644 --- a/vllm/model_executor/models/siglip2navit.py +++ b/vllm/model_executor/models/siglip2navit.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Implementation of SiglipVisionModel intended to be only used -within a vision language model. -""" +within a vision language model.""" from collections.abc import Iterable diff --git a/vllm/model_executor/models/stablelm.py b/vllm/model_executor/models/stablelm.py index 7c4c24813b..1851252882 100644 --- a/vllm/model_executor/models/stablelm.py +++ b/vllm/model_executor/models/stablelm.py @@ -20,8 +20,7 @@ # https://huggingface.co/stabilityai/stablelm-3b-4e1t/blob/main/modeling_stablelm_epoch.py # https://huggingface.co/stabilityai/stablelm-3b-4e1t/blob/main/config.json """Inference-only StableLM (https://github.com/Stability-AI/StableLM) -model compatible with HuggingFace weights. -""" +model compatible with HuggingFace weights.""" from collections.abc import Iterable from itertools import islice diff --git a/vllm/model_executor/models/transformers/base.py b/vllm/model_executor/models/transformers/base.py index eeec0a4b91..62f6d684e8 100644 --- a/vllm/model_executor/models/transformers/base.py +++ b/vllm/model_executor/models/transformers/base.py @@ -207,8 +207,7 @@ class Base( def _mark_model_components(self, vllm_config: "VllmConfig"): """Mark language model and tower submodules as `self.model` is created. - Nothing to do in `Base`, `MultiModalMixin` will override. - """ + Nothing to do in `Base`, `MultiModalMixin` will override.""" yield @cached_property @@ -281,8 +280,7 @@ class Base( def _decorate_for_torch_compile(self): """Decorate the model's decoder class to indicate to vLLM that it - supports torch compile if `can_enable_torch_compile` is True. - """ + supports torch compile if `can_enable_torch_compile` is True.""" self._decorate_cls_for_torch_compile( cls=self._pre_trained_model_classes.decoder, # Applied to a PreTrainedModel so the batch dimension will exist diff --git a/vllm/model_executor/models/transformers/fusers/base.py b/vllm/model_executor/models/transformers/fusers/base.py index 0b83afe6b7..ad24f2542a 100644 --- a/vllm/model_executor/models/transformers/fusers/base.py +++ b/vllm/model_executor/models/transformers/fusers/base.py @@ -55,20 +55,17 @@ class BaseFuser(ABC): self, module: nn.Module, prefix: str, vllm_config: "VllmConfig" ) -> nn.Module: """Apply the fusion to an already-validated `module`, returning the - module to install in its place (mutated in place, or freshly built). - """ + module to install in its place (mutated in place, or freshly built).""" def orig_to_new_stacked(self, prefix: str) -> dict[str, tuple[str, ShardId]]: """`WeightsMapper.orig_to_new_stacked` entries this fuser contributes - (none unless it stacks weights). - """ + (none unless it stacks weights).""" return {} @property def packed_modules_mapping(self) -> dict[str, list[str]]: """`packed_modules_mapping` entries this fuser contributes (none unless - it stacks weights). - """ + it stacks weights).""" return {} @@ -122,8 +119,7 @@ class RewriteFuser(BaseFuser): ) -> nn.Module: """Fuse an already-validated `module` in place (see `Fusers.__getitem__`). - Builds the merged submodule and binds the compiled forward. - """ + Builds the merged submodule and binds the compiled forward.""" self.update_attrs(module, prefix, vllm_config) module.forward = types.MethodType(self.fused_forward, module) return module @@ -132,8 +128,7 @@ class RewriteFuser(BaseFuser): @dataclass class StackedFuser(RewriteFuser): """A fuser that merges sibling projections into one stacked linear and - rewrites the forward to call it. - """ + rewrites the forward to call it.""" merged_name: ClassVar[str] """Attribute name of the merged module created by `update_attrs`.""" @@ -152,16 +147,14 @@ class StackedFuser(RewriteFuser): def shards(self) -> list[tuple[str, ShardId]]: """Each projection's original name and its shard id in the merged module. - Source for both `orig_to_new_stacked` and `packed_modules_mapping`. - """ + Source for both `orig_to_new_stacked` and `packed_modules_mapping`.""" def orig_to_new_stacked(self, prefix: str) -> dict[str, tuple[str, ShardId]]: """`WeightsMapper.orig_to_new_stacked` entries for one fused instance. Maps each checkpoint name to `(merged_name, shard_id)`, keyed by qualname so only this exact layer is remapped, never a same-named projection - elsewhere (e.g. an unfused MoE expert's `gate_proj`). - """ + elsewhere (e.g. an unfused MoE expert's `gate_proj`).""" merged = maybe_prefix(prefix, self.merged_name) return { maybe_prefix(prefix, name): (merged, shard) for name, shard in self.shards @@ -170,8 +163,7 @@ class StackedFuser(RewriteFuser): @property def packed_modules_mapping(self) -> dict[str, list[str]]: """`{merged_name: [projection names]}` so quantization can unpack the - fused layer into its per-shard configs. - """ + fused layer into its per-shard configs.""" return {self.merged_name: [name for name, _ in self.shards]} def _unguarded_calls( @@ -182,8 +174,7 @@ class StackedFuser(RewriteFuser): `update_attrs` deletes the projections it merges, so any reference to one beyond its call site must be a guard on its existence; folding those to their constant value keeps the rewritten forward off a name that no longer exists. A reference - that is not such a guard raises, so fusion is skipped. - """ + that is not such a guard raises, so fusion is skipped.""" calls = [] for name in names: call, refs = self_call_and_refs(funcdef, name) diff --git a/vllm/model_executor/models/transformers/fusers/mla.py b/vllm/model_executor/models/transformers/fusers/mla.py index fccb1a8ea9..fa4b34750c 100644 --- a/vllm/model_executor/models/transformers/fusers/mla.py +++ b/vllm/model_executor/models/transformers/fusers/mla.py @@ -232,8 +232,7 @@ class MLAFuser(StackedFuser): def update_forward(self, module: nn.Module) -> None: """Merge `q_a_proj` and `kv_a_proj` into one fused down proj then split. Bypass the KV expansion method so the compressed latent reaches the `vllm_mla` - attention interface unexpanded. - """ + attention interface unexpanded.""" funcdef, fn = recover_forward(type(module)) if self.has_q_lora: # q_a_proj is usually inside the `else` of `if self.q_lora_rank is None`. diff --git a/vllm/model_executor/models/transformers/fusers/moe.py b/vllm/model_executor/models/transformers/fusers/moe.py index b7f435b4e0..af3a101a0c 100644 --- a/vllm/model_executor/models/transformers/fusers/moe.py +++ b/vllm/model_executor/models/transformers/fusers/moe.py @@ -80,8 +80,7 @@ def _forced_dtype(nodes: Iterable[fx.Node]) -> torch.dtype | None: Computations that must run in higher precision say so in their forward (e.g. `hidden_states.type(torch.float32)`), so the dtype is readable from the graph - even when the config does not name it. - """ + even when the config does not name it.""" for node in nodes: if node.op not in ("call_method", "call_function"): continue @@ -126,8 +125,7 @@ class SharedExpertMLP(nn.Module): def _moe_block_forward(self: nn.Module, hidden_states: torch.Tensor) -> torch.Tensor: """Standard MoE block forward. - Routing and any shared experts are handled inside `self.experts: MoERunner`. - """ + Routing and any shared experts are handled inside `self.experts: MoERunner`.""" orig_shape = hidden_states.shape hidden_states = hidden_states.reshape(-1, orig_shape[-1]) num_tokens = hidden_states.shape[0] @@ -154,8 +152,7 @@ class MoEBlockFuser: def _match_router(gate: nn.Module) -> tuple[str, torch.dtype | None] | None: """Matches `topk(score(linear(x)))`, `score` being `softmax`/`sigmoid`. - Returns the scoring function and the dtype the router computes in. - """ + Returns the scoring function and the dtype the router computes in.""" state = {name for name, _ in named_state(gate)} if "weight" not in state or state - {"weight", "e_score_correction_bias"}: return None @@ -283,8 +280,7 @@ class MoEBlockFuser: self, moe_block: nn.Module, prefix: str ) -> SharedExpertMLP | None: """Build the HF shared expert (and its optional gate) - as a `SharedExpertMLP` for vLLM's fused MoE. - """ + as a `SharedExpertMLP` for vLLM's fused MoE.""" if self.shared_name is None: return None shared_experts = getattr(moe_block, self.shared_name) diff --git a/vllm/model_executor/models/transformers/fx_utils.py b/vllm/model_executor/models/transformers/fx_utils.py index b0f449a6d2..3cdc4e1201 100644 --- a/vllm/model_executor/models/transformers/fx_utils.py +++ b/vllm/model_executor/models/transformers/fx_utils.py @@ -43,8 +43,7 @@ def _reference_weight(module: nn.Module) -> torch.Tensor | None: """A weight whose trailing dim is the module's hidden size. Linears and 2-D gate weights are `[out, hidden]`; norm weights are - `[hidden]`. Used to fabricate a placeholder input of matching size/dtype. - """ + `[hidden]`. Used to fabricate a placeholder input of matching size/dtype.""" for child in module.modules(): if isinstance(child, nn.Linear): return child.weight @@ -59,8 +58,7 @@ class _MetaProxy(fx.Proxy): Shape questions (`len`, iteration, `.shape` unpacks) are answered by executing each op on the meta values, so PyTorch's meta kernels are the - single source of shape inference — no per-op rules. - """ + single source of shape inference — no per-op rules.""" meta: object = _UNKNOWN @@ -84,8 +82,7 @@ class _MetaAttribute(_MetaProxy, fx.proxy.Attribute): """Attribute proxy (e.g. `x.shape`) carrying its meta value. `Proxy.__getattr__` constructs `Attribute` directly, bypassing - `Tracer.proxy`, so the meta value must be grafted on here too. - """ + `Tracer.proxy`, so the meta value must be grafted on here too.""" def __init__(self, root: fx.Proxy, attr: str): super().__init__(root, attr) @@ -221,8 +218,7 @@ def _leaf_attention_interfaces(): """Patch `AttentionInterface.get_interface` so traced forwards see a leaf node. `vllm_attention_function` needs runtime context so it is untraceable. - Every interface returns `(attn_output, attn_weights)`. - """ + Every interface returns `(attn_output, attn_weights)`.""" from transformers.modeling_utils import AttentionInterface original = AttentionInterface.get_interface @@ -300,8 +296,7 @@ def forward_parameters(cls: type[nn.Module]) -> dict[str, inspect.Parameter]: def forward_input_count(cls: type[nn.Module]) -> int: """The number of tensor inputs `cls.forward` declares, excluding `self` and any `*args`/`**kwargs`. Read from the signature, so it is independent of - whether the trace completes (unlike counting placeholders). - """ + whether the trace completes (unlike counting placeholders).""" params = list(forward_parameters(cls).values()) if not params: return 1 # uninspectable: assume a single input and let matching decide @@ -378,8 +373,7 @@ def _in_boolean_context(funcdef: ast.FunctionDef, ref: ast.expr) -> bool: In these positions the object's identity never escapes, so a reference that is always truthy can be replaced by `True`. `and`/`or` are excluded: they - yield an operand, so the module could escape (`x and self.`). - """ + yield an operand, so the module could escape (`x and self.`).""" for node in ast.walk(funcdef): if ( isinstance(node, (ast.If, ast.IfExp, ast.While, ast.Assert)) @@ -412,8 +406,7 @@ def bypass_existence_guard( `not self.`): the reference itself to `True`. Any other surviving reference escapes the projection's value, which no longer - exists after fusion, so refuse rather than change semantics. - """ + exists after fusion, so refuse rather than change semantics.""" for node in ast.walk(funcdef): # `self. is (not) None`, either operand order. if not (isinstance(node, ast.Compare) and len(node.ops) == 1): @@ -474,8 +467,7 @@ def _base_name(node: ast.expr) -> str | None: def _rebound_names(region: list[ast.stmt]) -> set[str]: """Names rebound outright within `region` (`x = ...`, `del x`). - These are `Name` nodes in a `Store`/`Del` context. - """ + These are `Name` nodes in a `Store`/`Del` context.""" return { node.id for stmt in region @@ -489,8 +481,7 @@ def _inplace_target(node: ast.AST) -> str | None: A write through the name (`x[i] = ...`, `x.attr = ...`) or an in-place method call (`x.mul_(...)`) leaves the base name in a `Load` context, so it is not a - plain `Name` store (see `_rebound_names`). - """ + plain `Name` store (see `_rebound_names`).""" if isinstance(node, (ast.Attribute, ast.Subscript)) and isinstance( node.ctx, (ast.Store, ast.Del) ): @@ -711,8 +702,7 @@ def upstream_linear(node: object, module: nn.Module) -> fx.Node | None: Non-linear submodules are transparent too (e.g. the dropout GPT-style attentions apply after their output projection). Never walks through a leaf call (e.g. an attention interface): its inputs are what attention consumes, - not what produced the value. - """ + not what produced the value.""" stack = [node] seen: set[fx.Node] = set() while stack: @@ -735,8 +725,7 @@ def downstream_linear(node: fx.Node, module: nn.Module) -> fx.Node | None: """Nearest linear consuming `node`'s output, walking through casts/scalings. Never walks through a leaf call (e.g. an attention interface): what crosses - it is consumed by the attention computation, not projected. - """ + it is consumed by the attention computation, not projected.""" queue = list(node.users) seen: set[fx.Node] = set() while queue: diff --git a/vllm/model_executor/models/transformers/layers.py b/vllm/model_executor/models/transformers/layers.py index 51c4bfef98..4ff3651dfc 100644 --- a/vllm/model_executor/models/transformers/layers.py +++ b/vllm/model_executor/models/transformers/layers.py @@ -22,8 +22,7 @@ _VLLM_PKG = "vllm.model_executor.layers" def _resolve(module: str, name: str): """Return `name` from the hw-agnostic `module` when enabled and available, - else from vLLM. Logs which source was used. - """ + else from vLLM. Logs which source was used.""" if envs.VLLM_USE_HW_AGNOSTIC: try: obj = getattr(importlib.import_module(f"{_HW_PKG}.{module}"), name) diff --git a/vllm/model_executor/models/transformers/moe.py b/vllm/model_executor/models/transformers/moe.py index 73cf42cc5f..480bc7f66e 100644 --- a/vllm/model_executor/models/transformers/moe.py +++ b/vllm/model_executor/models/transformers/moe.py @@ -75,8 +75,7 @@ class TransformersMoERunner(MoERunner): ) -> torch.Tensor: """In Transformers `experts.forward` will have this signature. - We discard any extra kwargs because we cannot use them here. - """ + We discard any extra kwargs because we cannot use them here.""" # Note: we need to forward through a custom op so the topk_ids # can be transferred without interfering with cudagraphs. return torch.ops.vllm.transformers_moe_forward( @@ -368,8 +367,7 @@ class MoEMixin(MixtureOfExperts): moe_state: TransformersMoEState, ): """Return `topk_weights` from `gating_output` and the - `topk_ids` we stored in the layer earlier. - """ + `topk_ids` we stored in the layer earlier.""" topk_weights = gating_output topk_ids = moe_state.topk_ids assert topk_ids is not None diff --git a/vllm/model_executor/models/transformers/multimodal.py b/vllm/model_executor/models/transformers/multimodal.py index 7b435d40ba..855b267c02 100644 --- a/vllm/model_executor/models/transformers/multimodal.py +++ b/vllm/model_executor/models/transformers/multimodal.py @@ -424,8 +424,7 @@ class LegacyMultiModalProcessor(_MultiModalProcessorBase): out_mm_kwargs: MultiModalKwargsItems, ) -> Sequence[PromptUpdate]: """Empty, because `apply` writes the placeholder ranges itself rather than - deriving them from updates. - """ + deriving them from updates.""" return [] def _get_mm_token_ids(self, modality: str) -> list[int]: @@ -459,8 +458,7 @@ class LegacyMultiModalProcessor(_MultiModalProcessorBase): num_audios: int, ) -> dict[str, list[PlaceholderRange]]: """Take each contiguous run of the audio token as one item's placeholder, - and record how many tokens the run holds. - """ + and record how many tokens the run holds.""" audio_token_ids = self._get_mm_token_ids("audio") prompt_tensor = torch.tensor(prompt_ids) is_audio = torch.isin(prompt_tensor, torch.tensor(audio_token_ids)) @@ -518,8 +516,7 @@ class LegacyMultiModalProcessor(_MultiModalProcessorBase): mm_token_type_ids: torch.Tensor | None, ) -> dict[str, list[PlaceholderRange]]: """Split the positions the processor marks as image into one placeholder per - item, sized by the token count it reports for each image. - """ + item, sized by the token count it reports for each image.""" hf_processor = self.info.get_hf_processor(**hf_processor_mm_kwargs) if mm_token_type_ids is None: raise ValueError( @@ -572,8 +569,7 @@ class LegacyMultiModalProcessor(_MultiModalProcessorBase): timing_ctx: TimingContext, ) -> MultiModalInput: """Process the prompt and every multi-modal item in one HF processor call, - then read the placeholder ranges out of the token ids it returns. - """ + then read the placeholder ranges out of the token ids it returns.""" prompt = inputs.prompt mm_items = inputs.mm_data_items hf_processor_mm_kwargs = inputs.hf_processor_mm_kwargs @@ -711,8 +707,7 @@ class OffsetsMultiModalProcessor(_MultiModalProcessorBase): out_mm_kwargs: MultiModalKwargsItems, ) -> Sequence[PromptUpdate]: """Replace each modality's placeholder token with the token ids that item's - replacement text encodes to, marking which of them hold embeddings. - """ + replacement text encodes to, marking which of them hold embeddings.""" hf_processor = self.info.get_hf_processor(**hf_processor_mm_kwargs) tokenizer = self.info.get_tokenizer() @@ -907,8 +902,7 @@ class MultiModalMixin(SupportsMultiModal, SupportsMRoPE): self, model: "PreTrainedModel" ) -> dict[str, type["PreTrainedModel"]]: """Modalities whose encoder cannot be told apart from the model itself are - omitted, as are those `get_encoder` rejects. - """ + omitted, as are those `get_encoder` rejects.""" encoder_classes: dict[str, type[PreTrainedModel]] = {} for modality in _MODALITY_TO_TOKEN_TYPE_ID: try: @@ -1027,8 +1021,7 @@ class MultiModalMixin(SupportsMultiModal, SupportsMRoPE): def get_language_model(self) -> torch.nn.Module: """Transformers modeling backend multimodal classes do not contain a separate vLLM language model class. Therefore, in order to return a language model vLLM - class, we use a wrapper to give `self` the same interface as a text model. - """ + class, we use a wrapper to give `self` the same interface as a text model.""" # Exclude self and object bases = self.__class__.mro()[1:-1] # Keep only classes defined in `vllm.model_executor.models.transformers` @@ -1182,8 +1175,7 @@ class MultiModalMixin(SupportsMultiModal, SupportsMRoPE): ) -> dict[str, Any]: """Narrow the entries of `kwargs` that hold one row per item down to the item at `index`. Length is all there is to match on, so an unrelated entry of the - same length is narrowed too. - """ + same length is narrowed too.""" return { key: value[index : index + 1] if isinstance(value, (torch.Tensor, list)) and len(value) == num_items diff --git a/vllm/model_executor/models/transformers/utils.py b/vllm/model_executor/models/transformers/utils.py index 47921b988d..ddb2f4fb71 100644 --- a/vllm/model_executor/models/transformers/utils.py +++ b/vllm/model_executor/models/transformers/utils.py @@ -201,8 +201,7 @@ def attrsetter(attr: str) -> Callable[[object, object], None]: class _UninitializedEmbedding(nn.Embedding): """Make `__init__` inert, so that `VocabParallelEmbedding.__init__`' - call to `super().__init__` does not invoke `nn.Embedding.__init__`. - """ + call to `super().__init__` does not invoke `nn.Embedding.__init__`.""" def __init__(self): pass @@ -210,8 +209,7 @@ class _UninitializedEmbedding(nn.Embedding): class _VocabParallelEmbeddingBase(VocabParallelEmbedding, _UninitializedEmbedding): """Orders `VocabParallelEmbedding` ahead of `nn.Embedding` in the MRO, so that - `super().forward(...)` in an `nn.Embedding` subclass reaches vLLM's embedding. - """ + `super().forward(...)` in an `nn.Embedding` subclass reaches vLLM's embedding.""" @lru_cache diff --git a/vllm/model_executor/models/utils.py b/vllm/model_executor/models/utils.py index 5d76066b82..eaa64793de 100644 --- a/vllm/model_executor/models/utils.py +++ b/vllm/model_executor/models/utils.py @@ -47,8 +47,7 @@ ShardId: TypeAlias = str | int | tuple[int, ...] class WeightsMapper: """Maps the name of each weight if they match the following patterns. - If a key maps to a value of `None`, the corresponding weight is ignored. - """ + If a key maps to a value of `None`, the corresponding weight is ignored.""" orig_to_new_renaming: list["WeightRenaming"] = field(default_factory=list) orig_to_new_regex: Mapping[re.Pattern, str | None] = field(default_factory=dict) @@ -172,8 +171,7 @@ class WeightsMapper: rather than being rewritten to the stacked vLLM name (`qkv_proj`). Mappings to `None` are dropped because "do not load this weight" is meaningless to such a consumer, and applying it would silently shrink a quantization config's ignore - list or make LoRA name parsing fail. - """ + list or make LoRA name parsing fail.""" remove_none = lambda d: {k: v for k, v in d.items() if v is not None} return replace( self, diff --git a/vllm/model_executor/models/vision.py b/vllm/model_executor/models/vision.py index fb684ddba4..0c7cfb598e 100644 --- a/vllm/model_executor/models/vision.py +++ b/vllm/model_executor/models/vision.py @@ -116,8 +116,7 @@ def get_multimodal_config() -> MultiModalConfig | None: """Return the current ``MultiModalConfig``, or ``None`` when no engine config context is active (e.g., during unit tests) or when the current ``model_config`` does not carry a ``multimodal_config`` (e.g., minimal - stubs used in tests). - """ + stubs used in tests).""" vllm_config = get_current_vllm_config_or_none() if vllm_config is None or vllm_config.model_config is None: return None diff --git a/vllm/model_executor/utils.py b/vllm/model_executor/utils.py index 33418847da..a319794988 100644 --- a/vllm/model_executor/utils.py +++ b/vllm/model_executor/utils.py @@ -174,8 +174,7 @@ def get_moe_expert_mapping( It will be retrieved from the first module that has a `get_expert_mapping` method. If the model manually implements `get_expert_mapping`, it will be used. - Otherwise, it will use the first RoutedExperts layer. - """ + Otherwise, it will use the first RoutedExperts layer.""" for _, module in model.named_modules(): get_mapping = getattr(module, "get_expert_mapping", None) if get_mapping is not None: diff --git a/vllm/model_executor/warmup/qwen4_exp_qsa_warmup.py b/vllm/model_executor/warmup/qwen4_exp_qsa_warmup.py index d467e8eacf..2065b38338 100644 --- a/vllm/model_executor/warmup/qwen4_exp_qsa_warmup.py +++ b/vllm/model_executor/warmup/qwen4_exp_qsa_warmup.py @@ -18,8 +18,7 @@ logger = init_logger(__name__) def qwen4_exp_qsa_triton_warmup(worker: "Worker") -> None: """Warm every reachable QSA specialization: indexer decode-query-length - profiles plus the sparse attention split-K/merge configs. - """ + profiles plus the sparse attention split-K/merge configs.""" qsa_module = sys.modules.get("vllm.models.qwen4_exp.nvidia.indexer_qsa") attn_module = sys.modules.get("vllm.models.qwen4_exp.nvidia.qsa") if qsa_module is None or attn_module is None: diff --git a/vllm/models/deepseek_v32/common/kernels.py b/vllm/models/deepseek_v32/common/kernels.py index 124573b0e3..fd02a51076 100644 --- a/vllm/models/deepseek_v32/common/kernels.py +++ b/vllm/models/deepseek_v32/common/kernels.py @@ -1059,8 +1059,7 @@ def _fused_eh_norm_kernel( ): """MTP input fusion: zero embeds at position 0, RMSNorm(embeds) with enorm and RMSNorm(prev_hidden) with hnorm, written side-by-side into ``out`` - ([N, 2H]) ready for the eh_proj GEMM. Replaces where + 2x RMSNorm + cat. - """ + ([N, 2H]) ready for the eh_proj GEMM. Replaces where + 2x RMSNorm + cat.""" tok = tl.program_id(0) off = tl.arange(0, BLOCK) mask = off < H diff --git a/vllm/models/deepseek_v4/amd/model.py b/vllm/models/deepseek_v4/amd/model.py index e60083b118..c1a6903937 100644 --- a/vllm/models/deepseek_v4/amd/model.py +++ b/vllm/models/deepseek_v4/amd/model.py @@ -1425,8 +1425,7 @@ class DeepseekV4ForCausalLM(nn.Module, SupportsPP, SupportsEagle3): def get_mtp_target_hidden_states(self) -> torch.Tensor | None: """Pre-hc_head residual stream buffer (max_num_batched_tokens, hc_mult * hidden_size) for the MTP draft model. Populated by - forward(); valid after each target step. - """ + forward(); valid after each target step.""" return getattr(self.model, "_mtp_hidden_buffer", None) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/deepseek_v4/common/mm_preprocess.py b/vllm/models/deepseek_v4/common/mm_preprocess.py index f175558500..919146c551 100644 --- a/vllm/models/deepseek_v4/common/mm_preprocess.py +++ b/vllm/models/deepseek_v4/common/mm_preprocess.py @@ -91,8 +91,7 @@ def validate_image_sentinel_ids(tokenizer) -> None: def grid_tokens(best_height, best_width, patch_size, downsample_ratio): """Number of LLM tokens the aligner grid occupies (N-layout, including - row/align padding). - """ + row/align padding).""" n_llm_h = math.ceil((best_height // patch_size) / downsample_ratio) n_llm_w = math.ceil((best_width // patch_size) / downsample_ratio) num_tokens = n_llm_h * (n_llm_w + 1) + 2 @@ -197,8 +196,7 @@ def load_image( def build_image_block(n_llm_h: int, n_llm_w: int, start_pos: int): """Builds the N-layout token types (final order) and the aligner-row order - for IMAGE slots. - """ + for IMAGE slots.""" compress_pad = COMPRESS_PAD_TO - 1 - start_pos % COMPRESS_PAD_TO pad_h = n_llm_h % 2 rows = n_llm_h + pad_h @@ -241,8 +239,7 @@ def build_image_block_pad_free(n_llm_h: int, n_llm_w: int): class DeepseekV4VLImageProcessor: """Per-image transform (the PIL-input equivalent of the reference - ``load_image``). - """ + ``load_image``).""" def __init__(self, config: DeepseekV4Config) -> None: super().__init__() diff --git a/vllm/models/deepseek_v4/common/ops/fused_indexer_q.py b/vllm/models/deepseek_v4/common/ops/fused_indexer_q.py index d0168ff25e..669186edbb 100644 --- a/vllm/models/deepseek_v4/common/ops/fused_indexer_q.py +++ b/vllm/models/deepseek_v4/common/ops/fused_indexer_q.py @@ -312,8 +312,7 @@ class FusedIndexerQRopeQuantTritonKernel( def _indexer_weights_out_dtypes(vllm_config: Any) -> tuple[torch.dtype, ...]: """Weights dtypes the model's indexer layers ask for: fp32 for the dense scoring kernels, plus bf16 when the DeepSeek V4.1 sparse-logits indexer - (`SparseMQAIndexer`) is enabled. - """ + (`SparseMQAIndexer`) is enabled.""" if vllm_config.attention_config.indexer_sparse_logits: return (torch.float32, torch.bfloat16) return (torch.float32,) diff --git a/vllm/models/deepseek_v4/cpu/cpu_compressor.py b/vllm/models/deepseek_v4/cpu/cpu_compressor.py index a0c856dc55..6f0b9e06d8 100644 --- a/vllm/models/deepseek_v4/cpu/cpu_compressor.py +++ b/vllm/models/deepseek_v4/cpu/cpu_compressor.py @@ -42,8 +42,7 @@ class DeepseekV4CPUCompressor(DeepseekCompressor): weight loading (see ``DeepseekV4CPUAttention.process_weights_after_loading``) -- the CPU kernel requires fp32/contiguous but the checkpoint loads this weight - in bf16, and it never changes after loading. - """ + in bf16, and it never changes after loading.""" self._norm_weight_fp32 = self.norm.weight.to(torch.float32).contiguous() def forward( diff --git a/vllm/models/deepseek_v4/cpu/cpu_mla.py b/vllm/models/deepseek_v4/cpu/cpu_mla.py index a7f2af1cbb..52d4f4c3b0 100644 --- a/vllm/models/deepseek_v4/cpu/cpu_mla.py +++ b/vllm/models/deepseek_v4/cpu/cpu_mla.py @@ -118,8 +118,7 @@ class DeepseekV4CPUSparseSWAMetadataBuilder(DeepseekSparseSWAMetadataBuilder): ) -> dict[str, FlashMLASchedMeta | None]: """CPU never runs the FlashMLA tile-scheduler planner (that's a CUDA C++ decode-path concern) -- always return the all-``None`` sentinel - the shared base's own CPU branch returns. - """ + the shared base's own CPU branch returns.""" return { _LAYER_TYPE_SWAONLY: None, _LAYER_TYPE_C4A: None, diff --git a/vllm/models/deepseek_v4/cpu/cpu_sparse.py b/vllm/models/deepseek_v4/cpu/cpu_sparse.py index efbd6768f6..a2c3b00493 100644 --- a/vllm/models/deepseek_v4/cpu/cpu_sparse.py +++ b/vllm/models/deepseek_v4/cpu/cpu_sparse.py @@ -176,15 +176,13 @@ def _fused_indexer_q_rope_quant_cpu( class _NoOpEvent: """Stand-in for ``torch.cuda.Event`` on CPU: since CPU never sets an aux - stream list, these events are constructed but never actually used. - """ + stream list, these events are constructed but never actually used.""" class DeepseekV4CPUIndexerCache(DeepseekV4IndexerCache): """CPU indexer K-cache descriptor: same fields as the shared base, just pointing ``get_attn_backend()`` at ``DeepseekV4CPUIndexerBackend`` - instead of the shared, CUDA/XPU-oriented ``DeepseekV4IndexerBackend``. - """ + instead of the shared, CUDA/XPU-oriented ``DeepseekV4IndexerBackend``.""" def get_attn_backend(self) -> type[AttentionBackend]: return DeepseekV4CPUIndexerBackend @@ -211,8 +209,7 @@ class DeepseekV4CPUIndexer(DeepseekV4Indexer): compressor run straight-line instead of through ``maybe_execute_in_parallel``; the short-context check drops the CUDA-only ``is_current_stream_capturing()`` guard (always False - here). - """ + here).""" compressor = self.compressor attn_metadata = get_forward_context().attn_metadata @@ -312,8 +309,7 @@ class DeepseekV4CPUAttention(DeepseekV4Attention): """Snapshot and pack ``wo_a``'s weight into a bf16 copy for ``bmm_cpu`` before the FP8 kernel's own ``process_weights_after_loading`` VNNI-repacks it in place for - row-major reads ``_o_proj`` never does. - """ + row-major reads ``_o_proj`` never does.""" wo_a = self.wo_a quant_method = wo_a.quant_method orig_pwal = quant_method.process_weights_after_loading @@ -404,8 +400,7 @@ class DeepseekV4CPUAttention(DeepseekV4Attention): ) -> torch.Tensor: """CPU override: only the fp8_ds_mla (uint8) SWA cache layout is supported here, so the base method's bf16/per-tensor-fp8 branches - are dropped. - """ + are dropped.""" if not isinstance(attn_metadata, dict): # Profile run: kernel doesn't fire; produce a padded tensor so # downstream FlashMLA gets the right shape. @@ -450,8 +445,7 @@ class DeepseekV4CPUAttention(DeepseekV4Attention): ) -> tuple[torch.Tensor, torch.Tensor | None, torch.Tensor]: """CPU override: two ``RMSNorm`` calls instead of the shared ``fused_q_kv_rmsnorm``, whose raw ``@triton.jit`` kernel fails to - link under triton-cpu (``undefined symbol: __truncdfbf2``). - """ + link under triton-cpu (``undefined symbol: __truncdfbf2``).""" qr, kv = qr_kv.split([self.q_lora_rank, self.head_dim], dim=-1) return self.q_norm(qr), None, self.kv_norm(kv) @@ -469,8 +463,7 @@ class DeepseekV4CPUAttention(DeepseekV4Attention): ) -> None: """CPU override: no aux streams, so query-projection+KV-insert, the indexer, and the compressor run straight-line instead of through - execute_in_parallel/maybe_execute_in_parallel. - """ + execute_in_parallel/maybe_execute_in_parallel.""" attn_metadata = get_forward_context().attn_metadata indexer = self.indexer compressor = self.compressor @@ -519,8 +512,7 @@ class DeepseekV4CPUAttention(DeepseekV4Attention): out: torch.Tensor, ) -> None: """CPU override: identical body, minus ``@eager_break_during_capture`` - (this platform never captures a CUDA graph, so it was a no-op). - """ + (this platform never captures a CUDA graph, so it was a no-op).""" if self.indexer is not None and index_q is not None: assert index_weights is not None # index_q_scale is always None on CPU (FP8-only path). diff --git a/vllm/models/deepseek_v4/cpu/model.py b/vllm/models/deepseek_v4/cpu/model.py index a71b6eb635..6e88d21c27 100644 --- a/vllm/models/deepseek_v4/cpu/model.py +++ b/vllm/models/deepseek_v4/cpu/model.py @@ -907,8 +907,7 @@ class DeepseekV4ForCausalLM(nn.Module, SupportsPP, SupportsEagle3): def get_mtp_target_hidden_states(self) -> torch.Tensor | None: """Pre-hc_head residual stream buffer (max_num_batched_tokens, hc_mult * hidden_size) for the MTP draft model. Populated by - forward(); valid after each target step. - """ + forward(); valid after each target step.""" return getattr(self.model, "_mtp_hidden_buffer", None) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/deepseek_v4/nvidia/fi_moe.py b/vllm/models/deepseek_v4/nvidia/fi_moe.py index 96515374d6..2e94e75e7d 100644 --- a/vllm/models/deepseek_v4/nvidia/fi_moe.py +++ b/vllm/models/deepseek_v4/nvidia/fi_moe.py @@ -159,8 +159,7 @@ class DeepseekV4MegaMoEExpertsFI(DeepseekV4MegaMoEExperts): def _realloc_nvfp4_params(self) -> None: """Swap the mx-recipe scale params for the NVFP4 checkpoint's: fp8-e4m3 per-16 block scales plus the per-tensor second-level - scales (weight_scale_2, input_scale) modelopt exports. - """ + scales (weight_scale_2, input_scale) modelopt exports.""" n_e = self.num_local_experts inter = self.intermediate_size hidden = self.hidden_size diff --git a/vllm/models/deepseek_v4/nvidia/flashinfer_sparse.py b/vllm/models/deepseek_v4/nvidia/flashinfer_sparse.py index 70dc01efab..883ef5ecaf 100644 --- a/vllm/models/deepseek_v4/nvidia/flashinfer_sparse.py +++ b/vllm/models/deepseek_v4/nvidia/flashinfer_sparse.py @@ -56,8 +56,7 @@ def _get_flashinfer_dsv4_workspace(device: torch.device) -> torch.Tensor: def _packed_block_span(pool: torch.Tensor) -> int: """Per-block stride of ``pool`` in tokens (``stride(0)//stride(-2)``): == block_size for unpacked KV, larger when packed (#44577). Raises if not - token-aligned. - """ + token-aligned.""" block_stride = pool.stride(0) token_stride = pool.stride(-2) if block_stride % token_stride != 0: diff --git a/vllm/models/deepseek_v4/nvidia/model.py b/vllm/models/deepseek_v4/nvidia/model.py index 3bc5399f53..4aba14cd03 100644 --- a/vllm/models/deepseek_v4/nvidia/model.py +++ b/vllm/models/deepseek_v4/nvidia/model.py @@ -1985,8 +1985,7 @@ class DeepseekV4ForCausalLM( def get_mtp_target_hidden_states(self) -> torch.Tensor | None: """Pre-hc_head residual stream buffer (max_num_batched_tokens, hc_mult * hidden_size) for the MTP draft model. Populated by - forward(); valid after each target step. - """ + forward(); valid after each target step.""" return getattr(self.model, "_mtp_hidden_buffer", None) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/deepseek_v4/xpu/model.py b/vllm/models/deepseek_v4/xpu/model.py index ba47bd9631..f3e468ebb1 100644 --- a/vllm/models/deepseek_v4/xpu/model.py +++ b/vllm/models/deepseek_v4/xpu/model.py @@ -1378,8 +1378,7 @@ class DeepseekV4ForCausalLM(nn.Module, SupportsPP, SupportsEagle3, SupportsLoRA) def get_mtp_target_hidden_states(self) -> torch.Tensor | None: """Pre-hc_head residual stream buffer (max_num_batched_tokens, hc_mult * hidden_size) for the MTP draft model. Populated by - forward(); valid after each target step. - """ + forward(); valid after each target step.""" return getattr(self.model, "_mtp_hidden_buffer", None) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/deepseek_v41/amd/model.py b/vllm/models/deepseek_v41/amd/model.py index 50bd8e7cb7..b3eddc2024 100644 --- a/vllm/models/deepseek_v41/amd/model.py +++ b/vllm/models/deepseek_v41/amd/model.py @@ -1062,8 +1062,7 @@ class DeepseekV41LLMForCausalLM( @property def token_lookback_depth(self) -> int: """Tokens before a chunk start the engram hash needs; the model runner - passes them as `lookback_token_ids`. - """ + passes them as `lookback_token_ids`.""" engram_hash = self.model.engram_hash return engram_hash.lookback_depth if engram_hash is not None else 0 @@ -1087,8 +1086,7 @@ class DeepseekV41LLMForCausalLM( def get_mtp_target_hidden_states(self) -> torch.Tensor | None: """Pre-collapse residual stream buffer (max_num_batched_tokens, hc_mult * hidden_size) for the MTP draft model. Populated by - forward(); valid after each target step. - """ + forward(); valid after each target step.""" return getattr(self.model, "_mtp_hidden_buffer", None) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/deepseek_v41/amd/vl_model.py b/vllm/models/deepseek_v41/amd/vl_model.py index 0e379037b4..3227b50a4e 100644 --- a/vllm/models/deepseek_v41/amd/vl_model.py +++ b/vllm/models/deepseek_v41/amd/vl_model.py @@ -209,8 +209,7 @@ class DeepseekV41ForCausalLM(nn.Module, SupportsMultiModal, SupportsPP, Supports self, image_embeds: torch.Tensor, types: torch.Tensor ) -> torch.Tensor: """Full image span: aligner rows at IMAGE slots, the learned - delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END. - """ + delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END.""" types = types.to(image_embeds.device) span = image_embeds.new_empty(types.numel(), image_embeds.shape[-1]) dtype = image_embeds.dtype diff --git a/vllm/models/deepseek_v41/attention.py b/vllm/models/deepseek_v41/attention.py index 77f5958e5f..4275d25a76 100644 --- a/vllm/models/deepseek_v41/attention.py +++ b/vllm/models/deepseek_v41/attention.py @@ -1066,8 +1066,7 @@ class DeepseekV4Attention(nn.Module, AttentionLayerBase, ABC): def _compressed_kv_cache(self) -> torch.Tensor: """The compressed-KV cache tensor of this layer's kv source (own - cache for kv-source layers). - """ + cache for kv-source layers).""" if self.is_kv_source: return self.kv_cache assert self.compressed_cache_prefix is not None diff --git a/vllm/models/deepseek_v41/common/engram.py b/vllm/models/deepseek_v41/common/engram.py index 857063ecfb..c415bbaa6e 100644 --- a/vllm/models/deepseek_v41/common/engram.py +++ b/vllm/models/deepseek_v41/common/engram.py @@ -564,8 +564,7 @@ def _engram_head_shard_weight_loader( param: torch.nn.Parameter, loaded_weight: torch.Tensor ) -> None: """Load this rank's complete head buckets. ue8m0 scales arrive as - float8_e8m0fnu; keep the raw bytes (the param stores uint8). - """ + float8_e8m0fnu; keep the raw bytes (the param stores uint8).""" part_rows = param.shape[0] if loaded_weight.dtype == torch.float8_e8m0fnu: loaded_weight = loaded_weight.view(torch.uint8) @@ -740,8 +739,7 @@ class ParallelEngramEmbedding(nn.Module): def forward(self, indices: torch.Tensor) -> torch.Tensor: """indices: [num_tokens, n_hash_cols] -> [num_tokens, n_hash_cols, dim] - bf16, gathered from all shards for this replica's tokens. - """ + bf16, gathered from all shards for this replica's tokens.""" out = torch.empty( (indices.shape[0], self.part_n_hash_cols, self.dim), dtype=torch.bfloat16, @@ -1002,8 +1000,7 @@ class Engram(nn.Module): ) -> torch.Tensor: """hidden_states: [T, hc_mult, dim]; hash_ids: [T, n_hash_cols] (all tokens, pre sequence-parallel shard); token_mask: [T], False shuts - the gate so those positions pass through untouched. - """ + the gate so those positions pass through untouched.""" kv = self.wkv(self.embed(hash_ids).flatten(-2)) num_kv_tokens = hash_ids.shape[0] assert token_mask is None or token_mask.shape == (num_kv_tokens,) diff --git a/vllm/models/deepseek_v41/common/mm_preprocess.py b/vllm/models/deepseek_v41/common/mm_preprocess.py index ce56713e8c..4f87b816c9 100644 --- a/vllm/models/deepseek_v41/common/mm_preprocess.py +++ b/vllm/models/deepseek_v41/common/mm_preprocess.py @@ -82,8 +82,7 @@ def num_image_tokens(n_llm_h: int, n_llm_w: int) -> int: def solve_resize_ratio(height, width, patch_size, downsample_ratio, max_n_token): """Largest aspect-preserving pixel size whose token grid still fits in - max_n_token. Returns (best_height, best_width). - """ + max_n_token. Returns (best_height, best_width).""" r = height / width max_w_float = math.sqrt((max_n_token - 2) / r + 0.25) - 0.5 max_h_float = max_w_float * r @@ -106,8 +105,7 @@ def safe_resize( height, width, best_height, best_width, patch_size, downsample_ratio, max_n_token ): """Shrink the pixel size until the image costs at most max_n_token LLM - tokens. - """ + tokens.""" n_llm_h, n_llm_w = llm_grid(best_height, best_width, patch_size, downsample_ratio) if num_image_tokens(n_llm_h, n_llm_w) > max_n_token: best_height, best_width = solve_resize_ratio( @@ -173,8 +171,7 @@ def image_token_types(n_llm_h: int, n_llm_w: int) -> torch.Tensor: class DeepseekV4VLImageProcessor: """Per-image transform (the PIL-input equivalent of the reference - ``load_image``). - """ + ``load_image``).""" def __init__(self, config: DeepseekV41Config) -> None: super().__init__() diff --git a/vllm/models/deepseek_v41/nvidia/flashinfer_sparse.py b/vllm/models/deepseek_v41/nvidia/flashinfer_sparse.py index 650581a7df..0b43cfad19 100644 --- a/vllm/models/deepseek_v41/nvidia/flashinfer_sparse.py +++ b/vllm/models/deepseek_v41/nvidia/flashinfer_sparse.py @@ -54,8 +54,7 @@ def _get_flashinfer_dsv4_workspace(device: torch.device) -> torch.Tensor: def _packed_block_span(pool: torch.Tensor) -> int: """Per-block stride of ``pool`` in tokens (``stride(0)//stride(-2)``): == block_size for unpacked KV, larger when packed (#44577). Raises if not - token-aligned. - """ + token-aligned.""" block_stride = pool.stride(0) token_stride = pool.stride(-2) if block_stride % token_stride != 0: diff --git a/vllm/models/deepseek_v41/nvidia/model.py b/vllm/models/deepseek_v41/nvidia/model.py index 4d9d9d3108..21fa00e5c9 100644 --- a/vllm/models/deepseek_v41/nvidia/model.py +++ b/vllm/models/deepseek_v41/nvidia/model.py @@ -1179,8 +1179,7 @@ class DeepseekV41LLMForCausalLM( @property def token_lookback_depth(self) -> int: """Tokens before a chunk start the engram hash needs; the model runner - passes them as `lookback_token_ids`. - """ + passes them as `lookback_token_ids`.""" engram_hash = self.model.engram_hash return engram_hash.lookback_depth if engram_hash is not None else 0 @@ -1204,8 +1203,7 @@ class DeepseekV41LLMForCausalLM( def get_mtp_target_hidden_states(self) -> torch.Tensor | None: """Pre-collapse residual stream buffer (max_num_batched_tokens, hc_mult * hidden_size) for the MTP draft model. Populated by - forward(); valid after each target step. - """ + forward(); valid after each target step.""" return getattr(self.model, "_mtp_hidden_buffer", None) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/deepseek_v41/nvidia/vl_model.py b/vllm/models/deepseek_v41/nvidia/vl_model.py index 21386790cb..bfbcaa89a1 100644 --- a/vllm/models/deepseek_v41/nvidia/vl_model.py +++ b/vllm/models/deepseek_v41/nvidia/vl_model.py @@ -209,8 +209,7 @@ class DeepseekV41ForCausalLM(nn.Module, SupportsMultiModal, SupportsPP, Supports self, image_embeds: torch.Tensor, types: torch.Tensor ) -> torch.Tensor: """Full image span: aligner rows at IMAGE slots, the learned - delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END. - """ + delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END.""" types = types.to(image_embeds.device) span = image_embeds.new_empty(types.numel(), image_embeds.shape[-1]) dtype = image_embeds.dtype diff --git a/vllm/models/glm5next/amd/ops/kpool_compress.py b/vllm/models/glm5next/amd/ops/kpool_compress.py index 7e78a8fe32..97d8314c09 100644 --- a/vllm/models/glm5next/amd/ops/kpool_compress.py +++ b/vllm/models/glm5next/amd/ops/kpool_compress.py @@ -98,8 +98,7 @@ def _kpool_softmax_rotate_write_cache_kernel( BLOCK_D: tl.constexpr, ): """One program per pool. softmax(slot_score+ape)-weighted sum of slot_k -> - Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``. - """ + Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``.""" row = tl.program_id(0) do_write = True if HAS_WRITE_MASK: diff --git a/vllm/models/glm5next/common/kda.py b/vllm/models/glm5next/common/kda.py index 03e423b13c..436b9685cb 100644 --- a/vllm/models/glm5next/common/kda.py +++ b/vllm/models/glm5next/common/kda.py @@ -130,8 +130,7 @@ def _resolve_kda_prefill_backend( """Pick the chunked-prefill kernel: FlashKDA (fused CUDA, ~2-4x faster on SM90/SM10x/SM12x for bf16, head_dim 128 and a bounded gate) or the Triton ``chunk_kda_with_fused_gate`` path. ``backend`` comes from - ``additional_config.kda_prefill_backend`` (auto / triton / flashkda). - """ + ``additional_config.kda_prefill_backend`` (auto / triton / flashkda).""" if backend not in ("auto", "triton", "flashkda"): raise ValueError(f"Unsupported KDA prefill backend: {backend}") capability = current_platform.get_device_capability() @@ -369,8 +368,7 @@ class Glm5NextLinearAttention(GatedDeltaNetAttention): bounded gate ``lower_bound * sigmoid(exp(A_log) * (g + dt_bias))``, matching ``chunk_kda_with_fused_gate(..., safe_gate=True)``. Writes the attention output into ``out`` (a workspace buffer when ``None``) and - returns ``(out, final_state)``. - """ + returns ``(out, final_state)``.""" assert self._flashkda_buffer_specs is not None final_state, workspace, workspace_out = ( current_workspace_manager().get_simultaneous(*self._flashkda_buffer_specs) diff --git a/vllm/models/glm5next/common/multimodal.py b/vllm/models/glm5next/common/multimodal.py index 42cabc35b5..d2b21345d0 100644 --- a/vllm/models/glm5next/common/multimodal.py +++ b/vllm/models/glm5next/common/multimodal.py @@ -720,8 +720,7 @@ class Glm5NextMultiModalProcessor(Glm4vMultiModalProcessor): (image token repeat, video frame/timestamp structure) is owned by vLLM's prompt-update machinery — the inherited ``_get_prompt_updates`` builds the replacement content and the placeholder scan validates against - exactly that. - """ + exactly that.""" def _hf_processor_applies_updates( self, diff --git a/vllm/models/glm5next/common/sparse_indexer.py b/vllm/models/glm5next/common/sparse_indexer.py index 703cbb321a..ad38454570 100644 --- a/vllm/models/glm5next/common/sparse_indexer.py +++ b/vllm/models/glm5next/common/sparse_indexer.py @@ -138,8 +138,7 @@ def _gather_workspace_shapes( """Return ((values_shape, values_dtype), (scales_shape, scales_dtype)) for the K-gather workspace. FP8 path: (T, head_dim) fp8 + (T, 4) uint8 fp32 scales. MXFP4 path: (T, head_dim // 2) uint8 packed mxfp4 + - (T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales. - """ + (T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales.""" if use_fp4_cache: return ( ((total_seq_lens, head_dim // 2), torch.uint8), @@ -157,8 +156,7 @@ def kv_cache_as_quant_view( use_fp4_cache: bool, ) -> torch.Tensor: """4D ``[num_blocks, block_size, 1, head_width]`` view expected by - DeepGEMM, from the 3D indexer kv-cache allocation. - """ + DeepGEMM, from the 3D indexer kv-cache allocation.""" if use_fp4_cache: assert kv_cache.ndim == 3 and kv_cache.dtype == torch.uint8 num_blocks, block_size, _ = kv_cache.shape diff --git a/vllm/models/glm5next/nvidia/ops/fused_eh_norm.py b/vllm/models/glm5next/nvidia/ops/fused_eh_norm.py index f069fdf2c2..095db3917b 100644 --- a/vllm/models/glm5next/nvidia/ops/fused_eh_norm.py +++ b/vllm/models/glm5next/nvidia/ops/fused_eh_norm.py @@ -31,8 +31,7 @@ def _fused_eh_norm_kernel( ): """MTP input fusion: zero embeds at position 0, RMSNorm(embeds) with enorm and RMSNorm(prev_hidden) with hnorm, written side-by-side into ``out`` - ([N, 2H]) ready for the eh_proj GEMM. Replaces where + 2x RMSNorm + cat. - """ + ([N, 2H]) ready for the eh_proj GEMM. Replaces where + 2x RMSNorm + cat.""" tok = tl.program_id(0) off = tl.arange(0, BLOCK) mask = off < H diff --git a/vllm/models/glm5next/nvidia/ops/kpool_compress.py b/vllm/models/glm5next/nvidia/ops/kpool_compress.py index 010b231354..75ccfa8c2a 100644 --- a/vllm/models/glm5next/nvidia/ops/kpool_compress.py +++ b/vllm/models/glm5next/nvidia/ops/kpool_compress.py @@ -163,8 +163,7 @@ def _kpool_softmax_rotate_write_cache_kernel( BLOCK_D: tl.constexpr, ): """One program per pool. softmax(slot_score+ape)-weighted sum of slot_k -> - Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``. - """ + Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``.""" row = tl.program_id(0) do_write = True if HAS_WRITE_MASK: diff --git a/vllm/models/inkling/amd/model.py b/vllm/models/inkling/amd/model.py index 48ed8a2caa..711a33855c 100644 --- a/vllm/models/inkling/amd/model.py +++ b/vllm/models/inkling/amd/model.py @@ -72,8 +72,7 @@ def _sconv_add_norm( ROCm uses the portable collective path. The Lamport P2P implementation in the NVIDIA model relies on CUDA GDC and CUDA-specific symmetric-memory - publication semantics which cannot be linked into a gfx950 HSACO. - """ + publication semantics which cannot be linked into a gfx950 HSACO.""" norm_w = norm.weight if norm is not None else None eps = norm.variance_epsilon if norm is not None else 0.0 diff --git a/vllm/models/inkling/amd/moe.py b/vllm/models/inkling/amd/moe.py index 3a71b3ea5e..d8141eb4cf 100644 --- a/vllm/models/inkling/amd/moe.py +++ b/vllm/models/inkling/amd/moe.py @@ -192,8 +192,7 @@ def inkling_gate_select( class InklingGate(nn.Module): """Sigmoid gate with selection bias, log-sigmoid renorm after top-k, and - global scale (the served checkpoint's only configuration). - """ + global scale (the served checkpoint's only configuration).""" def __init__( self, @@ -247,8 +246,7 @@ class InklingGate(nn.Module): self, gating_output: torch.Tensor ) -> tuple[torch.Tensor, torch.Tensor]: """Full selection: (weights, ids) of [T, K + S]. The first K entries - are the routed top-k; the S trailing entries are the sink gammas. - """ + are the routed top-k; the S trailing entries are the sink gammas.""" return inkling_gate_select( gating_output, self.n_total_experts, @@ -269,8 +267,7 @@ class InklingGate(nn.Module): def _inkling_moe_ep_size() -> int: """EP size the MoERunner layer will run with (mirrors FusedMoEParallelConfig.make: experts shard over tp * dp * pcp when - expert parallelism is enabled). - """ + expert parallelism is enabled).""" parallel_config = get_current_vllm_config().parallel_config if not parallel_config.enable_expert_parallel: return 1 diff --git a/vllm/models/inkling/amd/mtp.py b/vllm/models/inkling/amd/mtp.py index dc7a8fd1e2..f9cba37f3c 100644 --- a/vllm/models/inkling/amd/mtp.py +++ b/vllm/models/inkling/amd/mtp.py @@ -166,8 +166,7 @@ class InklingMultiTokenPredictor(nn.Module): ) -> torch.Tensor: """Draft-prefill embedding: fused gather + backbone embed_norm, then the target's tower embeddings scattered in unnormed (the backbone - convention — MM embeds are merged after embed_norm). - """ + convention — MM embeds are merged after embed_norm).""" norm = self.backbone_embed_norm embeds = embed_rmsnorm( input_ids, @@ -196,8 +195,7 @@ class InklingMultiTokenPredictor(nn.Module): """The depth layer's [rmsnorm(hidden) | embed_norm(embed)] input in one launch: embedding row gather + the backbone embed_norm + the depth embed_norm chain on one side, hidden_norm on the other, written - straight into the cat buffer. - """ + straight into the cat buffer.""" hidden_w = layer.hidden_norm.weight embed_w = layer.embed_norm.weight eps = layer.hidden_norm.variance_epsilon @@ -329,8 +327,7 @@ class InklingMTP(nn.Module, SupportsMultiModalEmbeddings): """Greedy draft tokens via rank-local argmax + tiny (value, index) reduction — no full-vocab logits all-gather. The muP divisor is a positive scalar, so the argmax is invariant and the scaling is - skipped entirely. - """ + skipped entirely.""" return self.logits_processor.get_top_tokens(self.lm_head, hidden_states) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/inkling/amd/ops/norm.py b/vllm/models/inkling/amd/ops/norm.py index caee8a047e..d34c1c3259 100644 --- a/vllm/models/inkling/amd/ops/norm.py +++ b/vllm/models/inkling/amd/ops/norm.py @@ -238,8 +238,7 @@ def embed_rmsnorm( embedding-table gather. ``chain_weight`` additionally emits ``rmsnorm(out, chain_weight)`` (the first decoder layer's pre-attention norm) as a second output, still one - launch. Bit-exact vs the unfused module sequence. - """ + launch. Bit-exact vs the unfused module sequence.""" ids = input_ids.view(-1) (T,) = ids.shape n = embed_table.shape[1] @@ -333,8 +332,7 @@ def embed_dual_rmsnorm_cat( (draft decode steps) or precomputed ``embeds`` ([T, N], the target-merged multimodal embeddings at draft prefill); ``pre_norm_weight`` chains the backbone embed_norm in front of the depth embed_norm (bit-exact vs the - unfused sequence). The concat copies collapse into direct writes. - """ + unfused sequence). The concat copies collapse into direct writes.""" T, n = hidden.shape if embeds is not None: assert embeds.shape == hidden.shape diff --git a/vllm/models/inkling/nvidia/model.py b/vllm/models/inkling/nvidia/model.py index 4363cc883c..aeb460d64a 100644 --- a/vllm/models/inkling/nvidia/model.py +++ b/vllm/models/inkling/nvidia/model.py @@ -75,8 +75,7 @@ def _sconv_add_norm( """``h = hidden + sconv(TP-sum(delta)); y = rmsnorm(h)``. The Lamport path performs reduce-scatter + shard sconv + all-gather + - residual add + norm. The NCCL path handles unsupported configurations. - """ + residual add + norm. The NCCL path handles unsupported configurations.""" attn_metadata = get_forward_context().attn_metadata m = ( attn_metadata.get(sconv.owner.prefix) diff --git a/vllm/models/inkling/nvidia/moe.py b/vllm/models/inkling/nvidia/moe.py index 07c4ce5969..a8ea968076 100644 --- a/vllm/models/inkling/nvidia/moe.py +++ b/vllm/models/inkling/nvidia/moe.py @@ -191,8 +191,7 @@ def inkling_gate_select( class InklingGate(nn.Module): """Sigmoid gate with selection bias, log-sigmoid renorm after top-k, and - global scale (the served checkpoint's only configuration). - """ + global scale (the served checkpoint's only configuration).""" def __init__( self, @@ -244,8 +243,7 @@ class InklingGate(nn.Module): self, gating_output: torch.Tensor ) -> tuple[torch.Tensor, torch.Tensor]: """Full selection: (weights, ids) of [T, K + S]. The first K entries - are the routed top-k; the S trailing entries are the sink gammas. - """ + are the routed top-k; the S trailing entries are the sink gammas.""" return inkling_gate_select( gating_output, self.n_total_experts, @@ -266,8 +264,7 @@ class InklingGate(nn.Module): def _inkling_moe_ep_size() -> int: """EP size the FusedMoE layer will run with (mirrors FusedMoEParallelConfig.make: experts shard over tp * dp * pcp when - expert parallelism is enabled). - """ + expert parallelism is enabled).""" parallel_config = get_current_vllm_config().parallel_config if not parallel_config.enable_expert_parallel: return 1 diff --git a/vllm/models/inkling/nvidia/mtp.py b/vllm/models/inkling/nvidia/mtp.py index dc7a8fd1e2..f9cba37f3c 100644 --- a/vllm/models/inkling/nvidia/mtp.py +++ b/vllm/models/inkling/nvidia/mtp.py @@ -166,8 +166,7 @@ class InklingMultiTokenPredictor(nn.Module): ) -> torch.Tensor: """Draft-prefill embedding: fused gather + backbone embed_norm, then the target's tower embeddings scattered in unnormed (the backbone - convention — MM embeds are merged after embed_norm). - """ + convention — MM embeds are merged after embed_norm).""" norm = self.backbone_embed_norm embeds = embed_rmsnorm( input_ids, @@ -196,8 +195,7 @@ class InklingMultiTokenPredictor(nn.Module): """The depth layer's [rmsnorm(hidden) | embed_norm(embed)] input in one launch: embedding row gather + the backbone embed_norm + the depth embed_norm chain on one side, hidden_norm on the other, written - straight into the cat buffer. - """ + straight into the cat buffer.""" hidden_w = layer.hidden_norm.weight embed_w = layer.embed_norm.weight eps = layer.hidden_norm.variance_epsilon @@ -329,8 +327,7 @@ class InklingMTP(nn.Module, SupportsMultiModalEmbeddings): """Greedy draft tokens via rank-local argmax + tiny (value, index) reduction — no full-vocab logits all-gather. The muP divisor is a positive scalar, so the argmax is invariant and the scaling is - skipped entirely. - """ + skipped entirely.""" return self.logits_processor.get_top_tokens(self.lm_head, hidden_states) def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]: diff --git a/vllm/models/inkling/nvidia/ops/mm_towers.py b/vllm/models/inkling/nvidia/ops/mm_towers.py index 76a339377c..021cf5274b 100644 --- a/vllm/models/inkling/nvidia/ops/mm_towers.py +++ b/vllm/models/inkling/nvidia/ops/mm_towers.py @@ -60,8 +60,7 @@ def dmel_embed_sum_norm( eps: float, ) -> torch.Tensor: """``rmsnorm(sum_b weight[b * VOCAB + idx[:, b]])`` in one launch (no - [T, NB, D] intermediate). - """ + [T, NB, D] intermediate).""" T, nb = dmel_idx.shape D = weight.shape[1] assert weight.shape[0] % nb == 0 @@ -152,8 +151,7 @@ def rmsnorm_gelu( ) -> torch.Tensor: """Fused ``gelu(rmsnorm(x))`` (or plain rmsnorm); multiple rows per block when D is small. With ``fold``, x must be [N, T, H, W, D] and the output - comes back as ``fold_timespace_to_depth(result, *fold)``. - """ + comes back as ``fold_timespace_to_depth(result, *fold)``.""" D = x.shape[-1] flat = x.reshape(-1, D) assert flat.stride(1) == 1 and flat.stride(0) == D diff --git a/vllm/models/inkling/nvidia/ops/norm.py b/vllm/models/inkling/nvidia/ops/norm.py index caee8a047e..d34c1c3259 100644 --- a/vllm/models/inkling/nvidia/ops/norm.py +++ b/vllm/models/inkling/nvidia/ops/norm.py @@ -238,8 +238,7 @@ def embed_rmsnorm( embedding-table gather. ``chain_weight`` additionally emits ``rmsnorm(out, chain_weight)`` (the first decoder layer's pre-attention norm) as a second output, still one - launch. Bit-exact vs the unfused module sequence. - """ + launch. Bit-exact vs the unfused module sequence.""" ids = input_ids.view(-1) (T,) = ids.shape n = embed_table.shape[1] @@ -333,8 +332,7 @@ def embed_dual_rmsnorm_cat( (draft decode steps) or precomputed ``embeds`` ([T, N], the target-merged multimodal embeddings at draft prefill); ``pre_norm_weight`` chains the backbone embed_norm in front of the depth embed_norm (bit-exact vs the - unfused sequence). The concat copies collapse into direct writes. - """ + unfused sequence). The concat copies collapse into direct writes.""" T, n = hidden.shape if embeds is not None: assert embeds.shape == hidden.shape diff --git a/vllm/models/kimi_k3/nvidia/mla.py b/vllm/models/kimi_k3/nvidia/mla.py index 574757844a..87bf59749c 100644 --- a/vllm/models/kimi_k3/nvidia/mla.py +++ b/vllm/models/kimi_k3/nvidia/mla.py @@ -745,8 +745,7 @@ class MultiHeadLatentAttention(nn.Module, AttentionLayerBase): slot_mapping: torch.Tensor, ) -> torch.Tensor: """Fused decode query-concat + latent cache insert, dispatched by cache - dtype (same policy as prefill: fp8 cache -> fp8 query). - """ + dtype (same policy as prefill: fp8 cache -> fp8 query).""" if self.kv_cache_dtype == "fp8_ds_mla": cache = self.kv_cache if cache.dtype != torch.uint8: diff --git a/vllm/models/minimax_m3/amd/model.py b/vllm/models/minimax_m3/amd/model.py index 1a4ffdbd19..50cdb55183 100644 --- a/vllm/models/minimax_m3/amd/model.py +++ b/vllm/models/minimax_m3/amd/model.py @@ -334,8 +334,7 @@ def _aiter_moe_fused_shared_experts_enabled( class MiniMaxM3MoE(nn.Module): """Sigmoid-routed MoE block with a routing-bias correction and a shared - expert. - """ + expert.""" def __init__( self, diff --git a/vllm/models/minimax_m3/common/indexer.py b/vllm/models/minimax_m3/common/indexer.py index 24a9bd6c09..ac02bca1fc 100644 --- a/vllm/models/minimax_m3/common/indexer.py +++ b/vllm/models/minimax_m3/common/indexer.py @@ -173,8 +173,7 @@ class MiniMaxM3IndexerPrefillMetadata: @dataclass class MiniMaxM3IndexerDecodeMetadata: """Per-decode state (cudagraph-safe). ``decode_query_len`` is the uniform - per-request query length (1, or 1 + num_speculative_tokens). - """ + per-request query length (1, or 1 + num_speculative_tokens).""" seq_lens: torch.Tensor # [num_decodes] int32 block_table: torch.Tensor @@ -207,8 +206,7 @@ class MiniMaxM3IndexerMetadataBuilder( AttentionMetadataBuilder[MiniMaxM3IndexerMetadata] ): """Abstract base: shared setup only. The Triton and MSA builders are - parallel subclasses that each own their full ``build`` (no shared code). - """ + parallel subclasses that each own their full ``build`` (no shared code).""" # Full cudagraphs for uniform decode batches (incl. spec-decode verify). _cudagraph_support: ClassVar[AttentionCGSupport] = AttentionCGSupport.UNIFORM_BATCH diff --git a/vllm/models/minimax_m3/common/sparse_attention.py b/vllm/models/minimax_m3/common/sparse_attention.py index 5f24645f88..f385f82067 100644 --- a/vllm/models/minimax_m3/common/sparse_attention.py +++ b/vllm/models/minimax_m3/common/sparse_attention.py @@ -203,8 +203,7 @@ class MiniMaxM3SparsePrefillMetadata: @dataclass class MiniMaxM3SparseDecodeMetadata: """Per-decode state (cudagraph-safe). ``decode_query_len`` is the uniform - per-request query length (1, or 1 + num_speculative_tokens). - """ + per-request query length (1, or 1 + num_speculative_tokens).""" seq_lens: torch.Tensor # [num_decodes] int32 block_table: torch.Tensor diff --git a/vllm/models/minimax_m3/nvidia/indexer_msa.py b/vllm/models/minimax_m3/nvidia/indexer_msa.py index 0b3a336cd5..8a015d4e6e 100644 --- a/vllm/models/minimax_m3/nvidia/indexer_msa.py +++ b/vllm/models/minimax_m3/nvidia/indexer_msa.py @@ -85,8 +85,7 @@ class MiniMaxM3IndexerMSAPrefillMetadata: class MiniMaxM3IndexerMSAMetadata(MiniMaxM3IndexerMetadata): """Decode reuses the inherited base ``decode`` field (the Triton decode metadata); ``prefill_msa`` carries the fmha score plan for the prefill side - (the base ``prefill`` field is unused on this path). - """ + (the base ``prefill`` field is unused on this path).""" prefill_msa: MiniMaxM3IndexerMSAPrefillMetadata | None = None # Per-forward view (``[:num_tokens]``) of the builder's persistent unified @@ -112,8 +111,7 @@ class MiniMaxM3IndexerMSAMetadata(MiniMaxM3IndexerMetadata): class MiniMaxM3IndexerMSAMetadataBuilder(MiniMaxM3IndexerMetadataBuilder): """Decode metadata is the cudagraph-safe Triton decode metadata; the prefill - fmha plan is built eagerly (prefill batches are not captured). - """ + fmha plan is built eagerly (prefill batches are not captured).""" _cudagraph_support: ClassVar[AttentionCGSupport] = AttentionCGSupport.UNIFORM_BATCH diff --git a/vllm/models/minimax_m3/nvidia/model.py b/vllm/models/minimax_m3/nvidia/model.py index 734f675fbe..970b06d407 100644 --- a/vllm/models/minimax_m3/nvidia/model.py +++ b/vllm/models/minimax_m3/nvidia/model.py @@ -190,8 +190,7 @@ class MiniMaxM3MLP(nn.Module): class MiniMaxM3MoE(nn.Module): """Sigmoid-routed MoE block with a routing-bias correction and a shared - expert. - """ + expert.""" def __init__( self, @@ -783,8 +782,7 @@ class MiniMaxM3DecoderLayer(nn.Module): @property def ffn_all_reduce_deferred(self) -> bool: """This layer's FFN output is left un-reduced; the caller fuses the - all-reduce into the next RMSNorm. - """ + all-reduce into the next RMSNorm.""" if self.is_moe_layer: return self.block_sparse_moe.experts.moe_config.skip_final_all_reduce return not self.mlp.down_proj.reduce_results diff --git a/vllm/multimodal/cache.py b/vllm/multimodal/cache.py index fa6dabce41..b4fabfc21f 100644 --- a/vllm/multimodal/cache.py +++ b/vllm/multimodal/cache.py @@ -606,8 +606,7 @@ class ShmObjectStoreSenderCache(BaseMultiModalProcessorCache): @override def touch_sender_cache_item(self, mm_hash: str) -> None: """Touch the item in shared memory cache to prevent eviction. - Increments writer_flag on sender side. - """ + Increments writer_flag on sender side.""" self._shm_cache.touch(mm_hash) @override @@ -822,8 +821,7 @@ class ShmObjectStoreReceiverCache(BaseMultiModalReceiverCache): mm_item: MultiModalKwargsItem | None = None, ) -> None: """Touch the item in shared memory cache to prevent eviction. - Increments reader_count on receiver side. - """ + Increments reader_count on receiver side.""" assert mm_item is not None if "address" in mm_item: address = cast(int, mm_item["address"].data) diff --git a/vllm/multimodal/image.py b/vllm/multimodal/image.py index 4b1d67f2fb..ff2da044a6 100644 --- a/vllm/multimodal/image.py +++ b/vllm/multimodal/image.py @@ -38,8 +38,7 @@ def rgba_to_rgb( def _has_transparency(image: Image.Image) -> bool: """Detect whether an image carries transparency data (RGBA, LA, PA, - or tRNS chunk in P/L/RGB PNGs). - """ + or tRNS chunk in P/L/RGB PNGs).""" if image.mode in ("RGBA", "LA", "PA"): return True return "transparency" in getattr(image, "info", {}) diff --git a/vllm/multimodal/inputs.py b/vllm/multimodal/inputs.py index 585acd410d..91fa34e864 100644 --- a/vllm/multimodal/inputs.py +++ b/vllm/multimodal/inputs.py @@ -295,8 +295,7 @@ def _is_dense(t: torch.Tensor) -> bool: """Whether `t`'s elements fill a contiguous storage range, possibly permuted (e.g. a transposed matrix). Such layouts can be copied with pitched cudaMemcpy2D/3DAsync directly from pinned memory, whereas - gapped layouts (e.g. strided slices) stage through a pageable temp. - """ + gapped layouts (e.g. strided slices) stage through a pageable temp.""" if not t.is_contiguous(): expected_stride = 1 for stride, size in sorted(zip(t.stride(), t.shape)): diff --git a/vllm/multimodal/utils.py b/vllm/multimodal/utils.py index c12acfa1e1..3627dd9355 100644 --- a/vllm/multimodal/utils.py +++ b/vllm/multimodal/utils.py @@ -220,8 +220,7 @@ def strip_covered_mm_data( so the workers never consume the payload fields. M-RoPE models keep CPU-side metadata fields used to compute positions. SHM address items are also kept so workers can balance the sender's reference count. The - scheduler-side ``Request`` keeps the full features. - """ + scheduler-side ``Request`` keeps the full features.""" if not mm_features or num_computed_tokens == 0: return mm_features diff --git a/vllm/parser/engine/incremental_lexer.py b/vllm/parser/engine/incremental_lexer.py index b8f44ad535..8c3820b59a 100644 --- a/vllm/parser/engine/incremental_lexer.py +++ b/vllm/parser/engine/incremental_lexer.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Incremental text lexer that converts text chunks into terminal -tokens, with prefix-match buffering for ambiguous boundaries. -""" +tokens, with prefix-match buffering for ambiguous boundaries.""" from __future__ import annotations diff --git a/vllm/parser/engine/streaming_parser_engine.py b/vllm/parser/engine/streaming_parser_engine.py index 67d52bc34c..21d053ef28 100644 --- a/vllm/parser/engine/streaming_parser_engine.py +++ b/vllm/parser/engine/streaming_parser_engine.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Streaming parser engine that orchestrates token ID scanning, -incremental lexing, and state-machine-driven semantic event emission. -""" +incremental lexing, and state-machine-driven semantic event emission.""" from __future__ import annotations diff --git a/vllm/parser/engine/token_id_scanner.py b/vllm/parser/engine/token_id_scanner.py index 6ef0427b5c..60a64dcae2 100644 --- a/vllm/parser/engine/token_id_scanner.py +++ b/vllm/parser/engine/token_id_scanner.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Scan delta token IDs for special tokens and split the stream into -pre-lexed terminals and plain text chunks. -""" +pre-lexed terminals and plain text chunks.""" from __future__ import annotations diff --git a/vllm/parser/inkling.py b/vllm/parser/inkling.py index 6b1bcc7efa..2081fb2784 100644 --- a/vllm/parser/inkling.py +++ b/vllm/parser/inkling.py @@ -67,8 +67,7 @@ _WS = " \t\r\n" def _scan_json_value(raw: str, start: int) -> int | None: """Return the end index (exclusive) of the JSON object starting at - ``raw[start]``, or ``None`` when the object is still unterminated. - """ + ``raw[start]``, or ``None`` when the object is still unterminated.""" depth = 0 in_string = False escape = False diff --git a/vllm/platforms/cuda.py b/vllm/platforms/cuda.py index 96817b25d6..a46b607c8e 100644 --- a/vllm/platforms/cuda.py +++ b/vllm/platforms/cuda.py @@ -62,8 +62,7 @@ def _cuda_device_count_stateless(cuda_visible_devices: str | None = None) -> int CUDA_VISIBLE_DEVICES has already been set to the desired value. # This can be removed and simply replaced with torch.cuda.get_device_count - # after https://github.com/pytorch/pytorch/pull/122815 is released. - """ + # after https://github.com/pytorch/pytorch/pull/122815 is released.""" # Note: cuda_visible_devices is not used, but we keep it as an argument for # LRU Cache purposes. diff --git a/vllm/platforms/interface.py b/vllm/platforms/interface.py index 70937913e2..13e5b55402 100644 --- a/vllm/platforms/interface.py +++ b/vllm/platforms/interface.py @@ -42,8 +42,7 @@ def set_assigned_physical_gpu_ids(ids: list[int]) -> None: Idempotent: a second call with the same value is a no-op. Raises RuntimeError if called again with a different value. - This is expected to run during single-threaded worker initialization. - """ + This is expected to run during single-threaded worker initialization.""" global _assigned_physical_gpu_ids if _assigned_physical_gpu_ids is not None: if _assigned_physical_gpu_ids != ids: diff --git a/vllm/platforms/rocm.py b/vllm/platforms/rocm.py index 9bf95557ce..9474ec4835 100644 --- a/vllm/platforms/rocm.py +++ b/vllm/platforms/rocm.py @@ -91,8 +91,7 @@ def _rocm_device_count_stateless(cuda_visible_devices: str | None = None) -> int CUDA_VISIBLE_DEVICES has already been set to the desired value. # This can be removed and simply replaced with torch.cuda.get_device_count - # after https://github.com/pytorch/pytorch/pull/122815 is released. - """ + # after https://github.com/pytorch/pytorch/pull/122815 is released.""" # Note: cuda_visible_devices is not used, but we keep it as an argument for # LRU Cache purposes. @@ -127,8 +126,7 @@ def _get_wsl_kernel_version() -> tuple[int, ...] | None: def _sync_hip_cuda_env_vars(): """Ensure HIP_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES are consistent. - Treats empty string as unset. Raises on genuine conflicts. - """ + Treats empty string as unset. Raises on genuine conflicts.""" hip_val = os.environ.get("HIP_VISIBLE_DEVICES") or None cuda_val = os.environ.get("CUDA_VISIBLE_DEVICES") or None diff --git a/vllm/profiler/wrapper.py b/vllm/profiler/wrapper.py index ae9da1f4f7..bc679407c3 100644 --- a/vllm/profiler/wrapper.py +++ b/vllm/profiler/wrapper.py @@ -98,8 +98,7 @@ class WorkerProfiler(ABC): def step(self) -> None: """Update the profiler state at each worker step, - to handle delayed starts and max iteration limits. - """ + to handle delayed starts and max iteration limits.""" if not self._active: return diff --git a/vllm/renderers/base.py b/vllm/renderers/base.py index 36224a62b3..2cb4dd646c 100644 --- a/vllm/renderers/base.py +++ b/vllm/renderers/base.py @@ -377,8 +377,7 @@ class BaseRenderer(ABC, Generic[_T]): async def clear_mm_cache_async(self) -> None: """Serialize clear_mm_cache through the multimodal executor to avoid - races with concurrent process_inputs on the mm_processor_cache. - """ + races with concurrent process_inputs on the mm_processor_cache.""" await self._clear_mm_cache_async() def shutdown(self) -> None: diff --git a/vllm/renderers/hf.py b/vllm/renderers/hf.py index 26df7f2093..a32824eebd 100644 --- a/vllm/renderers/hf.py +++ b/vllm/renderers/hf.py @@ -103,8 +103,7 @@ _TOKENIZE_OVERRIDE_WARNING: Final[str] = ( def _ensure_prompt_embeds_placeholder_token(tokenizer: HfTokenizer) -> int: """Register `PROMPT_EMBEDS_PLACEHOLDER_TOKEN` as a special token and return - its token ID. - """ + its token ID.""" cached = _PROMPT_EMBEDS_PLACEHOLDER_TOKEN_ID_CACHE.get(tokenizer) if cached is not None: return cached @@ -193,8 +192,7 @@ def _build_mixed_prompt_embeds( positions: list[tuple[int, int]], ) -> tuple[torch.Tensor, list[bool]]: """Build the full-length `prompt_embeds` tensor and the `is_token_ids` - mask aligned to `token_ids`. - """ + mask aligned to `token_ids`.""" total_len = len(token_ids) hidden_size = prompt_embeds_tensors[0].shape[1] dtype = prompt_embeds_tensors[0].dtype diff --git a/vllm/renderers/online_derenderer.py b/vllm/renderers/online_derenderer.py index 09e0451ccc..5f30b552ba 100644 --- a/vllm/renderers/online_derenderer.py +++ b/vllm/renderers/online_derenderer.py @@ -616,8 +616,7 @@ def _convert_chat_logprobs_to_completion_logprobs( logprobs: ChatCompletionLogProbs, ) -> CompletionLogProbs: """Convert ChatCompletionLogProbs (per-token objects) to CompletionLogProbs - (parallel flat lists) as required by the /v1/completions response schema. - """ + (parallel flat lists) as required by the /v1/completions response schema.""" if logprobs.content is None: return CompletionLogProbs() diff --git a/vllm/sampling_params.py b/vllm/sampling_params.py index 8072892fe7..6cd7b4e81c 100644 --- a/vllm/sampling_params.py +++ b/vllm/sampling_params.py @@ -800,8 +800,7 @@ class SamplingParams( """Number of sample logprobs to return per output token, or `None` if no sample logprobs were requested. Takes `logprob_token_ids` into account: when `logprobs` is unset but `logprob_token_ids` is set, - returns `len(logprob_token_ids)`. - """ + returns `len(logprob_token_ids)`.""" if self.logprobs is not None: return self.logprobs return len(self.logprob_token_ids) if self.logprob_token_ids else None diff --git a/vllm/tool_parsers/hermes_tool_parser.py b/vllm/tool_parsers/hermes_tool_parser.py index 0a30096410..c5b318cd19 100644 --- a/vllm/tool_parsers/hermes_tool_parser.py +++ b/vllm/tool_parsers/hermes_tool_parser.py @@ -219,8 +219,7 @@ class Hermes2ProToolParser(ToolParser): Returns a ``DeltaMessage`` containing either plain content (for text preceding any tool call) or one or more ``DeltaToolCall`` - entries, or ``None`` if there is nothing new to send yet. - """ + entries, or ``None`` if there is nothing new to send yet.""" try: # Extract any content before tool calls. content = self._extract_content(current_text) diff --git a/vllm/tool_parsers/lfm2_tool_parser.py b/vllm/tool_parsers/lfm2_tool_parser.py index 7d59005a7a..2a0bab07e2 100644 --- a/vllm/tool_parsers/lfm2_tool_parser.py +++ b/vllm/tool_parsers/lfm2_tool_parser.py @@ -114,8 +114,7 @@ class Lfm2ToolParser(ToolParser): """Drop any orphan <|tool_call_end|> (and the preceding text) from trailing content. LFM2 occasionally echoes the call body after the first end token and caps it with a second end token; everything - through the last such orphan is model garbage, not user content. - """ + through the last such orphan is model garbage, not user content.""" last_orphan = raw_after.rfind(TOOL_CALL_END) if last_orphan != -1: return raw_after[last_orphan + len(TOOL_CALL_END) :] diff --git a/vllm/tool_parsers/utils.py b/vllm/tool_parsers/utils.py index 1617e25ee1..d2c8c6f412 100644 --- a/vllm/tool_parsers/utils.py +++ b/vllm/tool_parsers/utils.py @@ -426,8 +426,7 @@ def get_json_schema_from_tools( class UnexpectedAstError(Exception): """Raised when the AST structure does not match the expected - pythonic tool call format. - """ + pythonic tool call format.""" pass diff --git a/vllm/transformers_utils/config.py b/vllm/transformers_utils/config.py index 24111f52a3..54f3086431 100644 --- a/vllm/transformers_utils/config.py +++ b/vllm/transformers_utils/config.py @@ -539,8 +539,7 @@ def register_config_parser(config_format: str): def set_default_rope_theta(config: PretrainedConfig, default_theta: float) -> None: """Some models may have no rope_theta in their config but still use RoPE. - This function sets a default rope_theta if it's missing. - """ + This function sets a default rope_theta if it's missing.""" if getattr(config, "rope_parameters", None) is None: config.rope_parameters = {"rope_type": "default"} if "rope_theta" not in config.rope_parameters: @@ -549,8 +548,7 @@ def set_default_rope_theta(config: PretrainedConfig, default_theta: float) -> No def patch_legacy_rope_type(rope_parameters: dict[str, Any] | None) -> None: """Patch legacy RoPE type fields for backwards compatibility with - older custom models which would otherwise fail to load. - """ + older custom models which would otherwise fail to load.""" # No RoPE parameters to patch if rope_parameters is None: return diff --git a/vllm/transformers_utils/configs/extract_hidden_states.py b/vllm/transformers_utils/configs/extract_hidden_states.py index ab705d5834..2beec0e308 100644 --- a/vllm/transformers_utils/configs/extract_hidden_states.py +++ b/vllm/transformers_utils/configs/extract_hidden_states.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Config definitions for ExtractHiddenStatesModel, to be used with -the extract_hidden_states spec decoding method. -""" +the extract_hidden_states spec decoding method.""" import os diff --git a/vllm/transformers_utils/processor.py b/vllm/transformers_utils/processor.py index f8cb761848..64af034d9a 100644 --- a/vllm/transformers_utils/processor.py +++ b/vllm/transformers_utils/processor.py @@ -37,8 +37,7 @@ def _transformers_v4_compatibility_import(): subset of `ProcessorChatTemplateKwargs` as defined in Transformers v4. In Transformers v5 these were merged into `ProcessorChatTemplateKwargs` and `ChatTemplateLoadKwargs` was removed. For backward compatibility, we add an alias - for `ChatTemplateLoadKwargs` if it doesn't exist. - """ + for `ChatTemplateLoadKwargs` if it doesn't exist.""" old_import = getattr(processing_utils, "ChatTemplateLoadKwargs", None) new_import = getattr(processing_utils, "ProcessorChatTemplateKwargs", None) if old_import is None and new_import is not None: @@ -53,8 +52,7 @@ def _transformers_v4_compatibility_init() -> Any: processor instance before calling the original `ProcessorMixin.__init__`. This can be removed if `Molmo2ForConditionalGeneration` is upstreamed to - Transformers. - """ + Transformers.""" if hasattr(ProcessorMixin.__init__, "_vllm_patched"): return @@ -397,8 +395,7 @@ def get_feature_extractor( **kwargs: Any, ): """Load an audio feature extractor for the given model name - via HuggingFace. - """ + via HuggingFace.""" try: processor_name = convert_model_repo_to_path(processor_name) feature_extractor = AutoFeatureExtractor.from_pretrained( diff --git a/vllm/transformers_utils/processors/cohere_asr.py b/vllm/transformers_utils/processors/cohere_asr.py index bfa8fca50d..5665d3cbae 100644 --- a/vllm/transformers_utils/processors/cohere_asr.py +++ b/vllm/transformers_utils/processors/cohere_asr.py @@ -537,8 +537,7 @@ class CohereASRFeatureExtractor(SequenceFeatureExtractor): class CohereASRProcessor(ProcessorMixin): """HF-compatible processor combining CohereASRFeatureExtractor and a - tokenizer. - """ + tokenizer.""" feature_extractor_class = "CohereASRFeatureExtractor" tokenizer_class = "AutoTokenizer" diff --git a/vllm/transformers_utils/processors/glm5next.py b/vllm/transformers_utils/processors/glm5next.py index 6ad1748823..b6988d3b8f 100644 --- a/vllm/transformers_utils/processors/glm5next.py +++ b/vllm/transformers_utils/processors/glm5next.py @@ -261,8 +261,7 @@ def _resize_or_pad( allow_upscale: bool = False, ) -> torch.Tensor: """Resize onto the aligned canvas, or keep the aspect ratio and - zero-pad the right/bottom sides (``resize_mode="pad"``). - """ + zero-pad the right/bottom sides (``resize_mode="pad"``).""" height, width = stacked_images.shape[-2:] if resize_mode == "resize": @@ -308,8 +307,7 @@ def _pixel_budget( ) -> tuple[int, int]: """(min_pixels, max_pixels) from the token bounds of ``processor_config.json``; one vision token covers - ``temporal_patch_size * (patch_size * merge_size) ** 2`` pixels. - """ + ``temporal_patch_size * (patch_size * merge_size) ** 2`` pixels.""" if min_image_tokens is None or max_image_tokens is None: raise ValueError( "min_image_tokens and max_image_tokens must be provided by " diff --git a/vllm/transformers_utils/utils.py b/vllm/transformers_utils/utils.py index c5dc1a8ff3..ad07d901b4 100644 --- a/vllm/transformers_utils/utils.py +++ b/vllm/transformers_utils/utils.py @@ -116,8 +116,7 @@ def parse_safetensors_file_metadata(path: str | PathLike) -> dict[str, Any]: def convert_model_repo_to_path(model_repo: str) -> str: """When VLLM_USE_MODELSCOPE is True convert a model - repository string to a Path str. - """ + repository string to a Path str.""" if not envs.VLLM_USE_MODELSCOPE or Path(model_repo).exists(): return model_repo from modelscope.utils.file_utils import get_model_cache_root diff --git a/vllm/utils/cpu_resource_utils.py b/vllm/utils/cpu_resource_utils.py index 89d3e6ca7c..296fe46646 100644 --- a/vllm/utils/cpu_resource_utils.py +++ b/vllm/utils/cpu_resource_utils.py @@ -274,8 +274,7 @@ def get_visible_memory_node() -> list[int]: def _synthesize_cpu_list() -> list[LogicalCPUInfo]: """Synthesize a flat CPU list: each logical CPU is its own core on NUMA node 0. Used when lscpu output is unavailable or unparsable - (e.g. macOS, RISC-V). - """ + (e.g. macOS, RISC-V).""" cpu_count = os.cpu_count() assert cpu_count return [LogicalCPUInfo(i, i, 0) for i in range(cpu_count)] diff --git a/vllm/utils/deep_gemm.py b/vllm/utils/deep_gemm.py index 009c7b4258..3d96b496f1 100644 --- a/vllm/utils/deep_gemm.py +++ b/vllm/utils/deep_gemm.py @@ -704,8 +704,7 @@ def fp8_fp4_paged_mqa_logits( def has_deep_gemm_sparse_mqa() -> bool: """Whether the installed DeepGEMM provides the sparse-indexer kernels - (``fp8_fp4_(paged_)sparse_mqa_logits``, added in DeepGEMM 2.8, SM100-only). - """ + (``fp8_fp4_(paged_)sparse_mqa_logits``, added in DeepGEMM 2.8, SM100-only).""" _lazy_init() return ( _fp8_fp4_sparse_mqa_logits_impl is not None diff --git a/vllm/utils/gpu_sync_debug.py b/vllm/utils/gpu_sync_debug.py index 096f0d005b..8d0e7ae187 100644 --- a/vllm/utils/gpu_sync_debug.py +++ b/vllm/utils/gpu_sync_debug.py @@ -72,8 +72,7 @@ _sync_filter_head: tuple | None = None def _sync_warning_hook(message, category, filename, lineno, file=None, line=None): """Turn torch's sync warning into an error, but only on a thread that is - being checked and is outside any allow region. - """ + being checked and is outside any allow region.""" if _TORCH_SYNC_WARNING in str(message): mode = _checking.get() if mode is None or _allow_depth.get(): @@ -252,8 +251,7 @@ def _is_dense(t: torch.Tensor) -> bool: """Whether `t`'s elements fill a contiguous storage range, possibly permuted (e.g. a transposed matrix). Such layouts can be copied with pitched cudaMemcpy2D/3DAsync directly from/to pinned memory, whereas - gapped layouts (e.g. strided slices) stage through a pageable temp. - """ + gapped layouts (e.g. strided slices) stage through a pageable temp.""" if t.is_contiguous(): # The common case, answered by a memoized TensorImpl flag. return True diff --git a/vllm/utils/platform_utils.py b/vllm/utils/platform_utils.py index 975ad696d9..5d7fed3c99 100644 --- a/vllm/utils/platform_utils.py +++ b/vllm/utils/platform_utils.py @@ -29,8 +29,7 @@ def cuda_get_device_properties( device, names: Sequence[str], init_cuda=False ) -> tuple[Any, ...]: """Get specified CUDA device property values without initializing CUDA in - the current process. - """ + the current process.""" if init_cuda or cuda_is_initialized(): props = torch.cuda.get_device_properties(device) return tuple(getattr(props, name) for name in names) diff --git a/vllm/utils/torch_utils.py b/vllm/utils/torch_utils.py index ab395bd704..849d0a38f5 100644 --- a/vllm/utils/torch_utils.py +++ b/vllm/utils/torch_utils.py @@ -230,8 +230,7 @@ def _cgroup_cpu_limit() -> float | None: def available_cpu_count() -> int: """CPUs actually usable by this process: scheduling affinity capped by - the cgroup CPU quota (unlike `os.cpu_count()`, which is quota-blind). - """ + the cgroup CPU quota (unlike `os.cpu_count()`, which is quota-blind).""" if sys.platform != "linux": return os.cpu_count() or 1 count = len(os.sched_getaffinity(0)) diff --git a/vllm/v1/attention/backend.py b/vllm/v1/attention/backend.py index 792eeb37b9..afafa3c925 100644 --- a/vllm/v1/attention/backend.py +++ b/vllm/v1/attention/backend.py @@ -365,8 +365,7 @@ class AttentionBackend(ABC): @classmethod def supported_kv_cache_layouts(cls) -> tuple[KVCacheLayout, ...] | None: """Layouts this backend's kernels can consume, most preferred first, or - None when the kernels consume any layout and express no preference. - """ + None when the kernels consume any layout and express no preference.""" return None @classmethod @@ -558,8 +557,7 @@ M = TypeVar("M") class AttentionCGSupport(Enum): """Constants for the cudagraph support of the attention backend Here we do not consider the cascade attention, as currently - it is never cudagraph supported. - """ + it is never cudagraph supported.""" ALWAYS = 3 """Cudagraph always supported; supports mixed-prefill-decode""" diff --git a/vllm/v1/attention/backends/cpu_attn.py b/vllm/v1/attention/backends/cpu_attn.py index d2b9f5a526..b6864897bf 100644 --- a/vllm/v1/attention/backends/cpu_attn.py +++ b/vllm/v1/attention/backends/cpu_attn.py @@ -84,8 +84,7 @@ class CPUAttentionBackend(AttentionBackend): @classmethod def supports_attn_type(cls, attn_type: str) -> bool: """CPU attention supports decoder, - encoder-only and encoder-decoder attention. - """ + encoder-only and encoder-decoder attention.""" return attn_type in ( AttentionType.DECODER, AttentionType.ENCODER, diff --git a/vllm/v1/attention/backends/flashinfer.py b/vllm/v1/attention/backends/flashinfer.py index 694cef4106..3113c261dd 100755 --- a/vllm/v1/attention/backends/flashinfer.py +++ b/vllm/v1/attention/backends/flashinfer.py @@ -398,8 +398,7 @@ class FlashInferBackend(AttentionBackend): @classmethod def customize_spec(cls, spec: "AttentionSpec") -> "AttentionSpec": """NVFP4 stores K and V as separate per-head slots of packed fp4 data - plus fp8 block scales. - """ + plus fp8 block scales.""" if spec.state_content_bytes is not None or not spec.kv_quant_mode.is_nvfp4: return spec hs_k = nvfp4_kv_cache_full_dim(spec.head_size) diff --git a/vllm/v1/attention/backends/mla/amx_mla.py b/vllm/v1/attention/backends/mla/amx_mla.py index 22ee41a479..5f9ac7f17a 100644 --- a/vllm/v1/attention/backends/mla/amx_mla.py +++ b/vllm/v1/attention/backends/mla/amx_mla.py @@ -63,8 +63,7 @@ _SPLIT_OCCUPANCY_MULTIPLIER = 2 def _compute_num_kv_splits(max_seq_len: int, num_threads: int) -> int: """Mirrors TritonMLAImpl's _compute_num_kv_splits, using the CPU thread - count in place of SM count. - """ + count in place of SM count.""" ideal_splits = 1 while ideal_splits < max(1, max_seq_len // _MIN_WORK_PER_SPLIT): ideal_splits *= 2 diff --git a/vllm/v1/attention/backends/mla/flashmla_sparse.py b/vllm/v1/attention/backends/mla/flashmla_sparse.py index 6211a4e06c..265fb779c3 100644 --- a/vllm/v1/attention/backends/mla/flashmla_sparse.py +++ b/vllm/v1/attention/backends/mla/flashmla_sparse.py @@ -847,8 +847,7 @@ class FlashMLASparseImpl(SparseMLACommonImpl[FlashMLASparseMetadata]): prefill_meta: "FlashMLASparseMetadata.FP8SeparatePrefillDecode.Prefill", ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]: """All-gather this rank's upconverted KV shard so the chunk's rows attend - the whole context, and map their top-k onto the rank-major result. - """ + the whole context, and map their top-k onto the rank-major result.""" shard_rows = int(chunk.chunk_tot_seqlen) assert self.gathered_kv_workspace is not None gathered_kv = self.gathered_kv_workspace[: self.dcp_world_size * shard_rows] diff --git a/vllm/v1/attention/backends/mla/indexer.py b/vllm/v1/attention/backends/mla/indexer.py index 258f20215f..53206afd93 100644 --- a/vllm/v1/attention/backends/mla/indexer.py +++ b/vllm/v1/attention/backends/mla/indexer.py @@ -1118,8 +1118,7 @@ class DeepseekV32IndexerMetadataBuilder(AttentionMetadataBuilder): def _prefill_split_seq_lens(self, seq_lens_cpu: torch.Tensor) -> torch.Tensor: """Per-request KV lengths the prefill chunker budgets logits with; - subclasses whose logits rows are wider than the context override. - """ + subclasses whose logits rows are wider than the context override.""" return seq_lens_cpu @staticmethod diff --git a/vllm/v1/attention/backends/mla/prefill/base.py b/vllm/v1/attention/backends/mla/prefill/base.py index edea434727..1b589cb295 100644 --- a/vllm/v1/attention/backends/mla/prefill/base.py +++ b/vllm/v1/attention/backends/mla/prefill/base.py @@ -70,8 +70,7 @@ class MLAPrefillBackend(ABC): def supports_quant_output(self, quant_key: "QuantKey") -> bool: """Whether `run_prefill_new_tokens` can write quantized output directly (fused) for the given quant key, skipping the post-quant - pass. Overridden by backends that support it. - """ + pass. Overridden by backends that support it.""" return False def supports_out(self) -> bool: diff --git a/vllm/v1/attention/backends/rocm_aiter_unified_attn.py b/vllm/v1/attention/backends/rocm_aiter_unified_attn.py index b9eacdabca..9e3267c526 100644 --- a/vllm/v1/attention/backends/rocm_aiter_unified_attn.py +++ b/vllm/v1/attention/backends/rocm_aiter_unified_attn.py @@ -110,8 +110,7 @@ class RocmAiterUnifiedAttentionBackend(RocmAttentionBackend): @classmethod def customize_spec(cls, spec: AttentionSpec) -> AttentionSpec: """Keep K and V packed in the content dim, unlike the native HIP - kernels the base class targets. - """ + kernels the base class targets.""" # block_size == 1 is the per-token page-size probe (see # Platform.get_page_size_bytes); real blocks must be gatherable in # 16-token units by the ROCm kernel. diff --git a/vllm/v1/attention/backends/rocm_attn.py b/vllm/v1/attention/backends/rocm_attn.py index afb545eee8..2671249fb2 100644 --- a/vllm/v1/attention/backends/rocm_attn.py +++ b/vllm/v1/attention/backends/rocm_attn.py @@ -244,8 +244,7 @@ class RocmAttentionBackend(AttentionBackend): @classmethod def customize_spec(cls, spec: AttentionSpec) -> AttentionSpec: """K and V as two head groups so the native HIP kernels address each side - as one contiguous region (x-packed interior applied in split_kv_cache). - """ + as one contiguous region (x-packed interior applied in split_kv_cache).""" if spec.state_content_bytes is not None: return spec assert spec.head_size == spec.head_size_v, ( diff --git a/vllm/v1/attention/backends/triton_attn.py b/vllm/v1/attention/backends/triton_attn.py index cf7e571599..1b290c0ae9 100644 --- a/vllm/v1/attention/backends/triton_attn.py +++ b/vllm/v1/attention/backends/triton_attn.py @@ -275,8 +275,7 @@ class TritonAttentionBackend(AttentionBackend): @classmethod def customize_spec(cls, spec: "AttentionSpec") -> "AttentionSpec": """Per-token-head modes pack inline fp32 scales after each head's - data, so the content is (data + one scale) per K/V side. - """ + data, so the content is (data + one scale) per K/V side.""" mode = spec.kv_quant_mode if spec.state_content_bytes is not None or not mode.is_per_token_head: return spec diff --git a/vllm/v1/attention/ops/turboquant_soa/triton_turboquant_store.py b/vllm/v1/attention/ops/turboquant_soa/triton_turboquant_store.py index 90b620b345..0dc4150cbf 100644 --- a/vllm/v1/attention/ops/turboquant_soa/triton_turboquant_store.py +++ b/vllm/v1/attention/ops/turboquant_soa/triton_turboquant_store.py @@ -45,8 +45,7 @@ def _store_quantized_value( BLOCK_GRP: tl.constexpr, ): """Uniform quantization of values to VQB bits, pack, and store with - scale/zero in the per-block SoA metadata region (Opt#3 layout). - """ + scale/zero in the per-block SoA metadata region (Opt#3 layout).""" if VQB == 3: val_vec = tl.load(Value_ptr + base + d_offs, mask=d_mask, other=0.0).to( tl.float32 diff --git a/vllm/v1/core/kv_cache_coordinator.py b/vllm/v1/core/kv_cache_coordinator.py index 907b9690e0..8061999409 100644 --- a/vllm/v1/core/kv_cache_coordinator.py +++ b/vllm/v1/core/kv_cache_coordinator.py @@ -461,8 +461,7 @@ class KVCacheCoordinator(ABC): ) -> tuple[tuple[list[KVCacheBlock], ...], int, int]: """Returns the per-group hit blocks, the hit length, and the number of ``num_uncached_common_prefix_tokens`` (a shared prefix that a - sparse-retention group has not cached yet; 0 unless hybrid). - """ + sparse-retention group has not cached yet; 0 unless hybrid).""" pass def new_step_starts(self) -> None: diff --git a/vllm/v1/core/kv_cache_manager.py b/vllm/v1/core/kv_cache_manager.py index 9f6997b53d..49f62a2670 100644 --- a/vllm/v1/core/kv_cache_manager.py +++ b/vllm/v1/core/kv_cache_manager.py @@ -856,8 +856,7 @@ class KVCacheManager: self, request_id: str, start_token: int, end_token: int ) -> list[int]: """The request's block ids covering [start_token, end_token), from - the groups whose new blocks are zeroed by the worker. - """ + the groups whose new blocks are zeroed by the worker.""" ids: list[int] = [] for mgr in self.coordinator.single_type_managers: if mgr.records_new_block_ids: diff --git a/vllm/v1/core/sched/interface.py b/vllm/v1/core/sched/interface.py index d5a059bf4c..c868d249c8 100644 --- a/vllm/v1/core/sched/interface.py +++ b/vllm/v1/core/sched/interface.py @@ -178,8 +178,7 @@ 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 @@ -199,8 +198,7 @@ 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 diff --git a/vllm/v1/core/sched/request_queue.py b/vllm/v1/core/sched/request_queue.py index ab94e90752..ce58e6e1c7 100644 --- a/vllm/v1/core/sched/request_queue.py +++ b/vllm/v1/core/sched/request_queue.py @@ -43,8 +43,7 @@ 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 @@ -161,16 +160,14 @@ 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) diff --git a/vllm/v1/engine/async_llm.py b/vllm/v1/engine/async_llm.py index 64aa5fa2ce..3e399a1a81 100644 --- a/vllm/v1/engine/async_llm.py +++ b/vllm/v1/engine/async_llm.py @@ -871,8 +871,7 @@ class AsyncLLM(EngineClient): ) -> None: """Submit a pre-aborted request so the connector's request_finished hook runs to free any pre-admission KV-transfer resources (e.g. NIXL - prefill blocks pinned on the P node). - """ + prefill blocks pinned on the P node).""" request = EngineCoreRequest( request_id=request_id, prompt_token_ids=[0], diff --git a/vllm/v1/engine/core.py b/vllm/v1/engine/core.py index 5125954c42..9c84827a63 100644 --- a/vllm/v1/engine/core.py +++ b/vllm/v1/engine/core.py @@ -598,8 +598,7 @@ class EngineCore: def _should_throttle_prefills(self) -> bool: """Whether to defer new prefills this step (DP prefill balancing). - Overridden by the DP engine core; never throttles otherwise. - """ + Overridden by the DP engine core; never throttles otherwise.""" return False def step(self) -> tuple[dict[int, EngineCoreOutputs], bool]: @@ -1623,8 +1622,7 @@ class EngineCoreProc(EngineCore): @staticmethod def _convert_msgspec_args(method, args): """If a provided arg type doesn't match corresponding target method - arg type, try converting to msgspec object. - """ + arg type, try converting to msgspec object.""" if not args: return args arg_types = signature(method).parameters.values() @@ -2006,8 +2004,7 @@ class EngineCoreProc(EngineCore): class DPEngineCoreProc(EngineCoreProc): """ZMQ-wrapper for running EngineCore in background process - in a data parallel context. - """ + in a data parallel context.""" def __init__( self, diff --git a/vllm/v1/engine/core_client.py b/vllm/v1/engine/core_client.py index 6a08f2d3af..4ca565d56c 100644 --- a/vllm/v1/engine/core_client.py +++ b/vllm/v1/engine/core_client.py @@ -248,8 +248,7 @@ class EngineCoreClient(ABC): def dp_engines_running(self) -> bool: """Returns True if data parallel engines are collectively in a - running state. - """ + running state.""" raise NotImplementedError async def commit_elastic_ep(self) -> None: @@ -446,8 +445,7 @@ class InprocClient(EngineCoreClient): @dataclass class BackgroundResources: """Used as a finalizer for clean shutdown, avoiding - circular reference back to the client object. - """ + circular reference back to the client object.""" ctx: zmq.Context # If CoreEngineProcManager, it manages local engines; @@ -801,8 +799,7 @@ class MPClient(EngineCoreClient): def _apply_ready_response(self, payload: bytes) -> None: """Decode an EngineCoreReadyResponse and sync any post-initialization - config changes (e.g. auto-fitted max_model_len) back to the frontend. - """ + config changes (e.g. auto-fitted max_model_len) back to the frontend.""" vllm_config = self.vllm_config response = ( msgspec.msgpack.decode(payload, type=EngineCoreReadyResponse) @@ -1333,8 +1330,7 @@ class AsyncMPClient(MPClient): class DPAsyncMPClient(AsyncMPClient): """Asyncio-compatible client for multi-proc, multi-engine (data parallel) - EngineCore. Assumes external load-balancing by default. - """ + EngineCore. Assumes external load-balancing by default.""" def __init__( self, @@ -1518,8 +1514,7 @@ class DPAsyncMPClient(AsyncMPClient): class DPLBAsyncMPClient(DPAsyncMPClient): """Asyncio-compatible client for multi-proc, multi-engine (data parallel) - EngineCore. Load-balances between multiple engine processes. - """ + EngineCore. Load-balances between multiple engine processes.""" def __init__( self, @@ -1827,8 +1822,7 @@ class DPLBAsyncMPClient(DPAsyncMPClient): num_redundant_experts: int, ) -> None: """Prepare scale up by creating new engine cores and reconfiguring - existing ones. - """ + existing ones.""" self._setup_elastic_ep_reconfig_bootstrap() # Phase 1: Send reconfig messages to existing engines @@ -1920,8 +1914,7 @@ class DPLBAsyncMPClient(DPAsyncMPClient): async def _commit_scale_down_elastic_ep(self, new_data_parallel_size: int) -> None: """Scale down the data parallel size by shutting down and - reconfiguring existing engine cores. - """ + reconfiguring existing engine cores.""" cur_data_parallel_size = len(self.core_engines) self.eep_scaling_cache = ElasticScalingCache( diff --git a/vllm/v1/engine/detokenizer.py b/vllm/v1/engine/detokenizer.py index c75fdc53cf..9658c030ef 100644 --- a/vllm/v1/engine/detokenizer.py +++ b/vllm/v1/engine/detokenizer.py @@ -147,8 +147,7 @@ class BaseIncrementalDetokenizer(IncrementalDetokenizer, ABC): def get_next_output_text(self, finished: bool, delta: bool) -> str: """If delta is True, only new text since the last call to - this method is returned - """ + this method is returned""" # We return the full output text if the sequence is finished. buffer_length = 0 if finished else self.stop_buffer_length if not delta: diff --git a/vllm/v1/engine/utils.py b/vllm/v1/engine/utils.py index 43f2b80b05..c1002ba1dc 100644 --- a/vllm/v1/engine/utils.py +++ b/vllm/v1/engine/utils.py @@ -1041,8 +1041,7 @@ def get_engine_zmq_addresses( Set ``defer_api_server_ports=False`` only when the consumer cannot report a bound port back (e.g. the Rust front-end). IPC paths are - unaffected. - """ + unaffected.""" parallel_config = vllm_config.parallel_config local_engine_count = parallel_config.data_parallel_size_local local_start_index = parallel_config.data_parallel_rank_local diff --git a/vllm/v1/executor/abstract.py b/vllm/v1/executor/abstract.py index ce8a8db826..6b07bad17c 100644 --- a/vllm/v1/executor/abstract.py +++ b/vllm/v1/executor/abstract.py @@ -284,8 +284,7 @@ class Executor(ABC): @abstractmethod def check_health(self) -> None: """Checks if the executor is healthy. If not, it should raise an - exception. - """ + exception.""" raise NotImplementedError def shutdown(self) -> None: diff --git a/vllm/v1/executor/multiproc_executor.py b/vllm/v1/executor/multiproc_executor.py index 009df6ffba..dbaefe2186 100644 --- a/vllm/v1/executor/multiproc_executor.py +++ b/vllm/v1/executor/multiproc_executor.py @@ -384,8 +384,7 @@ class MultiprocExecutor(Executor): ec_output_aggregator: ECOutputAggregator | None = None, ) -> Any: """Returns single result if unique_reply_rank and/or an output - aggregator is provided, otherwise list. - """ + aggregator is provided, otherwise list.""" assert self.rpc_broadcast_mq is not None, ( "collective_rpc should not be called on follower node" ) @@ -452,8 +451,7 @@ class MultiprocExecutor(Executor): def _ensure_worker_termination(worker_procs: list[BaseProcess]): """Ensure that all worker processes are terminated. Assumes workers have received termination requests. Waits for processing, then sends - termination and kill signals if needed. - """ + termination and kill signals if needed.""" def wait_for_termination(procs, timeout): if not time: @@ -854,8 +852,7 @@ class WorkerProc: @staticmethod def worker_main(*args, **kwargs): """Worker initialization and execution loops. - This runs a background process - """ + This runs a background process""" # Signal handler used for graceful termination. # SystemExit exception is only raised once to allow this and worker # processes to terminate without error @@ -1099,8 +1096,7 @@ class WorkerProc: def set_multiprocessing_worker_envs(local_world_size: int = 1): """Set up environment variables that should be used when there are workers in a multiprocessing environment. This should be called by the parent - process before worker processes are created - """ + process before worker processes are created""" _maybe_force_spawn() if current_platform.is_cpu() or "OMP_NUM_THREADS" in os.environ: diff --git a/vllm/v1/executor/ray_utils.py b/vllm/v1/executor/ray_utils.py index 0f6d2c9c64..e609fb6e7e 100644 --- a/vllm/v1/executor/ray_utils.py +++ b/vllm/v1/executor/ray_utils.py @@ -55,8 +55,7 @@ try: class RayWorkerWrapper(WorkerWrapperBase): """Ray wrapper for vllm.worker.Worker, allowing Worker to be - lazily initialized after Ray sets CUDA_VISIBLE_DEVICES. - """ + lazily initialized after Ray sets CUDA_VISIBLE_DEVICES.""" def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) diff --git a/vllm/v1/kv_cache_interface.py b/vllm/v1/kv_cache_interface.py index 4a2ea1799f..17771d9ae6 100644 --- a/vllm/v1/kv_cache_interface.py +++ b/vllm/v1/kv_cache_interface.py @@ -1252,8 +1252,7 @@ class UniformTypeKVCacheSpecs(KVCacheSpec): def get_max_layers_per_page_size(self) -> int: """Max number of layers sharing a page size. For a balanced bucket - this equals the number of repetitions of the layer pattern. - """ + this equals the number of repetitions of the layer pattern.""" return Counter( spec.page_size_bytes for spec in self.kv_cache_specs.values() ).most_common(1)[0][1] diff --git a/vllm/v1/kv_cache_layout.py b/vllm/v1/kv_cache_layout.py index d784f51b96..7c1decd393 100644 --- a/vllm/v1/kv_cache_layout.py +++ b/vllm/v1/kv_cache_layout.py @@ -49,8 +49,7 @@ class KVCacheLayout(Enum): @property def is_block_compact(self) -> bool: """True when each page's [H, N, C] bytes form one contiguous run; i.e. - the L and B dimensions are outermost. - """ + the L and B dimensions are outermost.""" return set(self.value[:2]) == {_DIM_L, _DIM_B} @property diff --git a/vllm/v1/kv_offload/base.py b/vllm/v1/kv_offload/base.py index b22390e444..1144477628 100644 --- a/vllm/v1/kv_offload/base.py +++ b/vllm/v1/kv_offload/base.py @@ -472,8 +472,7 @@ class CopyRun: """A strided byte correspondence between this worker's physical page and a canonical page: for i in range(num_fragments), fragment i spans [local_offset + i * local_stride, +fragment_size) in the worker's page and - [canonical_offset + i * canonical_stride, +fragment_size) canonically. - """ + [canonical_offset + i * canonical_stride, +fragment_size) canonically.""" local_offset: int canonical_offset: int @@ -554,8 +553,7 @@ class TransferResult: class OffloadingWorker(ABC): """Runs in the worker process. Performs async KV transfers for ONE offloaded medium (e.g. CPU). Direction is explicit via submit_store / - submit_load, so there is no (src_medium, dst_medium) routing. - """ + submit_load, so there is no (src_medium, dst_medium) routing.""" @abstractmethod def submit_store( diff --git a/vllm/v1/kv_offload/cpu/gpu_worker.py b/vllm/v1/kv_offload/cpu/gpu_worker.py index b16fdeef6c..037e3631e4 100644 --- a/vllm/v1/kv_offload/cpu/gpu_worker.py +++ b/vllm/v1/kv_offload/cpu/gpu_worker.py @@ -126,8 +126,7 @@ def compute_sub_block_ptrs( class CopyPlan(NamedTuple): """Precomputed fragment-copy template for one data ref under the canonical CPU layout, unrolled from the ref's mapped runs. Offsets are relative to - the per-block base pointers on each side. - """ + the per-block base pointers on each side.""" frag_offsets_src: np.ndarray frag_offsets_dst: np.ndarray @@ -165,8 +164,7 @@ def _canonical_page_ids( ) -> np.ndarray: """Global canonical page ids matching compute_sub_block_ptrs' enumeration. These identify canonical pages consistently across ranks, so they key - CanonicalPageMapping.is_writer rotation. - """ + CanonicalPageMapping.is_writer rotation.""" if blocks_per_chunk == 1: return block_ids[:count] flat = ( @@ -179,8 +177,7 @@ def _canonical_block_sizes( layer_refs_per_group: list[list[CanonicalKVCacheRef]], num_tensors: int ) -> list[int]: """Canonical CPU bytes per GPU block for each tensor, taken from the refs' - mappings. Requires every ref to carry a mapping. - """ + mappings. Requires every ref to carry a mapping.""" canonical_bytes_per_block = [0] * num_tensors for layer_refs in layer_refs_per_group: for ref in layer_refs: @@ -343,8 +340,7 @@ class SingleDirectionOffloadingHandler: """Upper bound on the number of copy descriptors for a transfer. Exact for the direct layout. The canonical path may fill fewer: - writer rotation later drops the blocks this rank does not write. - """ + writer rotation later drops the blocks this rank does not write.""" num_copy_ops = 0 for g_idx, (group_size, layer_refs) in enumerate( zip(group_sizes, self.layer_refs_per_group) @@ -373,8 +369,7 @@ class SingleDirectionOffloadingHandler: """Fill one group's copy descriptors for the direct (worker-private) layout: one whole-page copy per (block, ref). - Returns (op_idx past the filled descriptors, bytes added). - """ + Returns (op_idx past the filled descriptors, bytes added).""" num_bytes = 0 for data_ref in self.layer_refs_per_group[g_idx]: t_idx = data_ref.tensor_idx @@ -417,8 +412,7 @@ class SingleDirectionOffloadingHandler: scatter each block through the ref's precomputed CopyPlan, keeping only the blocks this rank writes. - Returns (op_idx past the filled descriptors, bytes added). - """ + Returns (op_idx past the filled descriptors, bytes added).""" assert self._canonical_copy_plans is not None # Zero-copy reinterpretation for pointer arithmetic: uint64 and the # buffers' int64 are bit-equivalent for addresses @@ -505,8 +499,7 @@ class SingleDirectionOffloadingHandler: ) -> tuple[np.ndarray, np.ndarray]: """Keep only the blocks this rank writes: replicated ranks take turns writing shared canonical pages, keyed by the rank-consistent CPU-side - canonical page id. - """ + canonical page id.""" cpu_page_ids = _canonical_page_ids( group_dst, self.dst_blocks_per_chunk, diff --git a/vllm/v1/kv_offload/cpu/spec.py b/vllm/v1/kv_offload/cpu/spec.py index 9eba094d79..00b36e863a 100644 --- a/vllm/v1/kv_offload/cpu/spec.py +++ b/vllm/v1/kv_offload/cpu/spec.py @@ -28,8 +28,7 @@ def _all_workers_barrier() -> None: """Block until every worker rank has reached this point (gloo cpu group). A superset of the node-local mmap openers suffices: once the barrier - releases, every worker sharing the region file has mapped it. - """ + releases, every worker sharing the region file has mapped it.""" from vllm.distributed.parallel_state import ( get_inner_dp_world_group, get_world_group, @@ -162,8 +161,7 @@ class CPUOffloadingSpec(OffloadingSpec): def _uses_shared_region(self) -> bool: """Whether the worker CPU buffer is the shared mmap region (vs a private - per-rank tensor); replicated-layout dedup is gated on this being True. - """ + per-rank tensor); replicated-layout dedup is gated on this being True.""" return current_platform.is_cuda_alike() def create_worker(self, kv_caches: CanonicalKVCaches) -> CPUOffloadingWorker: diff --git a/vllm/v1/kv_offload/tiering/async_lookup.py b/vllm/v1/kv_offload/tiering/async_lookup.py index 93e77591fa..a6879d8c44 100644 --- a/vllm/v1/kv_offload/tiering/async_lookup.py +++ b/vllm/v1/kv_offload/tiering/async_lookup.py @@ -216,8 +216,7 @@ class AsyncLookupManager(ABC): def mark_miss(self, keys: Collection[OffloadKey]) -> None: """Force the cached verdict for ``keys`` to False after a failed load, so the scheduler stops re-issuing the doomed promotion (livelock, #49176). - Keys with no cached entry are skipped. - """ + Keys with no cached entry are skipped.""" for key in keys: state = self._lookup_state.get(key) if state is not None: diff --git a/vllm/v1/kv_offload/tiering/example/manager.py b/vllm/v1/kv_offload/tiering/example/manager.py index aef2b7328d..5ec13f62da 100644 --- a/vllm/v1/kv_offload/tiering/example/manager.py +++ b/vllm/v1/kv_offload/tiering/example/manager.py @@ -168,8 +168,7 @@ class ExampleSecondaryTierManager(SecondaryTierManager): @override def drain_jobs(self) -> None: """Synchronous tier — submit_*() returns only after the operation - completes, so there is nothing to wait for. - """ + completes, so there is nothing to wait for.""" return def get_num_chunks(self) -> int: diff --git a/vllm/v1/kv_offload/tiering/fs/io.py b/vllm/v1/kv_offload/tiering/fs/io.py index 53249a0ccd..cda7e46e59 100644 --- a/vllm/v1/kv_offload/tiering/fs/io.py +++ b/vllm/v1/kv_offload/tiering/fs/io.py @@ -139,8 +139,7 @@ def _load_block( ) -> None: """Read one KV block from disk; remove the file only on a provable short read (a too-short file is genuine corruption) and leave it untouched on any - other error. - """ + other error.""" fd: int | None = None view_slice = view.cast("B")[offset : offset + block_size] o_direct = O_DIRECT if use_o_direct else 0 diff --git a/vllm/v1/kv_offload/tiering/fs/manager.py b/vllm/v1/kv_offload/tiering/fs/manager.py index ef545f4e3c..3d51d95774 100644 --- a/vllm/v1/kv_offload/tiering/fs/manager.py +++ b/vllm/v1/kv_offload/tiering/fs/manager.py @@ -269,8 +269,7 @@ class FileSystemTierManager(SecondaryTierManager): @override def get_finished_jobs(self) -> Iterable[JobResult]: """Collect finished jobs; a failed promotion marks only its failed keys - as a miss here (scheduler thread). - """ + as a miss here (scheduler thread).""" results = [] for job_id, success, transfer_time in self._pool.get_finished(): if self.events is not None: diff --git a/vllm/v1/kv_offload/tiering/manager.py b/vllm/v1/kv_offload/tiering/manager.py index ba8dee8fad..6e0bf90a33 100644 --- a/vllm/v1/kv_offload/tiering/manager.py +++ b/vllm/v1/kv_offload/tiering/manager.py @@ -143,8 +143,7 @@ class CPUPrimaryTierOffloadingManager(CPUOffloadingManager): class _SecondaryTierFacingParent(ParentManager): """Wrapper that implements ParentManager by delegating to the - TieringOffloadingManager with exclude_tier_idx set to the origin tier. - """ + TieringOffloadingManager with exclude_tier_idx set to the origin tier.""" __slots__ = ("_m", "_origin_idx") diff --git a/vllm/v1/kv_offload/tiering/obj/manager.py b/vllm/v1/kv_offload/tiering/obj/manager.py index 810a56c7ae..3d6c66c483 100644 --- a/vllm/v1/kv_offload/tiering/obj/manager.py +++ b/vllm/v1/kv_offload/tiering/obj/manager.py @@ -308,8 +308,7 @@ class ObjectStoreSecondaryTierManager(SecondaryTierManager): def _poll_active_transfers(self) -> None: """Poll all in-flight transfers once; move newly-completed (success or - failure) into ``_pending_results`` and release their NIXL handles. - """ + failure) into ``_pending_results`` and release their NIXL handles.""" for job_id, entry in list(self._transfers.items()): try: state = self._agent.check_xfer_state(entry.xfer_handle) @@ -364,8 +363,7 @@ class ObjectStoreSecondaryTierManager(SecondaryTierManager): def get_finished_jobs(self) -> Iterable[JobResult]: """Poll transfers; a failed promotion marks its cached verdicts False - here (scheduler thread). - """ + here (scheduler thread).""" self._poll_active_transfers() results = self._pending_results self._pending_results = [] diff --git a/vllm/v1/kv_offload/tiering/p2p/manager.py b/vllm/v1/kv_offload/tiering/p2p/manager.py index 17ecaf1a82..703c632899 100644 --- a/vllm/v1/kv_offload/tiering/p2p/manager.py +++ b/vllm/v1/kv_offload/tiering/p2p/manager.py @@ -134,8 +134,7 @@ class P2PDestInfo: def _parse_source(kv_params: dict | None) -> P2PSourceInfo | None: """Parse the consumer sub-dict (PD ``remote_prefiller`` or symmetric - ``remote_kv_source``) into a ``P2PSourceInfo``, or None if absent/incomplete. - """ + ``remote_kv_source``) into a ``P2PSourceInfo``, or None if absent/incomplete.""" role = _remote_prefiller_params(kv_params) do_probe = False if role is None: @@ -156,8 +155,7 @@ def _parse_source(kv_params: dict | None) -> P2PSourceInfo | None: def _parse_dest(kv_params: dict | None) -> P2PDestInfo | None: """Parse the producer ``remote_decoder`` sub-dict into a ``P2PDestInfo``, - or None if the block is absent (not a remote-decode request). - """ + or None if the block is absent (not a remote-decode request).""" role = _remote_decoder_params(kv_params) if role is None: return None diff --git a/vllm/v1/kv_offload/tiering/spec.py b/vllm/v1/kv_offload/tiering/spec.py index 5cc438c34f..9adac0f787 100644 --- a/vllm/v1/kv_offload/tiering/spec.py +++ b/vllm/v1/kv_offload/tiering/spec.py @@ -414,8 +414,7 @@ class TieringOffloadingSpec(CPUOffloadingSpec): """Require a mapping on every ref and record layer portability. Fails loudly rather than persist direct-layout bytes under a - canonical format identity. - """ + canonical format identity.""" all_refs = [ ref for group_refs in kv_caches.group_data_refs for ref in group_refs ] diff --git a/vllm/v1/metrics/loggers.py b/vllm/v1/metrics/loggers.py index 0ff5876fd1..50e606d3b3 100644 --- a/vllm/v1/metrics/loggers.py +++ b/vllm/v1/metrics/loggers.py @@ -91,8 +91,7 @@ def load_stat_logger_plugin_factories() -> list[StatLoggerFactory]: class AggregateStatLoggerBase(StatLoggerBase): """Abstract base class for loggers that - aggregate across multiple DP engines. - """ + aggregate across multiple DP engines.""" @abstractmethod def __init__(self, vllm_config: VllmConfig, engine_indexes: list[int]): ... diff --git a/vllm/v1/metrics/perf.py b/vllm/v1/metrics/perf.py index e1e61720b4..dd046a8250 100644 --- a/vllm/v1/metrics/perf.py +++ b/vllm/v1/metrics/perf.py @@ -1820,8 +1820,7 @@ def get_required(obj: object, attr: str): def getattr_from_list(obj: object, attrs: list[str], default: object = None): """Try to get the first attr that exists in the object - from a list of attrs. Otherwise return None. - """ + from a list of attrs. Otherwise return None.""" for attr in attrs: if hasattr(obj, attr): return getattr(obj, attr) diff --git a/vllm/v1/metrics/ray_wrappers.py b/vllm/v1/metrics/ray_wrappers.py index 2d515d5963..dedc60ba54 100644 --- a/vllm/v1/metrics/ray_wrappers.py +++ b/vllm/v1/metrics/ray_wrappers.py @@ -82,8 +82,7 @@ class RayPrometheusMetric: class RayGaugeWrapper(RayPrometheusMetric): """Wraps around ray.util.metrics.Gauge to provide same API as - prometheus_client.Gauge - """ + prometheus_client.Gauge""" def __init__( self, @@ -117,8 +116,7 @@ class RayGaugeWrapper(RayPrometheusMetric): class RayCounterWrapper(RayPrometheusMetric): """Wraps around ray.util.metrics.Counter to provide same API as - prometheus_client.Counter - """ + prometheus_client.Counter""" def __init__( self, @@ -143,8 +141,7 @@ class RayCounterWrapper(RayPrometheusMetric): class RayHistogramWrapper(RayPrometheusMetric): """Wraps around ray.util.metrics.Histogram to provide same API as - prometheus_client.Histogram - """ + prometheus_client.Histogram""" def __init__( self, diff --git a/vllm/v1/sample/logits_processor/builtin.py b/vllm/v1/sample/logits_processor/builtin.py index ea50e56be4..99dd157e78 100644 --- a/vllm/v1/sample/logits_processor/builtin.py +++ b/vllm/v1/sample/logits_processor/builtin.py @@ -129,8 +129,7 @@ class LogitBiasLogitsProcessor(LogitsProcessor): def is_argmax_invariant(self) -> bool: """Logit bias can rebalance token probabilities and change the - outcome of argmax in greedy sampling. - """ + outcome of argmax in greedy sampling.""" return False def update_state(self, batch_update: BatchUpdate | None): @@ -189,8 +188,7 @@ class MinTokensLogitsProcessor(LogitsProcessor): def is_argmax_invariant(self) -> bool: """By censoring stop tokens, min-tokens can change the outcome - of the argmax operation in greedy sampling. - """ + of the argmax operation in greedy sampling.""" return False @staticmethod diff --git a/vllm/v1/sample/logits_processor/state.py b/vllm/v1/sample/logits_processor/state.py index 24360037f7..7988e8c6e9 100644 --- a/vllm/v1/sample/logits_processor/state.py +++ b/vllm/v1/sample/logits_processor/state.py @@ -69,8 +69,7 @@ class BatchUpdateBuilder: @property def removed(self) -> list[RemovedRequest]: """Removed request indices sorted in - descending order - """ + descending order""" self._ensure_removed_sorted() return self._removed diff --git a/vllm/v1/serial_utils.py b/vllm/v1/serial_utils.py index 8e1e6cf4f6..882bc44917 100644 --- a/vllm/v1/serial_utils.py +++ b/vllm/v1/serial_utils.py @@ -90,8 +90,7 @@ def _typestr(val: Any) -> tuple[str, str] | None: def _encode_type_info_recursive(obj: Any) -> Any: """Recursively encode type information for nested structures of - lists/dicts. - """ + lists/dicts.""" if obj is None: return None if type(obj) is list: @@ -105,8 +104,7 @@ def _decode_type_info_recursive( type_info: Any, data: Any, convert_fn: Callable[[Sequence[str], Any], Any] ) -> Any: """Recursively decode type information for nested structures of - lists/dicts. - """ + lists/dicts.""" if type_info is None: return data if isinstance(type_info, dict): diff --git a/vllm/v1/simple_kv_offload/manager.py b/vllm/v1/simple_kv_offload/manager.py index 372fc2201d..85dde88f2d 100644 --- a/vllm/v1/simple_kv_offload/manager.py +++ b/vllm/v1/simple_kv_offload/manager.py @@ -259,8 +259,7 @@ class SimpleCPUOffloadScheduler: gpu_config: "KVCacheConfig", cpu_capacity_bytes: int ) -> "KVCacheConfig": """Derive a CPU KVCacheConfig from the GPU config. - Same kv_cache_groups, num_blocks scaled by CPU/GPU memory ratio. - """ + Same kv_cache_groups, num_blocks scaled by CPU/GPU memory ratio.""" # Import here to avoid potential circular imports from vllm.v1.kv_cache_interface import KVCacheTensor @@ -315,8 +314,7 @@ class SimpleCPUOffloadScheduler: def bind_gpu_block_pool(self, gpu_block_pool: BlockPool) -> None: """Bind GPU block pool so that we can touch blocks during stores. - Called by Scheduler after kv_cache_manager is ready. - """ + Called by Scheduler after kv_cache_manager is ready.""" self._gpu_block_pool = gpu_block_pool def get_num_new_matched_tokens( @@ -1131,8 +1129,7 @@ class SimpleCPUOffloadScheduler: block_ids: list[int], ) -> tuple[bool, dict[str, Any] | None]: """Always returns (False, None). GPU blocks are protected by ref_cnt, - so the scheduler can free blocks immediately. - """ + so the scheduler can free blocks immediately.""" req_id = request.request_id # Release any temp CPU hit pin from get_num_new_matched_tokens() diff --git a/vllm/v1/spec_decode/extract_hidden_states.py b/vllm/v1/spec_decode/extract_hidden_states.py index 77700a411f..18ae2700e9 100644 --- a/vllm/v1/spec_decode/extract_hidden_states.py +++ b/vllm/v1/spec_decode/extract_hidden_states.py @@ -396,8 +396,7 @@ class ExtractHiddenStatesProposer: def validate_same_kv_cache_group(self, kv_cache_config: KVCacheConfig) -> None: """Validate all drafting layers belong to the same KV cache group - and record the group index for common_attn_metadata selection. - """ + and record the group index for common_attn_metadata selection.""" assert len(self.attn_layer_names) == 1 layer = self.attn_layer_names[0] for gid, group in enumerate(kv_cache_config.kv_cache_groups): diff --git a/vllm/v1/spec_decode/gemma4.py b/vllm/v1/spec_decode/gemma4.py index 318b283ceb..bea677dde8 100644 --- a/vllm/v1/spec_decode/gemma4.py +++ b/vllm/v1/spec_decode/gemma4.py @@ -221,8 +221,7 @@ class Gemma4Proposer(SpecDecodeBaseProposer): def validate_same_kv_cache_group(self, kv_cache_config: KVCacheConfig) -> None: """Draft layers span multiple KV cache groups (sliding + full attention with different head dimensions), so skip the base - class single-group assertion. - """ + class single-group assertion.""" def initialize_attn_backend( self, @@ -230,8 +229,7 @@ class Gemma4Proposer(SpecDecodeBaseProposer): kernel_block_sizes: list[int] | None = None, ) -> None: """Create separate AttentionGroup objects per KV cache spec - so that each head-dim variant gets its own metadata builder. - """ + so that each head-dim variant gets its own metadata builder.""" all_attn_layers = get_layers_from_vllm_config( self.vllm_config, AttentionLayerBase, # type: ignore[type-abstract] diff --git a/vllm/v1/spec_decode/llm_base_proposer.py b/vllm/v1/spec_decode/llm_base_proposer.py index dff94b0544..9f7ad68a88 100644 --- a/vllm/v1/spec_decode/llm_base_proposer.py +++ b/vllm/v1/spec_decode/llm_base_proposer.py @@ -785,8 +785,7 @@ class SpecDecodeBaseProposer: block_size: int, ) -> torch.Tensor: """Update positions, slot mappings, and sequence metadata for the - next draft step. Returns the updated positions tensor. - """ + next draft step. Returns the updated positions tensor.""" positions_1d = positions[0] if self.uses_mrope else positions if self.uses_mrope: out_pos = self.mrope_positions[0, :batch_size] diff --git a/vllm/v1/spec_decode/utils.py b/vllm/v1/spec_decode/utils.py index 6db4663660..471d51d355 100644 --- a/vllm/v1/spec_decode/utils.py +++ b/vllm/v1/spec_decode/utils.py @@ -847,6 +847,5 @@ def update_num_computed_tokens_for_batch_change( def unconditional_to_conditional_rates(rates: list[float]) -> list[float]: """Convert per-position unconditional rates to per-position conditional - rates for the early-terminating rejection loop (c_i = p_i / p_{i-1}). - """ + rates for the early-terminating rejection loop (c_i = p_i / p_{i-1}).""" return [p / q if q > 0.0 else 0.0 for p, q in zip(rates, [1.0, *rates[:-1]])] diff --git a/vllm/v1/utils.py b/vllm/v1/utils.py index ef800f247e..a89ccbb9ed 100644 --- a/vllm/v1/utils.py +++ b/vllm/v1/utils.py @@ -144,8 +144,7 @@ class CpuGpuBuffer: def copy_to_cpu(self, n: int | None = None) -> torch.Tensor: """NOTE: Because this method is non-blocking, explicit synchronization - is needed to ensure the data is copied to CPU. - """ + is needed to ensure the data is copied to CPU.""" if n is None: return self.cpu.copy_(self.gpu, non_blocking=True) return self.cpu[:n].copy_(self.gpu[:n], non_blocking=True) @@ -159,8 +158,7 @@ def get_engine_client_zmq_addr( """Return an IPC path (``local_only=True``) or ``tcp://host:port``. ``port=0`` lets the kernel assign the port at ``bind()`` time; the - caller must recover it via ``getsockopt(zmq.LAST_ENDPOINT)``. - """ + caller must recover it via ``getsockopt(zmq.LAST_ENDPOINT)``.""" if local_only: return get_open_zmq_ipc_path() return get_tcp_uri(host, port) @@ -265,8 +263,7 @@ class APIServerProcessManager: ) -> tuple[list[str], list[str]]: """Return (inputs, outputs) reported by each child, indexed by ``client_index``. Raises ``RuntimeError`` on timeout or premature - child exit. - """ + child exit.""" n = len(self._address_pipes) inputs: list[str | None] = [None] * n outputs: list[str | None] = [None] * n @@ -427,8 +424,7 @@ class RustFrontendProcessManager: class _SubprocessWrapper: """Wraps subprocess.Popen to provide the BaseProcess-like interface - needed by wait_for_completion_or_failure. - """ + needed by wait_for_completion_or_failure.""" def __init__(self, proc, name: str): self._proc = proc diff --git a/vllm/v1/worker/encoder_cudagraph.py b/vllm/v1/worker/encoder_cudagraph.py index 1084596422..3b587ad71f 100644 --- a/vllm/v1/worker/encoder_cudagraph.py +++ b/vllm/v1/worker/encoder_cudagraph.py @@ -76,8 +76,7 @@ class EncoderCudaGraphManager: model: SupportsEncoderCudaGraph, ): """Initialize CUDA graph manager with provided token budgets - and max batch size. - """ + and max batch size.""" self.vllm_config = vllm_config self.device = device self.dtype = dtype diff --git a/vllm/v1/worker/gpu/cudagraph_utils.py b/vllm/v1/worker/gpu/cudagraph_utils.py index 239b47f3d7..4690c7eae7 100644 --- a/vllm/v1/worker/gpu/cudagraph_utils.py +++ b/vllm/v1/worker/gpu/cudagraph_utils.py @@ -62,8 +62,7 @@ class AttentionState(NamedTuple): @dataclass(frozen=True) class BatchExecutionDescriptor: """Describes the shape of the batch and CG mode to run; this is used to make shape - matches between the capture and runtime. - """ + matches between the capture and runtime.""" cg_mode: CUDAGraphMode num_tokens: int @@ -91,8 +90,7 @@ def make_cudagraph_stats( class CreateForwardFn(Protocol): """Factory that prepares inputs (OUTSIDE the graph) and returns a forward_fn. Called with warmup=True for the warmup pass and warmup=False - for the captured pass. - """ + for the captured pass.""" def __call__( self, @@ -955,8 +953,7 @@ def profile_cudagraph_memory(runner: "GPUModelRunner") -> int: def _extrapolate_full_graph_memory(mem_samples: list[int], total_graphs: int) -> int: """Extrapolate the total FULL capture cost from samples of the largest graphs. The first capture allocates the pool baseline; later graphs mostly - reuse it, so the second sample is taken as the per-graph cost. - """ + reuse it, so the second sample is taken as the per-graph cost.""" if not mem_samples: return 0 first_capture = mem_samples[0] @@ -993,8 +990,7 @@ def _init_minimal_kv_cache_for_profiling(runner: "GPUModelRunner") -> None: def _teardown_profiling_state(runner: "GPUModelRunner") -> None: """Release the profiling KV cache and captured graphs while keeping model - weights, so the real ``initialize_kv_cache`` starts from a clean slate. - """ + weights, so the real ``initialize_kv_cache`` starts from a clean slate.""" torch.accelerator.synchronize() if hasattr(runner.model_state, "_mamba_ctx"): runner.model_state._mamba_ctx = None diff --git a/vllm/v1/worker/gpu/model_runner.py b/vllm/v1/worker/gpu/model_runner.py index dca5b260f2..97571df8a9 100644 --- a/vllm/v1/worker/gpu/model_runner.py +++ b/vllm/v1/worker/gpu/model_runner.py @@ -2228,8 +2228,7 @@ class GPUModelRunner(LoRAModelRunnerMixin): def shutdown(self) -> None: """Release GPU tensors (model weights, KV caches, workspace) so that - memory is reclaimable when running in the same process. - """ + memory is reclaimable when running in the same process.""" torch.accelerator.synchronize() self.cudagraph_manager = None self.fast_prefill = None diff --git a/vllm/v1/worker/gpu/model_states/interface.py b/vllm/v1/worker/gpu/model_states/interface.py index 6f0c9c672c..a5c8d6f4cf 100644 --- a/vllm/v1/worker/gpu/model_states/interface.py +++ b/vllm/v1/worker/gpu/model_states/interface.py @@ -144,8 +144,7 @@ class ModelState(ABC): ) -> None: """Hook run on real batches before the forward pass (after block tables are gathered). Used by mamba "align" prefix caching to pre-copy state - across block boundaries. No-op by default. - """ + across block boundaries. No-op by default.""" return None def postprocess_state( diff --git a/vllm/v1/worker/gpu/pp_utils.py b/vllm/v1/worker/gpu/pp_utils.py index f1124c3ee4..c2aaa1fba2 100644 --- a/vllm/v1/worker/gpu/pp_utils.py +++ b/vllm/v1/worker/gpu/pp_utils.py @@ -38,8 +38,7 @@ def compute_need_sampled_mask(input_batch: InputBatch) -> np.ndarray | None: """Return a bool array of shape `[input_batch.num_reqs]` marking requests that produce a sampled token this step, and therefore must have that token (and the draft block proposed from it) propagated to the earlier PP stages. - Returns None if no request in the batch produces a sample. - """ + Returns None if no request in the batch produces a sample.""" old_computed = input_batch.num_computed_tokens_np prefill_len = input_batch.prefill_len_np # Exclude non-final prefill chunks (they don't produce a sample). @@ -179,8 +178,7 @@ class PPHandler: def receive(self, input_batch: InputBatch) -> bool: """Returns True iff sampled tokens need to be gathered from *all* - requests in the batch. - """ + requests in the batch.""" assert not self.is_last_rank need_sampled_mask = compute_need_sampled_mask(input_batch) if need_sampled_mask is None: diff --git a/vllm/v1/worker/gpu/sample/output.py b/vllm/v1/worker/gpu/sample/output.py index 01ffa4bdb1..ff3675db13 100644 --- a/vllm/v1/worker/gpu/sample/output.py +++ b/vllm/v1/worker/gpu/sample/output.py @@ -76,8 +76,7 @@ MAX_COMPACT_SUPPORT = 2048 class SamplingMaskTensors(NamedTuple): """Device-side masks pending async D2H: compact ids, plus the bitmask as - the exact fallback for rows wider than ``max_num_kept``. - """ + the exact fallback for rows wider than ``max_num_kept``.""" # [num_requests, max_num_kept] token_ids: torch.Tensor diff --git a/vllm/v1/worker/gpu/sample/sampler.py b/vllm/v1/worker/gpu/sample/sampler.py index a6199f570c..b069604c29 100644 --- a/vllm/v1/worker/gpu/sample/sampler.py +++ b/vllm/v1/worker/gpu/sample/sampler.py @@ -107,8 +107,7 @@ class Sampler: self, idx_mapping_np: np.ndarray, include_token_ids: bool = True ) -> tuple[int, int] | None: """(num_logprobs, max_per_req_token_ids) for the given requests, or - None when none of them want logprobs. - """ + None when none of them want logprobs.""" max_num_logprobs = self.sampling_states.max_num_logprobs(idx_mapping_np) max_token_ids = ( self.logprob_token_ids_state.max_num_token_ids(idx_mapping_np) diff --git a/vllm/v1/worker/gpu/spec_decode/adaptive_verification.py b/vllm/v1/worker/gpu/spec_decode/adaptive_verification.py index 2d0c25a41e..7e829cf309 100644 --- a/vllm/v1/worker/gpu/spec_decode/adaptive_verification.py +++ b/vllm/v1/worker/gpu/spec_decode/adaptive_verification.py @@ -190,8 +190,7 @@ class AdaptiveVerificationManager: """Dummy-run kwargs whose step timings seed the cost tables. Run these inside StepTimingCollector.collect(), then hand the block's - timings to set_initial_cost_curves. - """ + timings to set_initial_cost_curves.""" max_num_tokens = self.req_states.max_num_batched_tokens size = self._cudagraph_limit = capture_sizes[-1] if capture_sizes else 0 # Also profile beyond the capture limit: real steps run there @@ -261,8 +260,7 @@ class AdaptiveVerificationManager: input_batch: "InputBatch", ) -> None: """Publish this step's raw confidences for the ranking kernel and start - copying them to the CPU, where a later step's budget reads them. - """ + copying them to the CPU, where a later step's budget reads them.""" num_reqs = input_batch.num_reqs ready_idx = self._stale_idx ^ 1 with gpu_sync_allowed(): diff --git a/vllm/v1/worker/gpu/spec_decode/dflash/cudagraph.py b/vllm/v1/worker/gpu/spec_decode/dflash/cudagraph.py index 854c958a12..725714fcdb 100644 --- a/vllm/v1/worker/gpu/spec_decode/dflash/cudagraph.py +++ b/vllm/v1/worker/gpu/spec_decode/dflash/cudagraph.py @@ -72,8 +72,7 @@ def _prepare_dflash_inputs_to_capture( class DFlashCudaGraphManager(CudaGraphManager): """DFlash CudaGraphManager for the parallel-drafting query forward, - building its own attention metadata from scratch. - """ + building its own attention metadata from scratch.""" def capture( self, diff --git a/vllm/v1/worker/gpu/spec_decode/eagle/utils.py b/vllm/v1/worker/gpu/spec_decode/eagle/utils.py index dd37396b6b..eb0f4793bf 100644 --- a/vllm/v1/worker/gpu/spec_decode/eagle/utils.py +++ b/vllm/v1/worker/gpu/spec_decode/eagle/utils.py @@ -28,8 +28,7 @@ def _should_share(eagle: nn.Module, flag: str, draft, target) -> bool: def get_target_lm_head(target_model: nn.Module, target_language_model: nn.Module): """The target's lm_head — from get_language_model() for - *ForConditionalGeneration targets, else the top-level module. - """ + *ForConditionalGeneration targets, else the top-level module.""" return getattr(target_language_model, "lm_head", None) or getattr( target_model, "lm_head", None ) diff --git a/vllm/v1/worker/gpu/spec_decode/speculator.py b/vllm/v1/worker/gpu/spec_decode/speculator.py index b09e5196b9..299cac6416 100644 --- a/vllm/v1/worker/gpu/spec_decode/speculator.py +++ b/vllm/v1/worker/gpu/spec_decode/speculator.py @@ -268,8 +268,7 @@ class DraftModelSpeculator(BaseSpeculator): @property def attn_vllm_config(self) -> VllmConfig: """Config for the draft's attention metadata builders. Overridden by - speculators whose attention mode differs from the target's. - """ + speculators whose attention mode differs from the target's.""" return self.vllm_config def set_attn( diff --git a/vllm/v1/worker/gpu_model_runner.py b/vllm/v1/worker/gpu_model_runner.py index bf46c3dbfe..5c85257fa3 100644 --- a/vllm/v1/worker/gpu_model_runner.py +++ b/vllm/v1/worker/gpu_model_runner.py @@ -481,8 +481,7 @@ class AsyncGPUPoolingModelRunnerOutput(AsyncModelRunnerOutput): class ExecuteModelState(NamedTuple): """Ephemeral cached state transferred between execute_model() and - sample_tokens(), after execute_model() returns None. - """ + sample_tokens(), after execute_model() returns None.""" scheduler_output: "SchedulerOutput" logits: torch.Tensor @@ -1072,8 +1071,7 @@ class GPUModelRunner( first scheduled token (column j is position start - 1 - j); -1 where the position is before the prompt or already past it. Generated positions are left to the model: under async scheduling the CPU token - table holds placeholders for them. - """ + table holds placeholders for them.""" buf = self.lookback_token_ids assert buf is not None buf.np.fill(-1) @@ -3206,8 +3204,7 @@ class GPUModelRunner( def _get_encoder_output_from_cache(self, mm_hash: str) -> torch.Tensor | None: """Return a cached encoder output for multimodal - embedding gather. - """ + embedding gather.""" return self.encoder_cache.get(mm_hash, None) def _gather_mm_embeddings( @@ -4179,8 +4176,7 @@ class GPUModelRunner( This is true when `discard_request_mask` is set for every scheduled request (e.g., for chunked prefill requests that are not the last - prefill chunk). - """ + prefill chunk).""" num_reqs = self.input_batch.num_reqs return bool(self.discard_request_mask.np[:num_reqs].all()) @@ -6573,8 +6569,7 @@ class GPUModelRunner( def shutdown(self) -> None: """Release GPU tensors (model weights, KV caches, workspace) so that - memory is reclaimable when running in the same process. - """ + memory is reclaimable when running in the same process.""" from vllm.model_executor.layers.rotary_embedding import _ROPE_DICT from vllm.v1.worker.workspace import reset_workspace_manager diff --git a/vllm/v1/worker/gpu_worker.py b/vllm/v1/worker/gpu_worker.py index 44621d08fb..acba1d9b67 100644 --- a/vllm/v1/worker/gpu_worker.py +++ b/vllm/v1/worker/gpu_worker.py @@ -336,8 +336,7 @@ class Worker(WorkerBase): def _scoped_allocator_max_split(self, max_split_size_mb: int): """Temporarily set max_split_size_mb to reduce allocator fragmentation at the cost of more cudaMalloc calls (negligible in practice). Restores the original - value on exit. - """ + value on exit.""" if not current_platform.is_cuda(): yield return diff --git a/vllm/v1/worker/startup_plan.py b/vllm/v1/worker/startup_plan.py index 5a570b3470..2c49420707 100644 --- a/vllm/v1/worker/startup_plan.py +++ b/vllm/v1/worker/startup_plan.py @@ -77,8 +77,7 @@ def compute_plan_fingerprint( def _plan_path(fingerprint: str) -> str: """Plans are regenerable derived state, so they live under the standard vLLM cache root (like the torch.compile cache) and relocate with - ``VLLM_CACHE_ROOT`` instead of needing a location knob of their own. - """ + ``VLLM_CACHE_ROOT`` instead of needing a location knob of their own.""" # VLLM_CACHE_ROOT is already user-expanded by envs.py. return os.path.join( envs.VLLM_CACHE_ROOT, "startup_plan", f"startup_plan_{fingerprint}.json" @@ -135,8 +134,7 @@ def _applicable_kv_cache_memory_bytes( def maybe_apply_startup_plan(worker: "Worker") -> None: """If enabled and ``--kv-cache-memory`` was not set explicitly, apply a persisted plan by setting ``worker.cache_config.kv_cache_memory_bytes``. - No-op unless ``VLLM_ENABLE_STARTUP_PLAN=1``. - """ + No-op unless ``VLLM_ENABLE_STARTUP_PLAN=1``.""" if ( not envs.VLLM_ENABLE_STARTUP_PLAN or worker.cache_config.kv_cache_memory_bytes is not None @@ -169,8 +167,7 @@ def maybe_apply_startup_plan(worker: "Worker") -> None: def maybe_save_startup_plan(worker: "Worker", kv_cache_memory_bytes: int) -> None: """Atomically persist this boot's profiling result for future boots. No-op unless ``VLLM_ENABLE_STARTUP_PLAN=1``; failures are logged, - never raised. - """ + never raised.""" if not envs.VLLM_ENABLE_STARTUP_PLAN: return fingerprint = compute_plan_fingerprint( diff --git a/vllm/v1/worker/worker_base.py b/vllm/v1/worker/worker_base.py index 6496a611e6..cf869edb26 100644 --- a/vllm/v1/worker/worker_base.py +++ b/vllm/v1/worker/worker_base.py @@ -128,8 +128,7 @@ class WorkerBase: def synchronize_device(self) -> None: """Block until in-flight device work completes; backends outside - ``torch.accelerator`` must override with their own wait. - """ + ``torch.accelerator`` must override with their own wait.""" if torch.accelerator.is_available(): torch.accelerator.synchronize()