AWS Builder Center
Fine-Tuning Foundation Models with Amazon Bedrock

Fine-Tuning Foundation Models with Amazon Bedrock

Learn how to customize foundation models using Amazon Bedrock fine-tuning. Explore training datasets, model customization workflows, Python implementation, evaluation metrics, deployment options, and practical AWS considerations.

Fine-Tuning Foundation Models with Amazon Bedrock

Foundation models have transformed the way developers build Generative AI applications. They can generate text, answer questions, summarise documents, and perform complex language tasks without requiring developers to train models from scratch.
However, general-purpose foundation models may not always produce outputs that match a specific business requirement, domain, or application workflow.
For example, a customer support application may need consistent response formatting, while a financial application may require specialised language and task-specific behaviour.
Fine-tuning helps address these requirements by adapting an existing foundation model using task-specific training data.
Amazon Bedrock provides managed model customization capabilities that allow developers to customize supported foundation models without managing the underlying training infrastructure.
This article explains how fine-tuning works, when to use it, and how to create a model customization workflow using Amazon Bedrock and Python.

Understanding Foundation Model Fine-Tuning

Fine-tuning is a model customization technique in which an existing foundation model is further trained using a dataset designed for a particular task.
Instead of training a model from the beginning, developers start with an already-trained model and provide additional examples that demonstrate the desired behaviour.
For example, consider a customer support application.
A general-purpose model might generate different response styles for similar customer questions. A fine-tuned model can learn from carefully prepared examples to produce more consistent responses.
A typical fine-tuning process involves:
  • Selecting a supported foundation model.
  • Preparing task-specific training data.
  • Uploading training and validation datasets.
  • Creating a model customization job.
  • Evaluating the resulting model.
  • Deploying the customized model for inference.
The objective is to improve performance on a specific use case while retaining the capabilities inherited from the original foundation model.

Why Use Amazon Bedrock for Fine-Tuning?

Amazon Bedrock is a managed service that provides access to foundation models from different providers through a unified AWS environment.
Its model customization capabilities allow developers to adapt supported models using their own training data.
Important capabilities include:
  • Managed customization: Run supported model customization jobs without managing the underlying training infrastructure.
  • Training data integration: Use datasets stored in Amazon S3.
  • Model selection: Choose from supported foundation models and customization methods.
  • Training evaluation: Review available training and validation metrics.
  • AWS integration: Connect model customization workflows with IAM, S3, and other AWS services.
  • Custom model management: Manage customized models and configure inference options.
Amazon Bedrock supports several customization approaches, including supervised fine-tuning, reinforcement fine-tuning, and model distillation. Their availability depends on the selected model and AWS Region.

Understanding Different Model Customization Techniques

Before implementing fine-tuning, it is important to understand the available customization approaches.

Supervised Fine-Tuning

Supervised fine-tuning uses labelled input-output examples to teach a model how to respond to specific tasks.
For example:
Input: Explain cloud computing in simple terms.
Expected output: Cloud computing provides computing resources such as servers, storage, and databases over the internet.
The model learns from these examples to produce outputs that better match the training objectives.
This approach is useful for:
  • Customer support applications.
  • Domain-specific question answering.
  • Structured response generation.
  • Classification and information extraction.
  • Consistent writing styles.

Reinforcement Fine-Tuning

Reinforcement fine-tuning uses feedback-based learning to improve model behaviour.
Instead of relying only on predefined input-output pairs, developers define reward functions that evaluate the quality of generated responses.
The model uses this feedback during training to improve its performance against the specified objectives.
This approach is useful when response quality can be evaluated using measurable criteria or custom reward functions.

Model Distillation

Model distillation transfers knowledge from a larger teacher model to a smaller student model.
The teacher generates responses for selected prompts, and the resulting examples are used to customize the student model.
This can help create smaller models that are more efficient for specific workloads.
It is useful when developers want to balance model quality, inference performance, and operational cost.

Fine-Tuning vs Prompt Engineering vs RAG

Fine-tuning is not the solution to every Generative AI problem. Developers should select the approach according to the actual requirement.
Technique
How it works
Best suited for
Prompt Engineering
Provides instructions and examples in the prompt
Improving responses without training
RAG
Retrieves external information and adds it to the prompt
Applications requiring current or private knowledge
Fine-Tuning
Updates model parameters using training data
Adapting model behaviour for specific tasks
For example, if an application needs access to frequently updated company documents, RAG is generally more appropriate.
If an application needs consistent response formatting or specialised task behaviour, fine-tuning may be more suitable.
These approaches can also be combined when an application requires both specialised behaviour and access to external knowledge.

