[model-gateway]: add gRPC router embeddings endpoint implementation (#15273)
This commit is contained in:
@@ -455,10 +455,22 @@ class SGLangSchedulerServicer(sglang_scheduler_pb2_grpc.SglangSchedulerServicer)
|
||||
input_text = grpc_req.tokenized.original_text
|
||||
input_ids = list(grpc_req.tokenized.input_ids)
|
||||
|
||||
# Convert sampling params
|
||||
sampling_params = self._convert_sampling_params(grpc_req.sampling_params)
|
||||
|
||||
# For embedding requests, max_new_tokens should be 0.
|
||||
# The scheduler logic expects an integer, not None.
|
||||
sampling_params.max_new_tokens = 0
|
||||
|
||||
sampling_params.normalize(tokenizer=None)
|
||||
|
||||
return TokenizedEmbeddingReqInput(
|
||||
rid=grpc_req.request_id,
|
||||
input_text=input_text,
|
||||
input_ids=input_ids,
|
||||
image_inputs={"mm_items": []},
|
||||
token_type_ids=list(grpc_req.token_type_ids),
|
||||
sampling_params=sampling_params,
|
||||
)
|
||||
|
||||
def _convert_sampling_params(
|
||||
|
||||
@@ -688,7 +688,9 @@ class GrpcRequestManager:
|
||||
batch_out.prompt_tokens[i] if batch_out.prompt_tokens else 0
|
||||
),
|
||||
"finish_reason": (
|
||||
batch_out.finish_reason[i] if batch_out.finish_reason else None
|
||||
batch_out.finished_reasons[i]
|
||||
if batch_out.finished_reasons
|
||||
else None
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -1710,9 +1710,14 @@ class Scheduler(
|
||||
if recv_req.image_inputs is not None:
|
||||
image_inputs = self._get_multimodal_inputs(recv_req.image_inputs)
|
||||
# Expand a single image token into multiple dummy tokens for receiving image embeddings
|
||||
req.origin_input_ids = self.pad_input_ids_func(
|
||||
req.origin_input_ids, image_inputs
|
||||
)
|
||||
# The `pad_input_ids_func` is model-specific and may be None for
|
||||
# embedding models or models not requiring special padding.
|
||||
# If None, `req.origin_input_ids` is expected to be correctly populated already.
|
||||
if self.pad_input_ids_func:
|
||||
req.origin_input_ids = self.pad_input_ids_func(
|
||||
req.origin_input_ids, image_inputs
|
||||
)
|
||||
|
||||
req.extend_image_inputs(image_inputs)
|
||||
|
||||
if len(req.origin_input_ids) >= self.max_req_input_len:
|
||||
|
||||
Reference in New Issue
Block a user