Skip to content

Fix for #2949. #2951

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 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
9 changes: 6 additions & 3 deletions src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ def _json_encode_hyperparameters(hyperparameters: Dict[str, Any]) -> Dict[str, A
current_hyperparameters = hyperparameters
if current_hyperparameters is not None:
hyperparameters = {
str(k): (v if isinstance(v, (Parameter, Expression, Properties)) else json.dumps(v))
str(k): (
v
if isinstance(v, (str, int, float, bool, Parameter, Expression, Properties))
else json.dumps(v)
)
for (k, v) in current_hyperparameters.items()
}
return hyperparameters
Expand Down Expand Up @@ -682,7 +686,7 @@ def _script_mode_hyperparam_update(self, code_dir: str, script: str) -> None:
hyperparams[JOB_NAME_PARAM_NAME] = self._current_job_name
hyperparams[SAGEMAKER_REGION_PARAM_NAME] = self.sagemaker_session.boto_region_name

self._hyperparameters.update(EstimatorBase._json_encode_hyperparameters(hyperparams))
self._hyperparameters.update(hyperparams)

def _stage_user_code_in_s3(self) -> str:
"""Uploads the user training script to S3 and returns the S3 URI.
Expand Down Expand Up @@ -2756,7 +2760,6 @@ def _prepare_init_params_from_job_description(cls, job_details, model_channel_na
init_params = super(Framework, cls)._prepare_init_params_from_job_description(
job_details, model_channel_name
)

init_params["entry_point"] = json.loads(
init_params["hyperparameters"].get(SCRIPT_PARAM_NAME)
)
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,6 @@ def test_custom_code_bucket(time, sagemaker_session):
expected_submit_dir
)


@patch("time.strftime", return_value=TIMESTAMP)
def test_custom_code_bucket_without_prefix(time, sagemaker_session):
code_bucket = "codebucket"
Expand All @@ -1268,7 +1267,7 @@ def test_custom_code_bucket_without_prefix(time, sagemaker_session):
_, _, train_kwargs = sagemaker_session.train.mock_calls[0]
assert train_kwargs["hyperparameters"]["sagemaker_submit_directory"] == json.dumps(
expected_submit_dir
)
)
Copy link
Member

Choose a reason for hiding this comment

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

lets remove this blank space



def test_invalid_custom_code_bucket(sagemaker_session):
Expand Down Expand Up @@ -1342,7 +1341,7 @@ def test_shuffle_config(sagemaker_session):
BASE_HP = {
"sagemaker_program": json.dumps(SCRIPT_NAME),
"sagemaker_submit_directory": json.dumps(
"s3://mybucket/{}/source/sourcedir.tar.gz".format(JOB_NAME)
"s3://mybucket/{}/source/sourcedir.tar.gz".format(JOB_NAME)
),
"sagemaker_job_name": json.dumps(JOB_NAME),
}
Expand Down