Skip to content

Commit 54f90a5

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: add sample for TensorBoard uploader
PiperOrigin-RevId: 578902243
1 parent c3b79b1 commit 54f90a5

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 Optional
16+
17+
from google.cloud import aiplatform
18+
19+
20+
# [START aiplatform_sdk_upload_tensorboard_to_experiment_sample]
21+
def upload_tensorboard_log_to_experiment_sample(
22+
experiment_name: str,
23+
logdir: str,
24+
project: str,
25+
location: str,
26+
run_name_prefix: Optional[str] = None,
27+
) -> None:
28+
29+
aiplatform.init(project=project, location=location, experiment=experiment_name)
30+
31+
# one time upload
32+
aiplatform.upload_tb_log(
33+
tensorboard_experiment_name=experiment_name,
34+
logdir=logdir,
35+
run_name_prefix=run_name_prefix,
36+
)
37+
38+
39+
# [END aiplatform_sdk_upload_tensorboard_to_experiment_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_log_to_experiment_sample
17+
import test_constants as constants
18+
19+
20+
def test_upload_tensorboard_to_experiment_sample(
21+
mock_sdk_init,
22+
mock_tensorboard_uploader_onetime,
23+
):
24+
upload_tensorboard_log_to_experiment_sample.upload_tensorboard_log_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+
)
31+
32+
mock_sdk_init.assert_called_once_with(
33+
project=constants.PROJECT,
34+
location=constants.LOCATION,
35+
experiment=constants.EXPERIMENT_NAME,
36+
)
37+
38+
mock_tensorboard_uploader_onetime.assert_called_once_with(
39+
logdir=constants.TENSORBOARD_LOG_DIR,
40+
tensorboard_experiment_name=constants.EXPERIMENT_NAME,
41+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
42+
)

0 commit comments

Comments
 (0)