orient_express 0.3.1__tar.gz → 0.3.3__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.
@@ -1,16 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: orient_express
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: A library to simplify model deployment to Vertex AI
5
5
  Author: Alexey Zankevich
6
6
  Author-email: alex.zankevich@shiftsmart.com
7
- Requires-Python: >=3.9
7
+ Requires-Python: >=3.9,<3.13
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
- Classifier: Programming Language :: Python :: 3.13
14
13
  Requires-Dist: google-cloud-aiplatform
15
14
  Requires-Dist: google-cloud-storage
16
15
  Requires-Dist: pandas
@@ -16,7 +16,9 @@ class ModelExpress:
16
16
  model=None,
17
17
  region="us-central1",
18
18
  serialized_model_path="model.joblib",
19
- docker_image_uri="us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-7:latest",
19
+ serving_container_image_uri="us-west1-docker.pkg.dev/shiftsmart-api/orient-express/xgboost-scikit-learn:latest",
20
+ serving_container_predict_route="/v1/models/orient-express-model:predict",
21
+ serving_container_health_route="/v1/models/orient-express-model",
20
22
  endpoint_name=None,
21
23
  machine_type="n1-standard-4",
22
24
  min_replica_count=1,
@@ -29,26 +31,35 @@ class ModelExpress:
29
31
  self.project_name = project_name
30
32
  self.bucket_name = bucket_name
31
33
  self.serialized_model_path = serialized_model_path
32
- self.docker_image_uri = docker_image_uri
34
+ self.serving_container_image_uri = serving_container_image_uri
35
+ self.serving_container_predict_route = serving_container_predict_route
36
+ self.serving_container_health_route = serving_container_health_route
33
37
  self.machine_type = machine_type
34
38
  self.min_replica_count = min_replica_count
35
39
  self.max_replica_count = max_replica_count
36
40
  self.endpoint = None
37
41
 
38
42
  if not endpoint_name:
39
- self.endpoint_name = f"model-xpress-{model_name}"
43
+ self.endpoint_name = f"orient-express-{model_name}"
40
44
  else:
41
45
  self.endpoint_name = endpoint_name
42
46
 
47
+ self._vertex_initialized = False
48
+
43
49
  def colab_auth(self):
44
50
  from google.colab import auth
45
51
 
46
52
  auth.authenticate_user()
47
53
 
48
54
  def _vertex_init(self):
49
- aiplatform.init(project=self.project_name, location=self.region)
55
+ if not self._vertex_initialized:
56
+ aiplatform.init(project=self.project_name, location=self.region)
57
+ self._vertex_initialized = True
50
58
 
51
59
  def get_latest_vertex_model(self, model_name):
60
+ """If there are a few models with the same name, load the most recent one.
61
+ It's highly recommended to keep only 1 model with the same name to avoid the confusion
62
+ """
52
63
  self._vertex_init()
53
64
 
54
65
  # Search for models with the specified display name
@@ -106,7 +117,9 @@ class ModelExpress:
106
117
  display_name=self.model_name,
107
118
  artifact_uri=artifact_uri,
108
119
  parent_model=parent_model,
109
- serving_container_image_uri=self.docker_image_uri,
120
+ serving_container_image_uri=self.serving_container_image_uri,
121
+ serving_container_health_route=self.serving_container_health_route,
122
+ serving_container_predict_route=self.serving_container_predict_route,
110
123
  sync=True,
111
124
  )
112
125
 
@@ -147,6 +160,8 @@ class ModelExpress:
147
160
  )
148
161
 
149
162
  def remote_predict(self, input_df):
163
+ self._vertex_init()
164
+
150
165
  if not self.endpoint:
151
166
  endpoint = self.get_endpoint()
152
167
  if not endpoint:
@@ -160,6 +175,8 @@ class ModelExpress:
160
175
  return predictions.predictions
161
176
 
162
177
  def local_predict(self, input_df):
178
+ self._vertex_init()
179
+
163
180
  if not self.model:
164
181
  self.load_model_from_registry()
165
182
 
@@ -172,14 +189,16 @@ class ModelExpress:
172
189
  return self.model.predict_proba(input_df)
173
190
 
174
191
  def load_model_from_registry(self):
192
+ self._vertex_init()
193
+
194
+ vertex_model = self.get_latest_vertex_model(self.model_name)
195
+
175
196
  if self.model_version:
197
+ # reload the model using a specific model version
176
198
  vertex_model = aiplatform.Model(
177
- model_name=self.model_name, version=self.model_version
199
+ model_name=vertex_model.resource_name, version=str(self.model_version)
178
200
  )
179
201
 
180
- else:
181
- vertex_model = self.get_latest_vertex_model(self.model_name)
182
-
183
202
  if not vertex_model:
184
203
  raise Exception(f"Model '{self.model_name}' not found in the registry.")
185
204
 
@@ -199,5 +218,4 @@ class ModelExpress:
199
218
  blob.download_to_filename(artifact_path)
200
219
 
201
220
  def df_to_features(self, df: pd.DataFrame):
202
- #
203
221
  return df.to_dict(orient="records")
@@ -1,12 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "orient_express"
3
- version = "0.3.1"
3
+ version = "0.3.3"
4
4
  description = "A library to simplify model deployment to Vertex AI"
5
5
  authors = ["Alexey Zankevich <alex.zankevich@shiftsmart.com>"]
6
6
  readme = "README.md"
7
7
 
8
8
  [tool.poetry.dependencies]
9
- python = ">=3.9"
9
+ python = ">=3.9,<3.13"
10
10
  google-cloud-aiplatform = "*"
11
11
  google-cloud-storage = "*"
12
12
  pandas = "*"
@@ -17,6 +17,12 @@ pytest = "8.3.3"
17
17
  scikit-learn = "1.5.2"
18
18
  xgboost = "2.1.2"
19
19
 
20
+ [tool.poetry.group.inference.dependencies]
21
+ scikit-learn = "1.5.2"
22
+ kserve = "0.14.0"
23
+ python-json-logger = "2.0.7"
24
+ gcsfs = "^2024.10.0"
25
+
20
26
  [build-system]
21
27
  requires = ["poetry-core"]
22
28
  build-backend = "poetry.core.masonry.api"
File without changes