Customizing foundation models with Amazon SageMaker AI | Amazon Web Services

Amazon Web Services · Advanced ·☁️ DevOps & Cloud ·7mo ago

Key Takeaways

Fine-tune foundation models with Amazon SageMaker using custom datasets and training jobs

Full Transcript

Hi, I'm Jazeppi Zappia, a IML specialist solution architect at AWS. The topic of foundation model customization spans a wide gamut of possibilities from prompt engineering and retrieval augmented generation all the way to supervised fine-tuning, preference optimization, continued pre-training, and even building models from scratch. In this video, I'm going to show how to customize your own foundation models using Amazon SageMaker AI. Let's get into it. Fine-tuning is used as a customization technique when you're trying to get a foundation model to perform better or in a very specific way when presented with a given task. This could reduce the amount of input or output tokens, correct inconsistency in model outputs, and even provide additional capabilities that didn't exist before, such as tool calling or advanced reasoning. When fine-tuning a model, the approaches fall in a few different buckets. First is quick experimentation with a small data set and a small number of epochs. Then you could do single instance training with bigger data sets and possibly with multiple GPUs. Then you have large-scale distributed training workloads with large models and data sets spanning multiple instances. SageMaker Studio spaces support GPU powered instances and could be used for smaller scale model customization where you're focused on quick iterations in a notebook environment but don't allow you to scale to multi-node training and results in a tightly coupled development environment. SageMaker managed training jobs provide ephemeral scalable resources for both single instance and distributed training workloads at scale. Managed training jobs support bringing your own custom containers as well as using managed containers where you can bring your own training script. This variety of options allows you to choose the one that gives you the flexibility without sacrificing time to value. SageMaker HyperPod provides long-running clusters that can be orchestrated via Slurm or Kubernetes, optimized for large-scale distributed training and provides direct access to the underlying instances via SSH. This provides the highest level of control while still taking advantage of managed infrastructure. SageMaker training jobs are tailored for organizations that want to focus on model development rather than infrastructure management and prefer ease of use with a managed experience. SageMaker training jobs feature a user-friendly interface, simplified setup and scaling, automatic handling of distributed training tasks, built-in synchronization, checkpointing, fault tolerance, and abstraction of infrastructure complexities. For organizations that require granular control over training infrastructure and extensive customization options, SageMaker Hyperpod is the ideal choice. HyperPod offers custom network configurations, flexible parallelism strategies, and support for custom orchestration techniques. It integrates seamlessly with tools such as Slurm, Amazon EKS, Nvidia's Nroot, and Pixus, and provides SSH access for in-depth debugging and custom configurations. Let's take a look at some code. In this example, I'll be using a SageMaker Studio code editor space and walk you through training models both through HyperPod and through manage training jobs. We'll start off with HyperPod. Here I have a SageMaker HyperPod cluster that is a mix of CPU and GPU powered instances using Amazon EKS as the orchestrator. This allows my Kubernetes cluster to see the HyperPod cluster as a set of nodes that I can directly deploy containers or pods to. The HyperPod nodes can additionally leverage shared persistent file systems that are available to the Kubernetes cluster. In this example, I've attached an Amazon FSX for Luster file system to the cluster which will provide high performance disk access for models and data. I've also taken advantage of a feature in SageMaker Studio that allows me to mount volumes to my code editor space. This way, I can load larger resources directly onto the FSX for Lustre file system without having to continuously shuffle data into my training job, accelerating my development cycle. For simplicity, I've already staged my training data and script on FSX. To submit your training job, you can use the cube cuddle command and a file with the configuration information. This job is for fine-tuning a DeepSeek distilled quen 7B model. Jumping right into the PyTorch job, you can see that the FSX volume here is tied to the persistent volume claim, allowing us to use the FSX for luster file system. The container for this job is one of the SageMaker managed PyTorch containers, but you could also have created your own. The invidia.com/GPU resource will ensure that this job gets allocated one GPU. Then you have some environment configuration followed by the entry point of the container. This command will install dependencies from a requirements.ext file. Then run our training script with a set of training arguments. The paths for these files correspond to the mount point at the end here where the container will mount the fsx for luster file system on /data. Running cubecuddle apply-fpod_finetuning.yaml will schedule this pod for deployment and fire off the training job. The training script will write the train model artifacts back to the fsx volume so it can be prepared for deployment. This will take a few minutes to complete. Running cube cuddle get pods will show the currently running pods on the cluster. You can see that the worker pod for training job has started. Running cube cuddle logs in the name of the pod will allow you to view the standard output from the training container. Right now it is installing dependencies and will eventually show a progress indicator once training begins. We'll come back to this once training has completed. The logs now show that the training job is finished and running cubecuddle get pods shows the training worker pod in a completed state. The train model artifacts are now located on the fsx for luster volume that we set up in the training configuration and is ready for deployment. You can deploy this model through SageMaker Hyperbot inference on the SageMaker managed endpoint, Amazon EKS, Amazon EC2 or anywhere else that you'd like. Let's go through a similar exercise with a manage training job. I've already installed my dependencies and downloaded a medical reasoning data set from hugging face for this example. I prepared a prompt template that I'll apply to all of my training samples. Then upload the files to S3 so that they could be downloaded by the training job. You can also provide an FSX for luster file system to the training job similar to the hyperpod example but I wanted to show a different method here. Next is the training configuration where I've defined all the locations for where the training script can expect to find data training hyperparameters and where to output the final model artifact. The training job will package these files in this folder as a tar file and upload it to S3 upon completion of the job. I'm leveraging PyTorch's fully sharded data parallel capability in the configuration here, which will take advantage of all available GPUs on my training instance to speed up the process. I'll upload my training configuration to S3, then set up my model trainer object. The SageMaker model trainer SDK construct simplifies the steps necessary to build SageMaker training jobs. All I need to do is specify my training container infrastructure configuration, the training parameters, and any custom code I want to use for the job. Then the path from where my training data is stored. After that, I call train and a SageMaker training job will be created for me. This will take a little while to complete. After the training job finishes, I can fetch the last training job from the model trainer, which gives me the path to the fine-tuned model artifacts. From there, I could use SageMaker's large model inference container, supply my model artifacts and inference configuration, and deploy the model for inference. Amazon SageMaker AI provides several manage hosting options for your models. Realtime inference is a model deployment option designed for use cases requiring immediate low latency responses and high throughput. It provides a persistent fully managed endpoint that can handle continuous inference requests and deliver responses in real time. Serverless inference is a pay-peruse option that provides ondemand inference without configuring or managing the underlying infrastructure. This is ideal for CPUbased inference workloads that have idle periods between spurts of traffic and can tolerate cold starts. Asynchronous inference is optimal for nearreal-time use cases. Inference that requires long processing times or have requests with large payloads. Asynchronous inference cues incoming requests and processes them on a fleet of instances, scaling the instance count to zero when there are no requests to process. Batch transform is ideal for longunning offline batch inference jobs on large data sets that don't require a persistent real-time endpoint. Batch transform handles the distribution of your data sets and models, removing the undifferiated heavy lifting of building your own job orchestration. Through these options for model hosting, SageMaker AI allows you to choose the one that best aligns with your application's specific requirements. Now that the HyperPod job has completed, you can see the fine-tuned model artifact stored in the FSX file system I mounted to the code editor space. From here, I could package the model artifact up myself or as part of the training script and store it in S3 for deployment to a managed endpoint. Once the SageMaker real-time endpoint has fully deployed, the model is ready to serve inference. I've created a predictor object for my endpoint using the SageMaker Python SDK that I can use to invoke the model. I've taken a sample data point from the medical data set we used for training earlier. I'll format it for my prompt and call predict on the predictor with the desired inference parameters to get a response. The inference response latency will be dependent on the size of the model and the type of instance serving the model. Finally, you can see the output from my request. The model is reasoning through the scenario I presented and giving an answer. Last, you can terminate your endpoint by running the delete model and delete endpoint APIs which will stop any of the running costs for hosting. To recap, in this video, you learned how you can use either SageMaker fully managed training jobs or SageMaker Hyperpod to fine-tune a foundation model on custom data set. Thanks for watching and happy experimenting with fine-tuning.

