Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added the PipelineJob.from_pipeline_func method (#1415)
The new factory method reduces the pipeline submission boilerplate to absolute minimum. ```python aiplatform.PipelineJob.from_pipeline_func(training_pipeline).submit() ``` What it does: 1. Compiles pipeline 2. Provides sensible default values for the pipeline display name, job_id, context etc. 3. Generates GCS directory for the pipeline output artifacts if needed 4. Creates the GCS bucket for the artifacts if it does not exist. (And gives the Pipelines service account the required permissions) Example usage: ```python def training_pipeline(number_of_epochs: int = 10): train_op( number_of_epochs=number_of_epochs, learning_rate="0.1", ) job = aiplatform.PipelineJob.from_pipeline_func(training_pipeline) job.submit() ``` --- Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-aiplatform/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
- Loading branch information
Showing
5 changed files
with
372 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import pytest | ||
|
||
from google.cloud import aiplatform | ||
from tests.system.aiplatform import e2e_base | ||
|
||
|
||
@pytest.mark.usefixtures("tear_down_resources") | ||
class TestPipelineJob(e2e_base.TestEndToEnd): | ||
|
||
_temp_prefix = "tmpvrtxsdk-e2e" | ||
|
||
def test_add_pipeline_job_to_experiment(self, shared_state): | ||
from kfp import components | ||
|
||
# Components: | ||
def train( | ||
number_of_epochs: int, | ||
learning_rate: float, | ||
): | ||
print(f"number_of_epochs={number_of_epochs}") | ||
print(f"learning_rate={learning_rate}") | ||
|
||
train_op = components.create_component_from_func(train) | ||
|
||
# Pipeline: | ||
def training_pipeline(number_of_epochs: int = 10): | ||
train_op( | ||
number_of_epochs=number_of_epochs, | ||
learning_rate="0.1", | ||
) | ||
|
||
# Submitting the pipeline: | ||
aiplatform.init( | ||
project=e2e_base._PROJECT, | ||
location=e2e_base._LOCATION, | ||
) | ||
job = aiplatform.PipelineJob.from_pipeline_func( | ||
pipeline_func=training_pipeline, | ||
) | ||
job.submit() | ||
|
||
shared_state.setdefault("resources", []).append(job) | ||
|
||
job.wait() |
Oops, something went wrong.