ray-embedding 0.12.2__py3-none-any.whl → 0.12.4__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/embedding_model.py +16 -0
- ray_embedding/model_router.py +9 -7
- {ray_embedding-0.12.2.dist-info → ray_embedding-0.12.4.dist-info}/METADATA +1 -1
- ray_embedding-0.12.4.dist-info/RECORD +9 -0
- ray_embedding-0.12.2.dist-info/RECORD +0 -9
- {ray_embedding-0.12.2.dist-info → ray_embedding-0.12.4.dist-info}/WHEEL +0 -0
- {ray_embedding-0.12.2.dist-info → ray_embedding-0.12.4.dist-info}/top_level.txt +0 -0
ray_embedding/embedding_model.py
CHANGED
|
@@ -56,6 +56,12 @@ class EmbeddingModel:
|
|
|
56
56
|
|
|
57
57
|
# Move all embeddings to CPU at once before conversion
|
|
58
58
|
embeddings_list = embeddings.cpu().tolist()
|
|
59
|
+
|
|
60
|
+
# free GPU memory now, don't wait for GC
|
|
61
|
+
del embeddings
|
|
62
|
+
if torch.cuda.is_available():
|
|
63
|
+
torch.cuda.empty_cache()
|
|
64
|
+
|
|
59
65
|
return embeddings_list
|
|
60
66
|
|
|
61
67
|
def wait_for_cuda(self, wait: int = 10):
|
|
@@ -73,3 +79,13 @@ class EmbeddingModel:
|
|
|
73
79
|
assert nvmlDeviceGetCount() >= 1
|
|
74
80
|
except:
|
|
75
81
|
raise RuntimeError("CUDA device is not available")
|
|
82
|
+
|
|
83
|
+
def __del__(self):
|
|
84
|
+
# Clean up and free any remaining GPU memory
|
|
85
|
+
try:
|
|
86
|
+
if hasattr(self, 'embedding_model'):
|
|
87
|
+
del self.embedding_model
|
|
88
|
+
if torch.cuda.is_available():
|
|
89
|
+
torch.cuda.empty_cache()
|
|
90
|
+
except Exception as e:
|
|
91
|
+
self.logger.warning(f"Error during cleanup: {e}")
|
ray_embedding/model_router.py
CHANGED
|
@@ -46,7 +46,7 @@ class ModelRouter:
|
|
|
46
46
|
f"to {len(batches)} mini-batches, each with max length {batch_size}.")
|
|
47
47
|
|
|
48
48
|
# Call embedding model replicas in parallel (rate-limited)
|
|
49
|
-
tasks = [self.
|
|
49
|
+
tasks = [self._compute_embeddings_rate_limited(model_handle, batch, dimensions) for batch in batches]
|
|
50
50
|
all_results = await asyncio.gather(*tasks, return_exceptions=True)
|
|
51
51
|
|
|
52
52
|
# Retry any failed model calls
|
|
@@ -64,7 +64,7 @@ class ModelRouter:
|
|
|
64
64
|
self.logger.info(f"Successfully computed embeddings from {len(batches)} mini-batches")
|
|
65
65
|
return [emb for result in all_results for emb in result]
|
|
66
66
|
|
|
67
|
-
async def
|
|
67
|
+
async def _compute_embeddings_rate_limited(self, model_handle: DeploymentHandle, batch: List[str], dimensions: int):
|
|
68
68
|
async with self.rate_limiter:
|
|
69
69
|
return await model_handle.remote(batch, dimensions)
|
|
70
70
|
|
|
@@ -88,10 +88,10 @@ class ModelRouter:
|
|
|
88
88
|
|
|
89
89
|
@web_api.post("/{path_prefix}/v1/embeddings", response_model=EmbeddingResponse)
|
|
90
90
|
async def compute_embeddings(self, path_prefix: str, request: EmbeddingRequest):
|
|
91
|
-
assert path_prefix in self.path_prefix, f"Invalid path prefix: {path_prefix}"
|
|
92
|
-
assert request.model in self.deployed_models, f"Invalid model: {request.model}"
|
|
93
|
-
|
|
94
91
|
try:
|
|
92
|
+
assert path_prefix in self.path_prefix, f"The API path prefix specified is invalid: '{path_prefix}'"
|
|
93
|
+
assert request.model in self.deployed_models, f"The model specified is invalid: {request.model}"
|
|
94
|
+
|
|
95
95
|
inputs = request.input if isinstance(request.input, list) else [request.input]
|
|
96
96
|
self.logger.info(f"Computing embeddings for a batch of {len(inputs)} texts using model: {request.model}")
|
|
97
97
|
embeddings = await self._compute_embeddings_from_resized_batches(request.model, inputs, request.dimensions)
|
|
@@ -101,11 +101,13 @@ class ModelRouter:
|
|
|
101
101
|
]
|
|
102
102
|
return EmbeddingResponse(object="list", data=response_data, model=request.model)
|
|
103
103
|
except Exception as e:
|
|
104
|
+
status_code = 400 if isinstance(e, AssertionError) else 500
|
|
104
105
|
self.logger.error(f"Failed to create embeddings: {e}")
|
|
105
|
-
raise HTTPException(status_code=
|
|
106
|
+
raise HTTPException(status_code=status_code, detail=str(e))
|
|
106
107
|
|
|
107
108
|
@web_api.get("/{path_prefix}/v1/models")
|
|
108
109
|
async def list_models(self, path_prefix: str):
|
|
109
110
|
"""Returns the list of available models in OpenAI-compatible format."""
|
|
110
|
-
|
|
111
|
+
if path_prefix not in self.path_prefix:
|
|
112
|
+
raise HTTPException(status_code=400, detail=f"The API path prefix specified is invalid: '{path_prefix}'")
|
|
111
113
|
return {"object": "list", "data": self.available_models}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ray_embedding/__init__.py,sha256=YS5LAZfRIwwVvE3C9g7hsauvjgIkqKtHyxkwMFFfAGY,46
|
|
2
|
+
ray_embedding/deploy.py,sha256=xE-NznVlYftTPIfN3aAqCF0DpFIvTuC4vMTNrGfjkxI,2627
|
|
3
|
+
ray_embedding/dto.py,sha256=rzPEB-R7XDYlTqeaXGGgfOjTWyTeRinnJ6LbI1oOWGY,1463
|
|
4
|
+
ray_embedding/embedding_model.py,sha256=j8jPhfVqS_x11oZrlXDbjo6z1NHXxOk8CnGIQemGfUQ,4040
|
|
5
|
+
ray_embedding/model_router.py,sha256=BsOEz24ttvpDD4LZsDVg9rLhn26FxgUsDAvcjI0Feao,5917
|
|
6
|
+
ray_embedding-0.12.4.dist-info/METADATA,sha256=e7i2fUgJhRYIvIrzLVlGYVr3FvPD1Eaoj7L08Slbxp4,1094
|
|
7
|
+
ray_embedding-0.12.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
ray_embedding-0.12.4.dist-info/top_level.txt,sha256=ziCblpJq1YsrryshFqxTRuRMgNuO1_tgvAAkGShATNA,14
|
|
9
|
+
ray_embedding-0.12.4.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
ray_embedding/__init__.py,sha256=YS5LAZfRIwwVvE3C9g7hsauvjgIkqKtHyxkwMFFfAGY,46
|
|
2
|
-
ray_embedding/deploy.py,sha256=xE-NznVlYftTPIfN3aAqCF0DpFIvTuC4vMTNrGfjkxI,2627
|
|
3
|
-
ray_embedding/dto.py,sha256=rzPEB-R7XDYlTqeaXGGgfOjTWyTeRinnJ6LbI1oOWGY,1463
|
|
4
|
-
ray_embedding/embedding_model.py,sha256=wHyDgDCR11VcV2by4bCCp6CSi0mI9zcwkmSbnL3WdRY,3519
|
|
5
|
-
ray_embedding/model_router.py,sha256=ELmD9gU6Tn8AUChN2CTaP3Puvnl8S5EcljnpRwsRI1Y,5701
|
|
6
|
-
ray_embedding-0.12.2.dist-info/METADATA,sha256=VHUh1jHfc47rgef1RuAmlepj_uS081sEp6JkxaGMWUw,1094
|
|
7
|
-
ray_embedding-0.12.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
ray_embedding-0.12.2.dist-info/top_level.txt,sha256=ziCblpJq1YsrryshFqxTRuRMgNuO1_tgvAAkGShATNA,14
|
|
9
|
-
ray_embedding-0.12.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|