Lesson 3 of 4 Deploying Foundation Models

Configuring Self-Hosted Foundation Model Serving

This lesson explains how self-hosting a large language model means fitting it onto accelerators, choosing a serving engine and allocating resources so throughput and latency meet requirements at acceptable cost.

Learning outcomes

After completing this lesson, you will be able to:

  • Size accelerator memory from parameters and precision.
  • Use large model inference containers.
  • Allocate resources with inference components.

Memory sizing

Model weights need roughly parameters x bytes per parameter of accelerator memory: a 7-billion-parameter model in 16-bit precision needs about 14 GB for weights, plus memory for the KV cache, which grows with batch size and sequence length. Quantization to 8-bit or 4-bit weights cuts memory by two or four times with a small quality loss. If the model does not fit on one GPU, tensor parallelism splits it across the GPUs of an instance.

The following diagram compares how the weights of a 70-billion-parameter model fit on the GPUs of two hosting options.

GPU memory for the 70-billion-parameter model. At FP16 its weights need about 140 GB, more than one 80 GB GPU. Option A splits them across eight 40 GB GPUs with tensor parallelism; option B quantises the weights to int8, about 70 GB, across four 48 GB GPUs. Both leave free memory for the KV cache, and option B is cheaper per hour.
Widths are proportional to memory; KV cache needs depend on batch size and context length.
Fill in the value

How much GPU memory?

Exam skills 3.1.7

Estimate the GPU memory that model weights need.

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

Large model inference containers

Serving large language models efficiently needs specialised software. SageMaker AI large model inference (LMI) containers package serving engines such as vLLM, TensorRT-LLM and LMI-Dist, configured with properties such as tensor_parallel_degree, which splits the model across GPUs, max_rolling_batch_size, the maximum model length and quantisation, which reduces memory by using lower-precision weights.

Continuous (rolling) batching adds new requests to a running batch as others finish, instead of waiting for the whole batch to complete, which greatly improves GPU utilisation and throughput. Streaming responses reduce the time to the first token, which is what users notice most in chat applications.

Match the pairs

LMI settings

Exam skills 3.1.7

Match each large model inference (LMI) container setting with its purpose.

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

Allocating resources with inference components

Inference components let several models share one endpoint's instances. Each component specifies the accelerator devices, CPU cores and memory needed per copy of its model, and the number of copies; SageMaker AI packs the copies onto instances efficiently. With managed instance scaling, the endpoint adds or removes instances as components scale, so capacity follows demand.

On Amazon Bedrock, Provisioned Throughput allocates capacity in model units, each providing a defined throughput, for workloads that need guaranteed capacity or that use custom models. The following table summarises the main settings.

SettingEffect
Instance type (GPU memory)Which model sizes fit
tensor_parallel_degreeSplit a model across GPUs
Quantization (int8, int4)Less memory, small quality loss
max_rolling_batch_sizeConcurrent sequences: throughput vs latency
Max model lengthLongest prompt plus output; affects KV cache memory
Inference component accelerators and copiesGPU sharing and per-model scaling
Worked example

Fitting a 70B model

A team must host a 70-billion-parameter open model with 8,000-token contexts on SageMaker AI.

Weights at FP16: 70e9 x 2 bytes = ~140 GB  -> does not fit on one 80 GB GPU
Option A: ml.p4d.24xlarge (8 x 40 GB = 320 GB), tensor_parallel_degree=8, FP16
Option B: ml.g6e.12xlarge (4 x 48 GB = 192 GB), tensor_parallel_degree=4, int8 weights (~70 GB)
Both leave memory for the KV cache; continuous batching raises throughput

After an evaluation confirms int8 quality is acceptable, Option B is chosen as cheaper per hour. Trying to deploy at FP16 on a single GPU would fail with out-of-memory errors regardless of batch size.

Check yourself

How can a model's GPU memory footprint be reduced with a small loss in quality?

Show answer

With quantisation, which stores weights at lower precision.

Exam Tips

Remember for the exam

  • Weights need roughly parameters x bytes per parameter of GPU memory, plus KV cache.
  • Model too large for one GPU: tensor parallelism.
  • Quantization reduces memory with small quality loss.
  • Continuous batching improves LLM throughput.
  • Share GPUs between models: inference components.