Understanding the Fine-Tuning Architecture

A typical Amazon Bedrock fine-tuning architecture contains the following components:
Amazon S3
Stores training datasets, validation datasets, and customization output files.
Amazon Bedrock
Manages the model customization workflow using a supported foundation model.
AWS IAM
Provides the required permissions for the customization service to access training and output data.
Customized Foundation Model
Contains the model parameters adjusted through the customization process.
Inference Deployment
Makes the customized model available for application requests through a supported inference option.

Workflow

Training Dataset → Amazon S3 → Amazon Bedrock Customization Job → Customized Model → Inference Deployment → AI Application
This architecture separates dataset storage, model customization, and application inference.

Building a Fine-Tuning Workflow with Amazon Bedrock

Let's understand how to prepare training data and submit a model customization job using Python.

Prerequisites

You need:
  • An AWS account.
  • Access to Amazon Bedrock.
  • A foundation model that supports the selected customization method.
  • An AWS Region where the selected model supports fine-tuning.
  • An Amazon S3 bucket.
  • An IAM service role with the required permissions.
  • Python 3.10 or newer.
  • AWS CLI and Boto3.
Model availability and customization support vary by AWS Region. Always verify the current model compatibility documentation before selecting a foundation model.

Step 1: Prepare the Training Dataset

Fine-tuning requires examples that demonstrate the expected behaviour of the model.
Amazon Bedrock accepts JSONL datasets for supported customization workflows. Each line represents a training record.
For a supported text-to-text model using the prompt-completion format, a dataset may look like this:
{"prompt":"Explain cloud computing in simple terms.","completion":"Cloud computing provides computing resources such as servers, storage, and databases over the internet."}
{"prompt":"What is machine learning?","completion":"Machine learning is a field of artificial intelligence that enables systems to learn patterns from data and make predictions."}
{"prompt":"Explain Amazon S3.","completion":"Amazon S3 is an object storage service used to store and retrieve data."}
Save the dataset as:
 training.jsonl 
For a more reliable training process, prepare a separate validation dataset when supported by the selected model.
Important dataset preparation practices:
  • Use accurate and relevant examples.
  • Remove duplicate records.
  • Maintain consistent response formatting.
  • Avoid unnecessary or unrelated information.
  • Remove sensitive information.
  • Ensure each record follows the selected model's required format.
  • Keep validation examples separate from training examples.
The exact JSONL schema, record limits, and validation requirements depend on the model and customization method. Do not assume that one dataset format works for every foundation model.

Step 2: Upload the Dataset to Amazon S3

Create an S3 bucket in the same AWS Region as the customization job.
A possible storage structure is:
bedrock-finetuning/
│
├── training/
│ └── training.jsonl
│
├── validation/
│ └── validation.jsonl
│
└── output/
Upload the training dataset:
aws s3 cp training.jsonl \
s3://your-bucket-name/training/training.jsonl
Upload the validation dataset:
aws s3 cp validation.jsonl \
s3://your-bucket-name/validation/validation.jsonl
The S3 bucket must be accessible to the IAM service role used by Amazon Bedrock.

Step 3: Configure AWS Credentials

Install the AWS SDK for Python:
pip install boto3
Configure your AWS credentials using the AWS CLI:
aws configure
Provide the required access key, secret access key, default Region, and output format.
Use IAM roles or another supported credential provider in production environments rather than storing credentials directly in application code.

Step 4: Submit a Fine-Tuning Job Using Python

Boto3 provides access to the Amazon Bedrock API.
The following example demonstrates the structure of a supervised fine-tuning job request.
import boto3

client = boto3.client(
"bedrock",
region_name="us-west-2"
)

response = client.create_model_customization_job(
jobName="customer-support-finetuning",
customModelName="customer-support-custom-model",
roleArn="YOUR_BEDROCK_SERVICE_ROLE_ARN",
baseModelIdentifier="YOUR_SUPPORTED_BASE_MODEL_ID",
customizationType="FINE_TUNING",
trainingDataConfig={
"s3Uri": "s3://your-bucket-name/training/training.jsonl"
},
outputDataConfig={
"s3Uri": "s3://your-bucket-name/output/"
}
)

print("Customization job submitted")
print(response["jobArn"])
Replace the placeholders with the actual IAM service role ARN, supported model identifier, and S3 locations.
If the selected model supports validation data, you can also configure the appropriate validation dataset field.
Hyperparameters and additional configuration options must follow the requirements of the selected foundation model.
This example illustrates the API request structure. Before execution, verify the current model identifier, Region, IAM permissions, dataset schema, and Boto3 API requirements.

Step 5: Monitor the Fine-Tuning Job

Model customization jobs can take several hours depending on the model, dataset size, and training configuration.
You can monitor the job using the returned job ARN.
import boto3

client = boto3.client(
"bedrock",
region_name="us-west-2"
)

job_arn = "YOUR_MODEL_CUSTOMIZATION_JOB_ARN"

response = client.get_model_customization_job(
jobIdentifier=job_arn
)

print("Job Status:", response["status"])
The job status helps identify whether the customization process is still running, completed successfully, or failed.
Review the available training metrics and output artifacts after completion.

Step 6: Evaluate the Customized Model

A successful training job does not automatically guarantee better application performance.
Evaluate the customized model using test examples that were not included in the training dataset.
Consider measuring:
  • Response accuracy.
  • Relevance to the requested task.
  • Consistency of output formatting.
  • Performance on unseen examples.
  • Response latency.
  • Token usage and operational cost.
  • Behaviour on unexpected or invalid inputs.
Compare the base model and customized model using the same evaluation dataset.
This helps determine whether fine-tuning provides a measurable improvement.

Step 7: Deploy the Customized Model

After customization completes successfully, configure an inference option for the resulting model.
Amazon Bedrock provides options that include:
  • Provisioned Throughput: Dedicated model capacity with predictable throughput.
  • On-demand custom model deployment: Available for supported customized models and Regions, allowing usage-based inference without purchasing dedicated provisioned capacity.
The available deployment options depend on the model and customization configuration.
Once deployment is ready, applications can send inference requests using the appropriate model or deployment identifier.
Always review the current Amazon Bedrock deployment documentation before selecting an inference option.

Integrating Fine-Tuned Models into Applications

A customized model can be integrated into applications such as:
  • Customer support platforms.
  • Internal business assistants.
  • Document processing systems.
  • Domain-specific AI applications.
  • Automated text classification systems.
A typical application architecture looks like this:
User Request → Application Backend → Amazon Bedrock → Customized Model → Generated Response
The application backend handles request validation, authentication, model invocation, and response processing.
This allows developers to use the customized model without managing the underlying model training infrastructure.

Security and Reliability Considerations

Fine-tuning workflows involve training datasets, model artifacts, and application requests. These components must be protected.
Important practices include:
  • IAM permissions: Apply least-privilege access to S3 and Amazon Bedrock resources.
  • Data encryption: Use appropriate encryption controls for datasets and model artifacts.
  • Dataset validation: Check training records before submitting customization jobs.
  • Sensitive data protection: Remove confidential information that should not be included in training.
  • Model evaluation: Test customized models before integrating them into production.
  • Access control: Restrict access to customized models and deployment resources.
  • Monitoring: Track job status, inference performance, and operational errors.
For production applications, establish clear processes for dataset versioning, model evaluation, deployment approval, and rollback.

Cost Considerations

Fine-tuning introduces costs beyond ordinary model inference.
Important cost factors include:
  • Training tokens processed during customization.
  • Number of training epochs.
  • Custom model storage.
  • Provisioned Throughput charges, when applicable.
  • On-demand inference charges, where supported.
  • Amazon S3 storage and data transfer.
Training with larger datasets and additional epochs can increase customization costs.
Developers should estimate costs before starting a job and monitor resource usage throughout the model lifecycle.
Always refer to the current Amazon Bedrock pricing page because costs vary by model, Region, and inference configuration.

Real-World Applications

Fine-tuning can support several practical use cases.
Customer Support Automation
Customize a model to produce consistent responses for common customer support requests.
Financial Text Classification
Adapt a model to classify financial documents and extract specific information.
Healthcare Documentation
Customize supported models for structured documentation workflows using carefully prepared and appropriately governed datasets.
Business Communication
Train a model to follow a consistent organizational writing style and response format.
Technical Assistance
Adapt a model to perform specialized technical tasks using domain-specific examples.
These applications require appropriate validation, data governance, and human review, particularly in sensitive domains.

Conclusion

Fine-tuning provides a practical approach to adapting foundation models for specialized tasks without training an entire model from scratch.
Amazon Bedrock simplifies the customization workflow by providing managed model training capabilities, integration with Amazon S3, and options for deploying customized models.
By preparing high-quality datasets, selecting supported foundation models, evaluating results, and applying appropriate security controls, developers can build more specialized Generative AI applications.
The key to successful fine-tuning is understanding the problem before choosing the customization method.
Start with a clear use case, prepare a reliable dataset, compare the customized model against the original model, and gradually integrate the improved model into your application.

References and Further Learning

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