Skip to content

Replace the SageMaker Python SDK with direct boto3 calls - #281

Merged
shchur merged 16 commits into
masterfrom
sagemaker-v3-core
Oct 2, 2026
Merged

shchur merged 16 commits into
masterfrom
sagemaker-v3-core

Conversation

@shchur

@shchur shchur commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Draft. Removes the SageMaker Python SDK dependency (sagemaker>=2.240,<3). AutoGluon-Cloud now builds SageMaker API requests itself and sends them through boto3.

Dependency

  • sagemaker is dropped; there is no replacement (no sagemaker-core). Only boto3 is needed.

Internals

  • Training jobs, models, endpoint configs, endpoints and transform jobs are created with plain CreateTrainingJob / CreateModel / CreateEndpointConfig / CreateEndpoint / CreateTransformJob requests. The v2 Estimator/Model/Predictor subclasses are gone.
  • A small AwsSession (in utils/aws_utils.py) holds the boto3 session and its sagemaker / sagemaker-runtime / s3 clients, plus S3 upload/download helpers. All calls go through the backend's own session.
  • Script mode is reproduced directly: training code is uploaded as sourcedir.tar.gz and passed to the container as a code input channel (so EnableNetworkIsolation works); serving code is repacked into model.tar.gz under code/.
  • The execution-role fallback is reimplemented: saved config, then the caller's STS identity, with the role path resolved through IAM.
  • Job waits stream CloudWatch logs with our own poller.
  • SagemakerEndpoint and the Endpoint base class are removed.
  • Unit tests check generated requests against botocore's service model.

API changes (breaking)

  • backend_kwargs (which held SDK-specific dicts) is replaced by backend_overrides: raw SageMaker request fields keyed by boto3 method name (create_training_job, create_model, production_variant, create_endpoint_config, create_endpoint, create_transform_job). They are deep-merged over the generated requests. Fields that link the created resources (e.g. ProductionVariants, ModelName on the variant / transform job, EndpointConfigName on the endpoint) can't be overridden, so cleanup only ever deletes resources AutoGluon-Cloud created.
  • predict() / predict_proba() take predictions_path (S3 prefix for the batch transform output) like fit_predict(), and always return the loaded results when wait=True. The download / persist / save_path options (previously keys of backend_kwargs) are removed.
  • Removed kwargs (backend_kwargs, model_kwargs, deploy_kwargs, transformer_kwargs, …) raise an error naming their replacement.
  • attach_endpoint() takes an endpoint name; detach_endpoint() returns the endpoint name.
  • SageMaker local mode is removed.
  • Custom training/serving scripts (entry_point / source_dir in the old SDK kwargs) are no longer supported and raise an explicit error; use custom_image_uri to customize the container.

Everything else is unchanged from master (role=, custom_image_uri, region resolution, tags).

Migration

Before After
fit(..., backend_kwargs={"autogluon_sagemaker_estimator_kwargs": {...}}) fit(..., backend_overrides={"create_training_job": {...}}) with CreateTrainingJob fields
deploy(..., backend_kwargs={"model_kwargs": {...}, "deploy_kwargs": {...}}) deploy(..., backend_overrides={"create_model": {...}, "production_variant": {...}, "create_endpoint_config": {...}})
predict(..., backend_kwargs={"transformer_kwargs": {...}}) predict(..., backend_overrides={"create_transform_job": {...}})
predict(df, backend_kwargs={"download": True, "save_path": p}) predict(df).to_csv(p); results are always returned when wait=True
predict(df, backend_kwargs={"download": False}) predict(df, wait=False), then get_batch_inference_job_info() for the S3 result path
predict(df, backend_kwargs={"transform_kwargs": {"output_path": uri}}) predict(df, predictions_path=uri)
detach_endpoint() returned an Endpoint object returns the endpoint name; attach_endpoint(name)
instance_type="local" not supported; use a SageMaker instance type

Examples:

# Environment variables in the inference container
predictor.deploy(backend_overrides={"create_model": {"PrimaryContainer": {"Environment": {"FOO": "bar"}}}})

# Managed spot training
predictor.fit(
    train_data,
    predictor_init_args={"label": "y"},
    backend_overrides={"create_training_job": {
        "EnableManagedSpotTraining": True,
        "StoppingCondition": {"MaxRuntimeInSeconds": 3600, "MaxWaitTimeInSeconds": 7200},
    }},
)

