AWS Builder Center
Fine-Tuning Dolly with LoRA on SageMaker

Fine-Tuning Dolly with LoRA on SageMaker

How I fine-tuned Dolly v2 3B using LoRA and deployed it to a SageMaker endpoint.

Cloud Engineer | AWS | Generative AI & Agentic AI

Fine-Tuning Dolly with LoRA on SageMaker

Introduction

I recently completed the AWS SimuLearn: Fine-Tuning an LLM on Amazon SageMaker hands-on lab on AWS Skill Builder.
This was one of the most challenging and rewarding labs in my AWS learning journey. Unlike my previous experiments with Amazon Bedrock, where I primarily invoked existing foundation models, this lab gave me hands-on experience fine-tuning a pretrained large language model and deploying it for real-time inference.
I worked with Dolly v2 3B, a pretrained LLM, and used Low-Rank Adaptation (LoRA) to customize it with AWS service FAQ datasets.
The most valuable part was understanding the complete model lifecycle: from preparing training data to serving a fine-tuned model through a SageMaker endpoint.
Here are my key takeaways.

1. Understanding the Business Scenario

The scenario involved a city's AI Hub that wanted to customize foundation models using domain-specific information.
Rather than training a language model from scratch, the goal was to adapt an existing LLM to better handle questions related to AWS services.
The solution needed to support three main capabilities:
  • Fine-tune a pretrained LLM using specialized FAQ datasets.
  • Apply parameter-efficient fine-tuning to reduce computational requirements.
  • Deploy the customized model to an endpoint that applications could invoke.
This introduced me to the concept of transfer learning, where knowledge from a pretrained model is adapted to a more specific task.

2. Exploring the Solution Architecture

The architecture combines model training, artifact storage, and real-time inference.
Component
Responsibility
Amazon SageMaker AI
Provides the development and model deployment environment
Jupyter Notebook
Runs data preparation and fine-tuning code
Dolly v2 3B
Pretrained language model
Hugging Face Transformers
Loads and processes the model
PEFT / LoRA
Enables parameter-efficient fine-tuning
Amazon S3
Stores model artifacts
SageMaker Endpoint
Hosts the model for inference
AWS Lambda
Invokes the deployed endpoint
Amazon API Gateway
Exposes the application backend
Amazon CloudFront + S3
Delivers the web application
The core workflow is:
Pretrained LLM + FAQ Dataset → LoRA Fine-Tuning → Model Artifacts → Amazon S3 → SageMaker Endpoint → Inference
What I found especially interesting was the separation between the model development environment and the infrastructure used to serve the model.

3. Preparing the FAQ Dataset

The first major step was preparing training data.
In the practice lab, I worked with an Amazon SageMaker FAQ dataset containing instruction-response pairs.
These pairs were formatted into a structure suitable for supervised fine-tuning.
For example:
Instruction: What security capabilities does Amazon SageMaker provide?
Response: A reference answer based on the FAQ dataset.
The notebook then used tokenization to convert the training text into numerical representations that the model could process.
This reinforced an important concept: the quality and structure of training data are critical to successful model customization.

4. Fine-Tuning Dolly v2 3B with LoRA

This was the most important technical part of the lab.
Dolly v2 3B is a pretrained language model with approximately three billion parameters.
Updating all parameters during fine-tuning can require substantial computational resources.
Instead, the lab used Low-Rank Adaptation (LoRA), a parameter-efficient fine-tuning technique.
LoRA introduces small trainable matrices into selected parts of the model, allowing us to adapt its behavior while keeping most pretrained weights frozen.
The notebook used Hugging Face PEFT and Trainer to perform the fine-tuning process.
One of the key operations was:
 trainer.train() 
This started the training process using the prepared dataset and training configuration.
I also explored model loading with 8-bit quantization to reduce GPU memory requirements.
My biggest takeaway: We do not always need to update every parameter of a large language model to customize it for a specific use case.

5. Saving Model Artifacts to Amazon S3

