SageMaker Python SDK

repository·master·Indexed 25 days ago

https://github.com/aws/sagemaker-python-sdk

An open-source library for training and deploying machine learning models on Amazon SageMaker. The SDK V3 is organized into a four-package hierarchy: sagemaker-core for foundation primitives and resource management, sagemaker-train for training jobs and hyperparameter tuning, sagemaker-serve for model deployment and inference via ModelBuilder, and sagemaker-mlops for workflow orchestration and pipeline management. It supports popular frameworks like PyTorch and MXNet, as well as custom Docker containers.

Tokens
146.7K
Snippets
332
Records
509
Agent score
80%

What's inside aws-sagemaker-python-sdk

  1. Overview of sagemaker-core

    master

    The sagemaker-core Python SDK provides an object-oriented interface for interacting with Amazon SageMaker resources. It is designed to offer full parity with SageMaker APIs while improving developer productivity through several key abstractions:

    • Object-Oriented Interface: Uses dedicated resource classes to manage SageMaker resources.
    • Resource Chaining: Simplifies workflows by allowing the output of one resource to be passed directly as the input to another.
    • Abstraction of Low-Level Details: Automatically manages resource state transitions and polling logic.
    • Intelligent Defaults: Streamlines setup by providing default values for common parameters like IAM roles and VPC configurations.
    • Developer Experience: Includes comprehensive type hints and auto code completion support for IDEs.
  2. Manage MLOps pipelines and workflows with sagemaker.mlops

    master
    The sagemaker.mlops module provides capabilities for managing Machine Learning Operations (MLOps), specifically focusing on pipeline management and workflow orchestration. Use this module to automate the lifecycle of machine learning models, from data processing to deployment.
  3. Manage datasets, evaluators, and model artifacts with SageMaker AI Registry

    master

    Use the SageMaker AI Registry to manage and organize model development workflows. This allows you to centralize and govern the assets used in your machine learning lifecycle.

    Key Capabilities:

    • Dataset Versioning: Register and version training datasets to ensure reproducibility.
    • Custom Evaluation: Create custom evaluators and reward functions to standardize model assessment.
    • Lineage Tracking: Track model lineage and metadata for governance and compliance.

    Prerequisites:

    • Appropriate SageMaker permissions.
    • Prepared datasets ready for registration.
    • A defined understanding of the evaluation metrics you intend to use.
  4. Explore the SageMaker Python SDK V3 API Reference

    master

    The SageMaker Python SDK V3 is organized into several core modules that handle different stages of the machine learning lifecycle. You can find detailed API documentation for the following modules:

    • sagemaker.core: The foundational module containing core abstractions and base classes.
    • sagemaker.train: APIs and utilities specifically for managing and executing training jobs.
    • sagemaker.serve: APIs and utilities for model deployment and serving.
    • sagemaker.mlops: Specialized package for MLOps workflows and automation.
  5. Launch model evaluation jobs

    master

    The SageMaker Python SDK provides several specialized evaluation patterns to assess model performance. Depending on your use case, you can launch evaluation jobs using one of the following methods:

    • LLM as a Judge (LLMAJ) Evaluation: Leverages large language models to qualitatively assess the outputs of other models.
    • InspectAI Evaluation: Executes open-source InspectAI benchmark tasks directly on SageMaker infrastructure.
    • Custom Scorer Evaluation: Applies user-defined evaluator functions to model outputs.
    • Benchmark Evaluation: Runs standardized performance benchmarks to measure model capabilities.
    • Multi-Turn RL (Agentic) Evaluation: Specifically designed for multi-turn agent models, using rollout-based metrics such as pass@k and mean reward to evaluate agentic behavior.
  6. Use sagemaker-mlops for workflow orchestration and step implementations

    master

    The sagemaker-mlops package provides the high-level tools needed to define and execute SageMaker pipelines. It includes the core pipeline definition classes and a wide variety of specialized step implementations.

    Core Orchestration

    • Pipeline: The primary class for defining a workflow.
    • Step: The base class for all step logic.

    Common Step Implementations

    • Training & Models: automl_step.py, model_step.py (creation and registration).
    • Logic & Control: condition_step.py (conditional execution), callback_step.py (custom logic), fail_step.py (explicit failure).
    • AWS Integrations: lambda_step.py (AWS Lambda invocation), function_step.py (Lambda function steps), emr_step.py (EMR cluster steps).
    • Quality & Monitoring: quality_check_step.py (model quality), clarify_check_step.py (bias and explainability), monitor_batch_transform_step.py (batch transform monitoring).
    • Execution: notebook_job_step.py (notebook execution).

    Model Building

    While ModelBuilder is technically located in the sagemaker-serve package, it is re-exported from sagemaker-mlops for convenience in orchestration workflows.

  7. Model Customization with Foundation Models in SageMaker Python SDK V3

    master

    SageMaker Python SDK V3 introduces specialized trainers designed specifically for foundation model fine-tuning. This feature is a V3 Exclusive Feature and provides a streamlined, serverless approach to customizing AI models (such as for legal research, chatbots, or domain-specific agents) by removing operational overhead and infrastructure management.

    Key capabilities include:

    • Serverless Training: Fully managed compute infrastructure that abstracts away complexity.
    • Advanced Customization Techniques: Support for Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), Reinforcement Learning with Verifiable Rewards (RLVR), and Reinforcement Learning with AI Feedback (RLAIF).
    • Integrated Assets: Access to integrated datasets and evaluators for training, refining, and evaluating custom models.
    • Production Readiness: Built-in evaluation, monitoring, and deployment capabilities with automatic resource management.
  8. Fine-tune Amazon Nova foundation models

    master
    You can adapt Amazon Nova foundation models to specific use cases using fine-tuning techniques. This includes using data mixing to prevent catastrophic forgetting (available for serverless compute only) and configuring training via recipes and overrides. Training can be executed on both SMTJ (SageMaker Training Jobs) and HyperPod compute environments.