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
8 changes: 8 additions & 0 deletions docs/api/sagemaker_serve.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ Model Deployment
:show-inheritance:



Autoscaling
-----------

.. automodule:: sagemaker.serve.autoscaling
:members: enable_autoscaling, disable_autoscaling, describe_autoscaling, suspend_autoscaling,
resume_autoscaling, TargetTrackingPolicy, StepScalingPolicy, StepAdjustment, Alarm,
ScheduledAction, CustomMetric, ScalingTarget
3 changes: 2 additions & 1 deletion migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ pipeline = Pipeline(
| AsyncPredictor | ModelBuilder | Async inference |
| JumpStartModel.benchmark_metrics / display_benchmark_metrics() / list_deployment_configs() | ModelBuilder.benchmark_metrics / display_benchmark_metrics() / list_deployment_configs() | Same names; usable on a pre-deploy JumpStart `ModelBuilder` |
| snapshot_download + S3Uploader (hand-rolled) | `from sagemaker.serve import download_huggingface_model` | Downloads a Hub snapshot and optionally uploads it to S3 |
| boto3 `register_scalable_target` + `put_scaling_policy` (hand-rolled) | `from sagemaker.serve.autoscaling import enable_autoscaling, disable_autoscaling, describe_autoscaling` | Target tracking (predefined, custom or metric-math metrics), step scaling and scheduled actions on a variant's instances, an inference component's copies or a serverless endpoint's provisioned concurrency; scale to zero for inference components and asynchronous endpoints; suspend and resume |

### Processing Features

Expand Down Expand Up @@ -504,7 +505,7 @@ pipeline = Pipeline(
| Async inference | `AsyncPredictor(...)` | Via ModelBuilder.deploy | 🔄 REPLACED |
| Multi-model endpoints | `MultiDataModel(...)` | Via ModelBuilder.deploy | 🔄 REPLACED |
| A/B testing (multi-variant) | Production variants with traffic splitting | ProductionVariant + traffic routing | 🔄 REPLACED |
| Endpoint auto-scaling | Via boto3 Application Auto Scaling | Via ModelBuilder.deploy | 🔄 REPLACED |
| Endpoint auto-scaling | Via boto3 Application Auto Scaling | `sagemaker.serve.autoscaling.enable_autoscaling(...)` / `disable_autoscaling(...)`; `ModelBuilder.deploy(managed_instance_scaling=...)` sets an inference-component endpoint's instance bounds | 🔄 REPLACED |
| Model compilation (Neo) | `Estimator.compile_model(...)` | `ModelBuilder.optimize()` | 🔄 REPLACED |

### MLOps and Workflows
Expand Down
6 changes: 5 additions & 1 deletion sagemaker-core/src/sagemaker/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,12 @@ def _serialize_shape(value: Any) -> dict:
dict: The dict of serialized shape
"""
serialized_dict = {}
# Keep falsy scalars such as False, 0 and "" (a MinInstanceCount of 0 is a real value).
# Drop Unassigned/None, and empty dicts and lists, so a nested shape with nothing set is
# still omitted from the request.
for k, v in vars(value).items():
if serialize_result := serialize(v):
serialize_result = serialize(v)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Low: This change makes _serialize_shape emit any field whose serialized value is a non-None, non-empty-dict, non-empty-list value, including 0, False and "". That is the intended fix (and is now consistent with _serialize_dict/_serialize_list), but it is a behavior-widening change for all shapes, not just managed instance scaling: fields previously set to an empty string or 0 and silently dropped will now be sent to the API. Worth confirming no existing callers relied on the old drop-on-falsy behavior (e.g. default "" fields on other shapes) — the added regression tests only cover a few shapes.

if serialize_result is not None and serialize_result != {} and serialize_result != []:
key = snake_to_pascal(k) if is_snake_case(k) else k
serialized_dict.update({key[0].upper() + key[1:]: serialize_result})
return serialized_dict
39 changes: 39 additions & 0 deletions sagemaker-core/tests/unit/generated/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from sagemaker.core.resources import TrainingJob, DataQualityJobDefinition
from sagemaker.core.shapes import (
AdditionalS3DataSource,
ProductionVariant,
ProductionVariantManagedInstanceScaling,
TrialComponent,
TrialComponentParameterValue,
)
Expand Down Expand Up @@ -401,6 +403,43 @@ def test_serialize_preserves_falsy_list_values():
assert serialize([None, "x", Unassigned(), 1]) == ["x", 1] # noqa: F405


def test_serialize_preserves_falsy_shape_fields():
# Regression: a shape field set to 0 or False was dropped, so e.g. a managed instance
# scaling MinInstanceCount of 0 never reached the API.
scaling = ProductionVariantManagedInstanceScaling(
status="ENABLED", min_instance_count=0, max_instance_count=2
)
assert serialize(scaling) == { # noqa: F405
"Status": "ENABLED",
"MinInstanceCount": 0,
"MaxInstanceCount": 2,
}
empty_uri = AdditionalS3DataSource(s3_data_type="filestring", s3_uri="")
assert serialize(empty_uri) == { # noqa: F405
"S3DataType": "filestring",
"S3Uri": "",
}


def test_serialize_still_omits_empty_nested_shapes_and_lists():
# A nested shape with nothing set (e.g. an empty StoppingCondition) stays out of the request.
assert serialize( # noqa: F405
ProductionVariant(
variant_name="AllTraffic",
managed_instance_scaling=ProductionVariantManagedInstanceScaling(),
)
) == {"VariantName": "AllTraffic"}
assert serialize(TrialComponent(trial_component_name="t", parameters={})) == { # noqa: F405
"TrialComponentName": "t"
}


def test_serialize_drops_unset_shape_fields():
assert "MaxInstanceCount" not in serialize( # noqa: F405
ProductionVariantManagedInstanceScaling(status="ENABLED", min_instance_count=1)
)


def test_serialize_method_nested_shape():
trial_component_parameters = {
"test_num_value": TrialComponentParameterValue(number_value=1),
Expand Down
Loading
Loading