feat: add v2 -> v3 runtime migration warnings#5978
Merged
Conversation
4 tasks
Add visible, suppressible runtime warnings to guide SageMaker Python SDK v2 users toward v3 as the v2 line is put on the path of deprecation. Two tiers, both built on a new warn_v2_deprecation() helper in sagemaker.deprecations: - Tier 1 (package level): a single nudge emitted on `import sagemaker`, guaranteeing every v2 user sees the migration notice regardless of which API they use. - Tier 2 (per interface): a targeted warning at the constructor of each major v2 interface that names the exact v3 replacement (and a copy-pasteable import where the migration guide publishes one). Base-class sites use type(self).__name__ so subclasses report their own name. Covered: Estimator/framework estimators, Model, Predictor, Transformer, HyperparameterTuner, Processor, Pipeline, ModelMonitor, Experiment, Run, ModelCard, AsyncPredictor, and the MLflow integration. Design notes: - SageMakerV2DeprecationWarning subclasses FutureWarning so it is shown by default (DeprecationWarning is silenced outside __main__). - Fires at most once per feature per process; also logs via logger. - Suppressible with SAGEMAKER_SUPPRESS_V2_WARNING=1 or standard warning filters. - Workflow Step.__init__ is intentionally NOT instrumented because it breaks existing len(w) warning-count assertions; Pipeline covers that surface. Adds unit tests in tests/unit/test_deprecations.py for visibility, once-per-process dedup, env-var suppression, subclass naming, and exact import rendering.
82971dd to
b8fee6d
Compare
mufaddal-rohawala
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: N/A
Description of changes:
Adds visible, suppressible runtime warnings that guide SageMaker Python SDK v2 users toward v3, now that the v2 line is on the path of deprecation. This targets the
master-v2maintenance branch.Two tiers, both built on a new
warn_v2_deprecation()helper insagemaker.deprecations:import sagemaker, so every v2 user sees the migration notice regardless of which API they use.Sample code and output:
type(self).__name__, so subclasses report their own name.Interfaces covered by Tier 2:
Estimator/framework estimators,Model,Predictor,Transformer,HyperparameterTuner,Processor,Pipeline,ModelMonitor,AutoML/AutoMLV2,Experiment,Run,ModelCard,AsyncPredictor, and the MLflow integration.Sample code and output:
Design notes:
SageMakerV2DeprecationWarningsubclassesFutureWarningso it is shown by default (DeprecationWarningis silenced outside__main__).logger.warningfor log-captured environments (e.g. training jobs).SAGEMAKER_SUPPRESS_V2_WARNING=1or standard Python warning filters.Step.__init__is intentionally not instrumented because it breaks existinglen(w)warning-count assertions;Pipelinecovers that surface.Testing done:
tests/unit/test_deprecations.pycovering: default visibility (FutureWarning), once-per-process dedup,SAGEMAKER_SUPPRESS_V2_WARNINGsuppression, subclass naming, and exact-import rendering. 24/24 pass.mlflow/sklearn, offline botocoreendpoints.json, a flaky timestamp-collision monitor test), each confirmed failing identically on the unmodified base viagit stash.flake8andblack --line-length 100clean on all changed files.Merge Checklist
General
FutureWarningon import is acceptable messaging.Tests
unique_name_from_baseto create resource names in integ tests (if appropriate) (N/A — unit tests only)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.