Skip to content

Commit 6851e77

Browse files
authored
Merge branch 'master' into processing-job-codeartifact-support
2 parents d68b19c + 7c49f5d commit 6851e77

File tree

10 files changed

+50
-10
lines changed

10 files changed

+50
-10
lines changed

CHANGELOG.md

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

3+
## v2.218.0 (2024-05-01)
4+
5+
### Features
6+
7+
* set default allow_pickle param to False
8+
9+
### Bug Fixes and Other Changes
10+
11+
* properly close files in lineage queries and tests
12+
313
## v2.217.0 (2024-04-24)
414

515
### Features

VERSION

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

src/sagemaker/base_deserializers.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ class NumpyDeserializer(SimpleBaseDeserializer):
196196
single array.
197197
"""
198198

199-
def __init__(self, dtype=None, accept="application/x-npy", allow_pickle=True):
199+
def __init__(self, dtype=None, accept="application/x-npy", allow_pickle=False):
200200
"""Initialize a ``NumpyDeserializer`` instance.
201201
202202
Args:
203203
dtype (str): The dtype of the data (default: None).
204204
accept (union[str, tuple[str]]): The MIME type (or tuple of allowable MIME types) that
205205
is expected from the inference endpoint (default: "application/x-npy").
206-
allow_pickle (bool): Allow loading pickled object arrays (default: True).
206+
allow_pickle (bool): Allow loading pickled object arrays (default: False).
207207
"""
208208
super(NumpyDeserializer, self).__init__(accept=accept)
209209
self.dtype = dtype
@@ -227,10 +227,21 @@ def deserialize(self, stream, content_type):
227227
if content_type == "application/json":
228228
return np.array(json.load(codecs.getreader("utf-8")(stream)), dtype=self.dtype)
229229
if content_type == "application/x-npy":
230-
return np.load(io.BytesIO(stream.read()), allow_pickle=self.allow_pickle)
230+
try:
231+
return np.load(io.BytesIO(stream.read()), allow_pickle=self.allow_pickle)
232+
except ValueError as ve:
233+
raise ValueError(
234+
"Please set the param allow_pickle=True \
235+
to deserialize pickle objects in NumpyDeserializer"
236+
).with_traceback(ve.__traceback__)
231237
if content_type == "application/x-npz":
232238
try:
233239
return np.load(io.BytesIO(stream.read()), allow_pickle=self.allow_pickle)
240+
except ValueError as ve:
241+
raise ValueError(
242+
"Please set the param allow_pickle=True \
243+
to deserialize pickle objectsin NumpyDeserializer"
244+
).with_traceback(ve.__traceback__)
234245
finally:
235246
stream.close()
236247
finally:

src/sagemaker/jumpstart/estimator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,12 @@ def attach(
734734

735735
model_version = model_version or "*"
736736

737-
additional_kwargs = {"model_id": model_id, "model_version": model_version}
737+
additional_kwargs = {
738+
"model_id": model_id,
739+
"model_version": model_version,
740+
"tolerate_vulnerable_model": True, # model is already trained
741+
"tolerate_deprecated_model": True, # model is already trained
742+
}
738743

739744
model_specs = verify_model_region_and_return_specs(
740745
model_id=model_id,

src/sagemaker/jumpstart/types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,9 +1064,8 @@ def from_json(self, json_obj: Dict[str, Any]) -> None:
10641064
Dictionary representation of the config component.
10651065
"""
10661066
for field in json_obj.keys():
1067-
if field not in self.__slots__:
1068-
raise ValueError(f"Invalid component field: {field}")
1069-
setattr(self, field, json_obj[field])
1067+
if field in self.__slots__:
1068+
setattr(self, field, json_obj[field])
10701069

10711070

10721071
class JumpStartMetadataConfig(JumpStartDataHolderType):

tests/integ/sagemaker/jumpstart/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def _to_s3_path(filename: str, s3_prefix: Optional[str]) -> str:
4848
("meta-textgeneration-llama-2-7b", "*"): ("training-datasets/sec_amazon/"),
4949
("meta-textgeneration-llama-2-7b", "2.*"): ("training-datasets/sec_amazon/"),
5050
("meta-textgeneration-llama-2-7b", "3.*"): ("training-datasets/sec_amazon/"),
51+
("meta-textgeneration-llama-2-7b", "4.*"): ("training-datasets/sec_amazon/"),
5152
("meta-textgenerationneuron-llama-2-7b", "*"): ("training-datasets/sec_amazon/"),
5253
}
5354

tests/integ/sagemaker/jumpstart/estimator/test_jumpstart_estimator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_gated_model_training_v1(setup):
140140
def test_gated_model_training_v2(setup):
141141

142142
model_id = "meta-textgeneration-llama-2-7b"
143-
model_version = "3.*" # model artifacts retrieved from jumpstart-private-cache-* buckets
143+
model_version = "4.*" # model artifacts retrieved from jumpstart-private-cache-* buckets
144144

145145
estimator = JumpStartEstimator(
146146
model_id=model_id,
@@ -150,6 +150,7 @@ def test_gated_model_training_v2(setup):
150150
tags=[{"Key": JUMPSTART_TAG, "Value": os.environ[ENV_VAR_JUMPSTART_SDK_TEST_SUITE_ID]}],
151151
environment={"accept_eula": "true"},
152152
max_run=259200, # avoid exceeding resource limits
153+
tolerate_vulnerable_model=True, # tolerate old version of model
153154
)
154155

155156
# uses ml.g5.12xlarge instance

tests/unit/sagemaker/deserializers/test_deserializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def test_numpy_deserializer_from_npy(numpy_deserializer):
142142
assert np.array_equal(array, result)
143143

144144

145-
def test_numpy_deserializer_from_npy_object_array(numpy_deserializer):
145+
def test_numpy_deserializer_from_npy_object_array():
146+
numpy_deserializer = NumpyDeserializer(allow_pickle=True)
146147
array = np.array([{"a": "", "b": ""}, {"c": "", "d": ""}])
147148
stream = io.BytesIO()
148149
np.save(stream, array)

tests/unit/sagemaker/jumpstart/estimator/test_estimator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,8 @@ def test_jumpstart_estimator_attach_eula_model(
10101010
"model_id": "gemma-model",
10111011
"model_version": "*",
10121012
"environment": {"accept_eula": "true"},
1013+
"tolerate_vulnerable_model": True,
1014+
"tolerate_deprecated_model": True,
10131015
},
10141016
)
10151017

@@ -1053,6 +1055,8 @@ def test_jumpstart_estimator_attach_no_model_id_happy_case(
10531055
additional_kwargs={
10541056
"model_id": "js-trainable-model-prepacked",
10551057
"model_version": "1.0.0",
1058+
"tolerate_vulnerable_model": True,
1059+
"tolerate_deprecated_model": True,
10561060
},
10571061
)
10581062

tests/unit/sagemaker/jumpstart/test_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,14 @@ def test_inference_configs_parsing():
10521052
)
10531053
assert list(config.config_components.keys()) == ["neuron-inference"]
10541054

1055+
spec = {
1056+
**BASE_SPEC,
1057+
**INFERENCE_CONFIGS,
1058+
**INFERENCE_CONFIG_RANKINGS,
1059+
"unrecognized-field": "blah", # New fields in base metadata fields should be ignored
1060+
}
1061+
specs1 = JumpStartModelSpecs(spec)
1062+
10551063

10561064
def test_set_inference_configs():
10571065
spec = {**BASE_SPEC, **INFERENCE_CONFIGS, **INFERENCE_CONFIG_RANKINGS}

0 commit comments

Comments
 (0)