After fine-tuning, the next challenge was preparing the model for deployment.
The notebook saved the trained LoRA adapter using:
 trainer.model.save_pretrained("dolly-3b-lora") 
However, the adapter weights alone were not sufficient to deploy a working inference application.
The deployment package also included components such as:
  • LoRA adapter weights and configuration.
  •  model.py  for model initialization and inference logic.
  •  requirements.txt  for Python dependencies.
  •  serving.properties  for model-serving configuration.
These components were packaged into a  .tar.gz  file and uploaded to Amazon S3.
This helped me understand a concept I had previously overlooked:
Model deployment is not just about storing model weights. It also requires the code, dependencies, and configuration needed to load and execute the model.
In this lab, the inference environment loads the pretrained Dolly model and applies the LoRA adapter.

6. Deploying to a SageMaker Endpoint

Once the model artifacts were stored in S3, I configured a SageMaker Model using:
  • The inference container image URI.
  • The S3 location of the packaged model artifacts.
  • An IAM execution role.
  • A predictor class for invoking the endpoint.
The model was then deployed using the SageMaker Python SDK.
The key operation was:
 predictor = model.deploy(1, "ml.g4dn.2xlarge", wait=False) 
This requests a SageMaker real-time endpoint backed by one GPU instance.
SageMaker provisions the required infrastructure, starts the inference container, and loads the model.
After the endpoint reaches the  InService  state, it can receive inference requests.
For example, the notebook used  predictor.predict()  to submit questions to the deployed model.
An important distinction I learned was:
  • SageMaker Model: Defines the model artifacts and serving configuration.
  • SageMaker Endpoint: Provides the running infrastructure that serves inference requests.
The endpoint can then be integrated with an application through AWS Lambda and API Gateway.

7. Completing the DIY Challenge

After the guided practice lab, I continued with the DIY challenge.
This time, I worked with a different dataset containing Amazon Bedrock FAQs.
The DIY objectives included:
  1. Fine-tuning Dolly using the Bedrock FAQ dataset.
  1. Packaging and uploading the new model artifacts.
  1. Deploying the customized model to a new SageMaker endpoint.
  1. Updating the AWS Lambda integration to use the new endpoint.
  1. Validating the endpoint and model configuration.
Completing this challenge helped reinforce the workflow without relying entirely on the guided practice.
It also demonstrated how a similar fine-tuning pipeline can be adapted to different domain-specific datasets.

8. Key Lessons Learned

This lab taught me several important lessons.
1. Fine-tuning is different from prompt engineering and RAG.
Prompt engineering changes the instructions provided to a model. RAG retrieves external context. Fine-tuning adapts trainable model parameters to a particular task or domain.
2. LoRA makes model customization more efficient.
Instead of updating all the pretrained weights, LoRA trains a smaller set of parameters, reducing the resources required for customization.
3. Model artifacts and inference containers serve different purposes.
Model artifacts provide the learned parameters and related files, while the container provides the environment needed to execute inference.
4. SageMaker endpoints bridge model development and applications.
A model trained in a notebook becomes accessible to other AWS services once it is deployed for inference.
5. Deployment is not the same as model quality.
A successful endpoint deployment confirms that the model can be hosted and invoked. Additional evaluation is still needed to determine whether the fine-tuned model produces accurate and useful responses.

9. Final Thoughts

This lab was an important milestone in my AWS Generative AI learning journey.
Previously, I focused on consuming foundation models through Amazon Bedrock and building applications using prompt engineering, RAG, and AI agents.
This time, I explored the model customization process itself.
My biggest takeaway is:
Fine-tuning an LLM is only one part of the journey. Preparing data, packaging model artifacts, deploying inference infrastructure, and evaluating model behavior are equally important.
For future exploration, I would like to compare LoRA with full fine-tuning, evaluate model performance before and after customization, and investigate techniques for reducing inference latency and deployment costs.
I'm excited to continue learning about machine learning engineering and production-ready AI systems on AWS.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article