[misc] Improve benchmark determinism and dataset API coverage (#33255)
This commit is contained in:
@@ -215,14 +215,78 @@ class ImageOpenAITestMixin(TestOpenAIMLLMServerBase):
|
||||
with ThreadPoolExecutor(4) as executor:
|
||||
list(executor.map(self.run_decode_with_image, image_ids))
|
||||
|
||||
def test_image_prefix_cache_reuse(self):
|
||||
"""Image prefix (radix) cache correctness across requests.
|
||||
|
||||
Repeating an identical image must reuse the multimodal prefix without
|
||||
changing the output, and a different image must NOT reuse the first
|
||||
image's KV. This guards against image-token pad_value / feature-hash
|
||||
regressions that would silently serve a cached *wrong* image's KV
|
||||
(a correctness bug invisible to single-request tests). Pure greedy
|
||||
request-level checks: no extra server flags, radix cache is on by
|
||||
default.
|
||||
"""
|
||||
client = openai.Client(api_key=self.api_key, base_url=self.base_url)
|
||||
|
||||
def describe(url: str) -> str:
|
||||
response = client.chat.completions.create(
|
||||
model="default",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "image_url", "image_url": {"url": url}},
|
||||
{
|
||||
"type": "text",
|
||||
"text": "Describe this image in one sentence.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
temperature=0,
|
||||
max_tokens=32,
|
||||
**(self.get_vision_request_kwargs()),
|
||||
)
|
||||
assert response.usage.prompt_tokens > 0
|
||||
content = response.choices[0].message.content
|
||||
assert isinstance(content, str) and content
|
||||
return content
|
||||
|
||||
# miss -> compute, then hit -> reuse the identical image's prefix
|
||||
first = describe(IMAGE_MAN_IRONING_URL)
|
||||
repeat = describe(IMAGE_MAN_IRONING_URL)
|
||||
# a different image must be computed on its own, not reuse `first`'s KV
|
||||
other = describe(IMAGE_SGL_LOGO_URL)
|
||||
# the original image again, after a different one occupied the cache
|
||||
first_again = describe(IMAGE_MAN_IRONING_URL)
|
||||
|
||||
self.assertEqual(
|
||||
first,
|
||||
repeat,
|
||||
"Repeating an identical image changed the output; image prefix "
|
||||
"reuse broke greedy determinism.",
|
||||
)
|
||||
self.assertEqual(
|
||||
first,
|
||||
first_again,
|
||||
"The identical image after a different one changed the output; "
|
||||
"image KV was cross-contaminated across requests.",
|
||||
)
|
||||
self.assertNotEqual(
|
||||
first,
|
||||
other,
|
||||
"A different image produced an identical description; a wrong "
|
||||
"image's KV may have been reused from the prefix cache.",
|
||||
)
|
||||
|
||||
def verify_single_image_response(self, response):
|
||||
assert response.choices[0].message.role == "assistant"
|
||||
text = response.choices[0].message.content
|
||||
assert isinstance(text, str)
|
||||
|
||||
# `driver` is for gemma-3-it
|
||||
assert (
|
||||
"man" in text or "person" or "driver" in text
|
||||
assert any(
|
||||
keyword in text for keyword in ("man", "person", "driver")
|
||||
), f"text: {text}, should contain man, person or driver"
|
||||
assert (
|
||||
"cab" in text
|
||||
|
||||
Reference in New Issue
Block a user