Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions components/src/dynamo/vllm/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Any, AsyncIterator, Dict, Final, Generic, Optional, TypeVar

import torch
from vllm import PoolingParams
from vllm.config import ModelConfig, VllmConfig
from vllm.inputs import EmbedsPrompt, TextPrompt, TokensPrompt
from vllm.lora.request import LoRARequest
Expand Down Expand Up @@ -2950,10 +2951,6 @@ async def generate(
``dimensions`` truncation so the byte count matches the requested
dimensionality.
"""
# Lazy import to avoid pulling PoolingParams into handlers.py at module
# load time for non-embedding workers.
from vllm import PoolingParams

model_name = request.get("model") or self.config.served_model_name or ""
input_field = request.get("input")
if input_field is None:
Expand Down Expand Up @@ -2985,7 +2982,16 @@ async def generate(
"expected 'float' or 'base64'"
)

pooling_params = PoolingParams()
# Request the pooled sentence embedding. With no task, vLLM's
# encode() resolves to per-token output (the full ``n_tokens x
# hidden`` hidden-state matrix), so the OpenAI ``/v1/embeddings``
# response ends up with the wrong shape (dim scales with input
# length) instead of one vector per input. ``task="embed"`` selects
# the pooled embedding and runs the model's configured pooler
# (normalization included for models like Qwen3-Embedding), matching
# vLLM's own embedding server. ``use_activation`` is intentionally
# left at the pooler default so per-model behaviour isn't overridden.
pooling_params = PoolingParams(task="embed")
Comment thread
tzulingk marked this conversation as resolved.
Resolved
# Use the per-request context id (same as the chat/completion paths
# in this file) so concurrent embeddings never collide inside
# ``AsyncLLM``. ``context.trace_id`` is a distributed-trace id
Expand Down
Loading