Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
0b769992
Unverified
Commit
0b769992
authored
Aug 26, 2024
by
ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟
Committed by
GitHub
Aug 26, 2024
Browse files
[Bugfix]: Use float32 for base64 embedding (#7855)
Signed-off-by:
Hollow Man
<
hollowman@opensuse.org
>
parent
1856aff4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
3 deletions
+13
-3
examples/openai_embedding_client.py
examples/openai_embedding_client.py
+0
-1
tests/entrypoints/openai/test_embedding.py
tests/entrypoints/openai/test_embedding.py
+10
-1
vllm/entrypoints/openai/serving_embedding.py
vllm/entrypoints/openai/serving_embedding.py
+3
-1
No files found.
examples/openai_embedding_client.py
View file @
0b769992
...
...
@@ -19,7 +19,6 @@ responses = client.embeddings.create(
"The best thing about vLLM is that it supports many different models"
],
model
=
model
,
encoding_format
=
"float"
,
)
for
data
in
responses
.
data
:
...
...
tests/entrypoints/openai/test_embedding.py
View file @
0b769992
...
...
@@ -128,9 +128,18 @@ async def test_batch_base64_embedding(embedding_client: openai.AsyncOpenAI,
for
data
in
responses_base64
.
data
:
decoded_responses_base64_data
.
append
(
np
.
frombuffer
(
base64
.
b64decode
(
data
.
embedding
),
dtype
=
"float"
).
tolist
())
dtype
=
"float
32
"
).
tolist
())
assert
responses_float
.
data
[
0
].
embedding
==
decoded_responses_base64_data
[
0
]
assert
responses_float
.
data
[
1
].
embedding
==
decoded_responses_base64_data
[
1
]
# Default response is float32 decoded from base64 by OpenAI Client
responses_default
=
await
embedding_client
.
embeddings
.
create
(
input
=
input_texts
,
model
=
model_name
)
assert
responses_float
.
data
[
0
].
embedding
==
responses_default
.
data
[
0
].
embedding
assert
responses_float
.
data
[
1
].
embedding
==
responses_default
.
data
[
1
].
embedding
vllm/entrypoints/openai/serving_embedding.py
View file @
0b769992
...
...
@@ -31,7 +31,9 @@ def _get_embedding(
if
encoding_format
==
"float"
:
return
output
.
embedding
elif
encoding_format
==
"base64"
:
embedding_bytes
=
np
.
array
(
output
.
embedding
).
tobytes
()
# Force to use float32 for base64 encoding
# to match the OpenAI python client behavior
embedding_bytes
=
np
.
array
(
output
.
embedding
,
dtype
=
"float32"
).
tobytes
()
return
base64
.
b64encode
(
embedding_bytes
).
decode
(
"utf-8"
)
assert_never
(
encoding_format
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment