ray-embedding 0.10.0__tar.gz → 0.10.1__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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ray-embedding
3
- Version: 0.10.0
3
+ Version: 0.10.1
4
4
  Summary: Deploy SentenceTransformers embedding models to a ray cluster
5
5
  Author: Crispin Almodovar
6
6
  Author-email:
@@ -24,10 +24,6 @@ web_api = FastAPI(title=f"Ray Embeddings - OpenAI-compatible API")
24
24
  "min_replicas": 0,
25
25
  "initial_replicas": 1,
26
26
  "max_replicas": 1,
27
- },
28
- user_config={
29
- "max_batch_size": 8,
30
- "batch_wait_timeout_s": 0.25,
31
27
  }
32
28
  )
33
29
  @serve.ingress(web_api)
@@ -56,12 +52,6 @@ class EmbeddingModel:
56
52
  ]
57
53
  self.logger.info(f"Successfully initialized embedding model {self.model} using device {self.torch_device}")
58
54
 
59
- async def reconfigure(self, user_config: Dict):
60
- assert "max_batch_size" in user_config and "batch_wait_timeout_s" in user_config, "Invalid user config"
61
- self.logger.info(f"Reconfiguring dynamic batching parameters: {user_config}")
62
- self.__create_embeddings_batch.set_max_batch_size(user_config["max_batch_size"])
63
- self.__create_embeddings_batch.set_batch_wait_timeout_s(user_config["batch_wait_timeout_s"])
64
-
65
55
  @web_api.post("/v1/embeddings", response_model=EmbeddingResponse)
66
56
  async def create_embeddings(self, request: EmbeddingRequest):
67
57
  """Generate embeddings for the input text using the specified model."""
@@ -69,7 +59,6 @@ class EmbeddingModel:
69
59
  assert request.model == self.served_model_name, (
70
60
  f"Model '{request.model}' is not supported. Use '{self.served_model_name}' instead."
71
61
  )
72
-
73
62
  if isinstance(request.input, str):
74
63
  request.input = [request.input]
75
64
 
@@ -77,7 +66,7 @@ class EmbeddingModel:
77
66
 
78
67
  # Compute embeddings and convert to a PyTorch tensor on the GPU
79
68
  embeddings = self.embedding_model.encode(
80
- request.input, convert_to_tensor=True, normalize_embeddings=True
69
+ request.input, convert_to_tensor=True, normalize_embeddings=True, show_progress_bar=False,
81
70
  ).to(self.torch_device)
82
71
 
83
72
  if truncate_dim is not None:
@@ -99,54 +88,6 @@ class EmbeddingModel:
99
88
  self.logger.error(e)
100
89
  raise HTTPException(status_code=500, detail=str(e))
101
90
 
102
- @serve.batch(max_batch_size=8, batch_wait_timeout_s=0.25)
103
- async def __create_embeddings_batch(self, requests_batch: List[EmbeddingRequest]) -> List[EmbeddingResponse]:
104
- self_0 = self[0] if isinstance(self, list) else self # Ray also passes an array of self refs; just take the first one
105
- embedding_model, matryoshka_dim, torch_device = self_0.embedding_model, self_0.matryoshka_dim, self_0.torch_device
106
-
107
- inputs, truncate_dims, num_inputs_list = [], [], []
108
- for request in requests_batch:
109
- input_text = request.input if isinstance(request.input, list) else [request.input] # Can be a list of texts
110
- inputs.extend(input_text)
111
- num_inputs_list.append(len(input_text))
112
- truncate_dims.append(request.dimensions or matryoshka_dim)
113
-
114
- embeddings = embedding_model.encode(
115
- inputs, convert_to_tensor=True, normalize_embeddings=True, show_progress_bar=False,
116
- ).to(torch_device)
117
-
118
- model_name = requests_batch[0].model
119
- truncate_needed = any(dim is not None for dim in truncate_dims)
120
- results_batch, ix = [], 0
121
-
122
- if truncate_needed:
123
- for truncate_dim, num_inputs in zip(truncate_dims, num_inputs_list):
124
- batch_embeddings = embeddings[ix: ix + num_inputs]
125
- ix += num_inputs
126
-
127
- if truncate_dim is not None:
128
- # Truncate and normalize using pytorch (faster)
129
- batch_embeddings = batch_embeddings[:, :truncate_dim]
130
- batch_embeddings = batch_embeddings / torch.norm(batch_embeddings, dim=1, keepdim=True)
131
-
132
- batch_embeddings = batch_embeddings.cpu().tolist()
133
- response_data = [
134
- {"index": emb_ix, "embedding": emb} for emb_ix, emb in enumerate(batch_embeddings)
135
- ]
136
- results_batch.append(EmbeddingResponse(object="list", data=response_data, model=model_name))
137
- else:
138
- embeddings_list = embeddings.cpu().tolist() # Move everything to CPU
139
- for num_inputs in num_inputs_list:
140
- batch_embeddings = embeddings_list[ix: ix + num_inputs]
141
- ix += num_inputs
142
-
143
- response_data = [
144
- {"index": emb_ix, "embedding": emb} for emb_ix, emb in enumerate(batch_embeddings)
145
- ]
146
- results_batch.append(EmbeddingResponse(object="list", data=response_data, model=model_name))
147
-
148
- return results_batch
149
-
150
91
  @web_api.get("/v1/models")
151
92
  async def list_models(self):
152
93
  """Returns the list of available models in OpenAI-compatible format."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ray-embedding
3
- Version: 0.10.0
3
+ Version: 0.10.1
4
4
  Summary: Deploy SentenceTransformers embedding models to a ray cluster
5
5
  Author: Crispin Almodovar
6
6
  Author-email:
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = ray-embedding
3
- version = 0.10.0
3
+ version = 0.10.1
4
4
  author = Crispin Almodovar
5
5
  author_email =
6
6
  description = Deploy SentenceTransformers embedding models to a ray cluster
File without changes