Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sagemaker-core/src/sagemaker/core/shapes/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,7 @@ class TransformResources(Base):
"""

instance_type: StrPipeVar
instance_count: int
instance_count: IntPipeVar
volume_kms_key_id: Optional[StrPipeVar] = Unassigned()
transform_ami_version: Optional[StrPipeVar] = Unassigned()

Expand Down
3 changes: 3 additions & 0 deletions sagemaker-core/src/sagemaker/core/tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
"ProcessingInstancePreference": {
"InstanceCount": "IntPipeVar",
},
"TransformResources": {
"InstanceCount": "IntPipeVar",
},
# RandomSeed accepts a pipeline variable (e.g. a ParameterInteger) so tuning pipelines
# can parameterize reproducibility (issue #5614 / #6171).
"HyperParameterTuningJobConfig": {
Expand Down
50 changes: 50 additions & 0 deletions sagemaker-core/tests/unit/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,56 @@ def test_load_config(self, mock_session):
assert config["output_config"]["s3_output_path"] == "s3://bucket/output"
assert config["resource_config"]["instance_count"] == 2

def test_instance_count_accepts_pipeline_variable(self, mock_session):
"""Regression for #6577.

``instance_count`` must accept a pipeline variable (e.g. a ParameterInteger).
Building the transform job request instantiates ``TransformResources`` with
``instance_count``; when that field was typed ``int``, pydantic raised
a ValidationError.
"""
from sagemaker.core.workflow.parameters import ParameterInteger
from sagemaker.core.shapes import TransformResources

count_param = ParameterInteger(name="InstanceCount", default_value=2)
resources = TransformResources(
instance_type="ml.m5.xlarge",
instance_count=count_param,
)
assert resources.instance_count is count_param

transformer = Transformer(
model_name="test-model",
instance_count=count_param,
instance_type="ml.m5.xlarge",
output_path="s3://bucket/output",
sagemaker_session=mock_session,
)
assert transformer.instance_count is count_param

config = transformer._load_config(
data="s3://bucket/input",
data_type="S3Prefix",
content_type="text/csv",
compression_type=None,
split_type="Line",
)
request = transformer._get_transform_request(
job_name="test-job",
model_name="test-model",
strategy=None,
max_concurrent_transforms=None,
max_payload=None,
env=None,
input_config=config["input_config"],
output_config=config["output_config"],
resource_config=config["resource_config"],
experiment_config=None,
tags=None,
data_processing=None,
)
assert request["TransformResources"].instance_count is count_param


class TestTransformerTransformWithTags:
"""Regression tests for tags handling in Transformer.transform() (issue #6090)."""
Expand Down
10 changes: 10 additions & 0 deletions sagemaker-core/tests/unit/tools/test_shapes_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ class TestInstancePreferencesPipeVarOverrides:
_MODEL = {
"TrainingInstanceCount": _COUNT,
"ProcessingInstanceCount": _COUNT,
"TransformInstanceCount": _COUNT,
"TrainingInstanceType": _STRING,
"ProcessingInstanceType": _STRING,
"TransformInstanceType": _STRING,
"ResourceConfig": {
"type": "structure",
"members": {
Expand Down Expand Up @@ -392,6 +394,13 @@ class TestInstancePreferencesPipeVarOverrides:
"InstanceCount": {"shape": "ProcessingInstanceCount"},
},
},
"TransformResources": {
"type": "structure",
"members": {
"InstanceType": {"shape": "TransformInstanceType"},
"InstanceCount": {"shape": "TransformInstanceCount"},
},
},
# Control: same integer shape, no override registered -> must stay int.
"UnrelatedConfig": {
"type": "structure",
Expand Down Expand Up @@ -421,6 +430,7 @@ def extractor(self, tmp_path):
("ProcessingClusterConfig", "instance_count"),
("ProcessingClusterConfig", "selected_instance_count"),
("ProcessingInstancePreference", "instance_count"),
("TransformResources", "instance_count"),
],
)
def test_count_members_generate_as_int_pipe_var(self, extractor, shape, member):
Expand Down
Loading