Skip to content

Allow code_location to have no key prefix #227

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 3 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG

* bug-fix: Unit Tests: Improve unit test runtime
* bug-fix: Estimators: Fix attach for LDA
* bug-fix: Estimators: allow code_location to have no key prefix

1.4.1
=====
Expand Down
2 changes: 1 addition & 1 deletion src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def _stage_user_code_in_s3(self):
code_s3_prefix = '{}/source'.format(self._current_job_name)
else:
code_bucket, key_prefix = parse_s3_url(self.code_location)
code_s3_prefix = '{}/{}/source'.format(key_prefix, self._current_job_name)
code_s3_prefix = '/'.join(filter(None, [key_prefix, self._current_job_name, 'source']))

return tar_and_upload_dir(session=self.sagemaker_session.boto_session,
bucket=code_bucket,
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ def test_custom_code_bucket(time, sagemaker_session):
assert train_kwargs['hyperparameters']['sagemaker_submit_directory'] == json.dumps(expected_submit_dir)


@patch('time.strftime', return_value=TIMESTAMP)
def test_custom_code_bucket_without_prefix(time, sagemaker_session):
code_bucket = 'codebucket'
code_location = 's3://{}'.format(code_bucket)
t = DummyFramework(entry_point=SCRIPT_PATH, role=ROLE, sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT, train_instance_type=INSTANCE_TYPE,
code_location=code_location)
t.fit('s3://bucket/mydata')

expected_key = '{}/source/sourcedir.tar.gz'.format(JOB_NAME)
_, s3_args, _ = sagemaker_session.boto_session.resource('s3').Object.mock_calls[0]
assert s3_args == (code_bucket, expected_key)

expected_submit_dir = 's3://{}/{}'.format(code_bucket, expected_key)
_, _, train_kwargs = sagemaker_session.train.mock_calls[0]
assert train_kwargs['hyperparameters']['sagemaker_submit_directory'] == json.dumps(expected_submit_dir)


def test_invalid_custom_code_bucket(sagemaker_session):
code_location = 'thisllworkright?'
t = DummyFramework(entry_point=SCRIPT_PATH, role=ROLE, sagemaker_session=sagemaker_session,
Expand Down