[watermark] compatibility validation (#56801)
Signed-off-by: Raphael Rialland <raphael.rialland@mistral.ai> Signed-off-by: Simon Veitner <sveitner@redhat.com> Co-authored-by: Simon Veitner <sveitner@redhat.com>
This commit is contained in:
co-authored by
Simon Veitner
parent
88f3c601b3
commit
c32495d58f
@@ -154,6 +154,40 @@ async def client(server):
|
||||
yield async_client
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def watermarked_server():
|
||||
args = [
|
||||
"--dtype",
|
||||
"half",
|
||||
"--enable-auto-tool-choice",
|
||||
"--structured-outputs-config.backend",
|
||||
"xgrammar",
|
||||
"--tool-call-parser",
|
||||
"hermes",
|
||||
"--reasoning-parser",
|
||||
"qwen3",
|
||||
"--gpu-memory-utilization",
|
||||
"0.4",
|
||||
"--enforce-eager",
|
||||
"--watermark-config",
|
||||
'{"algorithm":"gumbel","key":42}',
|
||||
] + ROCM_EXTRA_ARGS
|
||||
|
||||
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
|
||||
yield remote_server
|
||||
|
||||
|
||||
@pytest.fixture(params=["server", "watermarked_server"], ids=["plain", "watermarked"])
|
||||
def tool_use_server(request: pytest.FixtureRequest):
|
||||
return request.getfixturevalue(request.param)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def tool_use_client(tool_use_server):
|
||||
async with tool_use_server.get_async_client() as async_client:
|
||||
yield async_client
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
||||
@pytest.mark.parametrize("stream", [True, False])
|
||||
@@ -167,12 +201,13 @@ async def client(server):
|
||||
)
|
||||
@pytest.mark.parametrize("enable_thinking", [True, False])
|
||||
async def test_function_tool_use(
|
||||
client: openai.AsyncOpenAI,
|
||||
tool_use_client: openai.AsyncOpenAI,
|
||||
model_name: str,
|
||||
stream: bool,
|
||||
tool_choice: str | dict,
|
||||
enable_thinking: bool,
|
||||
):
|
||||
client = tool_use_client
|
||||
if not stream:
|
||||
# Non-streaming test
|
||||
chat_completion = await client.chat.completions.create(
|
||||
|
||||
@@ -1,32 +1,249 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
|
||||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
from fastapi import UploadFile
|
||||
|
||||
from vllm.entrypoints.openai.chat_completion.protocol import (
|
||||
BatchChatCompletionRequest,
|
||||
ChatCompletionRequest,
|
||||
)
|
||||
from vllm.entrypoints.openai.completion.protocol import CompletionRequest
|
||||
from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
|
||||
from vllm.entrypoints.speech_to_text.transcription.protocol import (
|
||||
TranscriptionRequest,
|
||||
)
|
||||
from vllm.entrypoints.speech_to_text.translation.protocol import TranslationRequest
|
||||
from vllm.sampling_params import StructuredOutputsParams
|
||||
|
||||
|
||||
def test_chat_request_disables_watermarking():
|
||||
def test_chat_request_preserves_watermarking_opt_out():
|
||||
request = ChatCompletionRequest(
|
||||
messages=[{"role": "user", "content": "hello"}], watermarking=False
|
||||
)
|
||||
|
||||
params = request.to_sampling_params(max_tokens=1, default_sampling_params={})
|
||||
|
||||
assert not params.watermarking
|
||||
assert params.watermarking is False
|
||||
|
||||
|
||||
def test_completion_request_disables_watermarking():
|
||||
def test_completion_request_preserves_watermarking_opt_out():
|
||||
request = CompletionRequest(prompt="hello", watermarking=False)
|
||||
|
||||
params = request.to_sampling_params(max_tokens=1)
|
||||
|
||||
assert not params.watermarking
|
||||
assert params.watermarking is False
|
||||
|
||||
|
||||
def test_responses_request_disables_watermarking():
|
||||
def test_responses_request_preserves_watermarking_opt_out():
|
||||
request = ResponsesRequest(input="hello", watermarking=False)
|
||||
|
||||
params = request.to_sampling_params(default_max_tokens=1)
|
||||
|
||||
assert not params.watermarking
|
||||
assert params.watermarking is False
|
||||
|
||||
|
||||
def test_batch_chat_request_preserves_watermarking_opt_out():
|
||||
request = BatchChatCompletionRequest(
|
||||
messages=[[{"role": "user", "content": "hello"}]], watermarking=False
|
||||
)
|
||||
|
||||
converted = request.to_chat_completion_request(request.messages[0])
|
||||
params = converted.to_sampling_params(max_tokens=1, default_sampling_params={})
|
||||
|
||||
assert params.watermarking is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"api_request,conversion,kwargs",
|
||||
[
|
||||
(
|
||||
ChatCompletionRequest(
|
||||
messages=[{"role": "user", "content": "hello"}],
|
||||
use_beam_search=True,
|
||||
watermarking=False,
|
||||
),
|
||||
"to_beam_search_params",
|
||||
{"max_tokens": 1, "default_sampling_params": {}},
|
||||
),
|
||||
(
|
||||
CompletionRequest(prompt="hello", use_beam_search=True, watermarking=False),
|
||||
"to_beam_search_params",
|
||||
{"max_tokens": 1, "default_sampling_params": {}},
|
||||
),
|
||||
(
|
||||
TranscriptionRequest(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
watermarking=False,
|
||||
),
|
||||
"to_sampling_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
(
|
||||
TranscriptionRequest(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
watermarking=False,
|
||||
),
|
||||
"to_beam_search_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
(
|
||||
TranslationRequest(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
watermarking=False,
|
||||
),
|
||||
"to_sampling_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
(
|
||||
TranslationRequest(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
watermarking=False,
|
||||
),
|
||||
"to_beam_search_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_request_preserves_watermarking_opt_out(api_request, conversion, kwargs):
|
||||
params = getattr(api_request, conversion)(**kwargs)
|
||||
|
||||
assert params.watermarking is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("request_cls", [TranscriptionRequest, TranslationRequest])
|
||||
def test_speech_requests_leave_watermarking_unspecified(request_cls):
|
||||
request = request_cls(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
temperature=0.8,
|
||||
)
|
||||
|
||||
sampling_params = request.to_sampling_params(default_max_tokens=1)
|
||||
beam_params = request.to_beam_search_params(default_max_tokens=1)
|
||||
|
||||
assert request.watermarking is None
|
||||
assert sampling_params.watermarking is None
|
||||
assert beam_params.watermarking is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"api_request,kwargs",
|
||||
[
|
||||
(
|
||||
ChatCompletionRequest(
|
||||
messages=[{"role": "user", "content": "choose A or B"}],
|
||||
temperature=0.8,
|
||||
structured_outputs=StructuredOutputsParams(choice=["A", "B"]),
|
||||
),
|
||||
{"max_tokens": 8, "default_sampling_params": {}},
|
||||
),
|
||||
(
|
||||
CompletionRequest(
|
||||
prompt="choose A or B",
|
||||
temperature=0.8,
|
||||
structured_outputs=StructuredOutputsParams(choice=["A", "B"]),
|
||||
),
|
||||
{"max_tokens": 8},
|
||||
),
|
||||
(
|
||||
ResponsesRequest(
|
||||
input="choose A or B",
|
||||
temperature=0.8,
|
||||
structured_outputs=StructuredOutputsParams(choice=["A", "B"]),
|
||||
),
|
||||
{"default_max_tokens": 8},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_request_preserves_unspecified_watermarking_with_structured_outputs(
|
||||
api_request, kwargs
|
||||
):
|
||||
params = api_request.to_sampling_params(**kwargs)
|
||||
|
||||
assert params.watermarking is None
|
||||
assert params.structured_outputs is not None
|
||||
assert params.structured_outputs.choice == ["A", "B"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"api_request,conversion,kwargs",
|
||||
[
|
||||
(
|
||||
ChatCompletionRequest(
|
||||
messages=[{"role": "user", "content": "hello"}], watermarking=True
|
||||
),
|
||||
"to_sampling_params",
|
||||
{"max_tokens": 1, "default_sampling_params": {}},
|
||||
),
|
||||
(
|
||||
ChatCompletionRequest(
|
||||
messages=[{"role": "user", "content": "hello"}],
|
||||
use_beam_search=True,
|
||||
watermarking=True,
|
||||
),
|
||||
"to_beam_search_params",
|
||||
{"max_tokens": 1, "default_sampling_params": {}},
|
||||
),
|
||||
(
|
||||
CompletionRequest(prompt="hello", watermarking=True),
|
||||
"to_sampling_params",
|
||||
{"max_tokens": 1},
|
||||
),
|
||||
(
|
||||
CompletionRequest(prompt="hello", use_beam_search=True, watermarking=True),
|
||||
"to_beam_search_params",
|
||||
{"max_tokens": 1},
|
||||
),
|
||||
(
|
||||
ResponsesRequest(input="hello", watermarking=True),
|
||||
"to_sampling_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
(
|
||||
TranscriptionRequest(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
watermarking=True,
|
||||
),
|
||||
"to_sampling_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
(
|
||||
TranslationRequest(
|
||||
file=UploadFile(file=BytesIO(), filename="audio.wav"),
|
||||
watermarking=True,
|
||||
),
|
||||
"to_sampling_params",
|
||||
{"default_max_tokens": 1},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_request_preserves_explicit_watermarking(api_request, conversion, kwargs):
|
||||
params = getattr(api_request, conversion)(**kwargs)
|
||||
|
||||
assert params.watermarking is True
|
||||
|
||||
|
||||
def test_batch_chat_request_preserves_explicit_watermarking():
|
||||
request = BatchChatCompletionRequest(
|
||||
messages=[[{"role": "user", "content": "hello"}]], watermarking=True
|
||||
)
|
||||
|
||||
converted = request.to_chat_completion_request(request.messages[0])
|
||||
params = converted.to_sampling_params(max_tokens=1, default_sampling_params={})
|
||||
|
||||
assert converted.watermarking is True
|
||||
assert params.watermarking is True
|
||||
|
||||
|
||||
def test_batch_chat_request_inherits_watermarking():
|
||||
request = BatchChatCompletionRequest(
|
||||
messages=[[{"role": "user", "content": "hello"}]]
|
||||
)
|
||||
|
||||
converted = request.to_chat_completion_request(request.messages[0])
|
||||
params = converted.to_sampling_params(max_tokens=1, default_sampling_params={})
|
||||
|
||||
assert converted.watermarking is None
|
||||
assert params.watermarking is None
|
||||
|
||||
Reference in New Issue
Block a user