Skip to content

Commit 583ec2d

Browse files
authored
feature: separating sagemaker dependencies into more use case specific installable components. (#1130)
1 parent d8752f4 commit 583ec2d

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

doc/overview.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ For example, the ``dataframe`` method gets a pandas dataframe summarizing the as
661661
# Look at summary of associated training jobs
662662
my_dataframe = my_tuner_analytics.dataframe()
663663
664+
You can install all necessary for this feature dependencies using pip:
665+
666+
::
667+
668+
pip install 'sagemaker[analytics]' --upgrade
669+
664670
For more detailed examples of running hyperparameter tuning jobs, see:
665671

666672
- `Using the TensorFlow estimator with hyperparameter tuning <https://github.com/awslabs/amazon-sagemaker-examples/blob/master/hyperparameter_tuning/tensorflow_mnist/hpo_tensorflow_mnist.ipynb>`__
@@ -718,6 +724,12 @@ The SageMaker Python SDK supports local mode, which allows you to create estimat
718724
This is a great way to test your deep learning scripts before running them in SageMaker's managed training or hosting environments.
719725
Local Mode is supported for frameworks images (TensorFlow, MXNet, Chainer, PyTorch, and Scikit-Learn) and images you supply yourself.
720726

727+
You can install all necessary for this feature dependencies using pip:
728+
729+
::
730+
731+
pip install 'sagemaker[local]' --upgrade
732+
721733
We can take the example in `Using Estimators <#using-estimators>`__ , and use either ``local`` or ``local_gpu`` as the instance type.
722734

723735
.. code:: python

setup.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,40 @@ def read_version():
3838
"numpy>=1.9.0",
3939
"protobuf>=3.1",
4040
"scipy>=0.19.0",
41-
"urllib3>=1.21, <1.25",
41+
"urllib3>=1.21, <1.25", # local mode dependencies -> remove in the next release
4242
"protobuf3-to-dict>=0.1.5",
4343
"requests>=2.20.0, <2.21",
44-
"fabric>=2.0",
44+
"docker-compose>=1.23.0", # local mode dependencies -> remove in the next release
4545
]
4646

47+
# Specific use case dependencies
48+
extras = {
49+
"analytics": ["pandas"],
50+
"local": ["urllib3>=1.21, <1.25", "docker-compose>=1.23.0"],
51+
"tensorflow": ["tensorflow>=1.3.0"],
52+
}
53+
# Meta dependency groups
54+
extras["all"] = [item for group in extras.values() for item in group]
55+
# Tests specific dependencies (do not need to be included in 'all')
56+
extras["test"] = (
57+
[
58+
extras["all"],
59+
"tox==3.13.1",
60+
"flake8",
61+
"pytest==4.4.1",
62+
"pytest-cov",
63+
"pytest-rerunfailures",
64+
"pytest-xdist",
65+
"mock",
66+
"contextlib2",
67+
"awslogs",
68+
"black==19.3b0 ; python_version >= '3.6'",
69+
"stopit==1.1.2",
70+
"apache-airflow==1.10.5",
71+
"fabric>=2.0",
72+
],
73+
)
74+
4775
# enum is introduced in Python 3.4. Installing enum back port
4876
if sys.version_info < (3, 4):
4977
required_packages.append("enum34>=1.1.6")
@@ -70,24 +98,6 @@ def read_version():
7098
"Programming Language :: Python :: 3.6",
7199
],
72100
install_requires=required_packages,
73-
extras_require={
74-
"test": [
75-
"tox==3.13.1",
76-
"flake8",
77-
"pytest==4.4.1",
78-
"pytest-cov",
79-
"pytest-rerunfailures",
80-
"pytest-xdist",
81-
"mock",
82-
"tensorflow>=1.3.0",
83-
"contextlib2",
84-
"awslogs",
85-
"pandas",
86-
"black==19.3b0 ; python_version >= '3.6'",
87-
"stopit==1.1.2",
88-
"apache-airflow==1.10.5",
89-
"docker-compose>=1.23.0",
90-
]
91-
},
101+
extras_require=extras,
92102
entry_points={"console_scripts": ["sagemaker=sagemaker.cli.main:main"]},
93103
)

src/sagemaker/local/entities.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
import os
2020
import tempfile
2121
import time
22-
import urllib3
2322

2423
import sagemaker.local.data
2524
from sagemaker.local.image import _SageMakerContainer
2625
from sagemaker.local.utils import copy_directory_structure, move_to_destination
27-
from sagemaker.utils import get_config_value
26+
from sagemaker.utils import DeferredError, get_config_value
27+
28+
try:
29+
import urllib3
30+
except ImportError as e:
31+
logging.warning("urllib3 failed to import. Local mode features will be impaired or broken.")
32+
# Any subsequent attempt to use urllib3 will raise the ImportError
33+
urllib3 = DeferredError(e)
34+
2835

2936
logger = logging.getLogger(__name__)
3037

src/sagemaker/local/local_session.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import platform
1818

1919
import boto3
20-
import urllib3
2120
from botocore.exceptions import ClientError
2221

2322
from sagemaker.local.image import _SageMakerContainer
@@ -29,7 +28,14 @@
2928
_LocalTransformJob,
3029
)
3130
from sagemaker.session import Session
32-
from sagemaker.utils import get_config_value
31+
from sagemaker.utils import DeferredError, get_config_value
32+
33+
try:
34+
import urllib3
35+
except ImportError as e:
36+
logging.warning("urllib3 failed to import. Local mode features will be impaired or broken.")
37+
# Any subsequent attempt to use urllib3 will raise the ImportError
38+
urllib3 = DeferredError(e)
3339

3440
logger = logging.getLogger(__name__)
3541

0 commit comments

Comments
 (0)