Concepts / Hardware Considerations for AI Models

Hardware Considerations for AI Models

Inference efficiency matters because a model's usability depends heavily on its inference cost and latency.

  • Programming

Why Speed and Price Decide Usefulness

Imagine two AI assistants built on the same underlying model. The first returns its answer after a noticeable pause, and each word arrives slowly. The second starts answering almost immediately and keeps going at a steady pace. A user will probably judge the second one as more pleasant to work with, even if the content is identical. The difference lies in how efficiently the model's inference runs, and that difference shapes what applications can reasonably be built on top of the model.

Inference efficiency matters because a model's usability depends heavily on its inference cost and latency. Cheaper inference makes AI-powered decisions more affordable, and faster inference makes it possible to put AI into a wider range of applications. Because so much value depends on these two properties, it is worth learning how they are measured before trying to improve them. You cannot tell whether an optimization helped unless you know what you were measuring in the first place.

In the real world

Two assistants share the same model. Assistant A pauses before it says anything and then types slowly. Assistant B starts right away and keeps a steady pace. Nothing about the answer's content has changed, yet a user experiences the two very differently. The product team would also care about cost: whichever assistant costs less to run for each conversation can be offered to more people. Both the feel of the product and its operating expense come from inference efficiency.

Following One Response Through Time

Think about a single response being generated, one token at a time. Before the first token appears, the model has to take in the input, and the source ties this step to the prefilling phase. Only after that does the model produce the rest of the output, which the source ties to the decoding phase. The diagram below traces this order for one request. Read it from left to right and notice where the first wait ends and where the repeated gaps begin.

Input receivedPrefillmodel takes in the inputFirst tokenTTFT ends hereToken 2decodingToken 3decodingLast tokenrequest arrivesTTFTTPOT gapTPOT gapTPOT gap
What happens in order during a single request, and which phase sets the wait before the first token versus the gap between later tokens?

What do you think happens?

Which phase of inference sets the wait before the first token appears?

  • Prefilling

  • Decoding

Reveal answer
Answer:

Prefilling

The model must first take in the input, which the source ties to the prefilling phase. Decoding produces the output that follows, so it governs the gaps after the first token rather than the initial wait.

Three Questions, Three Metrics

The source groups the common efficiency metrics into three families: latency, throughput, and utilization. Each one answers a different question about the same running system. Latency asks how long a single request takes to get a response. Throughput asks how much work the model can process over a period of time. Utilization asks how much of the available hardware capacity is being put to use. Keeping these questions separate matters, because a system can look excellent on one of them and poor on another.

MetricQuestion it answersWhat it tracks
LatencyHow long does one request take to get a response?Time for a single request
ThroughputHow much work can the model process over a period of time?Work completed per unit of time
UtilizationHow much of the available hardware capacity is in use?Share of hardware capacity being put to use

The three efficiency metric families and what each one measures

Key point

A fast single response does not guarantee a high-volume system, and a high-volume system does not guarantee quick individual responses. Always name which metric you are reporting.

Splitting Latency into TTFT and TPOT

For language model-based inference, the source recommends looking inside latency rather than treating it as one number. Latency can be broken into two parts. The first is time to first token, abbreviated TTFT, which is influenced by the prefilling phase. The second is time per output token, abbreviated TPOT, which is influenced by the decoding phase. Put simply, one clock measures how long you wait before anything appears, and the other measures how quickly the rest of the output follows.

Because of this split, the two latency clocks are not interchangeable. TTFT is paid once, at the start of a response. TPOT is paid again for every token that follows. A system can have a short TTFT and still feel slow if its TPOT is large, and the reverse is also possible. Measuring only the total time hides which part needs work.

Worked example

Reading the two clocks in an illustrative response

An illustrative response has 5 output tokens. The first token appears 0.8 seconds after the request is sent. Each of the remaining 4 tokens arrives 0.1 seconds after the one before it. What is the TTFT, what is the TPOT, and how long does the full response take?

  1. 1
    Identify TTFT

    TTFT is the wait before the first token appears, so TTFT is 0.8 seconds. It reflects the prefilling phase.

  2. 2
    Identify TPOT

    TPOT is the time per output token after the first. Each later token arrives 0.1 seconds after the previous one, so TPOT is 0.1 seconds per token. It reflects the decoding phase.

  3. 3
    Add the decoding gaps

    There are 4 gaps of 0.1 seconds after the first token, which totals 0.4 seconds.

  4. 4
    Combine the parts

    The full response time is the TTFT of 0.8 seconds plus the 0.4 seconds of decoding gaps, which equals 1.2 seconds.

Result

TTFT is 0.8 seconds, TPOT is 0.1 seconds per token, and the full response takes 1.2 seconds. Improving the first wait and improving the per-token gap are different tasks.

The Latency and Throughput Trade-off

Throughput is the lens through which cost is most directly seen. The source states that throughput metrics are directly related to cost: the more inputs a system can process in a given period, the more work each unit of hardware and time is doing. When throughput is low, the same hardware must stay busy for longer to handle the same workload, and that expense accumulates.

