Skip to content

Commit 58b440e

Browse files
committed
Merge remote-tracking branch 'origin' into feat/jumpstart-model-estimator-classes
2 parents 8b55e39 + 3a8a2e7 commit 58b440e

File tree

6 files changed

+51
-36
lines changed

6 files changed

+51
-36
lines changed

src/sagemaker/base_deserializers.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ def deserialize(self, stream, content_type):
189189

190190

191191
class NumpyDeserializer(SimpleBaseDeserializer):
192-
"""Deserialize a stream of data in .npy or UTF-8 CSV/JSON format to a numpy array."""
192+
"""Deserialize a stream of data in .npy, .npz or UTF-8 CSV/JSON format to a numpy array.
193+
194+
Note that when using application/x-npz archive format, the result will usually be a
195+
dictionary-like object containing multiple arrays (as per ``numpy.load()``) - instead of a
196+
single array.
197+
"""
193198

194199
def __init__(self, dtype=None, accept="application/x-npy", allow_pickle=True):
195200
"""Initialize a ``NumpyDeserializer`` instance.
@@ -223,6 +228,11 @@ def deserialize(self, stream, content_type):
223228
return np.array(json.load(codecs.getreader("utf-8")(stream)), dtype=self.dtype)
224229
if content_type == "application/x-npy":
225230
return np.load(io.BytesIO(stream.read()), allow_pickle=self.allow_pickle)
231+
if content_type == "application/x-npz":
232+
try:
233+
return np.load(io.BytesIO(stream.read()), allow_pickle=self.allow_pickle)
234+
finally:
235+
stream.close()
226236
finally:
227237
stream.close()
228238

src/sagemaker/lambda_helper.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def __init__(
3737
memory_size: int = 128,
3838
runtime: str = "python3.8",
3939
vpc_config: dict = None,
40-
architectures: list = None,
4140
environment: dict = None,
4241
layers: list = None,
4342
):
@@ -71,8 +70,6 @@ def __init__(
7170
memory_size (int): Memory of the Lambda function in megabytes. Default is 128 MB.
7271
runtime (str): Runtime of the Lambda function. Default is set to python3.8.
7372
vpc_config (dict): VPC to deploy the Lambda function to. Default is None.
74-
architectures (list): Which architecture to deploy to. Valid Values are
75-
'x86_64' and 'arm64', default is None.
7673
environment (dict): Environment Variables for the Lambda function. Default is None.
7774
layers (list): List of Lambda layers for the Lambda function. Default is None.
7875
"""
@@ -87,10 +84,9 @@ def __init__(
8784
self.timeout = timeout
8885
self.memory_size = memory_size
8986
self.runtime = runtime
90-
self.vpc_config = vpc_config
91-
self.environment = environment
92-
self.architectures = architectures
93-
self.layers = layers
87+
self.vpc_config = vpc_config or {}
88+
self.environment = environment or {}
89+
self.layers = layers or []
9490

9591
if function_arn is None and function_name is None:
9692
raise ValueError("Either function_arn or function_name must be provided.")
@@ -142,7 +138,6 @@ def create(self):
142138
MemorySize=self.memory_size,
143139
VpcConfig=self.vpc_config,
144140
Environment=self.environment,
145-
Architectures=self.architectures,
146141
Layers=self.layers,
147142
)
148143
return response
@@ -163,7 +158,6 @@ def update(self):
163158
response = lambda_client.update_function_code(
164159
FunctionName=self.function_name or self.function_arn,
165160
ZipFile=_zip_lambda_code(self.script),
166-
Architectures=self.architectures,
167161
)
168162
else:
169163
bucket = self.s3_bucket or self.session.default_bucket()
@@ -186,7 +180,6 @@ def update(self):
186180
zipped_code_dir=self.zipped_code_dir,
187181
s3_bucket=bucket,
188182
),
189-
Architectures=self.architectures,
190183
)
191184
return response
192185
except ClientError as e:

