-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve qwen2-vl startup (#2802)
* feat: tokenize each request individually and increase warmup image size * feat: adjust rotary embed and avoid cuda graphs of size 2 and smaller * fix: address image resize and rebase changes * feat: update to run qwen2-vl tests * fix: tweak param types
- Loading branch information
Showing
11 changed files
with
173 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ion-tests/models/__snapshots__/test_flash_qwen2_vl_warmup/test_flash_qwen2_vl_simple.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"choices": [ | ||
{ | ||
"finish_reason": "stop", | ||
"index": 0, | ||
"logprobs": null, | ||
"message": { | ||
"content": "The correct answer is: blue", | ||
"name": null, | ||
"role": "assistant", | ||
"tool_calls": null | ||
}, | ||
"usage": null | ||
} | ||
], | ||
"created": 1733445131, | ||
"id": "", | ||
"model": "Qwen/Qwen2-VL-2B-Instruct", | ||
"object": "chat.completion", | ||
"system_fingerprint": "2.4.2-dev0-native", | ||
"usage": { | ||
"completion_tokens": 7, | ||
"prompt_tokens": 27, | ||
"total_tokens": 34 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def flash_qwen2_vl_handle(launcher): | ||
with launcher( | ||
"Qwen/Qwen2-VL-2B-Instruct", | ||
max_input_length=40, | ||
max_batch_prefill_tokens=50, | ||
max_total_tokens=51, | ||
) 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=20, | ||
seed=42, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{"type": "text", "text": "What is the color of the sky?"}, | ||
], | ||
}, | ||
], | ||
) | ||
|
||
assert response.choices[0].message.content == "The correct answer is: blue" | ||
|
||
assert response == response_snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters