-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Hyperparameter validation #2856
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: Hyperparameter validation #2856
Conversation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
JGuinegagne
left a comment
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.
Mostly docstring changes and suggestions.
|
|
||
| TEXT = "text" | ||
| INT = "int" | ||
| FLOAT = "float" |
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.
shall we add a BOOL member while we are at it?
|
|
||
|
|
||
| class JumpStartHyperparametersError(Exception): | ||
| """Exception raised for errors with hyperparameters for JumpStart models.""" |
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.
nit:
"""Exception raised when validation of the parameter of a JumpStart model fails."""| If set to``VALIDATE_ALGORITHM``, all algorithm hyperparameters will be validated. | ||
| If set to ``VALIDATE_ALL``, all hyperparameters for the model will be validated. | ||
| (Default: None) | ||
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.
add a Raises: section in the docstring please.
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.
nit: also add ValueError in Raises docsting.
| if len(hyperparameter_spec) == 0: | ||
| raise JumpStartHyperparametersError( | ||
| f"Unable to perform validation -- cannot find hyperparameter '{hyperparameter_name}' in model specs." | ||
| ) |
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.
could you add another if to assert that hyperparameter_spec length is 1. If not, we should raise another exception as the name attribute should be unique in the hp set.
| raise JumpStartHyperparametersError( | ||
| f"Hyperparameter '{hyperparameter_name}' must have one of the following values: " | ||
| ", ".join(hyperparameter_spec.options) | ||
| ) |
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.
could you add support for min and max as well? For a TEXT parameter, that refers to the length of the string.
| def validate_hyperparameters( | ||
| model_id: str, | ||
| model_version: str, | ||
| hyperparameters: dict, |
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.
refine type please: Dict[str, Any]
| hyperparameters: dict, | ||
| validation_mode: HyperparameterValidationMode = HyperparameterValidationMode.VALIDATE_PROVIDED, | ||
| region: Optional[str] = JUMPSTART_DEFAULT_REGION_NAME, | ||
| ): |
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.
return type please: -> None
| hyperparameter_name: str, | ||
| hyperparameter_value: Any, | ||
| hyperparameter_specs: List[JumpStartHyperparameter], | ||
| ): |
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.
return type please -> None in your implementation
|
|
||
| if validation_mode == HyperparameterValidationMode.VALIDATE_PROVIDED: | ||
| for hyperparam_name, hyperparam_value in hyperparameters.items(): | ||
| _validate_hyperparameter(hyperparam_name, hyperparam_value, hyperparameters_specs) |
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.
question: this implementation fails fast, ie it raises the first validation exception it encounters. For example, if a model takes hp [a, b, c, d], and a, c and d are wrong, it will take the users 3 attempts to fix it. Do you think that is a concern?
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.
I think this is fine. Many validators fail at the first error, and force the user to correct upstream errors before tackling issues that occur downstream.
| if not hyperparameter_value_str[start_index:].isdigit(): | ||
| raise JumpStartHyperparametersError( | ||
| f"Hyperparameter '{hyperparameter_name}' must be integer type ('{hyperparameter_value}')." | ||
| ) |
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.
would this be simpler:
try:
int_value = int(hyperparameter_value)
except ValueError:
raise JumpStartHyperparametersError(f"...")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.
That won't work, because floats can be serialized into ints.
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.
Wouldn't the training script arg parser take care of the conversion in such a case?
src/sagemaker/hyperparameters.py
Outdated
| model_version: Optional[str] = None, | ||
| hyperparameters: Optional[dict] = None, | ||
| validation_mode: Optional[HyperparameterValidationMode] = None, | ||
| ): |
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.
add return type please: -> None
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Codecov Report
@@ Coverage Diff @@
## master-jumpstart #2856 +/- ##
====================================================
+ Coverage 89.27% 89.31% +0.03%
====================================================
Files 186 188 +2
Lines 16063 16200 +137
====================================================
+ Hits 14341 14469 +128
- Misses 1722 1731 +9
Continue to review full report at Codecov.
|
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…siveMin/exclusiveMax text params
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
JGuinegagne
left a comment
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.
only non-blocking comments
| raise JumpStartHyperparametersError( | ||
| f"Hyperparameter '{hyperparameter_name}' must have length greater than " | ||
| f"{hyperparameter_spec.exclusive_min}" | ||
| ) |
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.
non-blocking: there is no real use-case for exclusive min/max with discreet values like integer (in this case text size), it's only useful for continuous values like float or double. That said, it doesn't really hurt to keep it either, it just makes the code a bit longer.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…perparameter-validation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…perparameter-validation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
| If set to``VALIDATE_ALGORITHM``, all algorithm hyperparameters will be validated. | ||
| If set to ``VALIDATE_ALL``, all hyperparameters for the model will be validated. | ||
| (Default: None) | ||
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.
nit: also add ValueError in Raises docsting.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Issue #, if available:
Description of changes:
This PR adds utilities to perform hyperparameter validation. At a high level, a
validatefunction was added to thehyperparametersmodule. This gives users the ability to validate hyperparameters for their models.Testing done:
Unit testing has been done on the
validatefunctionMerge Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
unique_name_from_baseto create resource names in integ tests (if appropriate)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.