Content-Length: 741382 | pFad | http://github.com/googleapis/python-aiplatform/commit/b0a7dd357e642e395ba338e9c914ef313f7c3df5

33 chore: add sample for TensorBoard uploader · googleapis/python-aiplatform@b0a7dd3 · GitHub
Skip to content

Commit b0a7dd3

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: add sample for TensorBoard uploader
PiperOrigin-RevId: 529255415
1 parent fbd03b1 commit b0a7dd3

6 files changed

+226
-4
lines changed

samples/model-builder/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,42 @@ def mock_tensorboard():
451451
yield mock
452452

453453

454+
@pytest.fixture
455+
def mock_TensorBoard_uploaderTracker():
456+
mock = MagicMock(aiplatform.uploader_tracker)
457+
yield mock
458+
459+
454460
@pytest.fixture
455461
def mock_create_tensorboard(mock_tensorboard):
456462
with patch.object(aiplatform.Tensorboard, "create") as mock:
457463
mock.return_value = mock_tensorboard
458464
yield mock
459465

460466

467+
@pytest.fixture
468+
def mock_tensorboard_uploader_onetime():
469+
with patch.object(aiplatform, "upload_tb_log") as mock_tensorboard_uploader_onetime:
470+
mock_tensorboard_uploader_onetime.return_value = None
471+
yield mock_tensorboard_uploader_onetime
472+
473+
474+
@pytest.fixture
475+
def mock_tensorboard_uploader_start():
476+
with patch.object(
477+
aiplatform, "start_upload_tb_log"
478+
) as mock_tensorboard_uploader_start:
479+
mock_tensorboard_uploader_start.return_value = None
480+
yield mock_tensorboard_uploader_start
481+
482+
483+
@pytest.fixture
484+
def mock_tensorboard_uploader_end():
485+
with patch.object(aiplatform, "end_upload_tb_log") as mock_tensorboard_uploader_end:
486+
mock_tensorboard_uploader_end.return_value = None
487+
yield mock_tensorboard_uploader_end
488+
489+
461490
"""
462491
----------------------------------------------------------------------------
463492
Endpoint Fixtures
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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_log_sample]
21+
def upload_tensorboard_log_continuously_sample(
22+
tensorboard_experiment_name: str,
23+
logdir: str,
24+
tensorboard_id: str,
25+
project: str,
26+
location: str,
27+
experiment_display_name: Optional[str] = None,
28+
run_name_prefix: Optional[str] = None,
29+
description: Optional[str] = None,
30+
) -> None:
31+
32+
aiplatform.init(project=project, location=location)
33+
34+
# Continuous monitoring
35+
aiplatform.start_upload_tb_log(
36+
tensorboard_id=tensorboard_id,
37+
tensorboard_experiment_name=tensorboard_experiment_name,
38+
logdir=logdir,
39+
experiment_display_name=experiment_display_name,
40+
run_name_prefix=run_name_prefix,
41+
description=description,
42+
)
43+
aiplatform.end_upload_tb_log()
44+
45+
46+
# [END aiplatform_sdk_upload_tensorboard_log_sample]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_continuously_sample
17+
import test_constants as constants
18+
19+
20+
def test_upload_tensorboard_log_continuously_sample(
21+
mock_sdk_init,
22+
mock_tensorboard_uploader_start,
23+
mock_tensorboard_uploader_end,
24+
):
25+
upload_tensorboard_log_continuously_sample.upload_tensorboard_log_continuously_sample(
26+
project=constants.PROJECT,
27+
location=constants.LOCATION,
28+
logdir=constants.TENSORBOARD_LOG_DIR,
29+
tensorboard_id=constants.TENSORBOARD_ID,
30+
tensorboard_experiment_name=constants.TENSORBOARD_EXPERIMENT_NAME,
31+
experiment_display_name=constants.EXPERIMENT_NAME,
32+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
33+
description=constants.DESCRIPTION,
34+
)
35+
36+
mock_sdk_init.assert_called_once_with(
37+
project=constants.PROJECT,
38+
location=constants.LOCATION,
39+
)
40+
41+
mock_tensorboard_uploader_start.assert_called_once_with(
42+
logdir=constants.TENSORBOARD_LOG_DIR,
43+
tensorboard_id=constants.TENSORBOARD_ID,
44+
tensorboard_experiment_name=constants.TENSORBOARD_EXPERIMENT_NAME,
45+
experiment_display_name=constants.EXPERIMENT_NAME,
46+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
47+
description=constants.DESCRIPTION,
48+
)
49+
50+
mock_tensorboard_uploader_end.assert_called_once_with()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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_log_one_time_sample]
21+
def upload_tensorboard_log_one_time_sample(
22+
tensorboard_experiment_name: str,
23+
logdir: str,
24+
tensorboard_id: str,
25+
project: str,
26+
location: str,
27+
experiment_display_name: Optional[str] = None,
28+
run_name_prefix: Optional[str] = None,
29+
description: Optional[str] = None,
30+
verbosity: Optional[int] = 1,
31+
) -> None:
32+
33+
aiplatform.init(project=project, location=location)
34+
35+
# one time upload
36+
aiplatform.upload_tb_log(
37+
tensorboard_id=tensorboard_id,
38+
tensorboard_experiment_name=tensorboard_experiment_name,
39+
logdir=logdir,
40+
experiment_display_name=experiment_display_name,
41+
run_name_prefix=run_name_prefix,
42+
description=description,
43+
)
44+
45+
46+
# [END aiplatform_sdk_upload_tensorboard_log_one_time_sample]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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_one_time_sample
17+
import test_constants as constants
18+
19+
20+
def test_upload_tensorboard_log_one_time_sample(
21+
mock_sdk_init,
22+
mock_tensorboard_uploader_onetime,
23+
):
24+
upload_tensorboard_log_one_time_sample.upload_tensorboard_log_one_time_sample(
25+
project=constants.PROJECT,
26+
location=constants.LOCATION,
27+
logdir=constants.TENSORBOARD_LOG_DIR,
28+
tensorboard_id=constants.TENSORBOARD_ID,
29+
tensorboard_experiment_name=constants.TENSORBOARD_EXPERIMENT_NAME,
30+
experiment_display_name=constants.EXPERIMENT_NAME,
31+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
32+
description=constants.DESCRIPTION,
33+
)
34+
35+
mock_sdk_init.assert_called_once_with(
36+
project=constants.PROJECT,
37+
location=constants.LOCATION,
38+
)
39+
40+
mock_tensorboard_uploader_onetime.assert_called_once_with(
41+
logdir=constants.TENSORBOARD_LOG_DIR,
42+
tensorboard_id=constants.TENSORBOARD_ID,
43+
tensorboard_experiment_name=constants.TENSORBOARD_EXPERIMENT_NAME,
44+
experiment_display_name=constants.EXPERIMENT_NAME,
45+
run_name_prefix=constants.EXPERIMENT_RUN_NAME,
46+
description=constants.DESCRIPTION,
47+
)

samples/model-builder/test_constants.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@
272272
VALIDATION_OPTIONS = "fail-pipeline"
273273
PREDEFINED_SPLIT_COLUMN_NAME = "predefined"
274274

275-
TENSORBOARD_NAME = (
276-
f"projects/{PROJECT}/locations/{LOCATION}/tensorboards/my-tensorboard"
277-
)
278-
279275
SCHEMA_TITLE = "system.Schema"
280276
SCHEMA_VERSION = "0.0.1"
281277
METADATA = {}
@@ -332,3 +328,11 @@
332328
IS_DEFAULT_VERSION = False
333329
VERSION_ALIASES = ["test-version-alias"]
334330
VERSION_DESCRIPTION = "test-version-description"
331+
332+
# TensorBoard
333+
TENSORBOARD_LOG_DIR = "gs://fake-dir"
334+
TENSORBOARD_ID = "8888888888888888888"
335+
TENSORBOARD_NAME = (
336+
f"projects/{PROJECT}/locations/{LOCATION}/tensorboards/my-tensorboard"
337+
)
338+
TENSORBOARD_EXPERIMENT_NAME = "my-tensorboard-experiment"

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/googleapis/python-aiplatform/commit/b0a7dd357e642e395ba338e9c914ef313f7c3df5

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy