Custom Model Fine-Tuning
Custom Model Fine-Tuning
Section titled “Custom Model Fine-Tuning”This guide explains how to fine-tune Nova models for document classification using the IDP Accelerator.
Overview
Section titled “Overview”The Custom Model Fine-Tuning feature allows you to create specialized document classification models trained on your specific document types. This is particularly useful when:
- You have unique document types not well-recognized by base models
- You need higher accuracy for specific document classes
- You want to optimize classification for your domain-specific terminology
How It Works
Section titled “How It Works”flowchart LR A[Test Set] --> B[Validate] B --> C[Generate Training Data] C --> D[Train Model] D --> E[Deploy Endpoint] E --> F[Use in Configuration]- Select a Test Set: Choose an existing Test Set from Test Studio that contains labeled documents
- Validate: The system checks if the Test Set has sufficient data for fine-tuning
- Generate Training Data: Documents are converted to Bedrock’s training format
- Train Model: A Bedrock fine-tuning job trains a custom Nova model
- Deploy Endpoint: The trained model is deployed as an on-demand Custom Model Deployment
- Use in Configuration: Select the custom model when creating or editing configurations
Roles & Permissions
Section titled “Roles & Permissions”Custom Model Fine-tuning is available to Admin and Author roles. The GraphQL mutations (createFinetuningJob, deleteFinetuningJob) are enforced server-side via AppSync @aws_auth directives, so Reviewer and Viewer roles cannot create or delete jobs even via direct API calls. The query APIs (listFinetuningJobs, getFinetuningJob, listAvailableModels) are accessible to all authenticated users at the schema level, but the UI only exposes the Custom Models page to Admin and Author.
Note on config-version scoping: Fine-tuning jobs are currently global — they are not filtered by
allowedConfigVersions. A scoped Author can see all fine-tuning jobs and create jobs from any test set. However, when applying a custom model to a configuration version (via “Create Config Version”), the config-version scope is enforced — the Author can only target versions within their scope. See RBAC for the full permission matrix.
Prerequisites
Section titled “Prerequisites”- Deployed in
us-east-1region: Custom Model Fine-Tuning is only available when the IDP Accelerator is deployed to theus-east-1AWS region. The Custom Models navigation link is automatically hidden in deployments to other regions. - An existing Test Set with:
- At least 10 documents
- At least 2 document classes
- Baseline classifications for all documents
- Appropriate IAM permissions for Bedrock model customization
- Admin or Author role in the IDP Accelerator
Using the UI
Section titled “Using the UI”Creating a Fine-Tuning Job
Section titled “Creating a Fine-Tuning Job”- Navigate to Configuration → Custom Models in the left navigation
- Click Create Fine-Tuning Job
- Fill in the form:
- Job Name: A descriptive name for your fine-tuning job
- Test Set: Select the Test Set to use for training
- Base Model: Choose Nova 2 Lite or Nova 2 Pro as the base model (recommended)
- Review the validation results showing:
- Document count
- Class distribution
- Train/validation split
- Any warnings or errors
- Click Start Fine-Tuning
Monitoring Progress
Section titled “Monitoring Progress”The job will progress through these stages:
| Status | Description |
|---|---|
| VALIDATING | Checking Test Set data |
| GENERATING_DATA | Converting documents to training format |
| TRAINING | Bedrock is training the model (can take 1-4 hours) |
| DEPLOYING | Creating the on-demand endpoint |
| COMPLETED | Model is ready to use |
| FAILED | An error occurred (check error message) |
Using a Custom Model
Section titled “Using a Custom Model”Once a fine-tuning job completes:
- Go to Configuration → Versions
- Create or edit a configuration version
- In the model selector, you’ll see your custom models under “Custom Models”
- Select your fine-tuned model
- Save the configuration
Using the CLI
Section titled “Using the CLI”Validate a Test Set
Section titled “Validate a Test Set”idp-cli finetuning validate --test-set docsplitOutput:
Test Set Validation Results: Valid: Yes Documents: 150 Classes: 8 Train/Validation Split: 135/15
Class Distribution: drivers_license: 25 bank_statement: 30 pay_stub: 20 w2: 15 utility_bill: 20 insurance_card: 15 tax_return: 15 other: 10
Warnings: - Class 'other' has relatively few examples (10)Create a Fine-Tuning Job
Section titled “Create a Fine-Tuning Job”idp-cli finetuning create \ --test-set docsplit \ --base-model us.amazon.nova-pro-v1:0 \ --name my-classifierOutput:
Fine-tuning job created: Job ID: abc123-def456-... Status: VALIDATING
Monitor progress with: idp-cli finetuning status --job-id abc123-def456-...Check Job Status
Section titled “Check Job Status”idp-cli finetuning status --job-id abc123-def456-...Output:
Fine-Tuning Job Status: Job ID: abc123-def456-... Name: my-classifier Status: TRAINING Base Model: Nova Pro
Timeline: Created: 2024-01-15 10:00:00 Training Started: 2024-01-15 10:05:00
Training Metrics: Training Loss: 0.05 Validation Loss: 0.08List All Jobs
Section titled “List All Jobs”idp-cli finetuning listDelete a Job
Section titled “Delete a Job”idp-cli finetuning delete --job-id abc123-def456-...List Available Models
Section titled “List Available Models”idp models listOutput:
Base Models: - us.amazon.nova-2-lite-v1:0 (Nova 2 Lite - recommended) - us.amazon.nova-2-pro-v1:0 (Nova 2 Pro - recommended) - us.amazon.nova-lite-v1:0 (Nova Lite v1 - legacy) - us.amazon.nova-pro-v1:0 (Nova Pro v1 - legacy)
Custom Models: - my-classifier (Nova Pro) - Active - docsplit-v2 (Nova Lite) - ActiveUsing the SDK
Section titled “Using the SDK”from idp_sdk import IDPClient
client = IDPClient()
# Validate a test setvalidation = client.finetuning.validate_test_set("docsplit")print(f"Valid: {validation.is_valid}")print(f"Documents: {validation.document_count}")print(f"Classes: {validation.class_count}")
# Create a fine-tuning jobjob = client.finetuning.create_job( test_set_id="docsplit", base_model="us.amazon.nova-pro-v1:0", name="my-classifier")print(f"Job ID: {job.id}")
# Wait for completion (with progress updates)completed_job = client.finetuning.wait_for_completion( job.id, poll_interval=60 # Check every minute)print(f"Status: {completed_job.status}")print(f"Model ARN: {completed_job.custom_model_deployment_arn}")
# List available modelsmodels = client.models.list_available_models()for model in models.custom_models: print(f" {model.name} ({model.base_model})")Best Practices
Section titled “Best Practices”Data Quality
Section titled “Data Quality”- Diverse Examples: Include varied examples of each document class
- Balanced Classes: Try to have similar numbers of examples per class
- Clean Baselines: Ensure baseline classifications are accurate
- Sufficient Data: More examples generally lead to better results
Model Selection
Section titled “Model Selection”| Base Model | Best For |
|---|---|
| Nova 2 Lite | Faster training, lower cost, simpler documents (recommended) |
| Nova 2 Pro | Higher accuracy, complex documents, more classes (recommended) |
| Nova Lite (v1) | Legacy support |
| Nova Pro (v1) | Legacy support |
Training Tips
Section titled “Training Tips”- Start Small: Begin with Nova 2 Lite to validate your approach
- Monitor Metrics: Watch training/validation loss for overfitting
- Iterate: If results aren’t satisfactory, improve your training data
- Compare: Run evaluations comparing base vs. custom models
Troubleshooting
Section titled “Troubleshooting”Common Errors
Section titled “Common Errors”| Error | Solution |
|---|---|
| ”Insufficient documents” | Add more documents to your Test Set |
| ”Insufficient classes” | Ensure at least 2 document classes |
| ”Training failed” | Check Bedrock quotas and permissions |
| ”Deployment failed” | Verify Custom Model Deployment permissions |
Checking Logs
Section titled “Checking Logs”Fine-tuning job logs are available in CloudWatch:
- Log group:
/aws/lambda/idp-finetuning-* - Step Functions execution history in the AWS Console
IAM Permissions
Section titled “IAM Permissions”Ensure your deployment has these Bedrock permissions:
bedrock:CreateModelCustomizationJobbedrock:GetModelCustomizationJobbedrock:CreateCustomModelDeploymentbedrock:GetCustomModelDeploymentbedrock:ListCustomModelDeploymentsbedrock:DeleteCustomModelDeploymentCost Considerations
Section titled “Cost Considerations”Fine-tuning costs include:
- Training: Charged per training hour (varies by base model)
- Deployment: On-demand pricing when the model is invoked
- Storage: S3 storage for training data and model artifacts
Custom Model Deployments use on-demand pricing, so you only pay when the model is invoked. This is more cost-effective than Provisioned Throughput for variable workloads.
API Reference
Section titled “API Reference”GraphQL Queries
Section titled “GraphQL Queries”# List fine-tuning jobsquery ListFinetuningJobs($limit: Int, $nextToken: String) { listFinetuningJobs(limit: $limit, nextToken: $nextToken) { items { id jobName status baseModel createdAt } nextToken }}
# Get job detailsquery GetFinetuningJob($jobId: ID!) { getFinetuningJob(jobId: $jobId) { id jobName testSetId testSetName baseModel status createdAt trainingStartedAt trainingCompletedAt deploymentCompletedAt customModelArn customModelDeploymentArn trainingMetrics { trainingLoss validationLoss } errorMessage }}
# Validate test setquery ValidateTestSet($testSetId: ID!) { validateTestSetForFinetuning(testSetId: $testSetId) { isValid documentCount classCount classDistribution trainCount validationCount warnings errors }}
# List available modelsquery ListAvailableModels { listAvailableModels { baseModels { id name provider } customModels { id name baseModel status } }}GraphQL Mutations
Section titled “GraphQL Mutations”# Start fine-tuning jobmutation StartFinetuningJob($input: StartFinetuningJobInput!) { startFinetuningJob(input: $input) { id jobName status }}
# Delete fine-tuning jobmutation DeleteFinetuningJob($jobId: ID!) { deleteFinetuningJob(jobId: $jobId)}