-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added create_training_pipeline_custom_job_sample and create_training_pipeline_custom_training_managed_dataset_sample and fixed create_training_pipeline_image_classification_sample #343
Changes from 5 commits
c2caaa6
359b6e9
0ca06d5
94fd07b
68eff56
cca3652
75505d1
fec3e6c
f2b0a0b
0c06fdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
|
||
from typing import List, Union | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_create_and_import_dataset_tabular_bigquery_sample] | ||
def create_and_import_dataset_tabular_bigquery_sample( | ||
project: str, | ||
location: str, | ||
display_name: str, | ||
src_uris: Union[str, List[str]], | ||
sync: bool = True, | ||
): | ||
aiplatform.init(project=project, location=location) | ||
|
||
ds = aiplatform.TabularDataset.create( | ||
display_name=display_name, | ||
bq_source=src_uris, | ||
sync=sync, | ||
) | ||
|
||
ds.wait() | ||
|
||
print(ds.display_name) | ||
print(ds.resource_name) | ||
return ds | ||
|
||
|
||
# [END aiplatform_sdk_create_and_import_dataset_tabular_bigquery_sample] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
|
||
|
||
from google.cloud.aiplatform import schema | ||
|
||
import create_and_import_dataset_tabular_bigquery_sample | ||
import test_constants as constants | ||
|
||
|
||
def test_create_and_import_dataset_tabular_bigquery_sample(mock_sdk_init, mock_create_tabular_dataset): | ||
|
||
create_and_import_dataset_tabular_bigquery_sample.create_and_import_dataset_tabular_bigquery_sample( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
src_uris=constants.BIGQUERY_SOURCE, | ||
display_name=constants.DISPLAY_NAME, | ||
) | ||
|
||
mock_sdk_init.assert_called_once_with( | ||
project=constants.PROJECT, location=constants.LOCATION | ||
) | ||
mock_create_tabular_dataset.assert_called_once_with( | ||
display_name=constants.DISPLAY_NAME, | ||
bq_source=constants.BIGQUERY_SOURCE, | ||
sync=True, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
|
||
from typing import List, Union | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_create_and_import_dataset_tabular_gcs_sample] | ||
def create_and_import_dataset_tabular_gcs_sample( | ||
project: str, | ||
location: str, | ||
display_name: str, | ||
src_uris: Union[str, List[str]], | ||
sync: bool = True, | ||
): | ||
aiplatform.init(project=project, location=location) | ||
|
||
ds = aiplatform.TabularDataset.create( | ||
display_name=display_name, | ||
gcs_source=src_uris, | ||
sync=sync, | ||
) | ||
|
||
ds.wait() | ||
|
||
print(ds.display_name) | ||
print(ds.resource_name) | ||
return ds | ||
|
||
|
||
# [END aiplatform_sdk_create_and_import_dataset_tabular_gcs_sample] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
|
||
|
||
from google.cloud.aiplatform import schema | ||
|
||
import create_and_import_dataset_tabular_gcs_sample | ||
import test_constants as constants | ||
|
||
|
||
def test_create_and_import_dataset_tabular_gcs_sample(mock_sdk_init, mock_create_tabular_dataset): | ||
|
||
create_and_import_dataset_tabular_gcs_sample.create_and_import_dataset_tabular_gcs_sample( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
src_uris=constants.GCS_SOURCES, | ||
display_name=constants.DISPLAY_NAME, | ||
) | ||
|
||
mock_sdk_init.assert_called_once_with( | ||
project=constants.PROJECT, location=constants.LOCATION | ||
) | ||
mock_create_tabular_dataset.assert_called_once_with( | ||
display_name=constants.DISPLAY_NAME, | ||
gcs_source=constants.GCS_SOURCES, | ||
sync=True, | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||
# Copyright 2021 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 | ||||||
# | ||||||
# https://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. | ||||||
|
||||||
from google.cloud import aiplatform | ||||||
from typing import List | ||||||
|
||||||
|
||||||
# [START aiplatform_sdk_create_training_pipeline_custom_job_sample] | ||||||
def create_training_pipeline_custom_job_sample( | ||||||
project: str, | ||||||
display_name: str, | ||||||
args: List[str], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
script_path: str, | ||||||
sasha-gitg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
container_uri: str, | ||||||
location: str = "us-central1", | ||||||
model_display_name: str = None, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could do it, but I followed the example of the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also include the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
training_fraction_split: float = 0.8, | ||||||
sasha-gitg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
validation_fraction_split: float = 0.1, | ||||||
test_fraction_split: float = 0.1, | ||||||
sync: bool = True, | ||||||
): | ||||||
aiplatform.init(project=project, location=location) | ||||||
|
||||||
job = aiplatform.CustomTrainingJob(display_name=display_name, | ||||||
script_path=script_path, | ||||||
container_uri=container_uri) | ||||||
|
||||||
model = job.run( | ||||||
model_display_name=model_display_name, | ||||||
args=args, | ||||||
training_fraction_split=training_fraction_split, | ||||||
validation_fraction_split=validation_fraction_split, | ||||||
test_fraction_split=test_fraction_split, | ||||||
sync=sync, | ||||||
) | ||||||
|
||||||
model.wait() | ||||||
|
||||||
print(model.display_name) | ||||||
print(model.resource_name) | ||||||
print(model.uri) | ||||||
return model | ||||||
|
||||||
|
||||||
# [END aiplatform_sdk_create_training_pipeline_custom_job_sample] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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 create_training_pipeline_custom_job_sample | ||
import test_constants as constants | ||
|
||
|
||
def test_create_training_pipeline_custom_job_sample( | ||
mock_sdk_init, | ||
mock_init_custom_training_job, | ||
mock_run_custom_training_job, | ||
): | ||
|
||
create_training_pipeline_custom_job_sample.create_training_pipeline_custom_job_sample( | ||
project=constants.PROJECT, | ||
display_name=constants.DISPLAY_NAME, | ||
args=constants.ARGS, | ||
script_path=constants.SCRIPT_PATH, | ||
container_uri=constants.CONTAINER_URI, | ||
model_display_name=constants.DISPLAY_NAME_2, | ||
training_fraction_split=constants.TRAINING_FRACTION_SPLIT, | ||
validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, | ||
test_fraction_split=constants.TEST_FRACTION_SPLIT, | ||
) | ||
|
||
mock_sdk_init.assert_called_once_with( | ||
project=constants.PROJECT, location=constants.LOCATION | ||
) | ||
mock_init_custom_training_job.assert_called_once_with( | ||
display_name=constants.DISPLAY_NAME, | ||
script_path=constants.SCRIPT_PATH, | ||
container_uri=constants.CONTAINER_URI, | ||
) | ||
mock_run_custom_training_job.assert_called_once_with( | ||
model_display_name=constants.DISPLAY_NAME_2, | ||
args=constants.ARGS, | ||
training_fraction_split=constants.TRAINING_FRACTION_SPLIT, | ||
validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, | ||
test_fraction_split=constants.TEST_FRACTION_SPLIT, | ||
sync=True, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_create_training_pipeline_custom_job_sample] | ||
def create_training_pipeline_custom_training_managed_dataset_sample( | ||
project: str, | ||
display_name: str, | ||
script_path: str, | ||
container_uri: str, | ||
dataset_id: int, | ||
location: str = "us-central1", | ||
model_display_name: str = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments here as above. |
||
training_fraction_split: float = 0.8, | ||
validation_fraction_split: float = 0.1, | ||
test_fraction_split: float = 0.1, | ||
sync: bool = True, | ||
): | ||
aiplatform.init(project=project, location=location) | ||
|
||
job = aiplatform.CustomTrainingJob(display_name=display_name, | ||
script_path=script_path, | ||
container_uri=container_uri) | ||
|
||
my_image_ds = aiplatform.ImageDataset(dataset_id) | ||
|
||
model = job.run( | ||
dataset=my_image_ds, | ||
model_display_name=model_display_name, | ||
training_fraction_split=training_fraction_split, | ||
validation_fraction_split=validation_fraction_split, | ||
test_fraction_split=test_fraction_split, | ||
sync=sync, | ||
) | ||
|
||
model.wait() | ||
|
||
print(model.display_name) | ||
print(model.resource_name) | ||
print(model.uri) | ||
return model | ||
|
||
|
||
# [END aiplatform_sdk_create_training_pipeline_custom_job_sample] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a dupe of this: https://github.com/googleapis/python-aiplatform/pull/338/files#diff-1efd7e79aab7a269e6ed5cb0ce9d4a9c3016782762156e3869a4d77d9d4824daR20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it's under my name. Let me check with @aribray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assignments might have changed between her writing the sample and me starting. I will remove these and we can use Ari's.