|
1 | | -# Disabled because it's broken. |
2 | | -# import pytest |
3 | | -# |
4 | | -# |
5 | | -# @pytest.fixture(scope="module") |
6 | | -# def flash_qwen2_vl_handle(launcher): |
7 | | -# with launcher("Qwen/Qwen2-VL-7B-Instruct") as handle: |
8 | | -# yield handle |
9 | | -# |
10 | | -# |
11 | | -# @pytest.fixture(scope="module") |
12 | | -# async def flash_qwen2(flash_qwen2_vl_handle): |
13 | | -# await flash_qwen2_vl_handle.health(300) |
14 | | -# return flash_qwen2_vl_handle.client |
15 | | -# |
16 | | -# |
17 | | -# @pytest.mark.private |
18 | | -# async def test_flash_qwen2_vl_simple(flash_qwen2, response_snapshot): |
19 | | -# response = await flash_qwen2.chat( |
20 | | -# max_tokens=100, |
21 | | -# seed=42, |
22 | | -# messages=[ |
23 | | -# { |
24 | | -# "role": "user", |
25 | | -# "content": [ |
26 | | -# { |
27 | | -# "type": "image_url", |
28 | | -# "image_url": { |
29 | | -# "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png" |
30 | | -# }, |
31 | | -# }, |
32 | | -# {"type": "text", "text": "Describe this image."}, |
33 | | -# ], |
34 | | -# }, |
35 | | -# ], |
36 | | -# ) |
37 | | -# |
38 | | -# assert ( |
39 | | -# response.choices[0].message.content |
40 | | -# == "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." |
41 | | -# ) |
42 | | -# |
43 | | -# assert response == response_snapshot |
44 | | -# |
45 | | -# |
46 | | -# @pytest.mark.private |
47 | | -# async def test_flash_qwen2_vl_simple_streaming(flash_qwen2, response_snapshot): |
48 | | -# responses = await flash_qwen2.chat( |
49 | | -# max_tokens=100, |
50 | | -# seed=42, |
51 | | -# messages=[ |
52 | | -# { |
53 | | -# "role": "user", |
54 | | -# "content": [ |
55 | | -# { |
56 | | -# "type": "image_url", |
57 | | -# "image_url": { |
58 | | -# "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png" |
59 | | -# }, |
60 | | -# }, |
61 | | -# {"type": "text", "text": "Describe this image."}, |
62 | | -# ], |
63 | | -# }, |
64 | | -# ], |
65 | | -# stream=True, |
66 | | -# ) |
67 | | -# |
68 | | -# count = 0 |
69 | | -# generated = "" |
70 | | -# last_response = None |
71 | | -# async for response in responses: |
72 | | -# count += 1 |
73 | | -# generated += response.choices[0].delta.content |
74 | | -# last_response = response |
75 | | -# |
76 | | -# assert ( |
77 | | -# generated |
78 | | -# == "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." |
79 | | -# ) |
80 | | -# assert count == 58 |
81 | | -# assert last_response == response_snapshot |
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +@pytest.fixture(scope="module") |
| 5 | +def flash_qwen2_vl_handle(launcher): |
| 6 | + with launcher("Qwen/Qwen2-VL-7B-Instruct") as handle: |
| 7 | + yield handle |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(scope="module") |
| 11 | +async def flash_qwen2(flash_qwen2_vl_handle): |
| 12 | + await flash_qwen2_vl_handle.health(300) |
| 13 | + return flash_qwen2_vl_handle.client |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.private |
| 17 | +async def test_flash_qwen2_vl_simple(flash_qwen2, response_snapshot): |
| 18 | + response = await flash_qwen2.chat( |
| 19 | + max_tokens=100, |
| 20 | + seed=42, |
| 21 | + messages=[ |
| 22 | + { |
| 23 | + "role": "user", |
| 24 | + "content": [ |
| 25 | + { |
| 26 | + "type": "image_url", |
| 27 | + "image_url": { |
| 28 | + "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png" |
| 29 | + }, |
| 30 | + }, |
| 31 | + {"type": "text", "text": "Describe this image."}, |
| 32 | + ], |
| 33 | + }, |
| 34 | + ], |
| 35 | + ) |
| 36 | + |
| 37 | + assert ( |
| 38 | + response.choices[0].message.content |
| 39 | + == "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." |
| 40 | + ) |
| 41 | + |
| 42 | + assert response == response_snapshot |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.private |
| 46 | +async def test_flash_qwen2_vl_simple_streaming(flash_qwen2, response_snapshot): |
| 47 | + responses = await flash_qwen2.chat( |
| 48 | + max_tokens=100, |
| 49 | + seed=42, |
| 50 | + messages=[ |
| 51 | + { |
| 52 | + "role": "user", |
| 53 | + "content": [ |
| 54 | + { |
| 55 | + "type": "image_url", |
| 56 | + "image_url": { |
| 57 | + "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png" |
| 58 | + }, |
| 59 | + }, |
| 60 | + {"type": "text", "text": "Describe this image."}, |
| 61 | + ], |
| 62 | + }, |
| 63 | + ], |
| 64 | + stream=True, |
| 65 | + ) |
| 66 | + |
| 67 | + count = 0 |
| 68 | + generated = "" |
| 69 | + last_response = None |
| 70 | + async for response in responses: |
| 71 | + count += 1 |
| 72 | + generated += response.choices[0].delta.content |
| 73 | + last_response = response |
| 74 | + |
| 75 | + assert ( |
| 76 | + generated |
| 77 | + == "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." |
| 78 | + ) |
| 79 | + assert count == 58 |
| 80 | + assert last_response == response_snapshot |
0 commit comments