-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(components/google-cloud): Correct custom job default values (#6638)
* Correct custom job default values * update default values * Add IR test * revert changes in forcast test file * remove extra imports * correct place holder * fix default value for base_output_directory * update encryption key and base path * change fromat of encryption key * change output json * correct pipeline.json * print output manually * change dictSubset to dictequal in uni tests. * remove redundant tests
- Loading branch information
1 parent
8b67505
commit ab58885
Showing
4 changed files
with
283 additions
and
111 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
79 changes: 79 additions & 0 deletions
79
components/google-cloud/tests/experimental/custom_job/integration/test_custom_job_complie.py
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,79 @@ | ||
# Copyright 2021 The Kubeflow Authors. All Rights Reserved. | ||
# | ||
# 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. | ||
"""Test google-cloud-pipeline-Components to ensure the compile without error.""" | ||
|
||
import json | ||
import os | ||
import unittest | ||
import kfp | ||
from kfp import components | ||
from kfp.v2 import compiler | ||
from google_cloud_pipeline_components.experimental.custom_job import custom_job | ||
|
||
|
||
class CustomJobCompileTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
super(CustomJobCompileTest, self).setUp() | ||
self._project = "test_project" | ||
self._location = "us-central1" | ||
self._test_input_string = "test_input_string" | ||
self._package_path = "pipeline.json" | ||
self._test_component = components.load_component_from_text( | ||
"name: Producer\n" | ||
"inputs:\n" | ||
"- {name: input_text, type: String, description: 'Represents an input parameter.'}\n" | ||
"outputs:\n" | ||
"- {name: output_value, type: String, description: 'Represents an output paramter.'}\n" | ||
"implementation:\n" | ||
" container:\n" | ||
" image: google/cloud-sdk:latest\n" | ||
" command:\n" | ||
" - sh\n" | ||
" - -c\n" | ||
" - |\n" | ||
" set -e -x\n" | ||
" echo '$0, this is an output parameter' | gsutil cp - '$1'\n" | ||
" - {inputValue: input_text}\n" | ||
" - {outputPath: output_value}\n") | ||
|
||
def tearDown(self): | ||
if os.path.exists(self._package_path): | ||
os.remove(self._package_path) | ||
|
||
def test_custom_job_op_compile(self): | ||
|
||
custom_job_op = custom_job.custom_training_job_op(self._test_component) | ||
|
||
@kfp.dsl.pipeline(name="training-test") | ||
def pipeline(): | ||
custom_job_task = custom_job_op( | ||
self._test_input_string, | ||
project=self._project, | ||
location=self._location) | ||
|
||
compiler.Compiler().compile( | ||
pipeline_func=pipeline, package_path=self._package_path) | ||
|
||
with open(self._package_path) as f: | ||
executor_output_json = json.load(f, strict=False) | ||
|
||
with open( | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
'../testdata/custom_job_pipeline.json')) as ef: | ||
expected_executor_output_json = json.load(ef, strict=False) | ||
# Ignore the kfp SDK version during comparision | ||
del executor_output_json['pipelineSpec']['sdkVersion'] | ||
self.assertEqual(executor_output_json, expected_executor_output_json) |
146 changes: 146 additions & 0 deletions
146
components/google-cloud/tests/experimental/custom_job/testdata/custom_job_pipeline.json
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,146 @@ | ||
{ | ||
"pipelineSpec": { | ||
"components": { | ||
"comp-producer": { | ||
"executorLabel": "exec-producer", | ||
"inputDefinitions": { | ||
"parameters": { | ||
"base_output_directory": { | ||
"type": "STRING" | ||
}, | ||
"input_text": { | ||
"type": "STRING" | ||
}, | ||
"location": { | ||
"type": "STRING" | ||
}, | ||
"network": { | ||
"type": "STRING" | ||
}, | ||
"project": { | ||
"type": "STRING" | ||
}, | ||
"service_account": { | ||
"type": "STRING" | ||
}, | ||
"tensorboard": { | ||
"type": "STRING" | ||
} | ||
} | ||
}, | ||
"outputDefinitions": { | ||
"parameters": { | ||
"gcp_resources": { | ||
"type": "STRING" | ||
}, | ||
"output_value": { | ||
"type": "STRING" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"deploymentSpec": { | ||
"executors": { | ||
"exec-producer": { | ||
"container": { | ||
"args": [ | ||
"--type", | ||
"CustomJob", | ||
"--payload", | ||
"{\"display_name\": \"Producer\", \"job_spec\": {\"worker_pool_specs\": [{\"machine_spec\": {\"machine_type\": \"n1-standard-4\"}, \"replica_count\": 1, \"container_spec\": {\"image_uri\": \"google/cloud-sdk:latest\", \"command\": [\"sh\", \"-c\", \"set -e -x\\necho '$0, this is an output parameter' | gsutil cp - '$1'\\n\", \"{{$.inputs.parameters['input_text']}}\", \"{{$.outputs.parameters['output_value'].output_file}}\"]}, \"disk_spec\": {\"boot_disk_type\": \"pd-ssd\", \"boot_disk_size_gb\": 100}}], \"service_account\": \"{{$.inputs.parameters['service_account']}}\", \"network\": \"{{$.inputs.parameters['network']}}\", \"tensorboard\": \"{{$.inputs.parameters['tensorboard']}}\", \"base_output_directory\": {\"output_uri_prefix\": \"{{$.inputs.parameters['base_output_directory']}}\"}}}", | ||
"--project", | ||
"{{$.inputs.parameters['project']}}", | ||
"--location", | ||
"{{$.inputs.parameters['location']}}", | ||
"--gcp_resources", | ||
"{{$.outputs.parameters['gcp_resources'].output_file}}" | ||
], | ||
"command": [ | ||
"python3", | ||
"-u", | ||
"-m", | ||
"google_cloud_pipeline_components.container.experimental.gcp_launcher.launcher" | ||
], | ||
"image": "gcr.io/ml-pipeline/google-cloud-pipeline-components:latest" | ||
} | ||
} | ||
} | ||
}, | ||
"pipelineInfo": { | ||
"name": "training-test" | ||
}, | ||
"root": { | ||
"dag": { | ||
"tasks": { | ||
"producer": { | ||
"cachingOptions": { | ||
"enableCache": true | ||
}, | ||
"componentRef": { | ||
"name": "comp-producer" | ||
}, | ||
"inputs": { | ||
"parameters": { | ||
"base_output_directory": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "" | ||
} | ||
} | ||
}, | ||
"input_text": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "test_input_string" | ||
} | ||
} | ||
}, | ||
"location": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "us-central1" | ||
} | ||
} | ||
}, | ||
"network": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "" | ||
} | ||
} | ||
}, | ||
"project": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "test_project" | ||
} | ||
} | ||
}, | ||
"service_account": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "" | ||
} | ||
} | ||
}, | ||
"tensorboard": { | ||
"runtimeValue": { | ||
"constantValue": { | ||
"stringValue": "" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"taskInfo": { | ||
"name": "producer" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"schemaVersion": "2.0.0" | ||
}, | ||
"runtimeConfig": {} | ||
} |
Oops, something went wrong.