Skip to content

Commit a5ce90b

Browse files
authored
Revert "change: enable wrong-import-position pylint check (#907)"
This reverts commit 8489f86.
1 parent 34de9ae commit a5ce90b

14 files changed

+222
-250
lines changed

.pylintrc

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ disable=
100100
simplifiable-if-expression, # TODO: Simplify expressions
101101
too-many-public-methods, # TODO: Resolve
102102
ungrouped-imports, # TODO: Group imports
103+
wrong-import-position, # TODO: Correct import positions
103104
consider-using-ternary, # TODO: Consider ternary expressions
104105
chained-comparison, # TODO: Simplify chained comparison between operands
105106
simplifiable-if-statement, # TODO: Simplify ifs

src/sagemaker/amazon/record_pb2.py

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sagemaker/cli/tensorflow.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15-
from sagemaker.tensorflow import estimator
16-
from sagemaker.tensorflow import model
17-
1815
from sagemaker.cli.common import HostCommand, TrainCommand
1916

2017

@@ -33,7 +30,9 @@ def __init__(self, args):
3330
self.evaluation_steps = args.evaluation_steps
3431

3532
def create_estimator(self):
36-
return estimator.TensorFlow(
33+
from sagemaker.tensorflow import TensorFlow
34+
35+
return TensorFlow(
3736
training_steps=self.training_steps,
3837
evaluation_steps=self.evaluation_steps,
3938
py_version=self.python,
@@ -48,7 +47,9 @@ def create_estimator(self):
4847

4948
class TensorFlowHostCommand(HostCommand):
5049
def create_model(self, model_url):
51-
return model.TensorFlowModel(
50+
from sagemaker.tensorflow.model import TensorFlowModel
51+
52+
return TensorFlowModel(
5253
model_data=model_url,
5354
role=self.role_name,
5455
entry_point=self.script,

src/sagemaker/tensorflow/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@
1919
# classes for tensorflow serving. Currently tensorflow_serving_api can only be pip-installed for python 2.
2020
sys.path.append(os.path.dirname(__file__))
2121

22-
from sagemaker.tensorflow import ( # noqa: E402,F401 # pylint: disable=wrong-import-position
23-
estimator,
24-
)
25-
from sagemaker.tensorflow import model # noqa: E402,F401 # pylint: disable=wrong-import-position
22+
from sagemaker.tensorflow.estimator import TensorFlow # noqa: E402, F401
23+
from sagemaker.tensorflow.model import TensorFlowModel, TensorFlowPredictor # noqa: E402, F401

tests/component/test_tf_estimator.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import pytest
1616
from mock import Mock
17-
from sagemaker.tensorflow import estimator
17+
from sagemaker.tensorflow import TensorFlow
1818

1919

2020
SCRIPT = "resnet_cifar_10.py"
@@ -53,7 +53,7 @@ def sagemaker_session():
5353

5454
# Test that we pass all necessary fields from estimator to the session when we call deploy
5555
def test_deploy(sagemaker_session, tf_version):
56-
tensorflow_estimator = estimator.TensorFlow(
56+
estimator = TensorFlow(
5757
entry_point=SCRIPT,
5858
source_dir=SOURCE_DIR,
5959
role=ROLE,
@@ -64,13 +64,13 @@ def test_deploy(sagemaker_session, tf_version):
6464
base_job_name="test-cifar",
6565
)
6666

67-
tensorflow_estimator.fit("s3://mybucket/train")
68-
print("job succeeded: {}".format(tensorflow_estimator.latest_training_job.name))
67+
estimator.fit("s3://mybucket/train")
68+
print("job succeeded: {}".format(estimator.latest_training_job.name))
6969

70-
tensorflow_estimator.deploy(initial_instance_count=1, instance_type=INSTANCE_TYPE_CPU)
70+
estimator.deploy(initial_instance_count=1, instance_type=INSTANCE_TYPE_CPU)
7171
image = IMAGE_URI_FORMAT_STRING.format(REGION, CPU_IMAGE_NAME, tf_version, "cpu", "py2")
7272
sagemaker_session.create_model.assert_called_with(
73-
tensorflow_estimator._current_job_name,
73+
estimator._current_job_name,
7474
ROLE,
7575
{
7676
"Environment": {

tests/integ/test_horovod.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import sagemaker.utils
2424
import tests.integ as integ
25-
from sagemaker.tensorflow import estimator
25+
from sagemaker.tensorflow import TensorFlow
2626
from tests.integ import test_region, timeout, HOSTING_NO_P3_REGIONS
2727

2828
horovod_dir = os.path.join(os.path.dirname(__file__), "..", "data", "horovod")
@@ -47,7 +47,7 @@ def instance_type(request):
4747
@pytest.mark.canary_quick
4848
def test_horovod(sagemaker_session, instance_type, tmpdir):
4949
job_name = sagemaker.utils.unique_name_from_base("tf-horovod")
50-
tensorflow_estimator = estimator.TensorFlow(
50+
estimator = TensorFlow(
5151
entry_point=os.path.join(horovod_dir, "test_hvd_basic.py"),
5252
role="SageMakerRole",
5353
train_instance_count=2,
@@ -60,10 +60,10 @@ def test_horovod(sagemaker_session, instance_type, tmpdir):
6060
)
6161

6262
with timeout.timeout(minutes=integ.TRAINING_DEFAULT_TIMEOUT_MINUTES):
63-
tensorflow_estimator.fit(job_name=job_name)
63+
estimator.fit(job_name=job_name)
6464

6565
tmp = str(tmpdir)
66-
extract_files_from_s3(tensorflow_estimator.model_data, tmp)
66+
extract_files_from_s3(estimator.model_data, tmp)
6767

6868
for rank in range(2):
6969
assert read_json("rank-%s" % rank, tmp)["rank"] == rank
@@ -74,7 +74,7 @@ def test_horovod(sagemaker_session, instance_type, tmpdir):
7474
def test_horovod_local_mode(sagemaker_local_session, instances, processes, tmpdir):
7575
output_path = "file://%s" % tmpdir
7676
job_name = sagemaker.utils.unique_name_from_base("tf-horovod")
77-
tensorflow_estimator = estimator.TensorFlow(
77+
estimator = TensorFlow(
7878
entry_point=os.path.join(horovod_dir, "test_hvd_basic.py"),
7979
role="SageMakerRole",
8080
train_instance_count=2,
@@ -88,7 +88,7 @@ def test_horovod_local_mode(sagemaker_local_session, instances, processes, tmpdi
8888
)
8989

9090
with timeout.timeout(minutes=integ.TRAINING_DEFAULT_TIMEOUT_MINUTES):
91-
tensorflow_estimator.fit(job_name=job_name)
91+
estimator.fit(job_name=job_name)
9292

9393
tmp = str(tmpdir)
9494
extract_files(output_path.replace("file://", ""), tmp)

tests/integ/test_local_mode.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from sagemaker.local import LocalSession, LocalSagemakerRuntimeClient, LocalSagemakerClient
2929
from sagemaker.mxnet import MXNet
30-
from sagemaker.tensorflow import estimator
30+
from sagemaker.tensorflow import TensorFlow
3131

3232
# endpoint tests all use the same port, so we use this lock to prevent concurrent execution
3333
LOCK_PATH = os.path.join(tempfile.gettempdir(), "sagemaker_test_local_mode_lock")
@@ -90,7 +90,7 @@ def test_tf_local_mode(sagemaker_local_session):
9090
with stopit.ThreadingTimeout(5 * 60, swallow_exc=False):
9191
script_path = os.path.join(DATA_DIR, "iris", "iris-dnn-classifier.py")
9292

93-
tensorflow_estimator = estimator.TensorFlow(
93+
estimator = TensorFlow(
9494
entry_point=script_path,
9595
role="SageMakerRole",
9696
framework_version="1.12",
@@ -103,16 +103,16 @@ def test_tf_local_mode(sagemaker_local_session):
103103
sagemaker_session=sagemaker_local_session,
104104
)
105105

106-
inputs = tensorflow_estimator.sagemaker_session.upload_data(
106+
inputs = estimator.sagemaker_session.upload_data(
107107
path=DATA_PATH, key_prefix="integ-test-data/tf_iris"
108108
)
109-
tensorflow_estimator.fit(inputs)
110-
print("job succeeded: {}".format(tensorflow_estimator.latest_training_job.name))
109+
estimator.fit(inputs)
110+
print("job succeeded: {}".format(estimator.latest_training_job.name))
111111

112-
endpoint_name = tensorflow_estimator.latest_training_job.name
112+
endpoint_name = estimator.latest_training_job.name
113113
with lock.lock(LOCK_PATH):
114114
try:
115-
json_predictor = tensorflow_estimator.deploy(
115+
json_predictor = estimator.deploy(
116116
initial_instance_count=1, instance_type="local", endpoint_name=endpoint_name
117117
)
118118

@@ -124,7 +124,7 @@ def test_tf_local_mode(sagemaker_local_session):
124124

125125
assert dict_result == list_result
126126
finally:
127-
tensorflow_estimator.delete_endpoint()
127+
estimator.delete_endpoint()
128128

129129

130130
@pytest.mark.local_mode
@@ -133,7 +133,7 @@ def test_tf_distributed_local_mode(sagemaker_local_session):
133133
with stopit.ThreadingTimeout(5 * 60, swallow_exc=False):
134134
script_path = os.path.join(DATA_DIR, "iris", "iris-dnn-classifier.py")
135135

136-
tensorflow_estimator = estimator.TensorFlow(
136+
estimator = TensorFlow(
137137
entry_point=script_path,
138138
role="SageMakerRole",
139139
framework_version="1.12",
@@ -147,14 +147,14 @@ def test_tf_distributed_local_mode(sagemaker_local_session):
147147
)
148148

149149
inputs = "file://" + DATA_PATH
150-
tensorflow_estimator.fit(inputs)
151-
print("job succeeded: {}".format(tensorflow_estimator.latest_training_job.name))
150+
estimator.fit(inputs)
151+
print("job succeeded: {}".format(estimator.latest_training_job.name))
152152

153-
endpoint_name = tensorflow_estimator.latest_training_job.name
153+
endpoint_name = estimator.latest_training_job.name
154154

155155
with lock.lock(LOCK_PATH):
156156
try:
157-
json_predictor = tensorflow_estimator.deploy(
157+
json_predictor = estimator.deploy(
158158
initial_instance_count=1, instance_type="local", endpoint_name=endpoint_name
159159
)
160160

@@ -166,7 +166,7 @@ def test_tf_distributed_local_mode(sagemaker_local_session):
166166

167167
assert dict_result == list_result
168168
finally:
169-
tensorflow_estimator.delete_endpoint()
169+
estimator.delete_endpoint()
170170

171171

172172
@pytest.mark.local_mode
@@ -175,7 +175,7 @@ def test_tf_local_data(sagemaker_local_session):
175175
with stopit.ThreadingTimeout(5 * 60, swallow_exc=False):
176176
script_path = os.path.join(DATA_DIR, "iris", "iris-dnn-classifier.py")
177177

178-
tensorflow_estimator = estimator.TensorFlow(
178+
estimator = TensorFlow(
179179
entry_point=script_path,
180180
role="SageMakerRole",
181181
framework_version="1.12",
@@ -189,13 +189,13 @@ def test_tf_local_data(sagemaker_local_session):
189189
)
190190

191191
inputs = "file://" + DATA_PATH
192-
tensorflow_estimator.fit(inputs)
193-
print("job succeeded: {}".format(tensorflow_estimator.latest_training_job.name))
192+
estimator.fit(inputs)
193+
print("job succeeded: {}".format(estimator.latest_training_job.name))
194194

195-
endpoint_name = tensorflow_estimator.latest_training_job.name
195+
endpoint_name = estimator.latest_training_job.name
196196
with lock.lock(LOCK_PATH):
197197
try:
198-
json_predictor = tensorflow_estimator.deploy(
198+
json_predictor = estimator.deploy(
199199
initial_instance_count=1, instance_type="local", endpoint_name=endpoint_name
200200
)
201201

@@ -207,7 +207,7 @@ def test_tf_local_data(sagemaker_local_session):
207207

208208
assert dict_result == list_result
209209
finally:
210-
tensorflow_estimator.delete_endpoint()
210+
estimator.delete_endpoint()
211211

212212

213213
@pytest.mark.local_mode
@@ -216,7 +216,7 @@ def test_tf_local_data_local_script():
216216
with stopit.ThreadingTimeout(5 * 60, swallow_exc=False):
217217
script_path = os.path.join(DATA_DIR, "iris", "iris-dnn-classifier.py")
218218

219-
tensorflow_estimator = estimator.TensorFlow(
219+
estimator = TensorFlow(
220220
entry_point=script_path,
221221
role="SageMakerRole",
222222
framework_version="1.12",
@@ -231,13 +231,13 @@ def test_tf_local_data_local_script():
231231

232232
inputs = "file://" + DATA_PATH
233233

234-
tensorflow_estimator.fit(inputs)
235-
print("job succeeded: {}".format(tensorflow_estimator.latest_training_job.name))
234+
estimator.fit(inputs)
235+
print("job succeeded: {}".format(estimator.latest_training_job.name))
236236

237-
endpoint_name = tensorflow_estimator.latest_training_job.name
237+
endpoint_name = estimator.latest_training_job.name
238238
with lock.lock(LOCK_PATH):
239239
try:
240-
json_predictor = tensorflow_estimator.deploy(
240+
json_predictor = estimator.deploy(
241241
initial_instance_count=1, instance_type="local", endpoint_name=endpoint_name
242242
)
243243

@@ -249,7 +249,7 @@ def test_tf_local_data_local_script():
249249

250250
assert dict_result == list_result
251251
finally:
252-
tensorflow_estimator.delete_endpoint()
252+
estimator.delete_endpoint()
253253

254254

255255
@pytest.mark.local_mode

tests/integ/test_tf_cifar.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import tests.integ
2222
from tests.integ.timeout import timeout_and_delete_endpoint_by_name, timeout
2323

24-
from sagemaker.tensorflow import estimator
24+
from sagemaker.tensorflow import TensorFlow
2525
from sagemaker.utils import unique_name_from_base
2626

2727
PICKLE_CONTENT_TYPE = "application/python-pickle"
@@ -50,7 +50,7 @@ def test_cifar(sagemaker_session):
5050

5151
dataset_path = os.path.join(tests.integ.DATA_DIR, "cifar_10", "data")
5252

53-
tensorflow_estimator = estimator.TensorFlow(
53+
estimator = TensorFlow(
5454
entry_point="resnet_cifar_10.py",
5555
source_dir=script_path,
5656
role="SageMakerRole",
@@ -64,19 +64,17 @@ def test_cifar(sagemaker_session):
6464
base_job_name="test-cifar",
6565
)
6666

67-
inputs = tensorflow_estimator.sagemaker_session.upload_data(
67+
inputs = estimator.sagemaker_session.upload_data(
6868
path=dataset_path, key_prefix="data/cifar10"
6969
)
7070
job_name = unique_name_from_base("test-tf-cifar")
7171

72-
tensorflow_estimator.fit(inputs, logs=False, job_name=job_name)
73-
print("job succeeded: {}".format(tensorflow_estimator.latest_training_job.name))
72+
estimator.fit(inputs, logs=False, job_name=job_name)
73+
print("job succeeded: {}".format(estimator.latest_training_job.name))
7474

75-
endpoint_name = tensorflow_estimator.latest_training_job.name
75+
endpoint_name = estimator.latest_training_job.name
7676
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
77-
predictor = tensorflow_estimator.deploy(
78-
initial_instance_count=1, instance_type="ml.p2.xlarge"
79-
)
77+
predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")
8078
predictor.serializer = PickleSerializer()
8179
predictor.content_type = PICKLE_CONTENT_TYPE
8280

tests/integ/test_tf_keras.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import tests.integ
2121
from tests.integ.timeout import timeout_and_delete_endpoint_by_name, timeout
2222

23-
from sagemaker.tensorflow import estimator
23+
from sagemaker.tensorflow import TensorFlow
2424
from sagemaker.utils import unique_name_from_base
2525

2626

@@ -37,7 +37,7 @@ def test_keras(sagemaker_session):
3737
dataset_path = os.path.join(tests.integ.DATA_DIR, "cifar_10", "data")
3838

3939
with timeout(minutes=45):
40-
tensorflow_estimator = estimator.TensorFlow(
40+
estimator = TensorFlow(
4141
entry_point="keras_cnn_cifar_10.py",
4242
source_dir=script_path,
4343
role="SageMakerRole",
@@ -51,18 +51,16 @@ def test_keras(sagemaker_session):
5151
train_max_run=45 * 60,
5252
)
5353

54-
inputs = tensorflow_estimator.sagemaker_session.upload_data(
54+
inputs = estimator.sagemaker_session.upload_data(
5555
path=dataset_path, key_prefix="data/cifar10"
5656
)
5757
job_name = unique_name_from_base("test-tf-keras")
5858

59-
tensorflow_estimator.fit(inputs, job_name=job_name)
59+
estimator.fit(inputs, job_name=job_name)
6060

61-
endpoint_name = tensorflow_estimator.latest_training_job.name
61+
endpoint_name = estimator.latest_training_job.name
6262
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
63-
predictor = tensorflow_estimator.deploy(
64-
initial_instance_count=1, instance_type="ml.p2.xlarge"
65-
)
63+
predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")
6664

6765
data = np.random.randn(32, 32, 3)
6866
predict_response = predictor.predict(data)

0 commit comments

Comments
 (0)