src/sagemaker/multidatamodel.py

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(
9999
self.model = model
100100
self.container_mode = MULTI_MODEL_CONTAINER_MODE
101101
self.sagemaker_session = sagemaker_session or Session()
102+
self.endpoint_name = None
102103

103104
if self.sagemaker_session.s3_client is None:
104105
self.s3_client = self.sagemaker_session.boto_session.client(

tests/integ/sagemaker/experiments/test_run.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,15 @@ def test_run_name_vs_trial_component_name_edge_cases(sagemaker_session, input_na
134134
) as run1:
135135
assert not run1._experiment.tags
136136
assert not run1._trial.tags
137-
is_run_tc = is_run_trial_component(
138-
trial_component_name=run1._trial_component.trial_component_name,
139-
sagemaker_session=sagemaker_session,
140-
)
141-
assert is_run_tc
137+
138+
def verify_is_run():
139+
is_run_tc = is_run_trial_component(
140+
trial_component_name=run1._trial_component.trial_component_name,
141+
sagemaker_session=sagemaker_session,
142+
)
143+
assert is_run_tc
144+
145+
retry_with_backoff(verify_is_run, 4)
142146

143147
with load_run(
144148
experiment_name=exp_name,

tests/unit/sagemaker/deserializers/test_deserializers.py

+17
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ def test_numpy_deserializer_from_npy_object_array_with_allow_pickle_false():
164164
numpy_deserializer.deserialize(stream, "application/x-npy")
165165

166166

167+
def test_numpy_deserializer_from_npz(numpy_deserializer):
168+
arrays = {
169+
"alpha": np.ones((2, 3)),
170+
"beta": np.zeros((3, 2)),
171+
}
172+
stream = io.BytesIO()
173+
np.savez_compressed(stream, **arrays)
174+
stream.seek(0)
175+
176+
result = numpy_deserializer.deserialize(stream, "application/x-npz")
177+
178+
assert isinstance(result, np.lib.npyio.NpzFile)
179+
assert set(arrays.keys()) == set(result.keys())
180+
for key, arr in arrays.items():
181+
assert np.array_equal(arr, result[key])
182+
183+
167184
@pytest.fixture
168185
def json_deserializer():
169186
return JSONDeserializer()

tests/unit/test_lambda_helper.py

+10-20
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,9 @@ def test_create_lambda_happycase1(sagemaker_session):
187187
Code=code,
188188
Timeout=120,
189189
MemorySize=128,
190-
Architectures=None,
191-
VpcConfig=None,
192-
Environment=None,
193-
Layers=None,
190+
VpcConfig={},
191+
Environment={},
192+
Layers=[],
194193
)
195194

196195

@@ -216,10 +215,9 @@ def test_create_lambda_happycase2(sagemaker_session):
216215
Code=code,
217216
Timeout=120,
218217
MemorySize=128,
219-
Architectures=None,
220-
VpcConfig=None,
221-
Environment=None,
222-
Layers=None,
218+
VpcConfig={},
219+
Environment={},
220+
Layers=[],
223221
)
224222

225223

@@ -231,7 +229,6 @@ def test_create_lambda_happycase3(sagemaker_session):
231229
script=SCRIPT,
232230
handler=HANDLER,
233231
session=sagemaker_session,
234-
architectures=["x86_64"],
235232
environment={"Name": "my-test-lambda"},
236233
vpc_config={
237234
"SubnetIds": ["test-subnet-1"],
@@ -251,7 +248,6 @@ def test_create_lambda_happycase3(sagemaker_session):
251248
Code=code,
252249
Timeout=120,
253250
MemorySize=128,
254-
Architectures=["x86_64"],
255251
VpcConfig={"SubnetIds": ["test-subnet-1"], "SecurityGroupIds": ["sec-group-1"]},
256252
Environment={"Name": "my-test-lambda"},
257253
Layers=["my-test-layer-1", "my-test-layer-2"],
@@ -314,7 +310,6 @@ def test_update_lambda_happycase1(sagemaker_session):
314310
sagemaker_session.lambda_client.update_function_code.assert_called_with(
315311
FunctionName=FUNCTION_NAME,
316312
ZipFile=ZIPPED_CODE,
317-
Architectures=None,
318313
)
319314

320315

@@ -335,7 +330,6 @@ def test_update_lambda_happycase2(sagemaker_session):
335330
FunctionName=LAMBDA_ARN,
336331
S3Bucket=S3_BUCKET,
337332
S3Key=S3_KEY,
338-
Architectures=None,
339333
)
340334

341335

@@ -347,7 +341,6 @@ def test_update_lambda_happycase3(sagemaker_session):
347341
script=SCRIPT,
348342
handler=HANDLER,
349343
session=sagemaker_session,
350-
architectures=["x86_64"],
351344
environment={"Name": "my-test-lambda"},
352345
vpc_config={
353346
"SubnetIds": ["test-subnet-1"],
@@ -360,7 +353,6 @@ def test_update_lambda_happycase3(sagemaker_session):
360353
sagemaker_session.lambda_client.update_function_code.assert_called_with(
361354
FunctionName=FUNCTION_NAME,
362355
ZipFile=ZIPPED_CODE,
363-
Architectures=["x86_64"],
364356
)
365357

366358

@@ -380,7 +372,6 @@ def test_update_lambda_s3bucket_not_provided(s3_upload, sagemaker_session):
380372
FunctionName=LAMBDA_ARN,
381373
S3Bucket=sagemaker_session.default_bucket(),
382374
S3Key=s3_upload.return_value,
383-
Architectures=None,
384375
)
385376

386377

@@ -425,10 +416,9 @@ def test_upsert_lambda_happycase1(sagemaker_session):
425416
Code=code,
426417
Timeout=120,
427418
MemorySize=128,
428-
Architectures=None,
429-
VpcConfig=None,
430-
Environment=None,
431-
Layers=None,
419+
VpcConfig={},
420+
Environment={},
421+
Layers=[],
432422
)
433423

434424

@@ -455,7 +445,7 @@ def test_upsert_lambda_happycase2(sagemaker_session):
455445
lambda_obj.upsert()
456446

457447
sagemaker_session.lambda_client.update_function_code.assert_called_once_with(
458-
FunctionName=FUNCTION_NAME, ZipFile=ZIPPED_CODE, Architectures=None
448+
FunctionName=FUNCTION_NAME, ZipFile=ZIPPED_CODE
459449
)
460450

461451

0 commit comments

Comments
 (0)