-
Notifications
You must be signed in to change notification settings - Fork 177
Colbert #456
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
Merged
Merged
Colbert #456
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
052378f
inital commit
michaelfeil b11ea98
fmt
michaelfeil a873b21
lint
michaelfeil 791996e
Merge branch 'main' into model-parallel-device-interface
michaelfeil e4bb6a4
fix: typos, more docs
michaelfeil c4958e0
colbert v1
michaelfeil 7d5ce83
Merge branch 'main' into colbert
michaelfeil 642d879
Merge branch 'main' into colbert
michaelfeil 850736c
Merge branch 'main' into colbert
michaelfeil e6fe213
fix: usage of uvloop
michaelfeil 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
75 changes: 75 additions & 0 deletions
75
libs/infinity_emb/tests/end_to_end/test_sentence_transformers_colbert.py
This file contains hidden or 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,75 @@ | ||
| import pytest | ||
| import torch | ||
| from asgi_lifespan import LifespanManager | ||
| from httpx import AsyncClient | ||
| import numpy as np | ||
| from infinity_emb import create_server | ||
| from infinity_emb.args import EngineArgs | ||
| from infinity_emb.primitives import Device, InferenceEngine | ||
|
|
||
| PREFIX = "/v1_sentence_transformers_colbert" | ||
| MODEL: str = pytest.DEFAULT_COLBERT_MODEL # type: ignore[assignment] | ||
| batch_size = 64 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 | ||
| # def model_base() -> SentenceTransformer: | ||
| # # model = SentenceTransformer(MODEL) | ||
| # # if model.device == "cuda": | ||
| # # model = model.to(torch.float16) | ||
| # # return model | ||
| # model | ||
michaelfeil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def client(): | ||
| async with AsyncClient(app=app, base_url="http://test", timeout=20) as client, LifespanManager( | ||
| app | ||
| ): | ||
| yield client | ||
|
|
||
|
|
||
| # def test_load_model(model_base): | ||
| # # this makes sure that the error below is not based on a slow download | ||
| # # or internal pytorch errors | ||
| # model_base.encode(["This is a test sentence."]) | ||
michaelfeil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @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) | ||
|
|
||
michaelfeil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_embedding(client): | ||
| response = await client.post( | ||
| f"{PREFIX}/embeddings", json=dict(input=["This is a test", "hi", "hi"], model=MODEL) | ||
| ) | ||
| assert response.status_code == 200 | ||
| rdata = response.json() | ||
| assert "data" in rdata | ||
| assert len(rdata["data"]) == 3 | ||
| # TODO: Check if start and end tokens should be embedded | ||
| # TODO: Check if normalization is applied or should be applied? | ||
| assert len(rdata["data"][0]["embedding"]) == 6 # This is a test -> 6 tokens | ||
| assert len(rdata["data"][1]["embedding"]) == 3 # hi -> 3 tokens | ||
| np.testing.assert_allclose( | ||
| rdata["data"][1]["embedding"], rdata["data"][2]["embedding"], atol=5e-3 | ||
| ) | ||
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.
logic: redundant check for not self.mode_colbert since it's already in an if not self.mode_colbert block