← Back to article

Equation 14 · How AI Inference Serving Actually Works

What does this equation mean?

Mkv=2 L hkv dh s b pM_{\mathrm{kv}} = 2\,L\,h_{kv}\,d_h\,s\,b\,p

Read the formula alongside the article passage below. Each part has a deeper page with its role in the equation, the supporting passage and nearby citations.

Inputs and operations2Lh_kvd_hsbp
Result or conditionM_kv
How to read the two sides of this formula. Follow the article passage for the meaning of each quantity.

This equation states an equality: the expressions on both sides have the same value under the article’s assumptions. Read the equation part by part below; each part has a contextual explanation and a link to its mathematical background.

Read it piece by piece

MkvM_{\mathrm{kv}}

Symbol M_kv

the total resident size.

Understand this part →

LL

Symbol L

the number of layers.

Understand this part →

hkvh_{kv}

Symbol h_kv

the number of key-value attention heads.

Understand this part →

dhd_h

Symbol d_h

the head dimension.

Understand this part →

ss

Symbol s

the number of positions in each sequence.

Understand this part →

bb

Symbol b

the number of concurrently served sequences.

Understand this part →

pp

Symbol p

the bytes stored per element.

Understand this part →

=

=

The expressions on both sides represent the same quantity under the stated assumptions.

Understand this part →

See an illustrated explanation →
subscript

subscript

The lower label selects a particular version, component, or indexed member of the quantity. For example, x₀ and xₜ can be values at different positions.

Understand this part →

How to interpret it

Read it with the definitions, units, and assumptions supplied by the article.

What the article says around this equation

Its footprint follows directly from the shape of the cache. For a model with L layers, hkvh_{kv} key-value attention heads, head dimension dhd_h , holding a sequence of length s across b concurrently served sequences, stored at p bytes per element, the total resident size is Mkv=2 L hkv dh s b pM_{\mathrm{kv}} = 2\,L\,h_{kv}\,d_h\,s\,b\,p. with the factor of two accounting for storing both keys and values. Two things follow immediately from this equation, and both matter more than the equation’s arithmetic itself. It scales linearly with context length, so a conversation twice as long holds twice the cache. And it scales linearly with the batch b — the exact quantity the previous section identified as the only lever available to make a…
Read the full surrounding passage
Its footprint follows directly from the shape of the cache. For a model with L layers, hkvh_{kv} key-value attention heads, head dimension dhd_h , holding a sequence of length s across b concurrently served sequences, stored at p bytes per element, the total resident size is Mkv=2 L hkv dh s b pM_{\mathrm{kv}} = 2\,L\,h_{kv}\,d_h\,s\,b\,p. with the factor of two accounting for storing both keys and values. Two things follow immediately from this equation, and both matter more than the equation’s arithmetic itself. It scales linearly with context length, so a conversation twice as long holds twice the cache. And it scales linearly with the batch b — the exact quantity the previous section identified as the only lever available to make a memory-bound decode step efficient. The key-value cache therefore competes directly, in the same pool of device memory, with the batch size continuous batching is trying to grow. It is not a side cost of serving; it is the resource that sets the ceiling on the technique the previous section depends on.

Read the equation in its article →

Sources cited in the article section

These citations give research context. Read each source to check which claims it supports.

Return to How AI Inference Serving Actually Works

See this formula across 1 published context →

Browse the mathematical compendium →