Skip to content

Commit b320572

Browse files
committed
change: Format all files using Black
This commit contains no functional changes.
1 parent 4fb2e20 commit b320572

File tree

202 files changed

+23212
-16260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+23212
-16260
lines changed

doc/conf.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,65 @@ def __getattr__(cls, name):
2828
return MagicMock()
2929

3030

31-
MOCK_MODULES = ['tensorflow', 'tensorflow.core', 'tensorflow.core.framework', 'tensorflow.python',
32-
'tensorflow.python.framework', 'tensorflow_serving', 'tensorflow_serving.apis',
33-
'numpy', 'scipy', 'scipy.sparse']
31+
MOCK_MODULES = [
32+
"tensorflow",
33+
"tensorflow.core",
34+
"tensorflow.core.framework",
35+
"tensorflow.python",
36+
"tensorflow.python.framework",
37+
"tensorflow_serving",
38+
"tensorflow_serving.apis",
39+
"numpy",
40+
"scipy",
41+
"scipy.sparse",
42+
]
3443
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
3544

36-
project = u'sagemaker'
45+
project = u"sagemaker"
3746
version = pkg_resources.require(project)[0].version
3847

3948
# Add any Sphinx extension module names here, as strings. They can be extensions
4049
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
41-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
42-
'sphinx.ext.intersphinx', 'sphinx.ext.todo',
43-
'sphinx.ext.coverage', 'sphinx.ext.autosummary',
44-
'sphinx.ext.napoleon']
50+
extensions = [
51+
"sphinx.ext.autodoc",
52+
"sphinx.ext.doctest",
53+
"sphinx.ext.intersphinx",
54+
"sphinx.ext.todo",
55+
"sphinx.ext.coverage",
56+
"sphinx.ext.autosummary",
57+
"sphinx.ext.napoleon",
58+
]
4559

4660
# Add any paths that contain templates here, relative to this directory.
47-
templates_path = ['_templates']
61+
templates_path = ["_templates"]
4862

49-
source_suffix = '.rst' # The suffix of source filenames.
50-
master_doc = 'index' # The master toctree document.
63+
source_suffix = ".rst" # The suffix of source filenames.
64+
master_doc = "index" # The master toctree document.
5165

52-
copyright = u'%s, Amazon' % datetime.now().year
66+
copyright = u"%s, Amazon" % datetime.now().year
5367

5468
# The full version, including alpha/beta/rc tags.
5569
release = version
5670

5771
# List of directories, relative to source directory, that shouldn't be searched
5872
# for source files.
59-
exclude_trees = ['_build']
73+
exclude_trees = ["_build"]
6074

61-
pygments_style = 'default'
75+
pygments_style = "default"
6276

6377
autoclass_content = "both"
64-
autodoc_default_flags = ['show-inheritance', 'members', 'undoc-members']
65-
autodoc_member_order = 'bysource'
78+
autodoc_default_flags = ["show-inheritance", "members", "undoc-members"]
79+
autodoc_member_order = "bysource"
6680

67-
if 'READTHEDOCS' in os.environ:
68-
html_theme = 'default'
81+
if "READTHEDOCS" in os.environ:
82+
html_theme = "default"
6983
else:
70-
html_theme = 'haiku'
84+
html_theme = "haiku"
7185
html_static_path = []
72-
htmlhelp_basename = '%sdoc' % project
86+
htmlhelp_basename = "%sdoc" % project
7387

7488
# Example configuration for intersphinx: refer to the Python standard library.
75-
intersphinx_mapping = {'http://docs.python.org/': None}
89+
intersphinx_mapping = {"http://docs.python.org/": None}
7690

7791
# autosummary
7892
autosummary_generate = True