Original Description

Learn how to fine-tune a foundation model using fully managed training jobs or Amazon SageMaker HyperPod on custom dataset. Subscribe to AWS: https://go.aws/subscribe Create a free AWS account: https://go.aws/signup Try AWS for free: https://go.aws/free Connect with an expert: https://go.aws/contact Explore more: https://go.aws/more Next steps: Explore on AWS in Analyst Research: https://go.aws/reports Discover, deploy, and manage software that runs on AWS: https://go.aws/marketplace Join the AWS Partner Network: https://go.aws/partners Learn more on how Amazon builds and operates software: https://go.aws/library Do you have technical AWS questions? Ask the community of experts on AWS re:Post: https://go.aws/3lPaoPb Why AWS? Amazon Web Services is the world’s most comprehensive and broadly adopted cloud, enabling customers to build anything they can imagine. We offer the greatest choice of innovative cloud capabilities and expertise, on the most extensive global infrastructure with industry-leading security, reliability, and performance. #AWS #AmazonWebServices #CloudComputing
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Amazon Web Services · Amazon Web Services · 0 of 60

← Previous Next →
1 Agentic AI Design Patterns Introduction and walkthrough | Amazon Web Services
Agentic AI Design Patterns Introduction and walkthrough | Amazon Web Services
Amazon Web Services
2 Galileo on modernizing on banking infrastructure | Amazon Web Services
Galileo on modernizing on banking infrastructure | Amazon Web Services
Amazon Web Services
3 Alliander Speeds Innovation and Energy Transition Using AWS | Amazon Web Services
Alliander Speeds Innovation and Energy Transition Using AWS | Amazon Web Services
Amazon Web Services
4 AWS and Scuderia Ferrari HP streamline F1 power unit assembly | Amazon Web Services
AWS and Scuderia Ferrari HP streamline F1 power unit assembly | Amazon Web Services
Amazon Web Services
5 How AWS machine learning supports Scuderia Ferrari HP pit stops | Amazon Web Services
How AWS machine learning supports Scuderia Ferrari HP pit stops | Amazon Web Services
Amazon Web Services
6 Nasdaq Builds Market Infrastructure of the Future with AWS | Amazon Web Services
Nasdaq Builds Market Infrastructure of the Future with AWS | Amazon Web Services
Amazon Web Services
7 AWS Security Hub Exposure Findings | Amazon Web Services
AWS Security Hub Exposure Findings | Amazon Web Services
Amazon Web Services
8 How do I use Session Manager port forwarding to connect to my EC2 instance through RDP?
How do I use Session Manager port forwarding to connect to my EC2 instance through RDP?
Amazon Web Services
9 How do I extend an EBS volume with LVM partitions?
How do I extend an EBS volume with LVM partitions?
Amazon Web Services
10 AWS Graviton makes it easy to optimize performance, cost, and sustainability | Amazon Web Services
AWS Graviton makes it easy to optimize performance, cost, and sustainability | Amazon Web Services
Amazon Web Services
11 Run Cloud Adoption Framework workshops with Miro | Amazon Web Services
Run Cloud Adoption Framework workshops with Miro | Amazon Web Services
Amazon Web Services
12 Getting Started with AWS Cost Optimization Hub | Amazon Web Services
Getting Started with AWS Cost Optimization Hub | Amazon Web Services
Amazon Web Services
13 Why did my Amazon SQS messages get sent to a dead-letter queue?
Why did my Amazon SQS messages get sent to a dead-letter queue?
Amazon Web Services
14 Declarative Policies for EC2 | Amazon Web Services
Declarative Policies for EC2 | Amazon Web Services
Amazon Web Services
15 How do I troubleshoot IAM permission issues for the Billing and Cost Management console?
How do I troubleshoot IAM permission issues for the Billing and Cost Management console?
Amazon Web Services
16 Integrity at Scale: Inside the Flo Health Mission | Amazon Web Services
Integrity at Scale: Inside the Flo Health Mission | Amazon Web Services
Amazon Web Services
17 Fueling Success: Small shifts, powerful performance | Amazon Web Services
Fueling Success: Small shifts, powerful performance | Amazon Web Services
Amazon Web Services
18 WEX enhances customer experience with AI-powered chatbot | Amazon Web Services
WEX enhances customer experience with AI-powered chatbot | Amazon Web Services
Amazon Web Services
19 Accelerate troubleshooting with Amazon CloudWatch investigations | Amazon Web Services
Accelerate troubleshooting with Amazon CloudWatch investigations | Amazon Web Services
Amazon Web Services
20 Why is my Windows WorkSpace stuck in the starting, rebooting, or stopping status?
Why is my Windows WorkSpace stuck in the starting, rebooting, or stopping status?
Amazon Web Services
21 Telemetry Pipelines for AI | Amazon Web Services
Telemetry Pipelines for AI | Amazon Web Services
Amazon Web Services
22 Getting Control over Security and Observability Data | Amazon Web Services
Getting Control over Security and Observability Data | Amazon Web Services
Amazon Web Services
23 The Problem with Telemetry Data Volume | Amazon Web Services
The Problem with Telemetry Data Volume | Amazon Web Services
Amazon Web Services
24 Telemetry Pipelines on AWS | Amazon Web Services
Telemetry Pipelines on AWS | Amazon Web Services
Amazon Web Services
25 What are Telemetry Pipelines? | Amazon Web Services
What are Telemetry Pipelines? | Amazon Web Services
Amazon Web Services
26 Using AI for RegEx on Telemetry Pipelines | Amazon Web Services
Using AI for RegEx on Telemetry Pipelines | Amazon Web Services
Amazon Web Services
27 Multi-Session Support in the AWS Console | Amazon Web Services
Multi-Session Support in the AWS Console | Amazon Web Services
Amazon Web Services
28 How CloudHedge delivers assessment with AWS ISV Tooling Program at no cost?
How CloudHedge delivers assessment with AWS ISV Tooling Program at no cost?
Amazon Web Services
29 How customers speed up migration and modernization to AWS with CloudHedge | Amazon Web Services
How customers speed up migration and modernization to AWS with CloudHedge | Amazon Web Services
Amazon Web Services
30 Chaos Experiment with Amazon ElastiCache | Amazon Web Services
Chaos Experiment with Amazon ElastiCache | Amazon Web Services
Amazon Web Services
31 Amazon S3 Access Points: Easily manage access for shared datasets on S3 | Amazon Web Services
Amazon S3 Access Points: Easily manage access for shared datasets on S3 | Amazon Web Services
Amazon Web Services
32 ElastiCache Valkey 8.0 - Savings and Efficiency | Amazon Web Services
ElastiCache Valkey 8.0 - Savings and Efficiency | Amazon Web Services
Amazon Web Services
33 Pennymac scales document processing with AWS | Amazon Web Services
Pennymac scales document processing with AWS | Amazon Web Services
Amazon Web Services
34 AWS | Next Level Innovation | Amazon Web Services
AWS | Next Level Innovation | Amazon Web Services
Amazon Web Services
35 Driving Cloud Innovation: Mindtickle's Partnership with AWS Enterprise Support | Amazon Web Services
Driving Cloud Innovation: Mindtickle's Partnership with AWS Enterprise Support | Amazon Web Services
Amazon Web Services
36 A Leader's Edge from Executive Insights | Amazon Web Services
A Leader's Edge from Executive Insights | Amazon Web Services
Amazon Web Services
37 How do I create a custom Amazon WorkSpaces image?
How do I create a custom Amazon WorkSpaces image?
Amazon Web Services
38 Charles Leclerc tests his AI-generated race track | Amazon Web Services
Charles Leclerc tests his AI-generated race track | Amazon Web Services
Amazon Web Services
39 Redington Scales India’s Cloud Access with AWS Partnership | Amazon Web Services
Redington Scales India’s Cloud Access with AWS Partnership | Amazon Web Services
Amazon Web Services
40 How do I prevent the resources in my CloudFormation stack from getting deleted or updated?
How do I prevent the resources in my CloudFormation stack from getting deleted or updated?
Amazon Web Services
41 How do I troubleshoot authentication errors when I use RDP to connect to an EC2 Windows instance?
How do I troubleshoot authentication errors when I use RDP to connect to an EC2 Windows instance?
Amazon Web Services
42 Exploring the Possibilities of Digital Twin & AI at the Edge | Amazon Web Services
Exploring the Possibilities of Digital Twin & AI at the Edge | Amazon Web Services
Amazon Web Services
43 Exploring the Possibilities of Digital Twin & AI at the Edge | Amazon Web Services
Exploring the Possibilities of Digital Twin & AI at the Edge | Amazon Web Services
Amazon Web Services
44 AWS at the FORMULA 1 AWS GRAN PREMIO DELL'EMILIA-ROMAGNA 2025 | Amazon Web Services
AWS at the FORMULA 1 AWS GRAN PREMIO DELL'EMILIA-ROMAGNA 2025 | Amazon Web Services
Amazon Web Services
45 What's new in RCPs | Amazon Web Services
What's new in RCPs | Amazon Web Services
Amazon Web Services
46 API Caching using Amazon ElastiCache | Amazon Web Services
API Caching using Amazon ElastiCache | Amazon Web Services
Amazon Web Services
47 Pendula: Amazon Nova Customer Testimonial | Amazon Web Services
Pendula: Amazon Nova Customer Testimonial | Amazon Web Services
Amazon Web Services
48 InDebted : Amazon Nova Customer Testimonial | Amazon Web Services
InDebted : Amazon Nova Customer Testimonial | Amazon Web Services
Amazon Web Services
49 Amazon DynamoDB global tables with multi-Region strong consistency | Amazon Web Services
Amazon DynamoDB global tables with multi-Region strong consistency | Amazon Web Services
Amazon Web Services
50 Siemens Mobility uses AWS to operate securely, efficiently on a global scale | Amazon Web Services
Siemens Mobility uses AWS to operate securely, efficiently on a global scale | Amazon Web Services
Amazon Web Services
51 How do I reuse a knowledge base session in Amazon Bedrock?
How do I reuse a knowledge base session in Amazon Bedrock?
Amazon Web Services
52 EP5: MBZUAI, CMU : Causal AI, Answering The “Why“ and “What if“ Questions | AWS for AI Podcast
EP5: MBZUAI, CMU : Causal AI, Answering The “Why“ and “What if“ Questions | AWS for AI Podcast
Amazon Web Services
53 Hema scales time to market developing a data mesh on AWS (Technical) - Cloud Adventures
Hema scales time to market developing a data mesh on AWS (Technical) - Cloud Adventures
Amazon Web Services
54 Hema scales time to market developing a data mesh on AWS (Business) - Cloud Adventures
Hema scales time to market developing a data mesh on AWS (Business) - Cloud Adventures
Amazon Web Services
55 How Langfuse Scaled Their AI Platform with AWS: From Open-Source to Enterprise | Amazon Web Services
How Langfuse Scaled Their AI Platform with AWS: From Open-Source to Enterprise | Amazon Web Services
Amazon Web Services
56 SLMs and LLMs: What’s the Difference? | Amazon Web Services
SLMs and LLMs: What’s the Difference? | Amazon Web Services
Amazon Web Services
57 SLMs and LLMs: When to use them? | Amazon Web Services
SLMs and LLMs: When to use them? | Amazon Web Services
Amazon Web Services
58 SLMs on CPU | Amazon Web Services
SLMs on CPU | Amazon Web Services
Amazon Web Services
59 Intelligent Model Routing | Amazon Web Services
Intelligent Model Routing | Amazon Web Services
Amazon Web Services
60 SLMs, LLMs, and Model Routing in Agents | Amazon Web Services
SLMs, LLMs, and Model Routing in Agents | Amazon Web Services
Amazon Web Services

Related Reads

Up next
How to Code with Distrobox on the Steam Deck
Ian Wootten
Watch →