Skip to content

Commit 791d3db

Browse files
Merge branch 'master' into master
2 parents af1e554 + e09693c commit 791d3db

File tree

15 files changed

+184
-40
lines changed

15 files changed

+184
-40
lines changed

.github/workflows/codeql.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "CodeQL"
2+
on:
3+
push:
4+
branches: [ "master" ]
5+
pull_request:
6+
branches: [ "master" ]
7+
schedule:
8+
- cron: '30 8 * * *'
9+
jobs:
10+
analyze:
11+
name: Analyze (${{ matrix.language }})
12+
runs-on: ${{ 'ubuntu-latest' }}
13+
permissions:
14+
security-events: write
15+
packages: read
16+
17+
strategy:
18+
matrix:
19+
include:
20+
- language: python
21+
build-mode: none
22+
- language: java-kotlin
23+
build-mode: none
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@6ccd57f4c5d15bdc2fef309bd9fb6cc9db2ef1c6
27+
- name: Initialize CodeQL
28+
uses: github/codeql-action/init@4b1d7da102ff94aca014c0245062b1a463356d72
29+
with:
30+
languages: ${{ matrix.language }}
31+
build-mode: ${{ matrix.build-mode }}
32+
- name: Perform CodeQL Analysis
33+
uses: github/codeql-action/analyze@4b1d7da102ff94aca014c0245062b1a463356d72
34+
with:
35+
category: "/language:${{matrix.language}}"

src/sagemaker/estimator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
from sagemaker.interactive_apps import SupportedInteractiveAppTypes
6969
from sagemaker.interactive_apps.tensorboard import TensorBoardApp
7070
from sagemaker.instance_group import InstanceGroup
71+
from sagemaker.model_card.model_card import ModelCard, TrainingDetails
7172
from sagemaker.utils import instance_supports_kms
7273
from sagemaker.job import _Job
7374
from sagemaker.jumpstart.utils import (
@@ -1797,8 +1798,17 @@ def register(
17971798
else:
17981799
if "model_kms_key" not in kwargs:
17991800
kwargs["model_kms_key"] = self.output_kms_key
1800-
model = self.create_model(image_uri=image_uri, **kwargs)
1801+
model = self.create_model(image_uri=image_uri, name=model_name, **kwargs)
18011802
model.name = model_name
1803+
if self.model_data is not None and model_card is None:
1804+
training_details = TrainingDetails.from_model_s3_artifacts(
1805+
model_artifacts=[self.model_data], sagemaker_session=self.sagemaker_session
1806+
)
1807+
model_card = ModelCard(
1808+
name="estimator_card",
1809+
training_details=training_details,
1810+
sagemaker_session=self.sagemaker_session,
1811+
)
18021812
return model.register(
18031813
content_types,
18041814
response_types,

src/sagemaker/fw_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
"2.1.0",
153153
"2.1.2",
154154
"2.2.0",
155-
"2.3.0",
156155
"2.3.1",
157156
]
158157

src/sagemaker/image_uri_config/huggingface-llm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@
717717
"tag_prefix": "2.3.0-tgi2.2.0",
718718
"repository": "huggingface-pytorch-tgi-inference",
719719
"container_version": {
720-
"gpu": "cu121-ubuntu22.04"
720+
"gpu": "cu121-ubuntu22.04-v2.0"
721721
}
722722
}
723723
}

