[Bugfix][Frontend] Let pooling requests set padding (#51157)

Signed-off-by: Hert4 <ductransa01@gmail.com>
This commit is contained in:
Hert4
2026-08-27 11:06:20 +00:00
committed by GitHub
parent 42e7942ac9
commit 4a6a3272e8
4 changed files with 70 additions and 12 deletions
@@ -154,7 +154,13 @@ def run_siglip(seed: int):
)
print("Text embedding output:")
outputs = llm.embed(text, use_tqdm=False)
# SigLIP is trained with padding to a fixed length and no attention mask, so
# text embeddings only line up with image embeddings when they are padded.
outputs = llm.embed(
text,
tokenization_kwargs={"padding": "max_length"},
use_tqdm=False,
)
print_embeddings(outputs[0].outputs.embedding)
print("Image embedding output:")
@@ -35,6 +35,7 @@ def create_chat_embeddings(
encoding_format: Literal["base64", "float"] | NotGiven = NOT_GIVEN,
continue_final_message: bool = False,
add_special_tokens: bool = False,
padding: str | NotGiven = NOT_GIVEN,
) -> CreateEmbeddingResponse:
"""
Convenience function for accessing vLLM's Chat Embeddings API,
@@ -49,6 +50,7 @@ def create_chat_embeddings(
"encoding_format": encoding_format,
"continue_final_message": continue_final_message,
"add_special_tokens": add_special_tokens,
"padding": padding,
},
)
@@ -288,6 +290,8 @@ def run_siglip(client: OpenAI, model: str):
print("Image embedding output:", response.data[0].embedding)
# SigLIP is trained with padding to a fixed length and no attention mask, so
# text embeddings only line up with image embeddings when they are padded.
response = create_chat_embeddings(
client,
messages=[
@@ -300,6 +304,7 @@ def run_siglip(client: OpenAI, model: str):
],
model=model,
encoding_format="float",
padding="max_length",
)
print("Text embedding output:", response.data[0].embedding)