-
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.
Improve vlm support (add idefics3 support) (#2437)
* feat: expand vlm support and add image token logic and tests * fix: avoid unused perceiver config * feat: integrate image tokens into inputs embeds * feat: add simple idefics3 test * feat: update docs, image token logic and weight names * fix: improve image processing * feat: improve prefix for idefics3 * fix: bump idefics3 tests and snapshots * fix: improve text model loading * feat: consolidate changes with existing vlms and add support and test for smolvlm * fix: create new idefic3 file, simplify logic and adjust llama weight loading * fix: lint with ruff * fix: clean up idefics 3 and improve prefix handling * fix: improve typing * fix: improve prompt_split_image with ref to original impl * fix: adjust ruff lints and small refactors * fix: adjust FlashLlamaModel prefix logic
- Loading branch information
Showing
15 changed files
with
988 additions
and
43 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
67 changes: 67 additions & 0 deletions
67
...gration-tests/models/__snapshots__/test_idefics3/test_flash_idefics3_next_simple_url.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,67 @@ | ||
{ | ||
"details": { | ||
"best_of_sequences": null, | ||
"finish_reason": "eos_token", | ||
"generated_tokens": 9, | ||
"prefill": [], | ||
"seed": null, | ||
"tokens": [ | ||
{ | ||
"id": 2684, | ||
"logprob": -0.24902344, | ||
"special": false, | ||
"text": " There" | ||
}, | ||
{ | ||
"id": 374, | ||
"logprob": -0.0703125, | ||
"special": false, | ||
"text": " is" | ||
}, | ||
{ | ||
"id": 264, | ||
"logprob": -0.23535156, | ||
"special": false, | ||
"text": " a" | ||
}, | ||
{ | ||
"id": 35372, | ||
"logprob": -0.125, | ||
"special": false, | ||
"text": " statue" | ||
}, | ||
{ | ||
"id": 304, | ||
"logprob": -0.30273438, | ||
"special": false, | ||
"text": " in" | ||
}, | ||
{ | ||
"id": 279, | ||
"logprob": -0.20507812, | ||
"special": false, | ||
"text": " the" | ||
}, | ||
{ | ||
"id": 2217, | ||
"logprob": -0.076171875, | ||
"special": false, | ||
"text": " image" | ||
}, | ||
{ | ||
"id": 13, | ||
"logprob": -0.053710938, | ||
"special": false, | ||
"text": "." | ||
}, | ||
{ | ||
"id": 128258, | ||
"logprob": -0.011352539, | ||
"special": true, | ||
"text": "<end_of_utterance>" | ||
} | ||
], | ||
"top_tokens": null | ||
}, | ||
"generated_text": " There is a statue in the image." | ||
} |
61 changes: 61 additions & 0 deletions
61
integration-tests/models/__snapshots__/test_smolvlm/test_flash_smolvlm_next_simple_url.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,61 @@ | ||
{ | ||
"details": { | ||
"best_of_sequences": null, | ||
"finish_reason": "eos_token", | ||
"generated_tokens": 8, | ||
"prefill": [], | ||
"seed": null, | ||
"tokens": [ | ||
{ | ||
"id": 330, | ||
"logprob": -0.118652344, | ||
"special": false, | ||
"text": " A" | ||
}, | ||
{ | ||
"id": 11426, | ||
"logprob": -0.28320312, | ||
"special": false, | ||
"text": " bee" | ||
}, | ||
{ | ||
"id": 335, | ||
"logprob": -0.95703125, | ||
"special": false, | ||
"text": " on" | ||
}, | ||
{ | ||
"id": 253, | ||
"logprob": -0.06982422, | ||
"special": false, | ||
"text": " a" | ||
}, | ||
{ | ||
"id": 11986, | ||
"logprob": -0.49414062, | ||
"special": false, | ||
"text": " pink" | ||
}, | ||
{ | ||
"id": 8525, | ||
"logprob": -0.07763672, | ||
"special": false, | ||
"text": " flower" | ||
}, | ||
{ | ||
"id": 30, | ||
"logprob": -1.0703125, | ||
"special": false, | ||
"text": "." | ||
}, | ||
{ | ||
"id": 49154, | ||
"logprob": -0.092285156, | ||
"special": true, | ||
"text": "<end_of_utterance>" | ||
} | ||
], | ||
"top_tokens": null | ||
}, | ||
"generated_text": " A bee on a pink flower." | ||
} |
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,31 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def flash_idefics3_next_handle(launcher): | ||
with launcher("HuggingFaceM4/Idefics3-8B-Llama3") as handle: | ||
yield handle | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def flash_idefics3_next(flash_idefics3_next_handle): | ||
await flash_idefics3_next_handle.health(300) | ||
return flash_idefics3_next_handle.client | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.private | ||
async def test_flash_idefics3_next_simple_url(flash_idefics3_next, response_snapshot): | ||
ny_skyline = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" | ||
query = "What is in this image?" | ||
response = await flash_idefics3_next.generate( | ||
f"<|begin_of_text|><|begin_of_text|>User:![]({ny_skyline}){query}<end_of_utterance>\nAssistant:", | ||
max_new_tokens=10, | ||
seed=1337, | ||
) | ||
print(response) | ||
assert ( | ||
response.generated_text == " There is a statue in the image." | ||
), f"{repr(response.generated_text)}" | ||
assert response.details.generated_tokens == 9 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def flash_smolvlm_next_handle(launcher): | ||
with launcher("HuggingFaceTB/SmolVLM-Instruct") as handle: | ||
yield handle | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def flash_smolvlm_next(flash_smolvlm_next_handle): | ||
await flash_smolvlm_next_handle.health(300) | ||
return flash_smolvlm_next_handle.client | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.private | ||
async def test_flash_smolvlm_next_simple_url(flash_smolvlm_next, response_snapshot): | ||
ny_skyline = "https://huggingface.co/spaces/merve/chameleon-7b/resolve/main/bee.jpg" | ||
query = "What is in this image?" | ||
response = await flash_smolvlm_next.generate( | ||
f"<|begin_of_text|><|begin_of_text|>User:![]({ny_skyline}){query}<end_of_utterance>\nAssistant:", | ||
max_new_tokens=10, | ||
seed=1337, | ||
) | ||
print(response) | ||
assert ( | ||
response.generated_text == " A bee on a pink flower." | ||
), f"{repr(response.generated_text)}" | ||
assert response.details.generated_tokens == 8 | ||
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
Oops, something went wrong.