-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[CI/Build] Simplify OpenAI server setup in tests #5100
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
22c286a
Move common code inside `ServerRunner` and implement auto port selection
DarkLight1337 3b13e68
Rename `ServerRunner -> RemoteOpenAIServer`
DarkLight1337 67bf663
Merge branch 'upstream' into refactor-tests-5
DarkLight1337 1cdc3bc
Move embedding tests into its own file
DarkLight1337 99054b1
Update vision tests
DarkLight1337 f8914b7
Use `sys.executable` instead of `python3` alias
DarkLight1337 3f25d11
Simplify code
DarkLight1337 f74456e
Remove unnecessary GPU constraint
DarkLight1337 e927f4e
Merge branch 'upstream' into refactor-tests-5
DarkLight1337 0369c75
Fix wrong scope
DarkLight1337 d022069
Merge branch 'upstream' into refactor-tests-5
DarkLight1337 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,113 @@ | ||
import openai | ||
import pytest | ||
import ray | ||
|
||
from ..utils import VLLM_PATH, RemoteOpenAIServer | ||
|
||
EMBEDDING_MODEL_NAME = "intfloat/e5-mistral-7b-instruct" | ||
|
||
pytestmark = pytest.mark.openai | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def ray_ctx(): | ||
ray.init(runtime_env={"working_dir": VLLM_PATH}) | ||
yield | ||
ray.shutdown() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def embedding_server(ray_ctx): | ||
return RemoteOpenAIServer([ | ||
"--model", | ||
EMBEDDING_MODEL_NAME, | ||
# use half precision for speed and memory savings in CI environment | ||
"--dtype", | ||
"bfloat16", | ||
"--enforce-eager", | ||
"--max-model-len", | ||
"8192", | ||
"--enforce-eager", | ||
]) | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.fixture(scope="module") | ||
def embedding_client(embedding_server): | ||
return embedding_server.get_async_client() | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"model_name", | ||
[EMBEDDING_MODEL_NAME], | ||
) | ||
async def test_single_embedding(embedding_client: openai.AsyncOpenAI, | ||
model_name: str): | ||
input_texts = [ | ||
"The chef prepared a delicious meal.", | ||
] | ||
|
||
# test single embedding | ||
embeddings = await embedding_client.embeddings.create( | ||
model=model_name, | ||
input=input_texts, | ||
encoding_format="float", | ||
) | ||
assert embeddings.id is not None | ||
assert len(embeddings.data) == 1 | ||
assert len(embeddings.data[0].embedding) == 4096 | ||
assert embeddings.usage.completion_tokens == 0 | ||
assert embeddings.usage.prompt_tokens == 9 | ||
assert embeddings.usage.total_tokens == 9 | ||
|
||
# test using token IDs | ||
input_tokens = [1, 1, 1, 1, 1] | ||
embeddings = await embedding_client.embeddings.create( | ||
model=model_name, | ||
input=input_tokens, | ||
encoding_format="float", | ||
) | ||
assert embeddings.id is not None | ||
assert len(embeddings.data) == 1 | ||
assert len(embeddings.data[0].embedding) == 4096 | ||
assert embeddings.usage.completion_tokens == 0 | ||
assert embeddings.usage.prompt_tokens == 5 | ||
assert embeddings.usage.total_tokens == 5 | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"model_name", | ||
[EMBEDDING_MODEL_NAME], | ||
) | ||
async def test_batch_embedding(embedding_client: openai.AsyncOpenAI, | ||
model_name: str): | ||
# test List[str] | ||
input_texts = [ | ||
"The cat sat on the mat.", "A feline was resting on a rug.", | ||
"Stars twinkle brightly in the night sky." | ||
] | ||
embeddings = await embedding_client.embeddings.create( | ||
model=model_name, | ||
input=input_texts, | ||
encoding_format="float", | ||
) | ||
assert embeddings.id is not None | ||
assert len(embeddings.data) == 3 | ||
assert len(embeddings.data[0].embedding) == 4096 | ||
|
||
# test List[List[int]] | ||
input_tokens = [[4, 5, 7, 9, 20], [15, 29, 499], [24, 24, 24, 24, 24], | ||
[25, 32, 64, 77]] | ||
embeddings = await embedding_client.embeddings.create( | ||
model=model_name, | ||
input=input_tokens, | ||
encoding_format="float", | ||
) | ||
assert embeddings.id is not None | ||
assert len(embeddings.data) == 4 | ||
assert len(embeddings.data[0].embedding) == 4096 | ||
assert embeddings.usage.completion_tokens == 0 | ||
assert embeddings.usage.prompt_tokens == 17 | ||
assert embeddings.usage.total_tokens == 17 |
Oops, something went wrong.
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.
Do we want to test all 3 embeddings len? Not much to add and we have all convered.
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.
I only moved the tests in this PR. We can address other existing issues regarding those tests in a later PR.
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.
Actually, Can we also test the embeddings vectors? or is it not consistent?
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.
We will have to revamp the embeddings tests later anyway (currently it is using some unrecognized attributes, at least according to my IDE). Let's finish moving the tests first before updating them.
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.
Good point.