mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-23 11:30:37 +00:00
community[patch]: Update OpenVINO embedding and reranker to support static input shape (#22171)
It can help to deploy embedding models on NPU device
This commit is contained in:
@@ -210,9 +210,20 @@ class OpenVINOEmbeddings(BaseModel, Embeddings):
|
||||
0, len(sentences), batch_size, desc="Batches", disable=not show_progress_bar
|
||||
):
|
||||
sentences_batch = sentences_sorted[start_index : start_index + batch_size]
|
||||
features = self.tokenizer(
|
||||
sentences_batch, padding=True, truncation=True, return_tensors="pt"
|
||||
)
|
||||
|
||||
length = self.ov_model.request.inputs[0].get_partial_shape()[1]
|
||||
if length.is_dynamic:
|
||||
features = self.tokenizer(
|
||||
sentences_batch, padding=True, truncation=True, return_tensors="pt"
|
||||
)
|
||||
else:
|
||||
features = self.tokenizer(
|
||||
sentences_batch,
|
||||
padding="max_length",
|
||||
max_length=length.get_length(),
|
||||
truncation=True,
|
||||
return_tensors="pt",
|
||||
)
|
||||
|
||||
out_features = self.ov_model(**features)
|
||||
if mean_pooling:
|
||||
|
Reference in New Issue
Block a user