-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: End to End test for vision and audio #386
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e5c1498
update readme
wirthual 727da50
extract audio related code into audio utils
wirthual 7d0ace6
Merge branch 'main' of https://github.com/wirthual/infinity
wirthual eb62d3e
add test cases for audio and vision
wirthual 923b85e
revert docs v2
wirthual b48e808
revert docs v2
wirthual ef24535
fix test cases
wirthual a894760
add test for text only vision case
wirthual a592419
add text only case for audio
wirthual ad2d262
format code
wirthual 074105d
skip text test for not to see updated coverage
wirthual f2925c8
revert cli doc from main branch
wirthual File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import pytest | ||
import torch | ||
from asgi_lifespan import LifespanManager | ||
from fastapi import status | ||
from httpx import AsyncClient | ||
|
||
from infinity_emb import create_server | ||
from infinity_emb.args import EngineArgs | ||
from infinity_emb.primitives import Device, InferenceEngine | ||
|
||
PREFIX = "/v1_ct2" | ||
MODEL: str = pytest.DEFAULT_AUDIO_MODEL # type: ignore[assignment] | ||
batch_size = 32 if torch.cuda.is_available() else 8 | ||
|
||
app = create_server( | ||
url_prefix=PREFIX, | ||
engine_args_list=[ | ||
EngineArgs( | ||
model_name_or_path=MODEL, | ||
batch_size=batch_size, | ||
engine=InferenceEngine.torch, | ||
device=Device.auto if not torch.backends.mps.is_available() else Device.cpu, | ||
) | ||
], | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
async def client(): | ||
async with AsyncClient( | ||
app=app, base_url="http://test", timeout=20 | ||
) as client, LifespanManager(app): | ||
yield client | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_model_route(client): | ||
response = await client.get(f"{PREFIX}/models") | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
assert "data" in rdata | ||
assert rdata["data"][0].get("id", "") == MODEL | ||
assert isinstance(rdata["data"][0].get("stats"), dict) | ||
assert "audio_embed" in rdata["data"][0]["capabilities"] | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_audio_single(client): | ||
audio_url = "https://github.com/michaelfeil/infinity/raw/3b72eb7c14bae06e68ddd07c1f23fe0bf403f220/libs/infinity_emb/tests/data/audio/beep.wav" | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_audio", | ||
json={"model": MODEL, "input": audio_url}, | ||
) | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
assert "model" in rdata | ||
assert "usage" in rdata | ||
rdata_results = rdata["data"] | ||
assert rdata_results[0]["object"] == "embedding" | ||
assert len(rdata_results[0]["embedding"]) > 0 | ||
|
||
|
||
@pytest.mark.anyio | ||
@pytest.mark.skip("text only") | ||
async def test_audio_single_text_only(client): | ||
text = "a sound of a at" | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_audio", | ||
json={"model": MODEL, "input": text}, | ||
) | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
assert "model" in rdata | ||
assert "usage" in rdata | ||
rdata_results = rdata["data"] | ||
assert rdata_results[0]["object"] == "embedding" | ||
assert len(rdata_results[0]["embedding"]) > 0 | ||
|
||
|
||
@pytest.mark.anyio | ||
@pytest.mark.parametrize("no_of_audios", [1, 5, 10]) | ||
async def test_audio_multiple(client, no_of_audios): | ||
audio_urls = [ | ||
"https://github.com/michaelfeil/infinity/raw/3b72eb7c14bae06e68ddd07c1f23fe0bf403f220/libs/infinity_emb/tests/data/audio/beep.wav" | ||
] * no_of_audios | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_audio", | ||
json={"model": MODEL, "input": audio_urls}, | ||
) | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
rdata_results = rdata["data"] | ||
assert len(rdata_results) == no_of_audios | ||
assert "model" in rdata | ||
assert "usage" in rdata | ||
assert rdata_results[0]["object"] == "embedding" | ||
assert len(rdata_results[0]["embedding"]) > 0 | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_audio_fail(client): | ||
audio_url = "https://www.google.com/404" | ||
wirthual marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_audio", | ||
json={"model": MODEL, "input": audio_url}, | ||
) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_audio_empty(client): | ||
audio_url_empty = [] | ||
|
||
response_empty = await client.post( | ||
f"{PREFIX}/embeddings_audio", | ||
json={"model": MODEL, "input": audio_url_empty}, | ||
) | ||
assert response_empty.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY |
121 changes: 121 additions & 0 deletions
121
libs/infinity_emb/tests/end_to_end/test_torch_vision.py
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,121 @@ | ||
import pytest | ||
import torch | ||
from asgi_lifespan import LifespanManager | ||
from fastapi import status | ||
from httpx import AsyncClient | ||
|
||
from infinity_emb import create_server | ||
from infinity_emb.args import EngineArgs | ||
from infinity_emb.primitives import Device, InferenceEngine | ||
|
||
PREFIX = "/v1_ct2" | ||
MODEL: str = pytest.DEFAULT_VISION_MODEL # type: ignore[assignment] | ||
batch_size = 32 if torch.cuda.is_available() else 8 | ||
|
||
app = create_server( | ||
url_prefix=PREFIX, | ||
engine_args_list=[ | ||
EngineArgs( | ||
model_name_or_path=MODEL, | ||
batch_size=batch_size, | ||
engine=InferenceEngine.torch, | ||
device=Device.auto if not torch.backends.mps.is_available() else Device.cpu, | ||
) | ||
], | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
async def client(): | ||
async with AsyncClient( | ||
app=app, base_url="http://test", timeout=20 | ||
) as client, LifespanManager(app): | ||
yield client | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_model_route(client): | ||
response = await client.get(f"{PREFIX}/models") | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
assert "data" in rdata | ||
assert rdata["data"][0].get("id", "") == MODEL | ||
assert isinstance(rdata["data"][0].get("stats"), dict) | ||
assert "image_embed" in rdata["data"][0]["capabilities"] | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_vision_single(client): | ||
image_url = "http://images.cocodataset.org/val2017/000000039769.jpg" | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_image", | ||
json={"model": MODEL, "input": image_url}, | ||
) | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
assert "model" in rdata | ||
assert "usage" in rdata | ||
rdata_results = rdata["data"] | ||
assert rdata_results[0]["object"] == "embedding" | ||
assert len(rdata_results[0]["embedding"]) > 0 | ||
|
||
|
||
@pytest.mark.anyio | ||
@pytest.mark.skip("text only") | ||
async def test_vision_single_text_only(client): | ||
text = "a image of a cat" | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_image", | ||
json={"model": MODEL, "input": text}, | ||
) | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
assert "model" in rdata | ||
assert "usage" in rdata | ||
rdata_results = rdata["data"] | ||
assert rdata_results[0]["object"] == "embedding" | ||
assert len(rdata_results[0]["embedding"]) > 0 | ||
|
||
|
||
@pytest.mark.anyio | ||
@pytest.mark.parametrize("no_of_images", [1, 5, 10]) | ||
async def test_vision_multiple(client, no_of_images): | ||
image_urls = [ | ||
"http://images.cocodataset.org/val2017/000000039769.jpg" | ||
] * no_of_images | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_image", | ||
json={"model": MODEL, "input": image_urls}, | ||
) | ||
assert response.status_code == 200 | ||
rdata = response.json() | ||
rdata_results = rdata["data"] | ||
assert len(rdata_results) == no_of_images | ||
assert "model" in rdata | ||
assert "usage" in rdata | ||
assert rdata_results[0]["object"] == "embedding" | ||
assert len(rdata_results[0]["embedding"]) > 0 | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_vision_fail(client): | ||
image_url = "https://www.google.com/404" | ||
|
||
response = await client.post( | ||
f"{PREFIX}/embeddings_image", | ||
json={"model": MODEL, "input": image_url}, | ||
) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_vision_empty(client): | ||
image_url_empty = [] | ||
response = await client.post( | ||
f"{PREFIX}/embeddings_image", | ||
json={"model": MODEL, "input": image_url_empty}, | ||
) | ||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice spot