ray-embedding 0.9.8__tar.gz → 0.9.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ray-embedding might be problematic. Click here for more details.

@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ray-embedding
3
- Version: 0.9.8
3
+ Version: 0.9.9
4
4
  Summary: Deploy SentenceTransformers embedding models to a ray cluster
5
5
  Author: Crispin Almodovar
6
- Author-email: crispin.almodovar@docorto.ai
6
+ Author-email:
7
7
  Classifier: Programming Language :: Python :: 3
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Operating System :: OS Independent
@@ -24,11 +24,5 @@ A tool for deploying SentenceTransformers models to a ray cluster.
24
24
  - onnx-cpu
25
25
  - openvino-cpu
26
26
  - fastembed-onnx-cpu
27
-
28
- - spot instances
29
- - grpc
30
27
 
31
- ### To build:
32
- - python -m build
33
- - twine upload dist/*
34
28
 
@@ -12,11 +12,5 @@ A tool for deploying SentenceTransformers models to a ray cluster.
12
12
  - onnx-cpu
13
13
  - openvino-cpu
14
14
  - fastembed-onnx-cpu
15
-
16
- - spot instances
17
- - grpc
18
15
 
19
- ### To build:
20
- - python -m build
21
- - twine upload dist/*
22
16
 
@@ -29,7 +29,7 @@ def deploy_model(args: Dict[str, Any]) -> Application:
29
29
  elif torch_dtype == "float32":
30
30
  model_kwargs["torch_dtype"] = torch.float32
31
31
  else:
32
- del model_kwargs["torch_dtype"] # Remove
32
+ raise ValueError(f"Invalid torch_dtype: '{torch_dtype}'")
33
33
 
34
34
  deployment = EmbeddingModel.options(name=deployment_name).bind(model=model,
35
35
  backend=backend,
@@ -78,40 +78,48 @@ class EmbeddingModel:
78
78
  async def __create_embeddings_batch(self, requests_batch: List[EmbeddingRequest]) -> List[EmbeddingResponse]:
79
79
  self_0 = self[0] if isinstance(self, list) else self
80
80
 
81
- # Batch the text inputs
82
- inputs = []
83
- truncate_dims = []
81
+ inputs, truncate_dims, num_inputs_list = [], [], []
84
82
  for request in requests_batch:
85
- if isinstance(request.input, str):
86
- request.input = [request.input]
87
- inputs.extend(request.input)
83
+ input_text = request.input if isinstance(request.input, list) else [request.input] # Can be a list of texts
84
+ inputs.extend(input_text)
85
+ num_inputs_list.append(len(input_text))
88
86
  truncate_dims.append(request.dimensions or self_0.matryoshka_dim)
89
87
 
90
- # Compute embeddings for the batch of text inputs
91
88
  embeddings = self_0.embedding_model.encode(
92
89
  inputs, convert_to_tensor=True, normalize_embeddings=True, show_progress_bar=False,
93
90
  ).to(self_0.torch_device)
94
91
 
95
- # Truncate the embeddings; note that the truncate_dim can be different for each request
96
- # so we need to this step one by one
97
- results = []
98
- ix = 0
99
- for truncate_dim, request in zip(truncate_dims, requests_batch):
100
- num_inputs = len(request.input)
101
- batch_embeddings = embeddings[ix: ix + num_inputs]
102
- ix += num_inputs
103
- if truncate_dim is not None:
104
- batch_embeddings = batch_embeddings[:, :truncate_dim]
105
- batch_embeddings = batch_embeddings / torch.norm(batch_embeddings, dim=1, keepdim=True)
106
-
107
- batch_embeddings = batch_embeddings.cpu().tolist()
108
- response_data = [
109
- {"index": emb_ix, "embedding": emb}
110
- for emb_ix, emb in enumerate(batch_embeddings)
111
- ]
112
- results.append(EmbeddingResponse(object="list", data=response_data, model=request.model))
113
-
114
- return results
92
+ model_name = requests_batch[0].model
93
+ truncate_needed = any(dim is not None for dim in truncate_dims)
94
+ results_batch, ix = [], 0
95
+
96
+ if truncate_needed:
97
+ for truncate_dim, num_inputs in zip(truncate_dims, num_inputs_list):
98
+ batch_embeddings = embeddings[ix: ix + num_inputs]
99
+ ix += num_inputs
100
+
101
+ if truncate_dim is not None:
102
+ # Truncate and normalize using pytorch (faster)
103
+ batch_embeddings = batch_embeddings[:, :truncate_dim]
104
+ batch_embeddings = batch_embeddings / torch.norm(batch_embeddings, dim=1, keepdim=True)
105
+
106
+ batch_embeddings = batch_embeddings.cpu().tolist()
107
+ response_data = [
108
+ {"index": emb_ix, "embedding": emb} for emb_ix, emb in enumerate(batch_embeddings)
109
+ ]
110
+ results_batch.append(EmbeddingResponse(object="list", data=response_data, model=model_name))
111
+ else:
112
+ embeddings_list = embeddings.cpu().tolist() # Move everything to CPU
113
+ for num_inputs in num_inputs_list:
114
+ batch_embeddings = embeddings_list[ix: ix + num_inputs]
115
+ ix += num_inputs
116
+
117
+ response_data = [
118
+ {"index": emb_ix, "embedding": emb} for emb_ix, emb in enumerate(batch_embeddings)
119
+ ]
120
+ results_batch.append(EmbeddingResponse(object="list", data=response_data, model=model_name))
121
+
122
+ return results_batch
115
123
 
116
124
  @web_api.get("/v1/models")
117
125
  async def list_models(self):
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ray-embedding
3
- Version: 0.9.8
3
+ Version: 0.9.9
4
4
  Summary: Deploy SentenceTransformers embedding models to a ray cluster
5
5
  Author: Crispin Almodovar
6
- Author-email: crispin.almodovar@docorto.ai
6
+ Author-email:
7
7
  Classifier: Programming Language :: Python :: 3
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Operating System :: OS Independent
@@ -24,11 +24,5 @@ A tool for deploying SentenceTransformers models to a ray cluster.
24
24
  - onnx-cpu
25
25
  - openvino-cpu
26
26
  - fastembed-onnx-cpu
27
-
28
- - spot instances
29
- - grpc
30
27
 
31
- ### To build:
32
- - python -m build
33
- - twine upload dist/*
34
28
 
@@ -1,8 +1,8 @@
1
1
  [metadata]
2
2
  name = ray-embedding
3
- version = 0.9.8
3
+ version = 0.9.9
4
4
  author = Crispin Almodovar
5
- author_email = crispin.almodovar@docorto.ai
5
+ author_email =
6
6
  description = Deploy SentenceTransformers embedding models to a ray cluster
7
7
  long_description = file: README.md
8
8
  long_description_content_type = text/markdown