Skip to content
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

Add support for Hyperparameter Tuning on Google Cloud AI Platform #15429

Conversation

darshan-majithiya
Copy link

@darshan-majithiya darshan-majithiya commented Apr 19, 2021

The MLEngineStartTrainingJobOperator is modified in airflow/providers/google/cloud/operators/mlengine.py file.

The lines 1138-1142, 1192, 1214, 1279, and 1280 are added to the file.

These lines add support for Model training involving hyperparameter tuning on AI Platform.

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels Apr 19, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 19, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@@ -1189,6 +1189,7 @@ def __init__(
mode: str = 'PRODUCTION',
labels: Optional[Dict[str, str]] = None,
impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
hyperparameters: Optional[Dict] = None,
Copy link
Contributor

@marcosmarxm marcosmarxm Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter in class documentation and maybe a link to Google documentation can be helpful to users https://cloud.google.com/ai-platform/training/docs/using-hyperparameter-tuning and https://cloud.google.com/ai-platform/training/docs/reference/rest/v1/projects.jobs#HyperparameterSpec

:param hyperparameters Make a dictionary representing your HyperparameterSpec and add it to your training input.
:type Dict

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and pushed the code

@darshan-majithiya darshan-majithiya force-pushed the gcp-ai-platform-hyperparameter-tuning branch from 66d839e to 10f29f8 Compare April 20, 2021 07:59
Comment on lines 1138 to 1142
:param hyperparameters: Optional HyperparameterSpec dictionary for hyperparameter tuning
For further reference, check these:
https://cloud.google.com/ai-platform/training/docs/using-hyperparameter-tuning
https://cloud.google.com/ai-platform/training/docs/reference/rest/v1/projects.jobs#HyperparameterSpec
:type hyperparameters: Dict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look here

I think the way you wrote the documentation they wont be render as lists.
You can test locally using ./breeze build-docs -- --package-filter apache-airflow-providers-google to generate documentation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to run this locally. It exists without any error message.

I tried pushing the code to PR but the build throws an error for the 2nd URL line - https://cloud.google.com/ai-platform/training/docs/reference/rest/v1/projects.jobs#HyperparameterSpec. The line has 112 characters and the max allowed is 110. Will it be okay if I modify the /airflow/pylintrc file and update the max-line-length value to 112? Or is there any other workaround?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you enable pre-commit to validate pylint/flake etc?

Copy link
Author

@darshan-majithiya darshan-majithiya Apr 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to run pre-commit on my system. It's throwing permission error. Been trying to find a solution for a while, but haven't figured it yet.

Meanwhile, I've updated and pushed the documentation as per the demo in the link you had shared. Please check it out.

@darshan-majithiya darshan-majithiya force-pushed the gcp-ai-platform-hyperparameter-tuning branch from c91463d to 7c19baa Compare April 21, 2021 06:20
@darshan-majithiya darshan-majithiya changed the title Adding support for Hyperparameter Tuning on Google Cloud AI Platform Add support for Hyperparameter Tuning on Google Cloud AI Platform Apr 21, 2021
@github-actions
Copy link

The Workflow run is cancelling this PR. Building images for the PR has failed. Follow the workflow link to check the reason.

@darshan-majithiya darshan-majithiya force-pushed the gcp-ai-platform-hyperparameter-tuning branch from ddf814d to 7c19baa Compare April 21, 2021 07:16
@xinbinhuang
Copy link
Contributor

@leahecole
Copy link
Contributor

+1 to the request for test case, and also consider adding an example to https://github.com/apache/airflow/blob/master/airflow/providers/google/cloud/example_dags/example_mlengine.py

Thanks for your contribution! :)

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 23, 2021
@@ -1274,6 +1280,9 @@ def execute(self, context):
if self._service_account:
training_request['trainingInput']['serviceAccount'] = self._service_account

if self._hyperparameters:
training_request['trainingInput']['hyperparameters'] = self._hyperparameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests to avoid regression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers provider:google Google (including GCP) related issues stale Stale PRs per the .github/workflows/stale.yml policy file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants