[CI] Ignore ruff D209, rejoin the docstrings it split, and silence incompatible-rule warnings (#57212)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
1085b64425
commit
651a88c09a
@@ -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)
|
||||
|
||||
|
||||
@@ -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...<channel|>.
|
||||
"""
|
||||
message emits <|channel>thought\\n...<channel|>."""
|
||||
messages = [
|
||||
{"role": "user", "content": "Calculate something"},
|
||||
{
|
||||
@@ -280,8 +275,7 @@ class TestGemma4ChatTemplate:
|
||||
|
||||
def test_strip_thinking_in_model_content(self, gemma4_template):
|
||||
"""<|channel>...<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"},
|
||||
{
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user