Lesson 3 of 4 Foundation Model Deployment Strategies

Sizing GPUs and Loading Large Models Efficiently

This lesson explains how the size, memory behaviour and generation of large language models change how containers are sized, how GPUs are used and how quickly capacity can be added.

Learning outcomes

After completing this lesson, you will be able to:

  • Estimate memory requirements from parameters and precision.
  • Fit models with tensor parallelism and quantisation.
  • Speed up scale-out with model loading strategies.

Estimating memory requirements

Model weights need roughly 2 bytes per parameter at 16-bit precision (FP16 or BF16), 1 byte at 8-bit and half a byte at 4-bit. A 70-billion-parameter model therefore needs about 140 GB for weights at 16-bit precision, more than one GPU holds. On top of weights, the key-value (KV) cache stores attention state for every token of every active sequence; it grows with context length and with the number of concurrent requests, and often limits how many requests one instance can serve.

Memory planning therefore asks two questions: do the weights fit (with headroom), and how many concurrent sequences of the expected length fit in the remaining memory? The answers determine the instance type, the number of GPUs and the parallelism configuration.

The following diagram compares the memory a 70-billion-parameter model needs with the memory of one GPU.

Why a 70-billion-parameter model failed to load. At 16-bit precision its weights need about 140 GB, far more than one 24 GB GPU, before any KV cache. The fix is an instance with enough total GPU memory and a matching tensor parallel degree, possibly with 8-bit quantisation to leave room for the KV cache.
Validate quantised weights with an evaluation before using them.

2bytes

Per parameter for weights at 16-bit precision

1byte

Per parameter at 8-bit precision

140GB

Weights of a 70-billion-parameter model at 16-bit precision

Fill in the number

Sizing model weights

Exam skills 2.2.2 · 2.2.3

Estimate the GPU memory that model weights need at different precisions.

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

Fitting and using GPUs efficiently

Tensor parallelism splits each layer's computations across the GPUs of an instance, so a model too large for one GPU runs on four or eight. Quantization stores weights at 8-bit or 4-bit precision, roughly halving or quartering weight memory and often speeding inference, with a small quality loss that must be evaluated. Continuous batching keeps GPUs busy by adding requests to the running batch at each generation step instead of waiting for a whole batch to finish, and paged attention allocates KV cache memory in blocks to avoid waste.

Token processing capacity is described in tokens per second for prompt processing and for generation. Long prompts are processed in parallel and quickly; output tokens are produced one at a time, so output length dominates latency. Speculative decoding, where a small draft model proposes tokens that the large model verifies, can speed generation on self-hosted servers.

Model loading strategies

Loading tens or hundreds of gigabytes of weights makes scale-out slow: downloading the container, downloading weights from S3 and loading them into GPU memory can take many minutes. Strategies include streaming weights from S3 directly to GPU memory in parallel (the SageMaker AI Fast Model Loader), container caching so new instances do not download the image again, storing weights pre-sharded for the target parallelism, and keeping a minimum number of warm instances so traffic spikes do not wait for cold starts.

The following table summarises the challenges and responses.

ChallengeStrategy
Weights larger than one GPUTensor parallelism on a multi-GPU instance; quantisation
KV cache limits concurrencyPaged attention; shorter max context; more GPU memory
Low GPU utilisationContinuous batching; inference components sharing instances
Slow scale-outFast model loading, container caching, warm minimum capacity
Slow generationShorter outputs, quantisation, speculative decoding, smaller model
Match the pairs

LLM serving challenges

Exam skills 2.2.2

Match each LLM serving challenge with a strategy that addresses it.

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

Sizing a deployment

A team deploys a 70-billion-parameter model on a single GPU instance type with 24 GB GPUs and the endpoint fails with out-of-memory errors during loading.

At 16-bit precision the weights need about 140 GB, so they cannot fit on one 24 GB GPU. The fix is an instance with enough total GPU memory (for example eight GPUs with sufficient memory each) and a tensor parallel degree equal to the GPU count, possibly combined with 8-bit quantisation to leave room for the KV cache, validated by an evaluation to confirm quality.

Check yourself

Which part of GPU memory grows with context length and with the number of concurrent requests?

Show answer

The key-value (KV) cache, which holds attention state for every token of every active sequence.

Exam Tips

Remember for the exam

  • Weights need about 2 bytes per parameter at 16-bit precision.
  • The KV cache grows with context length and concurrency.
  • Too large for one GPU: tensor parallelism or quantisation.
  • Slow scale-out: fast model loading, cached containers, warm instances.