Concepts / Training Versus Inference Workloads

Training Versus Inference Workloads

An accelerator is a chip designed for a specific type of computational workload, and an AI accelerator is designed for AI workloads. GPUs are the dominant type.

  • Programming

Why the Chip Matters

Two programs can run the same model and still feel very different in speed and running cost. Part of the reason is the software, but a large part is the hardware underneath it. Some optimization techniques work on any machine, while others only pay off once you understand the machine you are running on. This article starts from the hardware side: it looks at the chips that run AI workloads and asks what those chips are built to do.

The link between models and hardware is older than the current boom. A shortage of sufficiently powerful computers was one factor in the first AI winter in the 1970s. The return of interest in deep learning in 2012 was also closely tied to compute. Keep this in mind as you read: the question of which chip runs a workload has shaped which AI research was practical at all.

What Makes a Chip an AI Accelerator

Definition

An accelerator is a chip designed for a specific type of computational workload, and an AI accelerator is a chip designed for AI workloads. Within the family of AI accelerators, the dominant type today is the GPU.

The word specific is the important part of the definition. A general-purpose processor is built to handle a wide range of tasks. An accelerator gives up some of that breadth in exchange for doing one kind of work well. An AI accelerator is tuned for the arithmetic that AI models repeat, and that focus is the reason it exists alongside the general-purpose processor rather than replacing it.

In the real world

The source points to NVIDIA as the biggest economic driver of the AI boom in the early 2020s. The useful lesson for a learner is not that GPUs are fast at everything. They are special because their design fits the arithmetic that AI models repeat constantly.

A historical episode shows why this matters. Before the AlexNet paper, training a model at AlexNet's scale generally meant running on thousands of CPUs. One commonly cited reason for that paper's influence is that it was the first to successfully use GPUs, graphics processing units, to train neural networks. A couple of GPUs were far more affordable for PhD students and researchers than thousands of CPUs, and that accessibility helped set off the deep learning research boom.

Tracing a Batch Through a CPU and a GPU

The central difference between a CPU and a GPU is their purpose. CPUs are designed for general-purpose use, meaning they are meant to handle a wide mix of tasks. GPUs are designed for parallel processing, meaning they are meant to do many pieces of work at the same time. Most of the other differences follow from that single choice.

A CPU has a few powerful cores. High-end consumer machines can have up to 64 of them. Many CPU cores handle multi-threaded workloads well, but they are at their best when a task needs high single-thread performance. Running an operating system, managing input and output operations, and handling complex sequential processes all fall into this category.

A GPU takes the opposite approach. It has thousands of smaller, less powerful cores. Those cores are optimized for work that can be broken into many small, independent calculations, such as graphics rendering and machine learning. Each core is weaker than a CPU core, but the sheer number of them is what matters when the work splits cleanly.

Few powerful coresUp to 64 in high-endconsumer machinesThousands ofsmaller coresEach core weaker than a CPUcoreBest at highsingle-threadperformanceOperating systems, I/O,sequential processesBest at manyindependentcalculationsGraphics rendering, machinelearningsuited tosuited to
How a CPU's few powerful cores differ from a GPU's many simpler cores when processing a batch of independent work.

Now imagine a batch of independent matrix entries arriving at each kind of chip. On the CPU, the batch is spread across a small number of strong workers. Each worker takes a share of the entries and handles it quickly, so the batch is finished by a handful of workers rather than a crowd.

Before

CPU: a few strong workers each take a larger share of the batch

A few entries worked on at a time

After

GPU: thousands of lighter workers each take a small piece of the batch at once

A large set of entries in progress together

On the GPU, the same entries are spread across thousands of smaller cores. Each core is less powerful, but because the entries are independent, none of those cores has to wait for another. At any moment, many entries are in progress together. The state of the batch changes from a few entries being worked on slowly to a large set being worked on at once.

Key point

Notice what changed and what did not. The work itself is the same, and the answer is the same. What changed is how the work is spread across hardware. The shape of the computation determines which design makes good use of its resources.

Why Matrix Multiplication Splits Across Workers

GPUs are optimized for tasks that can be broken into many smaller, independent calculations. The operation that makes up most machine learning workloads is matrix multiplication, and it is highly parallelizable. The key property is independence: if one piece of the answer does not need another piece's result, the two pieces can be worked out at the same time on different cores.

Formula

Read the formula as a recipe for one output cell. The entry in row i and column j of the result C is built from row i of A and column j of B. Two different output cells can be computed without knowing each other's results, which is exactly the independence the source describes.

C 1,1row 1 of A with column 1 ofBC 1,2row 1 of A with column 2 ofBC 2,1row 2 of A with column 1 ofBC 2,2row 2 of A with column 2 ofB
How each output cell of a matrix product maps to its own independent worker, so that all four can be computed at the same time.
Worked example

Four independent workers for a 2 by 2 product

Multiply two 2 by 2 matrices A and B, and show which output cells depend on each other.

  1. 1
    Identify the output cells

    The result C has four cells: C 1,1, C 1,2, C 2,1, and C 2,2.

  2. 2
    Assign one worker per cell

    Each cell needs one row of A and one column of B. C 1,1 uses row 1 of A and column 1 of B, and it does not use any other output cell.

  3. 3
    Check for dependencies

    No output cell needs another output cell's value. All four can start at the same time.

  4. 4
    Map to hardware

    On a CPU with a few strong cores, the four cells are shared among a few workers. On a GPU with thousands of cores, each cell can have its own worker, and a real model with far larger matrices gives far more independent entries to keep the cores busy.

