fix: fix image benchmark backend parity (#30867)
This commit is contained in:
@@ -199,22 +199,23 @@ def create_mm_data_row(
|
|||||||
# Vision tokens = total tokens - text tokens
|
# Vision tokens = total tokens - text tokens
|
||||||
vision_prompt_len = prompt_len - text_prompt_len
|
vision_prompt_len = prompt_len - text_prompt_len
|
||||||
|
|
||||||
supported_backends = [
|
supported_backends = (
|
||||||
"sglang",
|
"sglang",
|
||||||
"sglang-native",
|
"sglang-native",
|
||||||
"sglang-oai-chat",
|
"sglang-oai-chat",
|
||||||
"vllm-chat",
|
"vllm-chat",
|
||||||
]
|
"lmdeploy-chat",
|
||||||
|
)
|
||||||
if backend not in supported_backends:
|
if backend not in supported_backends:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Image dataset only supports backends: {supported_backends}, "
|
f"Image dataset only supports backends: {supported_backends}, "
|
||||||
f"got '{backend}'."
|
f"got '{backend}'."
|
||||||
)
|
)
|
||||||
|
|
||||||
# OpenAI chat handlers apply the chat template and receive images separately, so
|
# Chat-completions backends apply their own chat template, so send raw text.
|
||||||
# send the raw text. /generate does not apply a chat template, so it needs
|
# Native SGLang /generate does not apply a template and needs the image
|
||||||
# prompt_str, which contains the multimodal processor's image placeholders.
|
# placeholder-bearing prompt generated by the processor.
|
||||||
use_raw_prompt = backend in ("sglang-oai-chat", "vllm-chat")
|
use_raw_prompt = backend in ("sglang-oai-chat", "vllm-chat", "lmdeploy-chat")
|
||||||
|
|
||||||
return DatasetRow(
|
return DatasetRow(
|
||||||
prompt=text_prompt if use_raw_prompt else prompt_str,
|
prompt=text_prompt if use_raw_prompt else prompt_str,
|
||||||
|
|||||||
@@ -426,9 +426,11 @@ class TestBenchmarkDatasetsAPI(unittest.TestCase):
|
|||||||
self.assertTrue(all(isinstance(row, DatasetRow) for row in rows))
|
self.assertTrue(all(isinstance(row, DatasetRow) for row in rows))
|
||||||
self.assertTrue(all(row.image_data for row in rows))
|
self.assertTrue(all(row.image_data for row in rows))
|
||||||
|
|
||||||
def test_image_sampler_vllm_chat(self):
|
def test_image_sampler_chat_backends_use_raw_prompt(self):
|
||||||
|
for backend in ("sglang-oai-chat", "vllm-chat", "lmdeploy-chat"):
|
||||||
|
with self.subTest(backend=backend):
|
||||||
rows = sample_image_requests(
|
rows = sample_image_requests(
|
||||||
num_requests=2,
|
num_requests=1,
|
||||||
image_count=1,
|
image_count=1,
|
||||||
input_len=8,
|
input_len=8,
|
||||||
output_len=4,
|
output_len=4,
|
||||||
@@ -437,13 +439,13 @@ class TestBenchmarkDatasetsAPI(unittest.TestCase):
|
|||||||
image_content="blank",
|
image_content="blank",
|
||||||
image_format="png",
|
image_format="png",
|
||||||
image_resolution="8x8",
|
image_resolution="8x8",
|
||||||
backend="vllm-chat",
|
backend=backend,
|
||||||
random_image_count=False,
|
random_image_count=False,
|
||||||
)
|
)
|
||||||
self.assertEqual(len(rows), 2)
|
self.assertEqual(len(rows), 1)
|
||||||
self.assertTrue(all(isinstance(row, DatasetRow) for row in rows))
|
self.assertTrue(rows[0].image_data)
|
||||||
self.assertTrue(all(row.image_data for row in rows))
|
for marker in ("user:", "assistant:", "[IMAGE]"):
|
||||||
self.assertTrue(all("[IMAGE]" not in row.prompt for row in rows))
|
self.assertNotIn(marker, rows[0].prompt)
|
||||||
|
|
||||||
def test_image_sampler_random_resolution(self):
|
def test_image_sampler_random_resolution(self):
|
||||||
state = np.random.get_state()
|
state = np.random.get_state()
|
||||||
|
|||||||
Reference in New Issue
Block a user