Skip to content

Commit 9b2c6d6

Browse files
author
Deng
committed
Merge branch 'framework-gamma' of github.com:ChuyangDeng/sagemaker-python-sdk into framework-gamma
2 parents 254acea + 8851af6 commit 9b2c6d6

27 files changed

+191
-951
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Changelog
22

3+
## v1.50.16 (2020-02-26)
4+
5+
### Bug Fixes and Other Changes
6+
7+
* use sagemaker_session when initializing Constraints and Statistics
8+
* add sagemaker_session parameter to DataCaptureConfig
9+
* make AutoML.deploy use self.sagemaker_session by default
10+
11+
### Testing and Release Infrastructure
12+
13+
* unset region during integ tests
14+
* use sagemaker_session fixture in all Airflow tests
15+
* remove remaining TF legacy mode integ tests
16+
17+
## v1.50.15 (2020-02-25)
18+
19+
### Bug Fixes and Other Changes
20+
21+
* enable Neo integ tests
22+
23+
## v1.50.14.post0 (2020-02-24)
24+
25+
### Testing and Release Infrastructure
26+
27+
* remove TF framework mode notebooks from PR build
28+
* don't create docker network for all integ tests
29+
330
## v1.50.14 (2020-02-20)
431

532
### Bug Fixes and Other Changes

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.50.15.dev0
1+
1.50.17.dev0

buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ phases:
1616

1717
- start_time=`date +%s`
1818
- |
19-
execute-command-if-has-matching-changes "tox -e py36 -- tests/integ -m \"not local_mode\" -n 512 --reruns 3 --reruns-delay 5 --durations 50 --boto-config '{\"region_name\": \"us-east-2\"}'" "tests/" "src/*.py" "setup.py" "setup.cfg" "buildspec.yml"
19+
execute-command-if-has-matching-changes "env -u AWS_DEFAULT_REGION tox -e py36 -- tests/integ -m \"not local_mode\" -n 512 --reruns 3 --reruns-delay 5 --durations 50 --boto-config '{\"region_name\": \"us-east-2\"}'" "tests/" "src/*.py" "setup.py" "setup.cfg" "buildspec.yml"
2020
- ./ci-scripts/displaytime.sh 'py36 tests/integ' $start_time
2121

2222
post_build:

src/sagemaker/automl/automl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ def deploy(
216216
created from it.
217217
sagemaker_session (sagemaker.session.Session): A SageMaker Session
218218
object, used for SageMaker interactions (default: None). If not
219-
specified, one is created using the default AWS configuration
220-
chain.
219+
specified, the one originally associated with the ``AutoML`` instance is used.
221220
name (str): The pipeline model name. If None, a default model name will
222221
be selected on each ``deploy``.
223222
endpoint_name (str): The name of the endpoint to create (default:
@@ -248,6 +247,8 @@ def deploy(
248247
If ``predictor_cls`` is specified, the invocation of ``self.predictor_cls`` on
249248
the created endpoint name. Otherwise, ``None``.
250249
"""
250+
sagemaker_session = sagemaker_session or self.sagemaker_session
251+
251252
if candidate is None:
252253
candidate_dict = self.best_candidate()
253254
candidate = CandidateEstimator(candidate_dict, sagemaker_session=sagemaker_session)

src/sagemaker/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ def compile(
304304
https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html.
305305
input_shape (dict): Specifies the name and shape of the expected
306306
inputs for your trained model in json dictionary form, for
307-
example: {'data':[1,3,1024,1024]}, or {'var1': [1,1,28,28],
308-
'var2':[1,1,28,28]}
307+
example: {'data': [1,3,1024,1024]}, or {'var1': [1,1,28,28],
308+
'var2': [1,1,28,28]}
309309
output_path (str): Specifies where to store the compiled model
310310
role (str): Execution role
311311
tags (list[dict]): List of tags for labeling a compilation job. For
@@ -436,7 +436,8 @@ def deploy(
436436

437437
compiled_model_suffix = "-".join(instance_type.split(".")[:-1])
438438
if self._is_compiled_model:
439-
self.name += compiled_model_suffix
439+
name_prefix = self.name or utils.name_from_image(self.image)
440+
self.name = "{}{}".format(name_prefix, compiled_model_suffix)
440441

441442
self._create_sagemaker_model(instance_type, accelerator_type, tags)
442443
production_variant = sagemaker.production_variant(

src/sagemaker/model_monitor/data_capture_config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(
4141
capture_options=None,
4242
csv_content_types=None,
4343
json_content_types=None,
44+
sagemaker_session=None,
4445
):
4546
"""Initialize a DataCaptureConfig object for capturing data from Amazon SageMaker Endpoints.
4647
@@ -56,14 +57,21 @@ def __init__(
5657
which data to capture between request and response.
5758
csv_content_types ([str]): Optional. Default=["text/csv"].
5859
json_content_types([str]): Optional. Default=["application/json"].
59-
60+
sagemaker_session (sagemaker.session.Session): A SageMaker Session
61+
object, used for SageMaker interactions (default: None). If not
62+
specified, one is created using the default AWS configuration
63+
chain.
6064
"""
6165
self.enable_capture = enable_capture
6266
self.sampling_percentage = sampling_percentage
6367
self.destination_s3_uri = destination_s3_uri
6468
if self.destination_s3_uri is None:
69+
sagemaker_session = sagemaker_session or Session()
6570
self.destination_s3_uri = os.path.join(
66-
"s3://", Session().default_bucket(), _MODEL_MONITOR_S3_PATH, _DATA_CAPTURE_S3_PATH
71+
"s3://",
72+
sagemaker_session.default_bucket(),
73+
_MODEL_MONITOR_S3_PATH,
74+
_DATA_CAPTURE_S3_PATH,
6775
)
6876

6977
self.kms_key_id = kms_key_id

src/sagemaker/model_monitor/model_monitoring.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def create_monitoring_schedule(
278278
normalized_monitoring_output = self._normalize_monitoring_output(output=output)
279279

280280
statistics_object, constraints_object = self._get_baseline_files(
281-
statistics=statistics, constraints=constraints
281+
statistics=statistics, constraints=constraints, sagemaker_session=self.sagemaker_session
282282
)
283283

284284
statistics_s3_uri = None
@@ -402,7 +402,7 @@ def update_monitoring_schedule(
402402
}
403403

404404
statistics_object, constraints_object = self._get_baseline_files(
405-
statistics=statistics, constraints=constraints
405+
statistics=statistics, constraints=constraints, sagemaker_session=self.sagemaker_session
406406
)
407407

408408
statistics_s3_uri = None
@@ -781,7 +781,7 @@ def _generate_monitoring_schedule_name(self, schedule_name=None):
781781
return name_from_base(base=base_name)
782782

783783
@staticmethod
784-
def _get_baseline_files(statistics, constraints):
784+
def _get_baseline_files(statistics, constraints, sagemaker_session=None):
785785
"""Populates baseline values if possible.
786786
787787
Args:
@@ -791,6 +791,9 @@ def _get_baseline_files(statistics, constraints):
791791
constraints (sagemaker.model_monitor.Constraints or str): The constraints object or str.
792792
If none, this method will attempt to retrieve a previously baselined constraints
793793
object.
794+
sagemaker_session (sagemaker.session.Session): Session object which manages interactions
795+
with Amazon SageMaker APIs and any other AWS services needed. If not specified, one
796+
is created using the default AWS configuration chain.
794797
795798
Returns:
796799
sagemaker.model_monitor.Statistics, sagemaker.model_monitor.Constraints: The Statistics
@@ -799,9 +802,13 @@ def _get_baseline_files(statistics, constraints):
799802
800803
"""
801804
if statistics is not None and isinstance(statistics, string_types):
802-
statistics = Statistics.from_s3_uri(statistics_file_s3_uri=statistics)
805+
statistics = Statistics.from_s3_uri(
806+
statistics_file_s3_uri=statistics, sagemaker_session=sagemaker_session
807+
)
803808
if constraints is not None and isinstance(constraints, string_types):
804-
constraints = Constraints.from_s3_uri(constraints_file_s3_uri=constraints)
809+
constraints = Constraints.from_s3_uri(
810+
constraints_file_s3_uri=constraints, sagemaker_session=sagemaker_session
811+
)
805812

806813
return statistics, constraints
807814

@@ -1240,7 +1247,7 @@ def create_monitoring_schedule(
12401247
)
12411248

12421249
statistics_object, constraints_object = self._get_baseline_files(
1243-
statistics=statistics, constraints=constraints
1250+
statistics=statistics, constraints=constraints, sagemaker_session=self.sagemaker_session
12441251
)
12451252

12461253
constraints_s3_uri = None
@@ -1386,7 +1393,7 @@ def update_monitoring_schedule(
13861393
)
13871394

13881395
statistics_object, constraints_object = self._get_baseline_files(
1389-
statistics=statistics, constraints=constraints
1396+
statistics=statistics, constraints=constraints, sagemaker_session=self.sagemaker_session
13901397
)
13911398

13921399
statistics_s3_uri = None
@@ -1829,6 +1836,7 @@ def baseline_statistics(self, file_name=STATISTICS_JSON_DEFAULT_FILE_NAME, kms_k
18291836
return Statistics.from_s3_uri(
18301837
statistics_file_s3_uri=os.path.join(baselining_job_output_s3_path, file_name),
18311838
kms_key=kms_key,
1839+
sagemaker_session=self.sagemaker_session,
18321840
)
18331841
except ClientError as client_error:
18341842
if client_error.response["Error"]["Code"] == "NoSuchKey":
@@ -1866,6 +1874,7 @@ def suggested_constraints(self, file_name=CONSTRAINTS_JSON_DEFAULT_FILE_NAME, km
18661874
return Constraints.from_s3_uri(
18671875
constraints_file_s3_uri=os.path.join(baselining_job_output_s3_path, file_name),
18681876
kms_key=kms_key,
1877+
sagemaker_session=self.sagemaker_session,
18691878
)
18701879
except ClientError as client_error:
18711880
if client_error.response["Error"]["Code"] == "NoSuchKey":
@@ -1981,6 +1990,7 @@ def statistics(self, file_name=STATISTICS_JSON_DEFAULT_FILE_NAME, kms_key=None):
19811990
return Statistics.from_s3_uri(
19821991
statistics_file_s3_uri=os.path.join(baselining_job_output_s3_path, file_name),
19831992
kms_key=kms_key,
1993+
sagemaker_session=self.sagemaker_session,
19841994
)
19851995
except ClientError as client_error:
19861996
if client_error.response["Error"]["Code"] == "NoSuchKey":
@@ -2022,6 +2032,7 @@ def constraint_violations(
20222032
baselining_job_output_s3_path, file_name
20232033
),
20242034
kms_key=kms_key,
2035+
sagemaker_session=self.sagemaker_session,
20252036
)
20262037
except ClientError as client_error:
20272038
if client_error.response["Error"]["Code"] == "NoSuchKey":

src/sagemaker/model_monitor/monitoring_files.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def save(self, new_save_location_s3_uri=None):
6969
self.file_s3_uri = new_save_location_s3_uri
7070

7171
return S3Uploader.upload_string_as_file_body(
72-
body=json.dumps(self.body_dict), desired_s3_uri=self.file_s3_uri, kms_key=self.kms_key
72+
body=json.dumps(self.body_dict),
73+
desired_s3_uri=self.file_s3_uri,
74+
kms_key=self.kms_key,
75+
session=self.session,
7376
)
7477

7578

@@ -252,7 +255,10 @@ def from_s3_uri(cls, constraints_file_s3_uri, kms_key=None, sagemaker_session=No
252255
raise error
253256

254257
return cls(
255-
body_dict=body_dict, constraints_file_s3_uri=constraints_file_s3_uri, kms_key=kms_key
258+
body_dict=body_dict,
259+
constraints_file_s3_uri=constraints_file_s3_uri,
260+
kms_key=kms_key,
261+
sagemaker_session=sagemaker_session,
256262
)
257263

258264
@classmethod

src/sagemaker/predictor.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,22 @@ def enable_data_capture(self):
192192
to enable data capture. For a more customized experience, refer to
193193
update_data_capture_config, instead.
194194
"""
195-
self.update_data_capture_config(data_capture_config=DataCaptureConfig(enable_capture=True))
195+
self.update_data_capture_config(
196+
data_capture_config=DataCaptureConfig(
197+
enable_capture=True, sagemaker_session=self.sagemaker_session
198+
)
199+
)
196200

197201
def disable_data_capture(self):
198202
"""Updates the DataCaptureConfig for the Predictor's associated Amazon SageMaker Endpoint
199203
to disable data capture. For a more customized experience, refer to
200204
update_data_capture_config, instead.
201205
"""
202-
self.update_data_capture_config(data_capture_config=DataCaptureConfig(enable_capture=False))
206+
self.update_data_capture_config(
207+
data_capture_config=DataCaptureConfig(
208+
enable_capture=False, sagemaker_session=self.sagemaker_session
209+
)
210+
)
203211

204212
def update_data_capture_config(self, data_capture_config):
205213
"""Updates the DataCaptureConfig for the Predictor's associated Amazon SageMaker Endpoint

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def alternative_cpu_instance_type(sagemaker_session, request):
286286

287287
@pytest.fixture(scope="session")
288288
def cpu_instance_family(cpu_instance_type):
289-
"_".join(cpu_instance_type.split(".")[0:2])
289+
return "_".join(cpu_instance_type.split(".")[0:2])
290290

291291

292292
def pytest_generate_tests(metafunc):

tests/data/cifar_10/data/README

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/data/cifar_10/source/__init__.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/data/cifar_10/source/keras_cnn_cifar_10.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)