Skip to content

Commit 5780513

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
docs: Add upload Tensorboard profile log to Experiment sample.
PiperOrigin-RevId: 587819953
1 parent 6dfbad7 commit 5780513

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import FrozenSet
16+
17+
from google.cloud import aiplatform
18+
19+
20+
# [START aiplatform_sdk_upload_tensorboard_profile_logs_to_experiment_sample]
21+
def upload_tensorboard_profile_logs_to_experiment_sample(
22+
experiment_name: str,
23+
logdir: str,
24+
project: str,
25+
location: str,
26+
run_name_prefix: str,
27+
allowed_plugins: FrozenSet[str] = ["profile"],
28+
) -> None:
29+
30+
aiplatform.init(project=project, location=location, experiment=experiment_name)
31+
32+
# one time upload
33+
aiplatform.upload_tb_log(
34+
tensorboard_experiment_name=experiment_name,
35+
logdir=logdir,
36+
run_name_prefix=run_name_prefix,
37+
allowed_plugins=allowed_plugins,
38+
)
39+
40+
41+
# [END aiplatform_sdk_upload_tensorboard_profile_logs_to_experiment_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
from experiment_tracking import upload_tensorboard_profile_logs_to_experiment_sample
17+
import test_constants as constants
18+
19+
20+
def test_upload_tensorboard_profile_logs_to_experiment_sample(
21+
mock_sdk_init,
22+
mock_tensorboard_uploader_onetime,
23+
):
24+
upload_tensorboard_profile_logs_to_experiment_sample.upload_tensorboard_profile_logs_to_experiment_sample(
25+
project=constants.PROJECT,
26+
location=constants.LOCATION,
27+
logdir=constants.TENSORBOARD_LOG_DIR,
28+
experiment_name=constants.EXPERIMENT_NAME,
29+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
30+
allowed_plugins=constants.TENSORBOARD_PLUGIN_PROFILE_NAME,
31+
)
32+
33+
mock_sdk_init.assert_called_once_with(
34+
project=constants.PROJECT,
35+
location=constants.LOCATION,
36+
experiment=constants.EXPERIMENT_NAME,
37+
)
38+
39+
mock_tensorboard_uploader_onetime.assert_called_once_with(
40+
logdir=constants.TENSORBOARD_LOG_DIR,
41+
tensorboard_experiment_name=constants.EXPERIMENT_NAME,
42+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
43+
allowed_plugins=constants.TENSORBOARD_PLUGIN_PROFILE_NAME,
44+
)

samples/model-builder/test_constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,4 @@
337337
f"projects/{PROJECT}/locations/{LOCATION}/tensorboards/my-tensorboard"
338338
)
339339
TENSORBOARD_EXPERIMENT_NAME = "my-tensorboard-experiment"
340+
TENSORBOARD_PLUGIN_PROFILE_NAME = "profile"

0 commit comments

Comments
 (0)