Result

All four output cells are independent, so the product can be spread across many workers without any worker waiting for another.

The same logic scales up. A real model multiplies matrices far larger than two by two, which means far more independent entries. This is why a chip with thousands of cores can keep many of them busy on one multiplication.

Scalars, Vectors, and Tensors

Specialized compute units exist in hardware because different computations work on different shapes of data. The source identifies three shapes. A scalar is a single value. A vector is an ordered list of values. A tensor generalizes these to higher-dimensional arrays.

Compute units are specialized for scalars, vectors, or tensors, and chips often mix them. GPU tensor cores and TPUs are built around tensor operations, which is one reason the matrix arithmetic of AI models maps well onto them. Different hardware architectures have different memory layouts and specialized compute units that evolve over time, and these units are optimized for specific data types.

Training and Inference Hardware Priorities

Many chips can handle both training and inference, but one clear trend is the rise of chips specialized for inference. Training builds a model, while inference means running a trained model to produce outputs. A survey by Desislavov and colleagues (2023) reports that inference can exceed the cost of training in commonly used systems, and that inference accounts for up to 90 percent of machine learning costs for deployed AI systems. For anyone deploying models, inference hardware becomes a central decision.

AspectTraining hardwareInference hardware
Main concernThroughput and the memory needed for gradientsLatency, cost per request, and power
Numeric precisionNot stated as lower precision in the sourceOften optimized for lower precision
Memory accessNot stated as faster memory access in the sourceOften optimized for faster memory access
Why it is tuned this wayBuilding the model is the heavy computationEach deployed request should finish quickly and cheaply

Priorities that differ between training and inference hardware

Weighing Three Hardware Characteristics

A chip's specification sheet holds many details, and only some of them matter for a given use case. Across use cases, three characteristics stand out: computational capability, memory size and bandwidth, and power consumption. Computational capability describes how much work the chip can do. Memory size and bandwidth describe how much data it can hold and how quickly that data can move. Power consumption describes the energy it draws while doing that work.

WorkloadTraining or inferenceComputationalcapabilityHow much work the chip candoChip choiceWeighed togetherMemory size andbandwidthHow much data, and how fastit movesPower consumptionEnergy drawn while workingshapes the need forshapes the need forshapes the need forfeedsfeedsfeeds
How the three hardware characteristics relate to one another and to the workload when selecting a chip.

The three characteristics should be weighed together rather than one at a time. A chip with the most computational capability may draw too much power for a deployment that cares about running cost, and a chip with plenty of memory bandwidth may still be a poor fit if the workload does not move much data. The workload determines how much weight each characteristic deserves.

Common Mistakes When Choosing Hardware

  • Common mistake

    Assuming more cores always means a faster result

    What it looks like

    A CPU with a few powerful cores is compared with a GPU with thousands of smaller cores, and the GPU is assumed to be faster for every task.

    Why it fails

    Each GPU core is weaker than a CPU core. The GPU wins only when the work splits into many independent calculations.

    Do this instead

    Ask first whether the workload can be broken into many independent pieces, then decide which design fits.

  • Common mistake

    Treating inference as a small cost after training

    What it looks like

    A team plans its budget around training only and ignores the cost of serving the model.

    Why it fails

    The source reports that inference can exceed the cost of training in commonly used systems and can account for up to 90 percent of machine learning costs for deployed systems.

    Do this instead

    Weigh inference hardware as a central decision when deploying models.

  • Common mistake

    Choosing a chip by one specification alone

    What it looks like

    A buyer picks the chip with the highest computational capability and ignores its power draw.

    Why it fails

    Computational capability, memory size and bandwidth, and power consumption are linked, and the workload determines how they should be balanced.

    Do this instead

    Compare all three characteristics against the specific workload before deciding.

  • Common mistake

    Using the same hardware priorities for training and inference without checking the goal

Predicting Where the Speed Comes From

What do you think happens?

A GPU has thousands of cores, each weaker than a CPU core. Does a GPU finish one individual matrix entry faster than a CPU does?

  • Yes, each entry finishes faster on the GPU

  • No, individual cores are weaker, and the GPU's advantage comes from many entries running together

Reveal answer
Answer:

No, individual cores are weaker, and the GPU's advantage comes from many entries running together.

The source states that each GPU core is less powerful than a CPU core. The speedup comes from the number of independent entries that can be in progress at once, not from a faster single entry.

MEDIUM

A batch of 1,000 independent matrix entries must be computed. Explain which chip design, a CPU with a few powerful cores or a GPU with thousands of smaller cores, is likely to keep more of its resources busy, and why the answer does not depend on the entries being slower individually on the GPU.

Hints
  • Think about whether any entry must wait for another entry's result.
  • Consider how many workers the batch can be spread across on each chip.

Key Takeaways

  • An AI accelerator is a chip designed for AI workloads, and GPUs are the dominant type because their many smaller cores suit the independent calculations that machine learning repeats.
  • CPUs have a few powerful cores suited to general-purpose and sequential work, while GPUs have thousands of smaller cores suited to parallel work such as matrix multiplication.
  • Matrix multiplication is highly parallelizable because each output cell can be computed independently of the others.
  • Inference hardware is often tuned for lower precision, faster memory access, and low latency, since inference can account for up to 90 percent of machine learning costs.
  • Computational capability, memory size and bandwidth, and power consumption should be weighed together against the workload when choosing a chip.

Related concepts

More concepts starting with T