Content-Length: 437891 | pFad | https://github.com/googleapis/python-aiplatform/commit/31100c6dd6d7d4b0b588ed7f008e7661835b19d2

74 docs: Add run custom job on persistent resource sample. · googleapis/python-aiplatform@31100c6 · GitHub
Skip to content

Commit 31100c6

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
docs: Add run custom job on persistent resource sample.
PiperOrigin-RevId: 621913789
1 parent 33d2b4d commit 31100c6

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2024 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 google.cloud import aiplatform
17+
18+
19+
# [START aiplatform_sdk_create_custom_job_on_persistent_resource_sample]
20+
def create_custom_job_on_persistent_resource_sample(
21+
project: str,
22+
location: str,
23+
staging_bucket: str,
24+
display_name: str,
25+
container_uri: str,
26+
persistent_resource_id: str,
27+
service_account: str,
28+
) -> None:
29+
aiplatform.init(
30+
project=project, location=location, staging_bucket=staging_bucket
31+
)
32+
33+
worker_pool_specs = [{
34+
"machine_spec": {
35+
"machine_type": "n1-standard-4",
36+
"accelerator_type": "NVIDIA_TESLA_K80",
37+
"accelerator_count": 1,
38+
},
39+
"replica_count": 1,
40+
"container_spec": {
41+
"image_uri": container_uri,
42+
"command": [],
43+
"args": [],
44+
},
45+
}]
46+
47+
custom_job = aiplatform.CustomJob(
48+
display_name=display_name,
49+
worker_pool_specs=worker_pool_specs,
50+
persistent_resource_id=persistent_resource_id,
51+
)
52+
53+
custom_job.run(service_account=service_account)
54+
55+
56+
# [END aiplatform_sdk_create_custom_job_on_persistent_resource_sample]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2024 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+
import create_custom_job_on_persistent_resource_sample
17+
import test_constants as constants
18+
19+
20+
_PRESISTENT_RESOURCE_ID = "test_persistent_resource_id"
21+
22+
23+
def test_create_custom_job_on_persistent_resource_sample(
24+
mock_sdk_init,
25+
mock_get_custom_job,
26+
mock_run_custom_job,
27+
):
28+
create_custom_job_on_persistent_resource_sample.create_custom_job_on_persistent_resource_sample(
29+
project=constants.PROJECT,
30+
location=constants.LOCATION,
31+
staging_bucket=constants.STAGING_BUCKET,
32+
display_name=constants.DISPLAY_NAME,
33+
container_uri=constants.CONTAINER_URI,
34+
persistent_resource_id=_PRESISTENT_RESOURCE_ID,
35+
service_account=constants.SERVICE_ACCOUNT,
36+
)
37+
38+
mock_sdk_init.assert_called_once_with(
39+
project=constants.PROJECT,
40+
location=constants.LOCATION,
41+
staging_bucket=constants.STAGING_BUCKET,
42+
)
43+
44+
mock_get_custom_job.assert_called_once_with(
45+
display_name=constants.DISPLAY_NAME,
46+
worker_pool_specs=constants.CUSTOM_JOB_WORKER_POOL_SPECS,
47+
persistent_resource_id=_PRESISTENT_RESOURCE_ID,
48+
)
49+
50+
mock_run_custom_job.assert_called_once_with(
51+
service_account=constants.SERVICE_ACCOUNT,
52+
)

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: https://github.com/googleapis/python-aiplatform/commit/31100c6dd6d7d4b0b588ed7f008e7661835b19d2

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy