ray-embedding 0.9.7__py3-none-any.whl → 0.9.9__py3-none-any.whl

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.

ray_embedding/deploy.py CHANGED
@@ -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,
@@ -69,7 +69,6 @@ class EmbeddingModel:
69
69
  assert request.model == self.served_model_name, (
70
70
  f"Model '{request.model}' is not supported. Use '{self.served_model_name}' instead."
71
71
  )
72
- request.dimensions = request.dimensions or self.matryoshka_dim
73
72
  return await self.__create_embeddings_batch(request)
74
73
  except Exception as e:
75
74
  self.logger.error(e)
@@ -77,40 +76,50 @@ class EmbeddingModel:
77
76
 
78
77
  @serve.batch(max_batch_size=8, batch_wait_timeout_s=0.25)
79
78
  async def __create_embeddings_batch(self, requests_batch: List[EmbeddingRequest]) -> List[EmbeddingResponse]:
80
- # Batch the text inputs
81
- inputs = []
82
- truncate_dims = []
79
+ self_0 = self[0] if isinstance(self, list) else self
80
+
81
+ inputs, truncate_dims, num_inputs_list = [], [], []
83
82
  for request in requests_batch:
84
- if isinstance(request.input, str):
85
- request.input = [request.input]
86
- inputs.extend(request.input)
87
- truncate_dims.append(request.dimensions)
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))
86
+ truncate_dims.append(request.dimensions or self_0.matryoshka_dim)
88
87
 
89
- # Compute embeddings for the batch of text inputs
90
- embeddings = self.embedding_model.encode(
88
+ embeddings = self_0.embedding_model.encode(
91
89
  inputs, convert_to_tensor=True, normalize_embeddings=True, show_progress_bar=False,
92
- ).to(self.torch_device)
93
-
94
- # Truncate the embeddings; note that the truncate_dim can be different for each request
95
- # so we need to this step one by one
96
- results = []
97
- ix = 0
98
- for truncate_dim, request in zip(truncate_dims, requests_batch):
99
- num_inputs = len(request.input)
100
- batch_embeddings = embeddings[ix: ix + num_inputs]
101
- ix += num_inputs
102
- if truncate_dim is not None:
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}
109
- for emb_ix, emb in enumerate(batch_embeddings)
110
- ]
111
- results.append(EmbeddingResponse(object="list", data=response_data, model=request.model))
112
-
113
- return results
90
+ ).to(self_0.torch_device)
91
+
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
114
123
 
115
124
  @web_api.get("/v1/models")
116
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.7
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
 
@@ -0,0 +1,8 @@
1
+ ray_embedding/__init__.py,sha256=OYJT0rVaaGzY613JqgfktsCgroDnBkGOHxR2FE9UtRU,49
2
+ ray_embedding/deploy.py,sha256=oqOhMxS5UyZ4oGhfpL7kqvrxLO8QW41sF_FHbNSJe-w,1858
3
+ ray_embedding/dto.py,sha256=e91ejZbM_NB9WTjF1YnfuV71cajYIh0vOX8oV_g2OwM,595
4
+ ray_embedding/embedding_model.py,sha256=PBBuntLrJiwstD9AbD2n_ElU7rYZAYK0fMSESkMsFTU,5797
5
+ ray_embedding-0.9.9.dist-info/METADATA,sha256=XRtQFNU7mhhSXFZF1YMyIII3zW9PfTXkiUN6AEHVAkA,604
6
+ ray_embedding-0.9.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
7
+ ray_embedding-0.9.9.dist-info/top_level.txt,sha256=ziCblpJq1YsrryshFqxTRuRMgNuO1_tgvAAkGShATNA,14
8
+ ray_embedding-0.9.9.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- ray_embedding/__init__.py,sha256=OYJT0rVaaGzY613JqgfktsCgroDnBkGOHxR2FE9UtRU,49
2
- ray_embedding/deploy.py,sha256=YD_udSm13QbFPgSAkCrTQso15DmtIn0QEhErOFNg7jM,1841
3
- ray_embedding/dto.py,sha256=e91ejZbM_NB9WTjF1YnfuV71cajYIh0vOX8oV_g2OwM,595
4
- ray_embedding/embedding_model.py,sha256=jliy8iRGEbYBfhhnyopVq2fNj0naPsNpvzEaIcNYEe0,5194
5
- ray_embedding-0.9.7.dist-info/METADATA,sha256=dxTq3Zc1IJ69LIGdHdnr6shquTGo_opXbpG_9Is_XWk,712
6
- ray_embedding-0.9.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
7
- ray_embedding-0.9.7.dist-info/top_level.txt,sha256=ziCblpJq1YsrryshFqxTRuRMgNuO1_tgvAAkGShATNA,14
8
- ray_embedding-0.9.7.dist-info/RECORD,,