The more important lesson is the trade-off the source names between latency and throughput. You can potentially reduce cost if you are willing to accept increased latency, and reducing latency often involves increasing cost. The diagram below shows the two sides of this choice when a server groups more requests together. Grouping raises the number of requests served per period, but each individual request may wait longer.

Few requests groupedShorter wait perrequestLower throughputhigher cost per unit ofworkMany requests groupedLonger wait perrequestHigher throughputlower cost per unit of worklatencythroughputlatencythroughput
When the server groups more requests together, how do per-request latency and total work served per period move in opposite directions, and what does that do to cost?

Model Versus Service Optimization

Once you can measure efficiency, the next question is how to improve it. The source describes techniques for inference optimization that operate at two levels: the model level and the inference service level. The distinction is less about speed and more about what is allowed to change. The hierarchy below separates the two levels by what each one touches.

InferenceoptimizationModel levelchanges the model itself,may change behaviorInference servicelevelmodel kept intact, servingchangedchanges the modelchanges the serving
Which optimizations change the model itself, and which change how the serving system handles requests?

The two levels are easy to confuse because both aim at the same goals of lower cost and lower latency. The difference is the object being changed. Model-level work can alter the model, and the source warns that this can lead to changes in model behaviors. Service-level work typically keeps the model intact and changes how requests are handled, including how many are grouped together, which is the same lever behind the latency and throughput trade-off above.

The source also points out a practical reality. Given the availability of model APIs, most application developers will use these APIs with their built-in optimization instead of implementing these techniques themselves. Understanding both levels still helps you evaluate a model API you are considering. When a provider quotes a fast or cheap service, knowing which level of optimization might be behind that claim gives you better questions to ask.

Why Hardware Changes the Numbers

All of these metrics depend on the physical machine doing the work. How efficiently a model can run depends on the hardware it is run on, so the same model can show different latency and throughput numbers on different hardware. The source also notes that optimizing models on different accelerators is important. It gives this only as a high-level point, so the key idea for now is that hardware is part of the efficiency picture and cannot be ignored when comparing numbers.

Mistakes Beginners Make with These Metrics

  • Common mistake

    Treating latency as a single number

    Why it fails

    Latency for a language model splits into a wait before the first token and a gap for each later token, and each part is shaped by a different phase of inference.

    Do this instead

    Report TTFT and TPOT separately so you can tell whether the problem is the initial wait or the steady output pace.

  • Common mistake

    Assuming high throughput means fast responses

    Why it fails

    Throughput measures work completed over a period. The source names a trade-off in which a system optimized for volume may make each request wait longer.

    Do this instead

    Check latency and throughput together, and decide which one the application actually needs.

  • Common mistake

    Assuming lower latency always lowers cost

    Why it fails

    The source says reducing latency often involves increasing cost, so the two pull in opposite directions.

    Do this instead

    Treat the balance between latency and cost as a deliberate choice based on the application.

  • Common mistake

    Comparing numbers measured on different hardware

    Why it fails

    The efficiency of a model depends on the hardware it runs on, so the same model can produce different numbers elsewhere.

    Do this instead

    Only compare metrics gathered on comparable hardware.

  • Common mistake

    Confusing model-level changes with service-level changes when evaluating a provider's claim

Diagnosing a Slow Assistant

MEDIUM

A team reports that its assistant takes a long time before it begins answering, but once the answer starts, the words arrive at a comfortable pace. Using the TTFT and TPOT split, which latency clock is the likely problem, which inference phase influences it, and what kind of change would you investigate first? Explain your reasoning in two or three sentences.

Hints
  • Ask which clock measures the wait before anything appears.
  • TTFT is influenced by the prefilling phase, while TPOT is influenced by decoding.
  • A comfortable pace after the start points away from the per-token gap.

Closing Takeaways

  1. 1
    A model's usability depends heavily on its inference cost and latency, so these properties must be measured before they can be improved.
  2. 2
    Latency asks how long one request takes, throughput asks how much work is completed over time, and utilization asks how much hardware capacity is in use.
  3. 3
    Language model latency splits into TTFT, influenced by prefilling, and TPOT, influenced by decoding.
  4. 4
    Lower latency often raises cost and higher throughput is directly tied to cost, so the balance depends on what the application needs.
  5. 5
    Model-level optimization can change the model itself, while inference service-level optimization usually keeps the model intact and changes how it is served.

At a glance

  • A model's usability depends heavily on its inference cost and latency, so these properties must be measured before they can be improved.
  • Latency asks how long one request takes, throughput asks how much work is completed over time, and utilization asks how much hardware capacity is in use.
  • Language model latency splits into TTFT, influenced by prefilling, and TPOT, influenced by decoding.
  • Lower latency often raises cost and higher throughput is directly tied to cost, so the balance depends on what the application needs.
  • Model-level optimization can change the model itself, while inference service-level optimization usually keeps the model intact and changes how it is served.

More concepts starting with H