Lesson 2 of 4 Deploying Foundation Models

Bringing Externally Trained Models to AWS

This lesson explains how to deploy models trained or fine-tuned elsewhere, on premises, in another cloud or from open-source repositories, with SageMaker AI and Amazon Bedrock Custom Model Import.

Learning outcomes

After completing this lesson, you will be able to:

  • Host external models on SageMaker AI.
  • Import supported open-weight models with Bedrock Custom Model Import.
  • Choose the path for an external model.

Hosting external models on SageMaker AI

SageMaker AI can host any model whose artefacts can be served by a container. For supported frameworks, package the trained weights (and, if needed, an inference.py with model_fn, input_fn, predict_fn and output_fn) as model.tar.gz in S3, and create a model with the matching prebuilt framework image: PyTorch, TensorFlow, scikit-learn, XGBoost, Hugging Face or a large model inference (LMI) container for LLMs. Hugging Face Hub models can be deployed by model ID. Models in other formats can be converted (for example, to ONNX) or served with an extended container.

True or false

Host your own model

Exam skills 3.1.5 · 3.2.3

Check what a container needs to serve a model on SageMaker AI.

Log in to try this activity Interactive activities are free with an account.

Amazon Bedrock Custom Model Import

Custom Model Import brings open-weight models that you have fine-tuned elsewhere into Bedrock, so they are invoked through the same serverless Bedrock runtime APIs as other models. Supported architectures include families such as Llama, Mistral, Mixtral, Qwen and GPT-OSS, with weights in Hugging Face safetensors format imported from S3 or from a SageMaker AI model. Importing is free; inference is billed by the number of active model copies over time (in five-minute windows), measured in custom model units, and copies scale automatically with traffic, including down to zero, so the first request after idle can see a cold start.

Choosing the path

Models trained elsewhere, or open-weight models customised outside AWS, can be brought to AWS in several ways. Amazon Bedrock Custom Model Import serves supported open-weight architectures through the Bedrock APIs, with serverless scaling and no infrastructure to manage. Amazon Bedrock Marketplace offers specialised models deployed to managed endpoints. A SageMaker AI endpoint hosts any model the team can package in a container, with full control over hardware and serving. The choice depends on whether the model's architecture is supported and how much control the team needs. The following table summarises the choice.

SituationPath
Fine-tuned model of a supported architecture; want serverless Bedrock APIs, guardrails, knowledge basesBedrock Custom Model Import
Unsupported architecture or custom inference codeSageMaker AI endpoint
Classic ML model (scikit-learn, XGBoost) trained on premisesSageMaker AI endpoint with framework container
Need GPU-level control, custom batching or quantisationSageMaker AI endpoint with LMI container

The following diagram shows the path for importing a fine-tuned Llama model from an on-premises environment into Amazon Bedrock.

Bringing the on-premises fine-tuned Llama model to Bedrock. The safetensors weights, config and tokeniser files go to S3; a Custom Model Import job gives the model a Bedrock ARN; and product teams call it through the Converse API with their existing guardrail. Copies scale with demand, down to zero, and are billed only while active.
Import is free; inference is billed per active copy.
Scenario questions

Bring the model in

Exam skills 3.1.5

Choose how to deploy a model trained outside AWS.

Log in to try this activity Interactive activities are free with an account.
Worked example

A fine-tuned Llama model

A research team fine-tuned a Llama-family model on premises and wants product teams to use it through the same Converse API and Bedrock Guardrails they already use, without managing GPUs. Traffic is irregular.

  • Upload the safetensors weights, config and tokeniser files to S3.
  • Run a Custom Model Import job; the model gets a Bedrock model ARN.
  • Product teams call the imported model ARN with the Bedrock runtime, with their existing guardrail.

Because copies scale with demand and are billed only while active, irregular traffic costs less than an always-on GPU endpoint. A SageMaker AI endpoint would also work but would leave GPU capacity and a separate API for the product teams to manage.

Check yourself

Which weights format does Bedrock Custom Model Import use?

Show answer

Hugging Face safetensors, from S3 or SageMaker AI.

Exam Tips

Remember for the exam

  • Supported open-weight architecture, serverless Bedrock API: Custom Model Import.
  • Custom Model Import uses Hugging Face safetensors weights from S3 or SageMaker AI.
  • Imported models are billed by active model copies; cold starts can occur after idle.
  • Any framework or custom inference code: SageMaker AI endpoint.
  • Package SageMaker artefacts as model.tar.gz in S3.