Skip to content

feat: add v2 -> v3 runtime migration warnings#5978

Merged
jam-jee merged 1 commit into
aws:master-v2from
jam-jee:feat/v2-deprecation-warnings
Jul 1, 2026
Merged

feat: add v2 -> v3 runtime migration warnings#5978
jam-jee merged 1 commit into
aws:master-v2from
jam-jee:feat/v2-deprecation-warnings

Conversation

@jam-jee

@jam-jee jam-jee commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

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-v2 maintenance branch.

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, so every v2 user sees the migration notice regardless of which API they use.
    Sample code and output:
Code:  import sagemaker 
Output : SageMakerV2DeprecationWarning: You are using the SageMaker Python SDK v2, which is on path of deprecation. v3 is the actively developed major version.
See https://github.com/aws/sagemaker-python-sdk/blob/master/migration.md for the migration guide. Set SAGEMAKER_SUPPRESS_V2_WARNING=1 to silence this warning.
  • Tier 2 (per interface): a targeted warning at the constructor of each major v2 interface that names the exact v3 replacement (plus a copy-pasteable import where the migration guide publishes one). Base-class call sites use 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:

Code:  
from sagemaker.transformer import Transformer
Transformer(model_name="demo-model" , ***)
---
Output : /sagemaker/transformer.py:115: SageMakerV2DeprecationWarning: Transformer is part of the SageMaker Python SDK v2, which is on path of deprecation. In v3, use `sagemaker.core.shapes.TransformJob`.
See https://github.com/aws/sagemaker-python-sdk/blob/master/migration.md for the migration guide. Set SAGEMAKER_SUPPRESS_V2_WARNING=1 to silence this warning.

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 emitted via logger.warning for log-captured environments (e.g. training jobs).
  • Suppressible with SAGEMAKER_SUPPRESS_V2_WARNING=1 or standard Python warning filters.
  • Workflow Step.__init__ is intentionally not instrumented because it breaks existing len(w) warning-count assertions; Pipeline covers that surface.

Testing done:

  • Added unit tests in tests/unit/test_deprecations.py covering: default visibility (FutureWarning), once-per-process dedup, SAGEMAKER_SUPPRESS_V2_WARNING suppression, subclass naming, and exact-import rendering. 24/24 pass.
  • Ran each touched module's unit suite in isolation (estimator, model, predictor, transformer, tuner, processing, pipeline, model_monitoring, automl, experiments, model_card, predictor_async, mlflow) — green except pre-existing, environment-related failures (missing optional mlflow/sklearn, offline botocore endpoints.json, a flaky timestamp-collision monitor test), each confirmed failing identically on the unmodified base via git stash.
  • flake8 and black --line-length 100 clean on all changed files.

Merge Checklist

General

  • I have read the CONTRIBUTING doc
  • I certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the Python SDK team
    • Note: changes are additive (new warnings only); no API signatures or behavior change. Targeted at the v2 maintenance line. Flagging for team confirmation that emitting a default-visible FutureWarning on import is acceptable messaging.
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients that I've initialized as part of this change. (N/A — no new clients initialized)
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes
  • I have checked that my tests are not configured for a specific region or account (if appropriate)
  • I have used unique_name_from_base to create resource names in integ tests (if appropriate) (N/A — unit tests only)
  • If adding any dependency in requirements.txt files, I have spell checked and ensured they exist in PyPi (N/A — no new dependencies)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jam-jee jam-jee requested a review from a team as a code owner June 29, 2026 20:16
@jam-jee jam-jee requested a review from mollyheamazon June 29, 2026 20:16
@jam-jee jam-jee closed this Jun 29, 2026
@jam-jee jam-jee reopened this Jun 30, 2026
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.
@jam-jee jam-jee force-pushed the feat/v2-deprecation-warnings branch from 82971dd to b8fee6d Compare June 30, 2026 18:10
@jam-jee jam-jee merged commit a85423f into aws:master-v2 Jul 1, 2026
7 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants