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

Fix: Preserve hyperparameter order when invoking training jobs #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vsimkus
Copy link

@vsimkus vsimkus commented Sep 9, 2024

Fixes #221.

Removed the alphanumeric sorting of the hyperparameters in

def to_cmd_args(mapping): # type: (dict) -> list
"""Transform a dictionary in a list of cmd arguments.
Example:
>>>args = mapping.to_cmd_args({'model_dir': '/opt/ml/model', 'batch_size': 25})
>>>
>>>print(args)
['--model_dir', '/opt/ml/model', '--batch_size', 25]
Args:
mapping (dict[str, object]): A Python mapping.
Returns:
(list): List of cmd arguments.
"""
sorted_keys = sorted(mapping.keys())

This makes sure that training scripts are invoked with the same order of hyperparameters as passed in the hyperparameters argument to the SageMaker Estimator class. This sorting was undocumented and as argued in issue #221 can cause issues for scripts where order of the arguments matters.

I have updated the unit tests in test_mapping.py to verify that the order of the arguments is preserved.

I ran the unit tests with tox -e py310 -- -s -vv test/unit and they passed. Let's see if the CI tests find anything...

Merge Checklist

General

  • I have read the CONTRIBUTING doc
  • I used the commit message format described in CONTRIBUTING
  • I have used the regional endpoint when creating S3 and/or STS clients (if appropriate)
  • I have updated any necessary documentation, including READMEs

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Collaborator

@prtsh prtsh left a comment

Choose a reason for hiding this comment

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

Approved. Change replaces the args sorting so that the order of the hyper-param cli args is preserved. Do not see any intended harm with this change as the cli args are order agnostic.

@prtsh prtsh requested a review from bhaoz December 6, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SageMaker training toolkit reorders hyperparameters
2 participants