Skip to content

fix: Remove sagemaker_job_name from hyperparameters in TrainingStep #2950

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

Merged
merged 4 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sagemaker/workflow/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def arguments(self) -> RequestType:
)
request_dict = self.estimator.sagemaker_session._get_train_request(**train_args)
request_dict.pop("TrainingJobName")
request_dict["HyperParameters"].pop("sagemaker_job_name", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

wonder if it is possible that this request dict does not have HyperParameters in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will always be there, but let me add a safety check


return request_dict

Expand Down
22 changes: 6 additions & 16 deletions tests/unit/sagemaker/workflow/test_step_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ def test_register_model_with_model_repack_with_estimator(
assert len(request_dict["DependsOn"]) == 1
assert request_dict["DependsOn"][0] == "TestStep"
arguments = request_dict["Arguments"]
repacker_job_name = arguments["HyperParameters"]["sagemaker_job_name"]
assert BUCKET in arguments["HyperParameters"]["sagemaker_submit_directory"]
arguments["HyperParameters"].pop("sagemaker_submit_directory")
assert ordered(arguments) == ordered(
{
"AlgorithmSpecification": {
Expand All @@ -472,12 +473,8 @@ def test_register_model_with_model_repack_with_estimator(
"inference_script": '"dummy_script.py"',
"dependencies": f'"{dummy_requirements}"',
"model_archive": '"model.tar.gz"',
"sagemaker_submit_directory": '"s3://{}/{}/source/sourcedir.tar.gz"'.format(
BUCKET, repacker_job_name.replace('"', "")
),
"sagemaker_program": '"_repack_model.py"',
"sagemaker_container_log_level": "20",
"sagemaker_job_name": repacker_job_name,
"sagemaker_region": f'"{REGION}"',
"source_dir": "null",
},
Expand Down Expand Up @@ -585,7 +582,8 @@ def test_register_model_with_model_repack_with_model(model, model_metrics, drift
assert len(request_dict["DependsOn"]) == 1
assert request_dict["DependsOn"][0] == "TestStep"
arguments = request_dict["Arguments"]
repacker_job_name = arguments["HyperParameters"]["sagemaker_job_name"]
assert BUCKET in arguments["HyperParameters"]["sagemaker_submit_directory"]
arguments["HyperParameters"].pop("sagemaker_submit_directory")
assert ordered(arguments) == ordered(
{
"AlgorithmSpecification": {
Expand All @@ -599,12 +597,8 @@ def test_register_model_with_model_repack_with_model(model, model_metrics, drift
"HyperParameters": {
"inference_script": '"dummy_script.py"',
"model_archive": '"model.tar.gz"',
"sagemaker_submit_directory": '"s3://{}/{}/source/sourcedir.tar.gz"'.format(
BUCKET, repacker_job_name.replace('"', "")
),
"sagemaker_program": '"_repack_model.py"',
"sagemaker_container_log_level": "20",
"sagemaker_job_name": repacker_job_name,
"sagemaker_region": f'"{REGION}"',
"dependencies": "null",
"source_dir": "null",
Expand Down Expand Up @@ -717,7 +711,8 @@ def test_register_model_with_model_repack_with_pipeline_model(
assert len(request_dict["DependsOn"]) == 1
assert request_dict["DependsOn"][0] == "TestStep"
arguments = request_dict["Arguments"]
repacker_job_name = arguments["HyperParameters"]["sagemaker_job_name"]
assert BUCKET in arguments["HyperParameters"]["sagemaker_submit_directory"]
arguments["HyperParameters"].pop("sagemaker_submit_directory")
assert ordered(arguments) == ordered(
{
"AlgorithmSpecification": {
Expand All @@ -732,12 +727,8 @@ def test_register_model_with_model_repack_with_pipeline_model(
"dependencies": "null",
"inference_script": '"dummy_script.py"',
"model_archive": '"model.tar.gz"',
"sagemaker_submit_directory": '"s3://{}/{}/source/sourcedir.tar.gz"'.format(
BUCKET, repacker_job_name.replace('"', "")
),
"sagemaker_program": '"_repack_model.py"',
"sagemaker_container_log_level": "20",
"sagemaker_job_name": repacker_job_name,
"sagemaker_region": f'"{REGION}"',
"source_dir": "null",
},
Expand Down Expand Up @@ -917,7 +908,6 @@ def test_estimator_transformer_with_model_repack_with_estimator(estimator):
arguments = request_dict["Arguments"]
# pop out the dynamic generated fields
arguments["HyperParameters"].pop("sagemaker_submit_directory")
arguments["HyperParameters"].pop("sagemaker_job_name")
assert arguments == {
"AlgorithmSpecification": {
"TrainingInputMode": "File",
Expand Down
1 change: 0 additions & 1 deletion tests/unit/sagemaker/workflow/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ def test_training_step_tensorflow(sagemaker_session):
name="MyTrainingStep", estimator=estimator, inputs=inputs, cache_config=cache_config
)
step_request = step.to_request()
step_request["Arguments"]["HyperParameters"].pop("sagemaker_job_name", None)
step_request["Arguments"]["HyperParameters"].pop("sagemaker_program", None)
step_request["Arguments"].pop("ProfilerRuleConfigurations", None)
assert step_request == {
Expand Down