src/sagemaker/image_uri_config/pytorch-smp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"2.1": "2.1.2",
99
"2.2": "2.3.1",
1010
"2.2.0": "2.3.1",
11-
"2.3": "2.4.0"
11+
"2.3.1": "2.4.0"
1212
},
1313
"versions": {
1414
"2.0.1": {

src/sagemaker/image_uri_config/pytorch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@
10081008
"us-gov-west-1": "442386744353",
10091009
"us-iso-east-1": "886529160074",
10101010
"us-isob-east-1": "094389454867",
1011+
"us-isof-east-1": "303241398832",
10111012
"us-isof-south-1": "454834333376",
10121013
"us-west-1": "763104351884",
10131014
"us-west-2": "763104351884"
@@ -1052,6 +1053,7 @@
10521053
"us-gov-west-1": "442386744353",
10531054
"us-iso-east-1": "886529160074",
10541055
"us-isob-east-1": "094389454867",
1056+
"us-isof-east-1": "303241398832",
10551057
"us-isof-south-1": "454834333376",
10561058
"us-west-1": "763104351884",
10571059
"us-west-2": "763104351884"
@@ -2331,6 +2333,7 @@
23312333
"us-gov-west-1": "442386744353",
23322334
"us-iso-east-1": "886529160074",
23332335
"us-isob-east-1": "094389454867",
2336+
"us-isof-east-1": "303241398832",
23342337
"us-isof-south-1": "454834333376",
23352338
"us-west-1": "763104351884",
23362339
"us-west-2": "763104351884"
@@ -2419,6 +2422,7 @@
24192422
"us-gov-west-1": "442386744353",
24202423
"us-iso-east-1": "886529160074",
24212424
"us-isob-east-1": "094389454867",
2425+
"us-isof-east-1": "303241398832",
24222426
"us-isof-south-1": "454834333376",
24232427
"us-west-1": "763104351884",
24242428
"us-west-2": "763104351884"

src/sagemaker/image_uri_config/tensorflow.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,7 @@
21402140
"us-gov-west-1": "442386744353",
21412141
"us-iso-east-1": "886529160074",
21422142
"us-isob-east-1": "094389454867",
2143+
"us-isof-east-1": "303241398832",
21432144
"us-isof-south-1": "454834333376",
21442145
"us-west-1": "763104351884",
21452146
"us-west-2": "763104351884"
@@ -2181,6 +2182,7 @@
21812182
"us-gov-west-1": "442386744353",
21822183
"us-iso-east-1": "886529160074",
21832184
"us-isob-east-1": "094389454867",
2185+
"us-isof-east-1": "303241398832",
21842186
"us-isof-south-1": "454834333376",
21852187
"us-west-1": "763104351884",
21862188
"us-west-2": "763104351884"
@@ -4354,6 +4356,7 @@
43544356
"us-gov-west-1": "442386744353",
43554357
"us-iso-east-1": "886529160074",
43564358
"us-isob-east-1": "094389454867",
4359+
"us-isof-east-1": "303241398832",
43574360
"us-isof-south-1": "454834333376",
43584361
"us-west-1": "763104351884",
43594362
"us-west-2": "763104351884"

src/sagemaker/model.py

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ def register(
549549
model_package_group_name = utils.base_name_from_image(
550550
self.image_uri, default_base_name=ModelPackage.__name__
551551
)
552-
if model_package_group_name is not None:
552+
if (
553+
model_package_group_name is not None
554+
and model_type is not JumpStartModelType.PROPRIETARY
555+
):
553556
container_def = self.prepare_container_def(accept_eula=accept_eula)
554557
container_def = update_container_with_inference_params(
555558
framework=framework,
@@ -2466,32 +2469,55 @@ def update_model_card(self, model_card: Union[ModelCard, ModelPackageModelCard])
24662469
desc_model_package = sagemaker_session.sagemaker_client.describe_model_package(
24672470
ModelPackageName=self.model_package_arn
24682471
)
2472+
if hasattr(model_card, "model_package_details"):
2473+
model_card.model_package_details = None
24692474
update_model_card_req = model_card._create_request_args()
2470-
if update_model_card_req["ModelCardStatus"] is not None:
2471-
if (
2472-
desc_model_package["ModelCard"]["ModelCardStatus"]
2473-
== update_model_card_req["ModelCardStatus"]
2474-
):
2475-
del update_model_card_req["ModelCardStatus"]
2476-
24772475
if update_model_card_req.get("ModelCardName") is not None:
24782476
del update_model_card_req["ModelCardName"]
2479-
if update_model_card_req.get("Content") is not None:
2480-
previous_content_hash = _hash_content_str(
2481-
desc_model_package["ModelCard"]["ModelCardContent"]
2482-
)
2483-
current_content_hash = _hash_content_str(update_model_card_req["Content"])
2484-
if (
2485-
previous_content_hash == current_content_hash
2486-
or update_model_card_req.get("Content") == "{}"
2487-
or update_model_card_req.get("Content") == "null"
2488-
):
2489-
del update_model_card_req["Content"]
2490-
else:
2491-
update_model_card_req["ModelCardContent"] = update_model_card_req["Content"]
2492-
del update_model_card_req["Content"]
2493-
update_model_package_args = {
2494-
"ModelPackageArn": self.model_package_arn,
2495-
"ModelCard": update_model_card_req,
2496-
}
2497-
sagemaker_session.sagemaker_client.update_model_package(**update_model_package_args)
2477+
if update_model_card_req["Content"] is not None:
2478+
if "model_package_details" in update_model_card_req["Content"]:
2479+
update_model_card_req["Content"].pop("model_package_details", None)
2480+
update_model_card_req["ModelCardContent"] = update_model_card_req["Content"]
2481+
del update_model_card_req["Content"]
2482+
2483+
if "ModelCard" in desc_model_package:
2484+
if update_model_card_req["ModelCardStatus"] is not None:
2485+
if (
2486+
desc_model_package["ModelCard"]["ModelCardStatus"]
2487+
!= update_model_card_req["ModelCardStatus"]
2488+
):
2489+
new_mc_mp_req = update_model_card_req
2490+
del new_mc_mp_req["ModelCardContent"]
2491+
update_model_package_args = {
2492+
"ModelPackageArn": self.model_package_arn,
2493+
"ModelCard": new_mc_mp_req,
2494+
}
2495+
sagemaker_session.sagemaker_client.update_model_package(
2496+
**update_model_package_args
2497+
)
2498+
2499+
if update_model_card_req.get("ModelCardContent") is not None:
2500+
previous_content_hash = _hash_content_str(
2501+
desc_model_package["ModelCard"]["ModelCardContent"]
2502+
)
2503+
current_content_hash = _hash_content_str(update_model_card_req["ModelCardContent"])
2504+
if not (
2505+
previous_content_hash == current_content_hash
2506+
or update_model_card_req.get("ModelCardContent") == "{}"
2507+
or update_model_card_req.get("ModelCardContent") == "null"
2508+
):
2509+
new_mc_mp_req = update_model_card_req
2510+
del new_mc_mp_req["ModelCardStatus"]
2511+
update_model_package_args = {
2512+
"ModelPackageArn": self.model_package_arn,
2513+
"ModelCard": new_mc_mp_req,
2514+
}
2515+
sagemaker_session.sagemaker_client.update_model_package(
2516+
**update_model_package_args
2517+
)
2518+
else:
2519+
update_model_package_args = {
2520+
"ModelPackageArn": self.model_package_arn,
2521+
"ModelCard": update_model_card_req,
2522+
}
2523+
sagemaker_session.sagemaker_client.update_model_package(**update_model_package_args)

src/sagemaker/session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8348,7 +8348,9 @@ def _logs_for_job( # noqa: C901 - suppress complexity warning for this method
83488348
"""
83498349
sagemaker_client = sagemaker_session.sagemaker_client
83508350
request_end_time = time.time() + timeout if timeout else None
8351-
description = sagemaker_client.describe_training_job(TrainingJobName=job_name)
8351+
description = _wait_until(
8352+
lambda: sagemaker_client.describe_training_job(TrainingJobName=job_name)
8353+
)
83528354
print(secondary_training_status_message(description, None), end="")
83538355

83548356
instance_count, stream_names, positions, client, log_group, dot, color_wrap = _logs_init(

tests/integ/test_byo_estimator.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15+
import io
1516
import json
1617
import os
1718

19+
import numpy as np
20+
1821
import pytest
22+
import sagemaker.amazon.common as smac
23+
1924

2025
import sagemaker
2126
from sagemaker import image_uris
2227
from sagemaker.estimator import Estimator
28+
from sagemaker.s3 import S3Uploader
2329
from sagemaker.serializers import SimpleBaseSerializer
2430
from sagemaker.utils import unique_name_from_base
2531
from tests.integ import DATA_DIR, TRAINING_DEFAULT_TIMEOUT_MINUTES, datasets
@@ -102,6 +108,60 @@ def test_byo_estimator(sagemaker_session, region, cpu_instance_type, training_se
102108
assert prediction["score"] is not None
103109

104110

111+
@pytest.mark.release
112+
def test_estimator_register_publish_training_details(sagemaker_session, region, cpu_instance_type):
113+
114+
bucket = sagemaker_session.default_bucket()
115+
prefix = "model-card-sample-notebook"
116+
117+
raw_data = (
118+
(0.5, 0),
119+
(0.75, 0),
120+
(1.0, 0),
121+
(1.25, 0),
122+
(1.50, 0),
123+
(1.75, 0),
124+
(2.0, 0),
125+
(2.25, 1),
126+
(2.5, 0),
127+
(2.75, 1),
128+
(3.0, 0),
129+
(3.25, 1),
130+
(3.5, 0),
131+
(4.0, 1),
132+
(4.25, 1),
133+
(4.5, 1),
134+
(4.75, 1),
135+
(5.0, 1),
136+
(5.5, 1),
137+
)
138+
training_data = np.array(raw_data).astype("float32")
139+
labels = training_data[:, 1]
140+
141+
# upload data to S3 bucket
142+
buf = io.BytesIO()
143+
smac.write_numpy_to_dense_tensor(buf, training_data, labels)
144+
buf.seek(0)
145+
s3_train_data = f"s3://{bucket}/{prefix}/train"
146+
S3Uploader.upload_bytes(b=buf, s3_uri=s3_train_data, sagemaker_session=sagemaker_session)
147+
output_location = f"s3://{bucket}/{prefix}/output"
148+
container = image_uris.retrieve("linear-learner", region)
149+
estimator = Estimator(
150+
container,
151+
role="SageMakerRole",
152+
instance_count=1,
153+
instance_type=cpu_instance_type,
154+
output_path=output_location,
155+
sagemaker_session=sagemaker_session,
156+
)
157+
estimator.set_hyperparameters(
158+
feature_dim=2, mini_batch_size=10, predictor_type="binary_classifier"
159+
)
160+
estimator.fit({"train": s3_train_data})
161+
print(f"Training job name: {estimator.latest_training_job.name}")
162+
estimator.register()
163+
164+
105165
def test_async_byo_estimator(sagemaker_session, region, cpu_instance_type, training_set):
106166
image_uri = image_uris.retrieve("factorization-machines", region)
107167
endpoint_name = unique_name_from_base("byo")

0 commit comments

Comments
 (0)