|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Copyright 2022 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +import os |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +from google.cloud import aiplatform |
| 23 | +from google.cloud.aiplatform.compat.types import job_state as gca_job_state |
| 24 | +from tests.system.aiplatform import e2e_base |
| 25 | + |
| 26 | +_PREBUILT_CONTAINER_IMAGE = "gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest" |
| 27 | +_CUSTOM_CONTAINER_IMAGE = "python:3.8" |
| 28 | + |
| 29 | +_DIR_NAME = os.path.dirname(os.path.abspath(__file__)) |
| 30 | +_LOCAL_TRAINING_SCRIPT_PATH = os.path.join( |
| 31 | + _DIR_NAME, "test_resources/custom_job_script.py" |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.usefixtures( |
| 36 | + "prepare_staging_bucket", "delete_staging_bucket", "tear_down_resources" |
| 37 | +) |
| 38 | +class TestCustomJob(e2e_base.TestEndToEnd): |
| 39 | + |
| 40 | + _temp_prefix = "temp-vertex-sdk-custom-job" |
| 41 | + |
| 42 | + def test_from_local_script_prebuilt_container(self, shared_state): |
| 43 | + shared_state["resources"] = [] |
| 44 | + |
| 45 | + aiplatform.init( |
| 46 | + project=e2e_base._PROJECT, |
| 47 | + location=e2e_base._LOCATION, |
| 48 | + staging_bucket=shared_state["staging_bucket_name"], |
| 49 | + ) |
| 50 | + |
| 51 | + display_name = self._make_display_name("custom-job") |
| 52 | + |
| 53 | + custom_job = aiplatform.CustomJob.from_local_script( |
| 54 | + display_name=display_name, |
| 55 | + script_path=_LOCAL_TRAINING_SCRIPT_PATH, |
| 56 | + container_uri=_PREBUILT_CONTAINER_IMAGE, |
| 57 | + ) |
| 58 | + custom_job.run() |
| 59 | + |
| 60 | + shared_state["resources"].append(custom_job) |
| 61 | + |
| 62 | + assert custom_job.state == gca_job_state.JobState.JOB_STATE_SUCCEEDED |
| 63 | + |
| 64 | + def test_from_local_script_custom_container(self, shared_state): |
| 65 | + |
| 66 | + aiplatform.init( |
| 67 | + project=e2e_base._PROJECT, |
| 68 | + location=e2e_base._LOCATION, |
| 69 | + staging_bucket=shared_state["staging_bucket_name"], |
| 70 | + ) |
| 71 | + |
| 72 | + display_name = self._make_display_name("custom-job") |
| 73 | + |
| 74 | + custom_job = aiplatform.CustomJob.from_local_script( |
| 75 | + display_name=display_name, |
| 76 | + script_path=_LOCAL_TRAINING_SCRIPT_PATH, |
| 77 | + container_uri=_CUSTOM_CONTAINER_IMAGE, |
| 78 | + ) |
| 79 | + custom_job.run() |
| 80 | + |
| 81 | + shared_state["resources"].append(custom_job) |
| 82 | + |
| 83 | + assert custom_job.state == gca_job_state.JobState.JOB_STATE_SUCCEEDED |
0 commit comments