orient_express 0.3.2__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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: orient_express
3
- Version: 0.3.2
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
@@ -44,15 +44,22 @@ class ModelExpress:
44
44
  else:
45
45
  self.endpoint_name = endpoint_name
46
46
 
47
+ self._vertex_initialized = False
48
+
47
49
  def colab_auth(self):
48
50
  from google.colab import auth
49
51
 
50
52
  auth.authenticate_user()
51
53
 
52
54
  def _vertex_init(self):
53
- 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
54
58
 
55
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
+ """
56
63
  self._vertex_init()
57
64
 
58
65
  # Search for models with the specified display name
@@ -153,6 +160,8 @@ class ModelExpress:
153
160
  )
154
161
 
155
162
  def remote_predict(self, input_df):
163
+ self._vertex_init()
164
+
156
165
  if not self.endpoint:
157
166
  endpoint = self.get_endpoint()
158
167
  if not endpoint:
@@ -166,6 +175,8 @@ class ModelExpress:
166
175
  return predictions.predictions
167
176
 
168
177
  def local_predict(self, input_df):
178
+ self._vertex_init()
179
+
169
180
  if not self.model:
170
181
  self.load_model_from_registry()
171
182
 
@@ -178,14 +189,16 @@ class ModelExpress:
178
189
  return self.model.predict_proba(input_df)
179
190
 
180
191
  def load_model_from_registry(self):
192
+ self._vertex_init()
193
+
194
+ vertex_model = self.get_latest_vertex_model(self.model_name)
195
+
181
196
  if self.model_version:
197
+ # reload the model using a specific model version
182
198
  vertex_model = aiplatform.Model(
183
- model_name=self.model_name, version=self.model_version
199
+ model_name=vertex_model.resource_name, version=str(self.model_version)
184
200
  )
185
201
 
186
- else:
187
- vertex_model = self.get_latest_vertex_model(self.model_name)
188
-
189
202
  if not vertex_model:
190
203
  raise Exception(f"Model '{self.model_name}' not found in the registry.")
191
204
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "orient_express"
3
- version = "0.3.2"
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"
File without changes