Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/endpoints/test_openai_chat_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,53 @@ def test_create_messages_audio_format_error(
turns = [turn]
with pytest.raises(ValueError):
endpoint._create_messages(turns)

def test_format_payload_with_multiple_images_batch(
self, model_endpoint, sample_conversations
):
"""Test that image batch_size > 1 creates multiple image_url entries."""
endpoint = ChatEndpoint(model_endpoint)
turn = sample_conversations["session_1"].turns[0]
# Simulate batch_size=3 by adding 3 images to contents
turn.images = [
type(
"Image",
(),
{
"contents": [
"http://image.url/img1.png",
"http://image.url/img2.png",
"http://image.url/img3.png",
]
},
)()
]
turns = [turn]
request_info = RequestInfo(model_endpoint=model_endpoint, turns=turns)
payload = endpoint.format_payload(request_info)

expected_payload = {
"messages": [
{
"role": turn.role or "user",
"content": [
{"type": "text", "text": "Hello, world!"},
{
"type": "image_url",
"image_url": {"url": "http://image.url/img1.png"},
},
{
"type": "image_url",
"image_url": {"url": "http://image.url/img2.png"},
},
{
"type": "image_url",
"image_url": {"url": "http://image.url/img3.png"},
},
],
}
],
"model": "test-model",
"stream": False,
}
assert payload == expected_payload
49 changes: 49 additions & 0 deletions tests/integration/test_multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,52 @@ async def test_images_and_audio(
assert result.request_count == defaults.request_count
assert result.has_input_images
assert result.has_input_audio

async def test_image_batch_size(
self, cli: AIPerfCLI, aiperf_mock_server: AIPerfMockServer
):
"""Test that --batch-size-image produces correct number of images per turn."""
batch_size = 3
result = await cli.run(
f"""
aiperf profile \
--model {defaults.model} \
--url {aiperf_mock_server.url} \
--endpoint-type chat \
--request-count {defaults.request_count} \
--concurrency {defaults.concurrency} \
--image-width-mean 64 \
--image-height-mean 64 \
--batch-size-image {batch_size} \
--workers-max {defaults.workers_max} \
--ui {defaults.ui}
"""
)
assert result.request_count == defaults.request_count
assert result.has_input_images

# Verify inputs.json contains the correct number of images per turn
assert result.inputs is not None, "inputs.json should exist"
assert result.inputs.data, "inputs.json should contain data"

for session in result.inputs.data:
assert session.payloads, "session should have payloads"
for payload in session.payloads:
# Check OpenAI message format
messages = payload.get("messages", [])
assert messages, "payload should have messages"

for message in messages:
content = message.get("content", [])
if isinstance(content, list):
# Count image_url entries in the content array
image_count = sum(
1
for item in content
if isinstance(item, dict)
and item.get("type") == "image_url"
)
# Each turn should have exactly batch_size images
assert image_count == batch_size, (
f"Expected {batch_size} images per turn, got {image_count}"
)
Comment on lines +111 to +124
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Only assert image count for messages that contain images.

The current logic asserts image_count == batch_size for every message where content is a list. However, not all messages necessarily contain images (e.g., assistant responses or messages with only audio/video). This could cause false failures.

Apply this diff to check only messages with images:

                for message in messages:
                    content = message.get("content", [])
                    if isinstance(content, list):
                        # Count image_url entries in the content array
                        image_count = sum(
                            1
                            for item in content
                            if isinstance(item, dict)
                            and item.get("type") == "image_url"
                        )
-                       # Each turn should have exactly batch_size images
-                       assert image_count == batch_size, (
-                           f"Expected {batch_size} images per turn, got {image_count}"
-                       )
+                       # Each turn with images should have exactly batch_size images
+                       if image_count > 0:
+                           assert image_count == batch_size, (
+                               f"Expected {batch_size} images per turn, got {image_count}"
+                           )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for message in messages:
content = message.get("content", [])
if isinstance(content, list):
# Count image_url entries in the content array
image_count = sum(
1
for item in content
if isinstance(item, dict)
and item.get("type") == "image_url"
)
# Each turn should have exactly batch_size images
assert image_count == batch_size, (
f"Expected {batch_size} images per turn, got {image_count}"
)
for message in messages:
content = message.get("content", [])
if isinstance(content, list):
# Count image_url entries in the content array
image_count = sum(
1
for item in content
if isinstance(item, dict)
and item.get("type") == "image_url"
)
# Each turn with images should have exactly batch_size images
if image_count > 0:
assert image_count == batch_size, (
f"Expected {batch_size} images per turn, got {image_count}"
)
🤖 Prompt for AI Agents
In tests/integration/test_multimodal.py around lines 111 to 124, the test
currently asserts image_count == batch_size for every message whose content is a
list, which fails for turns that don't contain images; change the logic to only
perform the equality assertion when the message actually contains image entries
(e.g., check if any item in content has type "image_url" or simply if
image_count > 0) and skip the assertion for messages with zero image entries so
only image-containing messages are validated against batch_size.