examples/cli/host/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def model_fn(model_dir):
1212
:param: model_dir The directory where model files are stored.
1313
:return: a model (in this case a Gluon network)
1414
"""
15-
symbol = mx.sym.load('%s/model.json' % model_dir)
16-
outputs = mx.symbol.softmax(data=symbol, name='softmax_label')
17-
inputs = mx.sym.var('data')
18-
param_dict = gluon.ParameterDict('model_')
15+
symbol = mx.sym.load("%s/model.json" % model_dir)
16+
outputs = mx.symbol.softmax(data=symbol, name="softmax_label")
17+
inputs = mx.sym.var("data")
18+
param_dict = gluon.ParameterDict("model_")
1919
net = gluon.SymbolBlock(outputs, inputs, param_dict)
20-
net.load_params('%s/model.params' % model_dir, ctx=mx.cpu())
20+
net.load_params("%s/model.params" % model_dir, ctx=mx.cpu())
2121
return net
2222

2323

examples/cli/train/download_training_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
def download_training_data():
5-
gluon.data.vision.MNIST('./data/training', train=True)
6-
gluon.data.vision.MNIST('./data/training', train=False)
5+
gluon.data.vision.MNIST("./data/training", train=True)
6+
gluon.data.vision.MNIST("./data/training", train=False)
77

88

99
if __name__ == "__main__":

examples/cli/train/script.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ def train(channel_input_dirs, hyperparameters, **kwargs):
1515
ctx = mx.cpu()
1616

1717
# retrieve the hyperparameters we set in notebook (with some defaults)
18-
batch_size = hyperparameters.get('batch_size', 100)
19-
epochs = hyperparameters.get('epochs', 10)
20-
learning_rate = hyperparameters.get('learning_rate', 0.1)
21-
momentum = hyperparameters.get('momentum', 0.9)
22-
log_interval = hyperparameters.get('log_interval', 100)
18+
batch_size = hyperparameters.get("batch_size", 100)
19+
epochs = hyperparameters.get("epochs", 10)
20+
learning_rate = hyperparameters.get("learning_rate", 0.1)
21+
momentum = hyperparameters.get("momentum", 0.9)
22+
log_interval = hyperparameters.get("log_interval", 100)
2323

24-
training_data = channel_input_dirs['training']
24+
training_data = channel_input_dirs["training"]
2525

2626
# load training and validation data
2727
# we use the gluon.data.vision.MNIST class because of its built in mnist pre-processing logic,
@@ -35,8 +35,9 @@ def train(channel_input_dirs, hyperparameters, **kwargs):
3535
# Collect all parameters from net and its children, then initialize them.
3636
net.initialize(mx.init.Xavier(magnitude=2.24), ctx=ctx)
3737
# Trainer is for updating parameters with gradient.
38-
trainer = gluon.Trainer(net.collect_params(), 'sgd',
39-
{'learning_rate': learning_rate, 'momentum': momentum})
38+
trainer = gluon.Trainer(
39+
net.collect_params(), "sgd", {"learning_rate": learning_rate, "momentum": momentum}
40+
)
4041
metric = mx.metric.Accuracy()
4142
loss = gluon.loss.SoftmaxCrossEntropyLoss()
4243

@@ -61,32 +62,34 @@ def train(channel_input_dirs, hyperparameters, **kwargs):
6162

6263
if i % log_interval == 0 and i > 0:
6364
name, acc = metric.get()
64-
logger.info('[Epoch %d Batch %d] Training: %s=%f, %f samples/s' %
65-
(epoch, i, name, acc, batch_size / (time.time() - btic)))
65+
logger.info(
66+
"[Epoch %d Batch %d] Training: %s=%f, %f samples/s"
67+
% (epoch, i, name, acc, batch_size / (time.time() - btic))
68+
)
6669

6770
btic = time.time()
6871

6972
name, acc = metric.get()
70-
logger.info('[Epoch %d] Training: %s=%f' % (epoch, name, acc))
73+
logger.info("[Epoch %d] Training: %s=%f" % (epoch, name, acc))
7174

7275
name, val_acc = test(ctx, net, val_data)
73-
logger.info('[Epoch %d] Validation: %s=%f' % (epoch, name, val_acc))
76+
logger.info("[Epoch %d] Validation: %s=%f" % (epoch, name, val_acc))
7477

7578
return net
7679

7780

7881
def save(net, model_dir):
7982
# save the model
80-
y = net(mx.sym.var('data'))
81-
y.save('%s/model.json' % model_dir)
82-
net.collect_params().save('%s/model.params' % model_dir)
83+
y = net(mx.sym.var("data"))
84+
y.save("%s/model.json" % model_dir)
85+
net.collect_params().save("%s/model.params" % model_dir)
8386

8487

8588
def define_network():
8689
net = nn.Sequential()
8790
with net.name_scope():
88-
net.add(nn.Dense(128, activation='relu'))
89-
net.add(nn.Dense(64, activation='relu'))
91+
net.add(nn.Dense(128, activation="relu"))
92+
net.add(nn.Dense(64, activation="relu"))
9093
net.add(nn.Dense(10))
9194
return net
9295

@@ -99,13 +102,18 @@ def input_transformer(data, label):
99102
def get_train_data(data_dir, batch_size):
100103
return gluon.data.DataLoader(
101104
gluon.data.vision.MNIST(data_dir, train=True, transform=input_transformer),
102-
batch_size=batch_size, shuffle=True, last_batch='discard')
105+
batch_size=batch_size,
106+
shuffle=True,
107+
last_batch="discard",
108+
)
103109

104110

105111
def get_val_data(data_dir, batch_size):
106112
return gluon.data.DataLoader(
107113
gluon.data.vision.MNIST(data_dir, train=False, transform=input_transformer),
108-
batch_size=batch_size, shuffle=False)
114+
batch_size=batch_size,
115+
shuffle=False,
116+
)
109117

110118

111119
def test(ctx, net, val_data):

setup.py

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,62 @@ def read(fname):
2424

2525

2626
def read_version():
27-
return read('VERSION').strip()
27+
return read("VERSION").strip()
2828

2929

3030
# Declare minimal set for installation
31-
required_packages = ['boto3>=1.9.169', 'numpy>=1.9.0', 'protobuf>=3.1', 'scipy>=0.19.0',
32-
'urllib3>=1.21, <1.25', 'protobuf3-to-dict>=0.1.5', 'docker-compose>=1.23.0',
33-
'requests>=2.20.0, <2.21']
31+
required_packages = [
32+
"boto3>=1.9.169",
33+
"numpy>=1.9.0",
34+
"protobuf>=3.1",
35+
"scipy>=0.19.0",
36+
"urllib3>=1.21, <1.25",
37+
"protobuf3-to-dict>=0.1.5",
38+
"docker-compose>=1.23.0",
39+
"requests>=2.20.0, <2.21",
40+
]
3441

3542
# enum is introduced in Python 3.4. Installing enum back port
3643
if sys.version_info < (3, 4):
37-
required_packages.append('enum34>=1.1.6')
44+
required_packages.append("enum34>=1.1.6")
3845

39-
setup(name="sagemaker",
40-
version=read_version(),
41-
description="Open source library for training and deploying models on Amazon SageMaker.",
42-
packages=find_packages('src'),
43-
package_dir={'': 'src'},
44-
py_modules=[os.path.splitext(os.path.basename(path))[0] for path in glob('src/*.py')],
45-
long_description=read('README.rst'),
46-
author="Amazon Web Services",
47-
url='https://github.com/aws/sagemaker-python-sdk/',
48-
license="Apache License 2.0",
49-
keywords="ML Amazon AWS AI Tensorflow MXNet",
50-
classifiers=[
51-
"Development Status :: 5 - Production/Stable",
52-
"Intended Audience :: Developers",
53-
"Natural Language :: English",
54-
"License :: OSI Approved :: Apache Software License",
55-
"Programming Language :: Python",
56-
"Programming Language :: Python :: 2.7",
57-
"Programming Language :: Python :: 3.6",
58-
],
59-
60-
install_requires=required_packages,
61-
62-
extras_require={
63-
'test': ['tox', 'flake8', 'pytest==4.4.1', 'pytest-cov', 'pytest-rerunfailures',
64-
'pytest-xdist', 'mock', 'tensorflow>=1.3.0', 'contextlib2',
65-
'awslogs', 'pandas', 'black==19.3b0 ; python_version >= \'3.6\'']},
66-
67-
entry_points={
68-
'console_scripts': ['sagemaker=sagemaker.cli.main:main'],
69-
})
46+
setup(
47+
name="sagemaker",
48+
version=read_version(),
49+
description="Open source library for training and deploying models on Amazon SageMaker.",
50+
packages=find_packages("src"),
51+
package_dir={"": "src"},
52+
py_modules=[os.path.splitext(os.path.basename(path))[0] for path in glob("src/*.py")],
53+
long_description=read("README.rst"),
54+
author="Amazon Web Services",
55+
url="https://github.com/aws/sagemaker-python-sdk/",
56+
license="Apache License 2.0",
57+
keywords="ML Amazon AWS AI Tensorflow MXNet",
58+
classifiers=[
59+
"Development Status :: 5 - Production/Stable",
60+
"Intended Audience :: Developers",
61+
"Natural Language :: English",
62+
"License :: OSI Approved :: Apache Software License",
63+
"Programming Language :: Python",
64+
"Programming Language :: Python :: 2.7",
65+
"Programming Language :: Python :: 3.6",
66+
],
67+
install_requires=required_packages,
68+
extras_require={
69+
"test": [
70+
"tox",
71+
"flake8",
72+
"pytest==4.4.1",
73+
"pytest-cov",
74+
"pytest-rerunfailures",
75+
"pytest-xdist",
76+
"mock",
77+
"tensorflow>=1.3.0",
78+
"contextlib2",
79+
"awslogs",
80+
"pandas",
81+
"black==19.3b0 ; python_version >= '3.6'",
82+
]
83+
},
84+
entry_points={"console_scripts": ["sagemaker=sagemaker.cli.main:main"]},
85+
)

src/sagemaker/__init__.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,29 @@
1818
from sagemaker.amazon.kmeans import KMeans, KMeansModel, KMeansPredictor # noqa: F401
1919
from sagemaker.amazon.pca import PCA, PCAModel, PCAPredictor # noqa: F401
2020
from sagemaker.amazon.lda import LDA, LDAModel, LDAPredictor # noqa: F401
21-
from sagemaker.amazon.linear_learner import LinearLearner, LinearLearnerModel, LinearLearnerPredictor # noqa: F401
22-
from sagemaker.amazon.factorization_machines import FactorizationMachines, FactorizationMachinesModel # noqa: F401
21+
from sagemaker.amazon.linear_learner import (
22+
LinearLearner,
23+
LinearLearnerModel,
24+
LinearLearnerPredictor,
25+
) # noqa: F401
26+
from sagemaker.amazon.factorization_machines import (
27+
FactorizationMachines,
28+
FactorizationMachinesModel,
29+
) # noqa: F401
2330
from sagemaker.amazon.factorization_machines import FactorizationMachinesPredictor # noqa: F401
2431
from sagemaker.amazon.ntm import NTM, NTMModel, NTMPredictor # noqa: F401
25-
from sagemaker.amazon.randomcutforest import (RandomCutForest, RandomCutForestModel, # noqa: F401
26-
RandomCutForestPredictor)
32+
from sagemaker.amazon.randomcutforest import (
33+
RandomCutForest,
34+
RandomCutForestModel, # noqa: F401
35+
RandomCutForestPredictor,
36+
)
2737
from sagemaker.amazon.knn import KNN, KNNModel, KNNPredictor # noqa: F401
2838
from sagemaker.amazon.object2vec import Object2Vec, Object2VecModel # noqa: F401
29-
from sagemaker.amazon.ipinsights import IPInsights, IPInsightsModel, IPInsightsPredictor # noqa: F401
39+
from sagemaker.amazon.ipinsights import (
40+
IPInsights,
41+
IPInsightsModel,
42+
IPInsightsPredictor,
43+
) # noqa: F401
3044

3145
from sagemaker.algorithm import AlgorithmEstimator # noqa: F401
3246
from sagemaker.analytics import TrainingJobAnalytics, HyperparameterTuningJobAnalytics # noqa: F401
@@ -41,4 +55,4 @@
4155
from sagemaker.session import s3_input # noqa: F401
4256
from sagemaker.session import get_execution_role # noqa: F401
4357

44-
__version__ = pkg_resources.require('sagemaker')[0].version
58+
__version__ = pkg_resources.require("sagemaker")[0].version

0 commit comments

Comments
 (0)