Lesson 1 of 7 Cost and Capacity Optimization

Right-Sizing Inference Instance Families

This lesson explains how matching the instance family to the model's needs is the first and largest cost lever, since inference endpoints run continuously and often account for most ML cost.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish the instance families for inference.
  • Find the right instance with Inference Recommender.
  • Read a model's resource profile.

Instance families

SageMaker AI instance names follow the EC2 pattern. ml.m (general purpose) and ml.c (compute optimised) suit tree models, linear models and small neural networks. ml.r (memory optimised) suits models with large in-memory structures. ml.g5, ml.g6 and ml.g6e (NVIDIA GPUs) suit deep learning inference and small to medium LLMs. ml.p4d and ml.p5 suit the largest models. ml.inf2 (AWS Inferentia2) gives high throughput and low cost per inference for supported deep learning models compiled with the AWS Neuron SDK. Graviton-based instances (such as ml.c7g) lower cost for CPU inference.

Match the pairs

Instance families

Exam skills 4.2.1

Match each SageMaker AI instance family with the workload it suits.

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

Finding the right instance

SageMaker Inference Recommender runs load tests of a registered model on several instance types and reports latency, throughput and cost per inference, either as a quick default job or an advanced job with custom traffic patterns and latency requirements. AWS Compute Optimizer recommends right-sizing for EC2 instances and other resources from utilisation history. Endpoint utilisation metrics show over-provisioning: an endpoint at 10% CPU is a candidate for a smaller or cheaper instance.

The following table summarises the families.

FamilyBest for
ml.c / ml.m (and Graviton variants)Classic ML, small models, CPU inference
ml.rMemory-heavy models
ml.g5 / ml.g6 / ml.g6eDeep learning, small and medium LLMs
ml.p4d / ml.p5Largest models, highest throughput
ml.inf2 (Inferentia2)Lowest cost per inference for supported deep learning models
Scenario questions

Right-size it

Exam skills 4.2.1

Choose how to right-size an inference instance.

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

Reading a model's resource profile

Choosing a family starts with identifying the resource that limits the model. A gradient-boosted tree or linear model performs a modest amount of arithmetic per request and is usually limited by CPU, so compute-optimized instances, or Graviton variants where the framework supports Arm, give the best price. A model that keeps a large lookup table, embedding matrix or cache in memory is limited by RAM, and memory-optimized instances supply more memory per vCPU without paying for unneeded cores.

Deep learning models, especially transformers and convolutional networks, perform large matrix multiplications that GPUs and Inferentia execute far faster than CPUs. For them, the key question is memory on the accelerator: the weights, the activations of a batch and, for LLMs, the key-value cache must fit. A model that fits on one GPU with room for batching belongs on a single-GPU instance such as ml.g5 or ml.g6; a model that does not fit needs a multi-GPU instance with tensor parallelism or quantisation. Inferentia2 suits models that the Neuron SDK supports and that serve high volumes, where its lower cost per inference outweighs the effort of compilation.

Utilization metrics confirm or correct the choice after deployment. Low CPU and GPU utilisation at peak traffic indicates an oversized instance; GPU utilisation near zero on a GPU instance indicates a model that does not use the accelerator at all; high latency with low utilisation points to a bottleneck elsewhere, such as payload handling or downstream calls, which a larger instance would not fix. Decisions should be based on load tests and these metrics, not on assumptions about the model type.

The following diagram shows the measured finding for each of three endpoints and the change it led to.

Right-sizing three endpoints from measurements. The XGBoost endpoint never used its GPU, so it moves to a Graviton CPU instance; the image classifier is supported on Inferentia2 at 45% lower cost per inference; and the CPU-bound BERT classifier at its p99 limit moves to a GPU instance for lower latency at similar cost.
The scenario is illustrative.
Worked example

Right-sizing three endpoints

A team reviews three endpoints with Inference Recommender and utilisation data.

EndpointCurrentFindingChange
XGBoost churnml.g5.xlargeGPU unused (XGBoost on CPU path)ml.c7g.large
Image classifierml.g5.2xlarge, 20% GPUInferentia2 supported, 45% cheaper per inferenceml.inf2.xlarge
BERT classifierml.m5.4xlarge, p99 at limitCPU-boundml.g6.xlarge (lower latency, similar cost)

Each change follows from measurement. A blanket policy of "GPUs for everything" or "cheapest CPU for everything" would have been wrong for at least one of the three.

Check yourself

Which instances suit tree and linear models?

Show answer

CPU instances, not GPUs.

Exam Tips

Remember for the exam

  • Benchmark instance types for a model: SageMaker Inference Recommender.
  • Tree and linear models: CPU instances, not GPUs.
  • Lowest cost per inference for supported deep learning models: Inferentia2.
  • Low utilization: right-size to a smaller or cheaper instance.
  • Graviton lowers CPU inference cost.