Skip to content

Commit 636a654

Browse files
Ark-kuncopybara-github
authored andcommitted
fix: Fixed the vertexai.init partial initialization issues
PiperOrigin-RevId: 625560910
1 parent 0654c35 commit 636a654

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

google/cloud/aiplatform/initializer.py

+25-22
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,22 @@ def init(
192192
ValueError:
193193
If experiment_description is provided but experiment is not.
194194
"""
195-
196-
if api_endpoint is not None:
197-
self._api_endpoint = api_endpoint
198-
195+
# This method mutates state, so we need to be careful with the validation
196+
# First, we need to validate all passed values
197+
if api_transport:
198+
VALID_TRANSPORT_TYPES = ["grpc", "rest"]
199+
if api_transport not in VALID_TRANSPORT_TYPES:
200+
raise ValueError(
201+
f"{api_transport} is not a valid transport type. "
202+
+ f"Valid transport types: {VALID_TRANSPORT_TYPES}"
203+
)
204+
if location:
205+
utils.validate_region(location)
199206
if experiment_description and experiment is None:
200207
raise ValueError(
201208
"Experiment needs to be set in `init` in order to add experiment descriptions."
202209
)
203210

204-
if experiment_tensorboard and not isinstance(experiment_tensorboard, bool):
205-
metadata._experiment_tracker.set_tensorboard(
206-
tensorboard=experiment_tensorboard,
207-
project=project,
208-
location=location,
209-
credentials=credentials,
210-
)
211-
212211
# reset metadata_service config if project or location is updated.
213212
if (project and project != self._project) or (
214213
location and location != self._location
@@ -217,10 +216,14 @@ def init(
217216
logging.info("project/location updated, reset Experiment config.")
218217
metadata._experiment_tracker.reset()
219218

219+
# Then we change the main state
220+
if api_endpoint is not None:
221+
self._api_endpoint = api_endpoint
222+
if api_transport:
223+
self._api_transport = api_transport
220224
if project:
221225
self._project = project
222226
if location:
223-
utils.validate_region(location)
224227
self._location = location
225228
if staging_bucket:
226229
self._staging_bucket = staging_bucket
@@ -233,22 +236,22 @@ def init(
233236
if service_account is not None:
234237
self._service_account = service_account
235238

239+
# Finally, perform secondary state updates
240+
if experiment_tensorboard and not isinstance(experiment_tensorboard, bool):
241+
metadata._experiment_tracker.set_tensorboard(
242+
tensorboard=experiment_tensorboard,
243+
project=project,
244+
location=location,
245+
credentials=credentials,
246+
)
247+
236248
if experiment:
237249
metadata._experiment_tracker.set_experiment(
238250
experiment=experiment,
239251
description=experiment_description,
240252
backing_tensorboard=experiment_tensorboard,
241253
)
242254

243-
if api_transport:
244-
VALID_TRANSPORT_TYPES = ["grpc", "rest"]
245-
if api_transport not in VALID_TRANSPORT_TYPES:
246-
raise ValueError(
247-
f"{api_transport} is not a valid transport type. "
248-
+ f"Valid transport types: {VALID_TRANSPORT_TYPES}"
249-
)
250-
self._api_transport = api_transport
251-
252255
def get_encryption_spec(
253256
self,
254257
encryption_spec_key_name: Optional[str],

0 commit comments

Comments
 (0)