Known gaps / follow-ups

  • User-supplied tags: passing Tags via backend_overrides replaces the default autogluon-cloud-* tags, since lists are not merged.
  • Reusable backend settings (VPC, KMS, tags), plus named args for container environment and spot training. Until then these can be set through backend_overrides.
  • CloudPredictor.deploy() returning an endpoint object, matching FoundationModel.deploy().
  • Deploying a predictor that was never fit should raise instead of creating a serve-script-only endpoint.
  • Needs a live run, including from SageMaker Studio, for the role fallback and model repacking.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-c4683e8 is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/c4683e8/index.html

shchur added 2 commits October 2, 2026 10:05
…ures to their jobs

- Replace role/vpc_config/kms_key/tags constructor args with backend=SageMakerConfig(...),
  shared by cloud predictors and foundation models; add explicit region and split
  output_kms_key/volume_kms_key.
- Rename sagemaker_overrides to backend_overrides and accept it on foundation-model predict.
- Bind JobPredictionFuture to the submitted job and upload fit inputs under a per-job prefix
  so later submissions don't overwrite earlier ones.
…ker-core resources

sagemaker-core resource classes route every call through a process-wide client that
ignores the session argument, which breaks per-object region/credentials. Send requests
through the session's own sagemaker / sagemaker-runtime clients instead.

- Build requests in SageMaker API / boto3 PascalCase; backend_overrides fields use the
  same format as the AWS API reference. Override keys stay the boto3 method names.
- SageMakerConfig.vpc_config and inference_config keep their snake_case keys and are
  mapped explicitly; unknown keys raise before any resource is created.
- Wait for endpoints with botocore's endpoint_in_service waiter.
- Remove the sagemaker-core session-binding and acronym-serialization workarounds.
- Unit tests validate generated requests against botocore's service model.
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-7e43a3d is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/7e43a3d/index.html

The remaining uses were thin helpers around boto3. Replace them with small local
implementations so all AWS calls go through the backend's own boto3 session.

- AwsSession wraps a boto3.Session with cached sagemaker / sagemaker-runtime / s3
  clients plus upload_data / download_data.
- get_execution_role derives the role from the caller's STS identity and resolves
  its path via IAM (falling back to service-role/ for SageMaker console roles);
  IAM users get an actionable error instead of a guess.
- repack_model_with_serving_code repacks the model tarball directly.
- Move sagemaker_timestamp / unique_name_from_base to utils.misc and drop the
  serializer/deserializer base classes.
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-ca921eb is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/ca921eb/index.html

Keep the public API as close to master as possible so the PR only swaps the
SageMaker SDK for direct boto3 calls.

- Restore the `role=` constructor arg and `custom_image_uri`; remove
  SageMakerConfig, vpc/kms/user tags and the environment / use_spot_instances /
  max_wait args (all reachable via backend_overrides).
- Revert unrelated changes: prediction-future binding, per-job upload prefix,
  docs/API surface tweaks, internal backend refactors.
@shchur shchur changed the title Migrate to SageMaker Python SDK v3 (sagemaker-core) Replace the SageMaker Python SDK with direct boto3 calls Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-7b0778f is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/7b0778f/index.html

shchur added 2 commits October 2, 2026 12:11
- Replace predict()/predict_proba()'s download / persist / save_path with
  predictions_path, the S3 prefix the batch transform job writes to. With
  wait=True results are always loaded and returned, as in fit_predict().
- Inline resolve_image_uri: use custom_image_uri or retrieve_image_uri().
@shchur
shchur marked this pull request as ready for review October 2, 2026 12:19
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-1d51cdd is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/1d51cdd/index.html

shchur added 4 commits October 2, 2026 12:36
- Clean up the model and endpoint config when deploy() fails partway, and give
  each deploy a unique endpoint config name so a leftover config can't block a
  redeploy.
- Batch transform: delete only the model this call created, and register the
  job under its actual (possibly overridden) name.
- Pass training code as a `code` input channel, as SDK v2 did, so training
  works with EnableNetworkIsolation.
- attach_job() raises again when the training job did not complete.
- backend_overrides can't set fields that link created resources
  (ProductionVariants / their ModelName, EndpointConfigName on the endpoint,
  ModelName on the transform job), so cleanup only deletes our own resources.
- Validate inference_mode before creating anything.
- Rollback deletes log failures instead of masking the original error.
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-d56f415 is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/d56f415/index.html

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Job PR-281-025258c is done.
Docs are uploaded to https://d12sc05jpx1wj5.cloudfront.net/PR-281/025258c/index.html

@shchur
shchur merged commit b106897 into master Oct 2, 2026
8 checks passed
@shchur
shchur deleted the sagemaker-v3-core branch October 2, 2026 14:25
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.

1 participant