47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def idefics_handle(launcher):
|
|
with launcher(
|
|
"HuggingFaceM4/idefics-9b-instruct", num_shard=2, dtype="float16"
|
|
) as handle:
|
|
yield handle
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
async def idefics(idefics_handle):
|
|
await idefics_handle.health(300)
|
|
return idefics_handle.client
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_idefics(idefics, response_snapshot):
|
|
response = await idefics.generate(
|
|
"User:![](https://huggingface.co/spaces/HuggingFaceM4/idefics_playground/resolve/6af279110440b7ba0c43f6a0be93b9926f062c42/example_images/chicken_on_money.png)Can you tell me a very short story based on the image?",
|
|
max_new_tokens=10,
|
|
decoder_input_details=True,
|
|
)
|
|
|
|
assert response.details.generated_tokens == 10
|
|
assert response == response_snapshot
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_idefics_load(idefics, generate_load, response_snapshot):
|
|
responses = await generate_load(
|
|
idefics,
|
|
"User:![](https://huggingface.co/spaces/HuggingFaceM4/idefics_playground/resolve/6af279110440b7ba0c43f6a0be93b9926f062c42/example_images/chicken_on_money.png)Can you tell me a very short story based on the image?",
|
|
max_new_tokens=10,
|
|
n=4,
|
|
)
|
|
|
|
generated_texts = [r.generated_text for r in responses]
|
|
|
|
assert len(generated_texts) == 4
|
|
assert generated_texts, all(
|
|
[text == generated_texts[0] for text in generated_texts]
|
|
)
|
|
|
|
assert responses == response_snapshot
|