Skip to content

Commit ac28b7c

Browse files
authored
Merge branch 'master' into pytorch
2 parents d603c51 + 9362bba commit ac28b7c

13 files changed

+158
-16
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*Issue #, if available:*
2+
3+
*Description of changes:*
4+
5+
## Merge Checklist
6+
7+
_Put an `x` in 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._
8+
9+
- [ ] I have read the [CONTRIBUTING](https://github.com/aws/sagemaker-python-sdk/blob/master/CONTRIBUTING.md) doc
10+
- [ ] I have added tests that prove my fix is effective or that my feature works (if appropriate)
11+
- [ ] I have updated the [changelog](https://github.com/aws/sagemaker-python-sdk/blob/master/CHANGELOG.rst) with a description of my changes (if appropriate)
12+
- [ ] I have updated any necessary [documentation](https://github.com/aws/sagemaker-python-sdk/blob/master/README.rst) (if appropriate)
13+
14+
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ scratch*.py
1818
examples/tensorflow/distributed_mnist/data
1919
*.iml
2020
doc/_build
21+
doc/_static
22+
doc/_templates
2123
**/.DS_Store
2224
venv/
2325
*~

.rtd-environment.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Conda environment file used by our custom ReadTheDocs environment.
2+
3+
name: sagemaker
4+
5+
dependencies:
6+
- python>=3
7+
- numpy
8+
- scipy

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
CHANGELOG
33
=========
44

5+
1.2.3
6+
=========
7+
* bug-fix: Fix local mode not using the right s3 bucket
8+
59
1.2.2
610
=====
711

CODE_OF_CONDUCT.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Code of Conduct
2+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4+
[email protected] with any additional questions or comments.

CONTRIBUTING.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Contributing Guidelines
2+
3+
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4+
documentation, we greatly value feedback and contributions from our community.
5+
6+
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7+
information to effectively respond to your bug report or contribution.
8+
9+
10+
## Reporting Bugs/Feature Requests
11+
12+
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13+
14+
When filing an issue, please check [existing open](https://github.com/aws/sagemaker-python-sdk/issues), or [recently closed](https://github.com/aws/sagemaker-python-sdk/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
15+
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16+
17+
* A reproducible test case or series of steps
18+
* The version of our code being used
19+
* Any modifications you've made relevant to the bug
20+
* A description of your environment or deployment
21+
22+
23+
## Contributing via Pull Requests
24+
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25+
26+
1. You are working against the latest source on the *master* branch.
27+
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28+
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29+
30+
To send us a pull request, please:
31+
32+
1. Fork the repository.
33+
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34+
3. Include unit tests when you contribute new features or make bug fixes, as they help to a) prove that your code works correctly, and b) guard against future breaking changes to lower the maintenance cost.
35+
4. Ensure local tests pass.
36+
5. Update the [changelog](https://github.com/aws/sagemaker-python-sdk/blob/master/CHANGELOG.rst) with a description of your changes for any code contribution.
37+
6. Commit to your fork using [clear and imperative commit messages](https://chris.beams.io/posts/git-commit/).
38+
7. Send us a pull request, answering any default questions in the pull request interface.
39+
8. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
40+
41+
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
42+
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
43+
44+
45+
## Finding contributions to work on
46+
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/sagemaker-python-sdk/labels/help%20wanted) issues is a great place to start.
47+
48+
49+
## Code of Conduct
50+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
51+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
52+
[email protected] with any additional questions or comments.
53+
54+
55+
## Security issue notifications
56+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
57+
58+
59+
## Licensing
60+
61+
See the [LICENSE](https://github.com/aws/sagemaker-python-sdk/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
62+
63+
We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.

README.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You can install from source by cloning this repository and issuing a pip install
4747

4848
git clone https://github.com/aws/sagemaker-python-sdk.git
4949
python setup.py sdist
50-
pip install dist/sagemaker-1.2.2.tar.gz
50+
pip install dist/sagemaker-1.2.3.tar.gz
5151

5252
Supported Python versions
5353
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -56,7 +56,8 @@ SageMaker Python SDK is tested on: \* Python 2.7 \* Python 3.5
5656

5757
Licensing
5858
~~~~~~~~~
59-
SageMaker Python SDK is licensed under the Apache 2.0 License. It is copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. The license is available at: http://aws.amazon.com/apache2.0/
59+
SageMaker Python SDK is licensed under the Apache 2.0 License. It is copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. The license is available at:
60+
http://aws.amazon.com/apache2.0/
6061

6162
Running tests
6263
~~~~~~~~~~~~~

doc/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ def __getattr__(cls, name):
1515

1616

1717
MOCK_MODULES = ['tensorflow', 'tensorflow.core', 'tensorflow.core.framework', 'tensorflow.python',
18-
'tensorflow.python.framework', 'tensorflow_serving', 'tensorflow_serving.apis']
18+
'tensorflow.python.framework', 'tensorflow_serving', 'tensorflow_serving.apis',
19+
'numpy', 'scipy', 'scipy.sparse']
1920
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
2021

21-
version = '1.2.2'
22+
version = '1.2.3'
2223
project = u'sagemaker'
2324

2425
# Add any Sphinx extension module names here, as strings. They can be extensions

readthedocs.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ReadTheDocs environment customization to allow us to use conda to install
2+
# libraries which have C dependencies for the doc build. See:
3+
# http://docs.readthedocs.io/en/latest/yaml-config.html
4+
5+
conda:
6+
file: .rtd-environment.yml
7+
8+
python:
9+
setup_py_install: true

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def read(fname):
1111

1212

1313
setup(name="sagemaker",
14-
version="1.2.pytorch",
14+
version="1.3.dev",
1515
description="Open source library for training and deploying models on Amazon SageMaker.",
1616
packages=find_packages('src'),
1717
package_dir={'': 'src'},

src/sagemaker/local/image.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def train(self, input_data_config, hyperparameters):
8787
os.mkdir(os.path.join(self.container_root, 'output'))
8888

8989
data_dir = self._create_tmp_folder()
90-
bucket_name = self.sagemaker_session.default_bucket()
9190
volumes = []
9291

9392
# Set up the channels for the containers. For local data we will
@@ -102,7 +101,8 @@ def train(self, input_data_config, hyperparameters):
102101
channel_dir = os.path.join(data_dir, channel_name)
103102
os.mkdir(channel_dir)
104103

105-
if uri.lower().startswith("s3://"):
104+
if parsed_uri.scheme == 's3':
105+
bucket_name = parsed_uri.netloc
106106
self._download_folder(bucket_name, key, channel_dir)
107107
else:
108108
volumes.append(_Volume(uri, channel=channel_name))

tests/integ/test_tf_cifar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __call__(self, data):
3131

3232

3333
def test_cifar(sagemaker_session, tf_full_version):
34-
with timeout(minutes=15):
34+
with timeout(minutes=20):
3535
script_path = os.path.join(DATA_DIR, 'cifar_10', 'source')
3636

3737
dataset_path = os.path.join(DATA_DIR, 'cifar_10', 'data')

tests/unit/test_image.py

+44-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818
import yaml
19-
from mock import patch, Mock
19+
from mock import call, patch, Mock
2020

2121
import sagemaker
2222
from sagemaker.local.image import _SageMakerContainer
@@ -40,7 +40,7 @@
4040
'S3DataSource': {
4141
'S3DataDistributionType': 'FullyReplicated',
4242
'S3DataType': 'S3Prefix',
43-
'S3Uri': 's3://foo/bar'
43+
'S3Uri': 's3://my-own-bucket/prefix'
4444
}
4545
}
4646
}
@@ -54,12 +54,12 @@ def sagemaker_session():
5454
boto_mock.client('sts').get_caller_identity.return_value = {'Account': '123'}
5555
boto_mock.resource('s3').Bucket(BUCKET_NAME).objects.filter.return_value = []
5656

57-
ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
57+
sms = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
5858

59-
ims.default_bucket = Mock(name='default_bucket', return_value=BUCKET_NAME)
60-
ims.expand_role = Mock(return_value=EXPANDED_ROLE)
59+
sms.default_bucket = Mock(name='default_bucket', return_value=BUCKET_NAME)
60+
sms.expand_role = Mock(return_value=EXPANDED_ROLE)
6161

62-
return ims
62+
return sms
6363

6464

6565
@patch('sagemaker.local.local_session.LocalSession')
@@ -181,16 +181,22 @@ def test_check_output():
181181
@patch('sagemaker.local.local_session.LocalSession')
182182
@patch('sagemaker.local.image._execute_and_stream_output')
183183
@patch('sagemaker.local.image._SageMakerContainer._cleanup')
184-
def test_train(LocalSession, _execute_and_stream_output, _cleanup, tmpdir, sagemaker_session):
184+
@patch('sagemaker.local.image._SageMakerContainer._download_folder')
185+
def test_train(_download_folder, _cleanup, _execute_and_stream_output, LocalSession, tmpdir, sagemaker_session):
185186

187+
directories = [str(tmpdir.mkdir('container-root')), str(tmpdir.mkdir('data'))]
186188
with patch('sagemaker.local.image._SageMakerContainer._create_tmp_folder',
187-
side_effect=[str(tmpdir.mkdir('container-root')), str(tmpdir.mkdir('data'))]):
189+
side_effect=directories):
188190

189191
instance_count = 2
190192
image = 'my-image'
191193
sagemaker_container = _SageMakerContainer('local', instance_count, image, sagemaker_session=sagemaker_session)
192194
sagemaker_container.train(INPUT_DATA_CONFIG, HYPERPARAMETERS)
193195

196+
channel_dir = os.path.join(directories[1], 'b')
197+
download_folder_calls = [call('my-own-bucket', 'prefix', channel_dir)]
198+
_download_folder.assert_has_calls(download_folder_calls)
199+
194200
docker_compose_file = os.path.join(sagemaker_container.container_root, 'docker-compose.yaml')
195201

196202
call_args = _execute_and_stream_output.call_args[0][0]
@@ -231,6 +237,36 @@ def test_serve(up, copy, copytree, tmpdir, sagemaker_session):
231237
assert config['services'][h]['command'] == 'serve'
232238

233239

240+
@patch('os.makedirs')
241+
def test_download_folder(makedirs):
242+
boto_mock = Mock(name='boto_session')
243+
boto_mock.client('sts').get_caller_identity.return_value = {'Account': '123'}
244+
245+
session = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
246+
247+
train_data = Mock()
248+
validation_data = Mock()
249+
250+
train_data.bucket_name.return_value = BUCKET_NAME
251+
train_data.key = '/prefix/train/train_data.csv'
252+
validation_data.bucket_name.return_value = BUCKET_NAME
253+
validation_data.key = '/prefix/train/validation_data.csv'
254+
255+
s3_files = [train_data, validation_data]
256+
boto_mock.resource('s3').Bucket(BUCKET_NAME).objects.filter.return_value = s3_files
257+
258+
obj_mock = Mock()
259+
boto_mock.resource('s3').Object.return_value = obj_mock
260+
261+
sagemaker_container = _SageMakerContainer('local', 2, 'my-image', sagemaker_session=session)
262+
sagemaker_container._download_folder(BUCKET_NAME, '/prefix', '/tmp')
263+
264+
obj_mock.download_file.assert_called()
265+
calls = [call(os.path.join('/tmp', 'train/train_data.csv')),
266+
call(os.path.join('/tmp', 'train/validation_data.csv'))]
267+
obj_mock.download_file.assert_has_calls(calls)
268+
269+
234270
def test_ecr_login_non_ecr():
235271
session_mock = Mock()
236272
sagemaker.local.image._ecr_login_if_needed(session_mock, 'ubuntu')

0 commit comments

Comments
 (0)