Concepts / Memory Requirements for Serving Models

Memory Requirements for Serving Models

Replica parallelism copies the whole model to handle more requests at once, at the cost of more chips; it does not make an individual request faster.

  • Programming

Why a Single Chip Is Not Enough

What do you think happens?

If you copy a model onto a second chip and send half of the incoming requests to each copy, does any single request finish faster?

  • Yes, each request finishes about twice as fast

  • No, each request takes the same time, but the service handles more requests at once

Reveal answer
Answer:

No, each request takes the same time, but the service handles more requests at once

Replica parallelism copies the whole model to handle more requests at once, at the cost of more chips. It does not make an individual request faster.

Serving an AI model is a resource problem. Accelerators such as GPUs are built to do many calculations at once, and that property is what makes them useful for serving models. It also gives engineers a set of choices when a service has to grow. Parallelism strategies are the family of methods that spread work across several chips or machines so the service can keep up with demand, or so it can run a model too large for one device.

Serving problems usually arrive in one of two forms. Sometimes there are too many requests, and each request is quick enough on its own, so the goal is to answer more of them at the same time. Other times the model itself is too large to fit on one device, so the goal is to split the model. Some strategies also respond to a third pressure, which is very long input sequences. The rest of this article follows these pressures one at a time, and it tracks where the memory and the work end up in each case.

Copying the Whole Model With Replicas

Replica parallelism is the simplest strategy to put into practice. You make several identical copies of the model you want to serve. Each copy handles its own requests, so the service as a whole can process more requests at the same time than a single copy could.

Trace one request through a replicated service. A request arrives, it is routed to one replica, and that replica runs the full model from start to finish. A second request can be routed to a different replica and run at the same moment. Neither request runs through a shorter path than it would on a single copy. What changes is how many requests are in progress at once.

The trade-off is hardware cost. Every extra replica needs its own chips to run on. More replicas let more simultaneous requests be handled, but the number of chips you pay for grows with them. Replica parallelism therefore scales throughput by buying capacity rather than by making any one request cheaper or faster.

The Placement Question as a Bin-Packing Problem

Once you create replicas, or serve several models at once, you face a placement question. You have a fixed number of chips, and you must decide how many replicas of each model to create and which chip hosts each replica. Chips also differ in how much memory they have, so a model that fits on one chip may not fit on another.

This placement question is called the bin-packing problem. Each chip is a container with a fixed capacity. Each model replica is an item that must be placed. The goal is to arrange the items so they fit without overflowing. The problem gets harder as you add more models, more replicas, and more chips, because the number of possible arrangements grows quickly.

Start with the arithmetic. Assume every model is stored at 8-bit precision, which means each parameter takes one byte. A 13B model therefore needs roughly 13 GB just for its weights. This estimate ignores extra memory used at runtime, so a real placement needs more headroom than the raw numbers suggest.

Worked example

Can a 70B model fit on a 48 GB chip?

A 70B model is stored at 8-bit precision, so each parameter takes one byte. Decide whether one copy of its weights fits on a chip with 48 GB of memory, ignoring runtime overhead first.

  1. 1
    Convert parameters to bytes

    70B means 70 billion parameters. At one byte per parameter, the weights need about 70 GB.

  2. 2
    Compare with chip capacity

    The chip has 48 GB. The weights alone need about 70 GB, which is more than 48 GB.

  3. 3
    Check the other chip sizes

    The 70 GB of weights does not fit on the 24 GB, 40 GB, or 48 GB chips. Only the 80 GB chip has enough room, and even there about 10 GB remains for runtime needs.

Result

The 70B model cannot be placed on a 48 GB chip. It can only be placed on the 80 GB chip, and it leaves little headroom for runtime memory.

24 GB chip8B model, 8 GB used, 16 GBfree40 GB chip13B model, 13 GB used, 27GB free48 GB chip34B model, 34 GB used, 14GB free80 GB chip70B model, 70 GB used, 10GB free
Given models of different sizes and chips with fixed memory, how do the model weights fill each chip, and where does leftover space occur?

The diagram shows one arrangement that works, and it leaves free space on every chip. The free space is not wasted by accident. It is headroom for runtime memory, which the simple arithmetic ignores. Other arrangements are possible, and choosing among them is the bin-packing problem. A 70B model cannot go on a 24 GB, 40 GB, or 48 GB chip at all, so some chips are simply ruled out for some models before any packing choice is made.

Splitting One Model Across Machines

Sometimes a model is so large that no single machine can hold it. Model parallelism addresses this by splitting the same model across multiple machines. Each machine holds part of the model, so the model as a whole can run even though no single machine could host it alone.

Model parallelism makes placement harder. You are no longer deciding only which chip gets which whole model. You also decide how to cut the model into pieces and how those pieces fit across chips. There are several ways to make the cuts. The two most important for inference are tensor parallelism and pipeline parallelism.

