Skip to main content

Bring Your Own Model with Amazon Bedrock

Learning Objectives

After completing this unit, you’ll be able to:

  • Evaluate model customization patterns.
  • Outline a complete model development lifecycle.
  • Compare methods for bringing custom models in Amazon Bedrock.

Why Build Your Own Foundation Model?

By developing your own model or customizing an existing base model, you can create solutions that help you solve your unique challenges. Consider a healthcare organization dealing with medical records. The organization can use a general-purpose language model to process text. However, the model might struggle with medical terminology, fail to maintain HIPPA compliance, or miss important medical details. A custom model trained on medical literature and anonymized patient records could provide more accurate, compliant, and relevant results.

Amazon Bedrock provides the Custom Model Import feature to bring a model you’ve customized in another environment. This could be a model that has been fine-tuned, adapted for a specific domain, or pretrained from scratch with a custom architecture.

Let’s explore how each of these approaches shape the model.

  • Fine-tuned or Continued Pre-training model: You can customize the model weights using your proprietary data while maintaining the base model’s architecture. This approach is ideal when you want to specialize a model for specific tasks without rebuilding the model from scratch.
  • Adaptation: This pattern helps when standard models don’t generate accurate results for your specific domain. The goal is to help the base model perform well on the new domain’s data. To achieve the desired result, you can consider techniques such as adversarial training, feature-level adaptation, or data augmentation.
  • Pretrained from scratch: This approach offers the most flexibility but requires significant architectural changes. Beyond customizing weights and vocabulary, you can modify fundamental architectural elements such as attention heads, hidden layers, and context length.

Follow the Model Development Lifecycle

If you’re considering developing new models or customizing base models, you need to understand the complete lifecycle of machine learning (ML) model development, from setting business goals to ongoing monitoring.

ML lifecycle with data processing sub-phases included, outlined in detail in the content.

Identify Business Goal

  • Business considerations: Define business objectives that the AI or ML model aims to address. This can include improving operational efficiency, improving customer experience, increasing revenue, or reducing costs.
  • Business opportunities: Consider new business processes that might come out of this implementation.

Frame ML Problem

  • Task definition: Define specific problems that the new or customized model helps you solve.
  • Scoping: Identify the appropriate or proven approaches for model development based on available data and desired outputs.

Process Data

  • Data collection: Start data preparation by gathering relevant domain-specific data. For example, if you work for a financial services company, you might want to collect historical transaction data, customer interactions, and market reports. This data forms the foundation of your model’s knowledge.
  • Data processing: Raw data rarely comes in a perfect format. At this stage, it’s important to cleanse, standardize, and structure your data. You might need to remove personally identifiable information (PII), standardize formats, and fix missing values. In other words, process your data to make sure it matches the base model’s expected format.
  • Feature engineering: Transform raw data into meaningful features your model can learn from. This might involve generating embeddings for text, creating variables, and adapting your data to work with the model’s existing architecture.

Develop Model

  • Training: This is where your model learns from the processed data. You configure hyperparameters, implement training loops, and monitor metrics to ensure learning progresses effectively.
  • Tuning: Fine-tune your model to enhance performance by adjusting learning rates and model architecture based on validation results.
  • Evaluation: Test and evaluate model performance against domain-specific metrics. Also, ensure that the results follow responsible AI principles for accuracy, bias, transparency, and more. Document test results and validation metrics for compliance and governance.

Model Deployment

  • Artifact management: Before deploying the model, package and set up your model files, including weights, configurations, and dependencies. You can store model files in Amazon S3, properly versioned and encrypted.
  • Infrastructure setup: Prepare the deployment environment, set up additional security controls, and configure networking requirements.
  • Deployment: Deploy the model into production. You’ll learn about available methods to import your model through Amazon Bedrock later in this unit.

Model Monitoring

  • Performance tracking: Monitor your model performance, resource utilization, and costs.
  • Alerting: Configure alerts for anomaly detection and performance degradation.

Bring Your Model into Amazon Bedrock

There are two ways to bring your model into Amazon Bedrock: from an Amazon S3 bucket or from Amazon SageMaker AI. For both approaches, you start the job of importing your customized model through either the Amazon Bedrock console or the API. In the job, you specify the Amazon S3 URI for the source of the model files or choose Amazon SageMaker AI model.

Before you initiate an import, there are a few prerequisites you need to complete.

  • You must create a policy to access your model files and attach the policy to an IAM role for Amazon Bedrock.
  • (Optional) You can set up encryption at rest and in transit.

For more information, see Prerequisites for importing custom model and Code samples for custom model import.

Let’s review the requirements specific to each approach.

Import from Amazon S3

This method involves storing your model files in an Amazon S3 bucket. Ensure that your model files follow the Hugging Face weights format. This approach is ideal when you have custom model training pipelines or want to maintain complete control over your model artifacts.

Import from Amazon SageMaker AI

If you’re already using SageMaker AI for model development, this approach streamlines the import process. Bedrock can directly import SageMaker AI models, automatically detecting the architecture and completing the necessary conversions. Use this approach when your training pipeline is in SageMaker AI and you want to use SageMaker AI's built-in algorithms.

For step-by-step instructions on importing your custom model from Amazon S3 or Amazon SageMaker AI, see Submit a model import job.

Validation Testing

After importing your model, run tests to make sure your custom model performs as expected. The tests can include:

  • Functional tests to ensure the model performs correctly and produces expected results.
  • Performance tests to evaluate how the model handles various loads and meets response time, throughput, and accuracy requirements.
  • Integration tests to validate the model works seamlessly with other components of the system.
  • Security and compliance validation tests to ensure the model meets security standards and adheres to relevant regulatory requirements.

Wrap Up

In this unit, you learned how to bring your own foundation models to Amazon Bedrock, from initial preparation through customization, import, and validation phases.

Resources

在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