Skip to content

Commit

Permalink
feat: update to run qwen2-vl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drbh committed Jan 16, 2025
1 parent 822bd04 commit bd59f96
Showing 1 changed file with 80 additions and 81 deletions.
161 changes: 80 additions & 81 deletions integration-tests/models/test_flash_qwen2_vl.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,80 @@
# Disabled because it's broken.
# import pytest
#
#
# @pytest.fixture(scope="module")
# def flash_qwen2_vl_handle(launcher):
# with launcher("Qwen/Qwen2-VL-7B-Instruct") as handle:
# yield handle
#
#
# @pytest.fixture(scope="module")
# async def flash_qwen2(flash_qwen2_vl_handle):
# await flash_qwen2_vl_handle.health(300)
# return flash_qwen2_vl_handle.client
#
#
# @pytest.mark.private
# async def test_flash_qwen2_vl_simple(flash_qwen2, response_snapshot):
# response = await flash_qwen2.chat(
# max_tokens=100,
# seed=42,
# messages=[
# {
# "role": "user",
# "content": [
# {
# "type": "image_url",
# "image_url": {
# "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"
# },
# },
# {"type": "text", "text": "Describe this image."},
# ],
# },
# ],
# )
#
# assert (
# response.choices[0].message.content
# == "The image depicts an anthropomorphic rabbit, wearing a futuristic spacesuit, in an extraterrestrial environment. The setting appears to be a red planet resembling Mars, with rugged terrain and rocky formations in the background. The moon is visible in the distant sky, adding to the lunar landscape."
# )
#
# assert response == response_snapshot
#
#
# @pytest.mark.private
# async def test_flash_qwen2_vl_simple_streaming(flash_qwen2, response_snapshot):
# responses = await flash_qwen2.chat(
# max_tokens=100,
# seed=42,
# messages=[
# {
# "role": "user",
# "content": [
# {
# "type": "image_url",
# "image_url": {
# "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"
# },
# },
# {"type": "text", "text": "Describe this image."},
# ],
# },
# ],
# stream=True,
# )
#
# count = 0
# generated = ""
# last_response = None
# async for response in responses:
# count += 1
# generated += response.choices[0].delta.content
# last_response = response
#
# assert (
# generated
# == "The image depicts an anthropomorphic rabbit, wearing a futuristic spacesuit, in an extraterrestrial environment. The setting appears to be a red planet resembling Mars, with rugged terrain and rocky formations in the background. The moon is visible in the distant sky, adding to the lunar landscape."
# )
# assert count == 58
# assert last_response == response_snapshot
import pytest


@pytest.fixture(scope="module")
def flash_qwen2_vl_handle(launcher):
with launcher("Qwen/Qwen2-VL-7B-Instruct") as handle:
yield handle


@pytest.fixture(scope="module")
async def flash_qwen2(flash_qwen2_vl_handle):
await flash_qwen2_vl_handle.health(300)
return flash_qwen2_vl_handle.client


@pytest.mark.private
async def test_flash_qwen2_vl_simple(flash_qwen2, response_snapshot):
response = await flash_qwen2.chat(
max_tokens=100,
seed=42,
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"
},
},
{"type": "text", "text": "Describe this image."},
],
},
],
)

assert (
response.choices[0].message.content
== "The image depicts an anthropomorphic rabbit, wearing a futuristic spacesuit, in an extraterrestrial environment. The setting appears to be a red planet resembling Mars, with rugged terrain and rocky formations in the background. The moon is visible in the distant sky, adding to the lunar landscape."
)

assert response == response_snapshot


@pytest.mark.private
async def test_flash_qwen2_vl_simple_streaming(flash_qwen2, response_snapshot):
responses = await flash_qwen2.chat(
max_tokens=100,
seed=42,
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"
},
},
{"type": "text", "text": "Describe this image."},
],
},
],
stream=True,
)

count = 0
generated = ""
last_response = None
async for response in responses:
count += 1
generated += response.choices[0].delta.content
last_response = response

assert (
generated
== "The image depicts an anthropomorphic rabbit, wearing a futuristic spacesuit, in an extraterrestrial environment. The setting appears to be a red planet resembling Mars, with rugged terrain and rocky formations in the background. The moon is visible in the distant sky, adding to the lunar landscape."
)
assert count == 58
assert last_response == response_snapshot

0 comments on commit bd59f96

Please sign in to comment.