Long Inputs: Context Versus Sequence Parallelism

Context parallelism and sequence parallelism are less common than the strategies above, but both were developed to make the processing of long input sequences more efficient. The two names sound similar, so it helps to remember what each one splits. Context parallelism splits the input. Sequence parallelism splits the operations.

In context parallelism, each device receives a different portion of the input sequence and processes that portion separately. For example, the first half of a long input might be handled on one machine while the second half is handled on another.

In sequence parallelism, the input is not cut into portions. Instead, the operators needed for the whole input are divided. Every part of the input may still need several kinds of computation. If the input requires both attention and feedforward computation, one machine might carry out the attention step while another carries out the feedforward step, with the whole input passing between them.

Device 1first half of the inputtokensDevice 1attention step over thewhole inputDevice 2second half of the inputtokensDevice 2feedforward step over thewhole input
What dimension of the input is divided across devices in each strategy, and how do the two differ in what each device stores?

Mistakes When Choosing a Strategy

  • Common mistake

    Expecting replicas to make one request faster

    What it looks like

    A team adds a second replica and expects each user's response to arrive twice as quickly.

    Why it fails

    Replica parallelism lets more requests run at once. Each request still runs the full model on one copy, so its time does not shrink.

    Do this instead

    Use replicas when the problem is too many requests, and use tensor parallelism when the goal is lower latency for each request.

  • Common mistake

    Assuming pipeline parallelism lowers latency

    What it looks like

    A model is split into stages across devices, and the team expects single requests to finish sooner.

    Why it fails

    Pipeline parallelism divides the model into stages, and each request must pass through every stage in order, which increases latency per request.

    Do this instead

    Choose pipeline parallelism when the model is too large for one device, and accept that each request will take longer.

  • Common mistake

    Ignoring runtime memory when placing models

    What it looks like

    A 13B model at 8-bit precision is placed on a 13 GB device because its weights need about 13 GB.

    Why it fails

    The estimate ignores extra memory used at runtime, so there is no headroom for the work the model does while serving.

    Do this instead

    Leave room above the raw weight size when packing models onto chips.

  • Common mistake

    Mixing up context and sequence parallelism

    What it looks like

    A team splits a long document by sentences across machines and calls this sequence parallelism.

    Why it fails

    Splitting the input among devices is context parallelism. Sequence parallelism instead divides the operators needed for the whole input.

    Do this instead

    Ask whether the input itself is being divided, which points to context parallelism, or whether the operations are being divided, which points to sequence parallelism.

Choosing a Strategy for a Serving Goal

Each strategy answers a different pressure on a serving system. Match the strategy to the problem you are trying to solve, then check the trade-off you accept in return.

StrategyWhat it splitsMain benefitMain trade-off
Replica parallelismWhole copies of the modelMore requests handled at onceMore chips to pay for; single requests are not faster
Tensor parallelismTensors inside each layerCan reduce latency per requestDevices must combine partial results for each layer
Pipeline parallelismConsecutive stages of layersLets a model too large for one device runIncreases latency per request
Context parallelismThe input sequenceHandles long inputs across devicesEach device processes only part of the input
Sequence parallelismThe operators for the whole inputHandles long inputs by dividing the workWhole input passes between devices for different steps

Parallelism strategies by what they split and what they cost

EASY

A service must answer many more requests per minute, but each request is already fast enough. Which strategy should it choose, and what cost should the team expect to pay?

Hints
  • Ask which pressure is present: too many requests, a model too large for one device, or very long inputs.
  • Think about what the replica strategy buys and what it costs in hardware.

Trace Review of the Three Pressures

  • Too many requests: copy the whole model with replicas, and pay for more chips.
  • Model too large for one device: split it with tensor parallelism inside layers, or pipeline parallelism across stages.
  • Very long input: split the input with context parallelism, or split the operators with sequence parallelism.
  • Placing models of different sizes on chips with different memory is a bin-packing problem that grows harder as models, replicas, and chips increase.

Key Takeaways

  • Replica parallelism copies the whole model to handle more requests at once, at the cost of more chips, and it does not make an individual request faster.
  • Placing models of different sizes onto chips with different memory is a bin-packing problem, and it gets harder as models, replicas, and chips are added.
  • Tensor parallelism splits the tensors inside each layer and can reduce latency, while pipeline parallelism splits the model into sequential stages and increases latency per request.
  • Context parallelism divides the input sequence among devices, while sequence parallelism divides the operators needed for the whole input; both target long inputs.
  • Choose a strategy by first identifying the pressure, whether too many requests, a model too large for one device, or very long inputs, and then weighing the trade-off that strategy brings.

More concepts starting with M