Skip to content

Commit 06e06d7

Browse files
author
Eli Davidson
committed
refactor(core): apply accept_eula to additional sources in container_def
Move the additional-model-data-source EULA handling out of the JumpStart-specific block in _build_for_jumpstart and into _apply_accept_eula_to_additional_model_data_sources next to container_def, the single place the primary model's accept_eula already becomes ModelAccessConfig. Both the primary model and the additional sources are now driven by the same accept_eula flag in adjacent code, and every container-assembly call site (including the deployment-config path that never passes through _build_for_jumpstart) gets the gated-source enforcement. _build_for_jumpstart is reduced to pure propagation. No behavior change on the JumpStart path: all 63 serve tests pass unchanged, plus 103 core session_helper tests.
1 parent c852786 commit 06e06d7

2 files changed

Lines changed: 56 additions & 32 deletions

File tree

‎sagemaker-core/src/sagemaker/core/helper/session_helper.py‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3072,6 +3072,47 @@ def _optimization_job_status(sagemaker_client, job_name):
30723072
return desc
30733073

30743074

3075+
def _apply_accept_eula_to_additional_model_data_sources(additional_model_data_sources, accept_eula):
3076+
"""Apply EULA acceptance to additional model data sources.
3077+
3078+
This is the additional-source counterpart of the primary model handling in
3079+
``container_def`` below, driven by the same ``accept_eula`` flag. Sources
3080+
resolved from JumpStart specs may carry a ``HostingEulaKey``: a truthy value
3081+
marks a gated source that requires explicit license acceptance. Acceptance
3082+
is folded into the source's ``S3DataSource.ModelAccessConfig`` and a gated
3083+
source without acceptance raises before any request is made. The
3084+
``HostingEulaKey`` itself is JumpStart-internal metadata the CreateModel
3085+
API rejects, so it is always removed.
3086+
3087+
Args:
3088+
additional_model_data_sources (list[dict]): AdditionalModelDataSources
3089+
entries, possibly carrying JumpStart ``HostingEulaKey`` metadata.
3090+
accept_eula (bool): Whether model terms of use have been accepted.
3091+
3092+
Returns:
3093+
list[dict]: The sources in CreateModel API shape.
3094+
3095+
Raises:
3096+
ValueError: If a gated source is present and ``accept_eula`` is not True.
3097+
"""
3098+
applied_sources = []
3099+
for source in additional_model_data_sources:
3100+
applied_source = dict(source)
3101+
if applied_source.pop("HostingEulaKey", None):
3102+
if not accept_eula:
3103+
raise ValueError(
3104+
"accept_eula must be set to True to deploy this model. "
3105+
"Please set accept_eula=True on the ModelBuilder instance "
3106+
"to confirm you have read and accepted the end-user license "
3107+
"agreement for this model."
3108+
)
3109+
s3_data_source = dict(applied_source.get("S3DataSource", {}))
3110+
s3_data_source["ModelAccessConfig"] = {"AcceptEula": True}
3111+
applied_source["S3DataSource"] = s3_data_source
3112+
applied_sources.append(applied_source)
3113+
return applied_sources
3114+
3115+
30753116
def container_def(
30763117
image_uri,
30773118
model_data_url=None,
@@ -3115,7 +3156,13 @@ def container_def(
31153156
c_def = {"Image": image_uri, "Environment": env}
31163157

31173158
if additional_model_data_sources:
3118-
c_def["AdditionalModelDataSources"] = additional_model_data_sources
3159+
c_def["AdditionalModelDataSources"] = (
3160+
_apply_accept_eula_to_additional_model_data_sources(
3161+
additional_model_data_sources, accept_eula
3162+
)
3163+
if isinstance(additional_model_data_sources, list)
3164+
else additional_model_data_sources
3165+
)
31193166

31203167
if isinstance(model_data_url, str) and (
31213168
not (model_data_url.startswith("s3://") and model_data_url.endswith("tar.gz"))

‎sagemaker-serve/src/sagemaker/serve/model_builder_servers.py‎

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,41 +1017,18 @@ def _build_for_jumpstart(self) -> Model:
10171017
# Propagate additional model data sources resolved from the JumpStart
10181018
# spec (e.g. speculative decoding draft models like EAGLE). The JumpStart
10191019
# factory (_add_additional_model_data_sources_to_kwargs) already returns
1020-
# these in CreateModel API shape via camel_case_to_pascal_case(...).
1021-
#
1022-
# A source carrying a truthy ``HostingEulaKey`` is gated and requires the
1023-
# user to accept its end-user license agreement, exactly like the base
1024-
# model. ``container_def`` folds ``accept_eula`` into the base model's
1025-
# ModelAccessConfig but passes additional sources through untouched, so
1026-
# the acceptance must be translated onto each gated source here: enforce
1027-
# ``accept_eula`` and move it into the source's ``ModelAccessConfig``
1028-
# (mirroring _add_model_access_configs_to_model_data_sources and the base
1029-
# model's handling in _create_model). Ungated sources simply drop the
1030-
# JumpStart-internal ``HostingEulaKey`` metadata, which the CreateModel
1031-
# API rejects. Without any of this, sources declared in the spec are
1032-
# dropped from the CreateModel call and the container fails to find the
1033-
# referenced artifacts at runtime.
1020+
# these in CreateModel API shape via camel_case_to_pascal_case(...);
1021+
# EULA handling (enforcing accept_eula on gated sources and stripping
1022+
# the JumpStart-internal HostingEulaKey) happens in ``container_def``,
1023+
# the same place the primary model's accept_eula is applied. Without
1024+
# this propagation, sources declared in the spec are dropped from the
1025+
# CreateModel call and the container fails to find the referenced
1026+
# artifacts at runtime.
10341027
additional_model_data_sources = getattr(
10351028
init_kwargs, "additional_model_data_sources", None
10361029
)
10371030
if isinstance(additional_model_data_sources, list) and additional_model_data_sources:
1038-
accept_eula = getattr(self, "accept_eula", None)
1039-
sanitized_sources = []
1040-
for source in additional_model_data_sources:
1041-
sanitized_source = dict(source)
1042-
if sanitized_source.pop("HostingEulaKey", None):
1043-
if not accept_eula:
1044-
raise ValueError(
1045-
"accept_eula must be set to True to deploy this model. "
1046-
"Please set accept_eula=True on the ModelBuilder instance "
1047-
"to confirm you have read and accepted the end-user license "
1048-
"agreement for this model."
1049-
)
1050-
s3_data_source = dict(sanitized_source.get("S3DataSource", {}))
1051-
s3_data_source["ModelAccessConfig"] = {"AcceptEula": True}
1052-
sanitized_source["S3DataSource"] = s3_data_source
1053-
sanitized_sources.append(sanitized_source)
1054-
self.additional_model_data_sources = sanitized_sources
1031+
self.additional_model_data_sources = additional_model_data_sources
10551032

10561033
# Handle model artifacts for fine-tuned models
10571034
if hasattr(init_kwargs, "model_data") and init_kwargs.model_data:

0 commit comments

Comments
 (0)