<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Memory-Bound on lo0 — Tech Blog</title><link>https://blog.lo0.es/en/tags/memory-bound/</link><description>Recent content in Memory-Bound on lo0 — Tech Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Tue, 09 Jun 2026 01:30:00 +0000</lastBuildDate><atom:link href="https://blog.lo0.es/en/tags/memory-bound/index.xml" rel="self" type="application/rss+xml"/><item><title>The roofline flips: why optimising small models is a different performance game</title><link>https://blog.lo0.es/en/posts/roofline-flips-optimising-small-models/</link><pubDate>Tue, 09 Jun 2026 01:30:00 +0000</pubDate><guid>https://blog.lo0.es/en/posts/roofline-flips-optimising-small-models/</guid><description>&lt;blockquote>
&lt;p>This post is the anchor of a mini-series on inference performance in &lt;strong>small models (SLMs)&lt;/strong>. Almost every optimisation post on the blog, &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache&lt;/a>, &lt;a href="https://blog.lo0.es/en/posts/optimising-decode-vllm-squeezing-every-token-small-hardware/">decode&lt;/a>, &lt;a href="https://blog.lo0.es/en/posts/quantization-llm-inference-fp8-int4-gguf/">quantisation&lt;/a>, was written with a 70B in mind. Here I argue that when the model shrinks by an order of magnitude, the &lt;em>roofline&lt;/em> changes regime and several of those intuitions flip. This is not a nuance: it is a different game.&lt;/p>
&lt;/blockquote>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>Autoregressive decode in a large LLM is &lt;strong>memory-bandwidth-bound&lt;/strong>: at every step you have to move all the model weights from HBM to the registers of the SMs, and that dominates over the arithmetic operations. The GPU spends its time waiting for bytes, not computing. That single sentence, that decode &amp;ldquo;waits on HBM&amp;rdquo;, is the root of half the optimisations on this blog. In a small model (SLM, say 0.5B–7B) the sentence stops being true in the simple form we used to tell it. At &lt;em>batch&lt;/em> 1 you are still memory-bound with respect to the hardware, yes, but the forward pass is so cheap (moving 6 GB at 1 TB/s takes ~6 ms, not 70 ms) that the &lt;strong>fixed per-step costs&lt;/strong>, kernel launches, Python scheduler overhead, the &lt;code>sampler&lt;/code>, host↔device copies, the &lt;code>synchronize&lt;/code> calls, stop being noise and start eating 20-30 % of the time. The bottleneck moves from HBM to orchestration. The concrete, quantitative consequences: (1) &lt;strong>CUDA graphs&lt;/strong> and cutting scheduler overhead pay off &lt;em>more&lt;/em> in SLMs than in large models; (2) &lt;strong>weight quantisation&lt;/strong> gives &lt;em>less&lt;/em> latency improvement at batch 1 in SLMs, because proportionally there are fewer weights to move relative to activations, KV cache and fixed overhead; (3) batching has more headroom because you cross the &lt;em>ridge point&lt;/em> late; (4) the KV cache can dominate relative memory. All of this comes out of a single model, the roofline, applied with numerical honesty.&lt;/p>
&lt;h2 id="the-analogy-the-pantry-and-the-waiter">The analogy: the pantry and the waiter&lt;/h2>
&lt;p>A kitchen with two very different services.&lt;/p>
&lt;p>&lt;strong>Tasting menu service, one enormous slow dish (the 70B LLM).&lt;/strong> Every dish involves heavy ingredients that the assistant has to fetch from the pantry at the back, several times, carrying boxes. The chef, by contrast, assembles the dish in a moment: the slow part is fetching the ingredients, not cooking them. If you want the service to go faster, you do not hire a more skilful chef: you widen the corridor to the pantry, or make each trip bring more boxes. The pantry is HBM; the trip is memory bandwidth; cooking is compute. The big dish is bound by the pantry.&lt;/p>
&lt;p>&lt;strong>Tapas service, tiny plates (the SLM).&lt;/strong> Now each tapa has two ingredients and is assembled in a second. The trip to the pantry per tapa is very short. But a cost appears that was negligible for the big dish: the &lt;strong>waiter&lt;/strong>. For every tapa, the waiter has to walk to the kitchen, pick up the plate, carry it to the bar, walk back, take the order, call it out. That back and forth is &lt;strong>fixed&lt;/strong>: it costs the same for one tapa as for the enormous dish. When the tapa is assembled in a second, the waiter, not the pantry, is the bottleneck. Shortening the corridor to the pantry (widening HBM, quantising the weights) barely improves the service any more; what improves it is the waiter chaining several orders together without going back to the kitchen each time (CUDA graphs) or serving several tables in one pass (batching).&lt;/p>
&lt;p>The roofline is the tool that says, with numbers, at what point the waiter dominates over the pantry. That boundary is the &lt;em>ridge point&lt;/em>, and the joke in the title is that in SLMs we cross the regime much earlier than large-model intuition led us to believe.&lt;/p>
&lt;h2 id="the-bare-mechanism-what-the-roofline-says">The bare mechanism: what the roofline says&lt;/h2>
&lt;p>The roofline model (Williams, Waterman and Patterson, 2009) starts from a single quantity: &lt;strong>arithmetic intensity&lt;/strong>, which is how many operations you do per byte moved from memory.&lt;/p>
$$\text{AI} = \frac{\text{FLOPs}}{\text{bytes moved from memory}} \quad [\text{FLOP/byte}]$$
&lt;p>The hardware has two ceilings: compute (peak FLOPS) and memory (peak bandwidth × AI). Achievable performance is the minimum of the two:&lt;/p>
$$\text{Perf} = \min\big(\text{peak FLOPS},\; \text{BW} \times \text{AI}\big)$$
&lt;p>Where the two lines cross is the &lt;strong>ridge point&lt;/strong>, the AI above which you stop being limited by memory and start being limited by compute:&lt;/p>
$$\text{AI}_{\text{ridge}} = \frac{\text{peak FLOPS}}{\text{peak BW}}$$
&lt;p>If your kernel has an AI below the ridge, you are &lt;strong>memory-bound&lt;/strong> (the GPU waits for bytes). Above it, &lt;strong>compute-bound&lt;/strong> (the GPU computes flat out and memory is in surplus). What matters is that the ridge point is a property of the hardware, not of the model. Let us look at the numbers, approximate, and I flag them as such because marketing figures mix &lt;em>dense&lt;/em> and &lt;em>sparse&lt;/em>, different dtypes and unrealistic thermal conditions.&lt;/p>
&lt;p>&lt;strong>Generic 4×H100 SXM cluster (320 GB, NVLink, native FP8).&lt;/strong> Per GPU, ~989 TFLOPS BF16 &lt;em>dense&lt;/em> (~1,979 TFLOPS FP8 &lt;em>dense&lt;/em>; the figure with &lt;em>sparsity&lt;/em> is double that and almost never applies to LLM inference). HBM3 ~3.35 TB/s. The ridge in BF16:&lt;/p>
$$\text{AI}_{\text{ridge}}^{\text{H100,BF16}} \approx \frac{989 \times 10^{12}}{3.35 \times 10^{12}} \approx 295 \ \text{FLOP/byte}$$
&lt;p>In FP8 the ridge rises to ~590 FLOP/byte (twice the FLOPS against the same BW). Careful: these are datasheet peak figures; in practice a real kernel rarely gets past 70-80 % of either ceiling.&lt;/p>
&lt;p>&lt;strong>RTX 4090 (24 GB, Ada Lovelace).&lt;/strong> ~330 TFLOPS FP16 with FP16 accumulation via tensor cores (the &amp;ldquo;660 TOPS&amp;rdquo; figure that circulates is with sparsity), and ~1 TB/s of GDDR6X. The ridge:&lt;/p>
$$\text{AI}_{\text{ridge}}^{\text{4090,FP16}} \approx \frac{330 \times 10^{12}}{1.0 \times 10^{12}} \approx 330 \ \text{FLOP/byte}$$
&lt;p>Curiously, the same order as the H100 in BF16: the 4090 has less BW but also fewer FLOPS, and the ratio comes out similar. The ridge sits around &lt;strong>300 FLOP/byte&lt;/strong> in both cases. Hold on to that number.&lt;/p>
&lt;p>And where does decode fall? In decode at &lt;em>batch&lt;/em> 1, each weight is loaded once from HBM and used for a single multiply-accumulate (one token, one row of activation). The AI of the decode GEMM at batch 1 is on the order of &lt;strong>AI ≈ 1-2 FLOP/byte&lt;/strong> (each weight byte takes part in ~2 FLOP). With &lt;em>batch&lt;/em> B, the same weight loaded once serves B rows of activation, so the AI scales roughly linearly:&lt;/p>
$$\text{AI}_{\text{decode}}(B) \approx 2B \ \text{FLOP/byte} \quad (\text{for the weight GEMM part})$$
&lt;p>You cross the ridge when &lt;code>2B ≈ 300&lt;/code>, that is B ≈ 150 as an order of magnitude (in practice earlier, because of attention and overheads, but that is the frame). The clean conclusion: &lt;strong>decode at low batch is always deeply memory-bound&lt;/strong>, nowhere near the ridge. That is why we say &amp;ldquo;decode waits on HBM&amp;rdquo;, and why quantising weights (moving fewer bytes) speeds up decode in a large model almost linearly. So far, this is the standard story from the large-model posts.&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 780 420" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Roofline diagram with ridge point and where the large and small models fall">
&lt;!-- axes -->
&lt;line x1="80" y1="360" x2="740" y2="360" stroke="currentColor" stroke-width="1.6"/>
&lt;line x1="80" y1="360" x2="80" y2="40" stroke="currentColor" stroke-width="1.6"/>
&lt;text x="410" y="400" text-anchor="middle" fill="currentColor" font-size="13" font-weight="600">Arithmetic intensity (FLOP/byte) — log scale&lt;/text>
&lt;text x="28" y="200" text-anchor="middle" fill="currentColor" font-size="13" font-weight="600" transform="rotate(-90 28 200)">Achievable performance (FLOPS)&lt;/text>
&lt;!-- memory ceiling (ramp) -->
&lt;line x1="80" y1="360" x2="470" y2="90" stroke="#1f5fa8" stroke-width="2.6"/>
&lt;!-- compute ceiling (flat) -->
&lt;line x1="470" y1="90" x2="740" y2="90" stroke="#a52a2a" stroke-width="2.6"/>
&lt;!-- ridge point -->
&lt;line x1="470" y1="90" x2="470" y2="360" stroke="currentColor" stroke-width="1" stroke-dasharray="4 3"/>
&lt;circle cx="470" cy="90" r="5" fill="#5a2db0"/>
&lt;text x="470" y="78" text-anchor="middle" fill="#5a2db0" font-size="12" font-weight="600">ridge ≈ 300 FLOP/byte&lt;/text>
&lt;text x="270" y="200" text-anchor="middle" fill="#1f5fa8" font-size="12" font-weight="600" transform="rotate(-35 270 200)">memory-bound (BW × AI)&lt;/text>
&lt;text x="600" y="80" text-anchor="middle" fill="#a52a2a" font-size="12" font-weight="600">compute-bound (peak FLOPS)&lt;/text>
&lt;!-- decode batch 1 point -->
&lt;circle cx="120" cy="332" r="6" fill="#a48000"/>
&lt;text x="120" y="322" text-anchor="middle" fill="#a48000" font-size="11" font-weight="600">decode B=1 · AI≈2&lt;/text>
&lt;!-- large batch decode point -->
&lt;circle cx="360" cy="167" r="6" fill="#2a7a40"/>
&lt;text x="360" y="157" text-anchor="middle" fill="#2a7a40" font-size="11" font-weight="600">decode B≈64 · AI≈128&lt;/text>
&lt;!-- SLM note -->
&lt;rect x="90" y="300" width="250" height="48" fill="#fff4d6" stroke="#a48000" stroke-width="1.2"/>
&lt;text x="100" y="318" fill="#222" font-size="11" font-weight="600">SLM at B=1: the point is here (memory-bound),&lt;/text>
&lt;text x="100" y="333" fill="#222" font-size="11">but the roofline does NOT model the fixed&lt;/text>
&lt;text x="100" y="346" fill="#222" font-size="11">per-step overhead → see second diagram.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;h2 id="the-point-of-the-title-why-it-flips-in-slms">The point of the title: why it flips in SLMs&lt;/h2>
&lt;p>The classic roofline has a blind spot that does not matter in large models and is everything in small ones: &lt;strong>it only models the work inside the kernel&lt;/strong>. It assumes the only time is &lt;code>bytes/BW&lt;/code> or &lt;code>FLOPs/FLOPS&lt;/code>. But a real decode step is not just the GEMM. It is a sequence of dozens of kernels (QKV projections, attention, the two MLP layers, normalisations, residuals, the logits head, sampling) and, around each one, there is a &lt;strong>fixed orchestration cost&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Kernel launches&lt;/strong> (&lt;code>kernel launch&lt;/code>): each &lt;code>cudaLaunchKernel&lt;/code> costs on the order of 5-10 µs of CPU/driver overhead, regardless of kernel size. A decode forward with ~30-60 kernels launched sequentially drags ~0.3-0.6 ms just in launching.&lt;/li>
&lt;li>&lt;strong>Python scheduler overhead&lt;/strong>: the &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">vLLM scheduler&lt;/a> loop prepares metadata, decides which requests enter the step, builds the input tensors. In pure Python this is hundreds of µs to a couple of ms per step, especially at low concurrency where it is not amortised.&lt;/li>
&lt;li>&lt;strong>Sampling and post-processing&lt;/strong>: applying temperature, top-p, penalties, the &lt;code>argmax&lt;/code>/multinomial, copying the token back. Another block of hundreds of µs.&lt;/li>
&lt;li>&lt;strong>Synchronisations and host↔device copies&lt;/strong>: every &lt;code>synchronize&lt;/code> or small copy adds latency that is neither FLOPs nor HBM bytes.&lt;/li>
&lt;/ul>
&lt;p>Let us call the sum of all of that &lt;strong>T_fixed&lt;/strong>, the per-step cost independent of model size, on the order of 1-3 ms in an unoptimised Python stack. The real time of a step is now:&lt;/p>
$$T_{\text{step}} \approx \underbrace{\frac{\text{weight bytes}}{\text{BW}}}_{T_{\text{HBM}} \text{ (memory-bound)}} + \; T_{\text{fixed}}$$
&lt;p>In a 70B BF16, moving ~140 GB at 3.35 TB/s takes ~42 ms of &lt;code>T_HBM&lt;/code>. Against that, a &lt;code>T_fixed&lt;/code> of 1-3 ms is &lt;strong>noise (2-7 %)&lt;/strong>. The classic roofline is right: the model &lt;em>is&lt;/em> memory-bound, full stop. But in a 3B BF16, &lt;code>T_HBM&lt;/code> drops to a few ms, and suddenly &lt;code>T_fixed&lt;/code> is the same order as &lt;code>T_HBM&lt;/code>. The bottleneck stops being the pantry and becomes the waiter. This is the flip in the title, and four counterintuitive consequences follow from it:&lt;/p>
&lt;p>&lt;strong>(a) At batch 1 you are still memory-bound &lt;em>with respect to the hardware&lt;/em>.&lt;/strong> The AI has not changed: it is still ~2 FLOP/byte, below the ridge. Anyone reading only the roofline will conclude &amp;ldquo;memory-bound, quantise the weights&amp;rdquo;. That is true but &lt;strong>incomplete&lt;/strong>: the roofline does not see &lt;code>T_fixed&lt;/code>.&lt;/p>
&lt;p>&lt;strong>(b) Fixed costs become a huge fraction of the step.&lt;/strong> This is the central point. In the 70B, &lt;code>T_fixed / T_step ≈ 5 %&lt;/code>. In the 3B it can be 20-30 %. The effective bottleneck of the 3B is half HBM, half orchestration.&lt;/p>
&lt;p>&lt;strong>(c) That is why CUDA graphs and cutting scheduler overhead pay off MORE in SLMs.&lt;/strong> A &lt;a href="https://blog.lo0.es/en/posts/sms-cuda-streams-cuda-graphs-inference/">CUDA graph&lt;/a> captures the whole kernel sequence of the step and relaunches it with a single &lt;code>cudaGraphLaunch&lt;/code>, removing almost all of the per-kernel launch overhead and much of the per-iteration Python scheduler work. In the 70B, shaving 0.5 ms off a 42 ms step is a +1 % you barely notice. In the 3B, shaving those same 0.5 ms off a ~7 ms step is +7 %, and if you take away nearly all of &lt;code>T_fixed&lt;/code> you can gain 20-30 %. The same optimisation, a different prize, because the denominator changed.&lt;/p>
&lt;p>&lt;strong>(d) Weight quantisation gives LESS latency improvement at batch 1 in SLMs.&lt;/strong> This is the most counterintuitive one. In the 70B, &lt;code>T_HBM&lt;/code> is almost the whole step; going from BF16 to INT4 quadruples the effective weight bandwidth and almost quadruples decode speed. In the 3B, &lt;code>T_HBM&lt;/code> is only &lt;em>part&lt;/em> of the step (the rest is &lt;code>T_fixed&lt;/code> + attention + KV). By Amdahl&amp;rsquo;s law, if the weights are 60 % of the step and you speed them up 4×, the total step improves only &lt;code>1/(0.4 + 0.6/4) = 1.8×&lt;/code>, not 4×. And proportionally there are fewer weights to move relative to activations, KV cache and fixed overhead. Aggressive quantisation in SLMs does help, yes, but &lt;strong>not through raw latency at batch 1&lt;/strong>, where it gives diminishing returns, rather through capacity and concurrency (we will see that at the end).&lt;/p>
&lt;p>&lt;strong>(e) The KV cache can dominate relative memory.&lt;/strong> With 6 GB of weights (3B BF16), a single long-context session can approach that order of magnitude in KV cache. In a 70B (140 GB of weights) the KV is proportionally small until high concurrency. In SLMs the VRAM balance tips towards KV much earlier (the detail is in &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache&lt;/a>), and that changes which memory optimisation is the lever.&lt;/p>
&lt;h2 id="the-maths-that-matter-a-3b-on-a-4090">The maths that matter: a 3B on a 4090&lt;/h2>
&lt;p>Let us do the whole calculation, which is where the flip shows up without rhetoric.&lt;/p>
&lt;p>&lt;strong>Model:&lt;/strong> 3B parameters, BF16 → 2 bytes/param → ~6 GB of weights. &lt;strong>Hardware:&lt;/strong> RTX 4090, BW ≈ 1 TB/s.&lt;/p>
&lt;p>&lt;strong>Memory-bound ceiling for decode (batch 1).&lt;/strong> Each token requires loading the 6 GB once:&lt;/p>
$$T_{\text{HBM}} = \frac{6 \times 10^{9} \ \text{bytes}}{1 \times 10^{12} \ \text{bytes/s}} = 6 \times 10^{-3}\ \text{s} = 6\ \text{ms/token}$$
$$\text{Ceiling} = \frac{1}{6\ \text{ms}} \approx 166\ \text{tok/s}$$
&lt;p>That is the theoretical memory-bound ceiling: 166 tok/s, assuming that moving the weights is the only cost. The classic roofline would stop here and say &amp;ldquo;166 tok/s, go get more BW or quantise&amp;rdquo;.&lt;/p>
&lt;p>&lt;strong>Now the fixed overhead.&lt;/strong> Let us put &lt;code>T_fixed ≈ 2 ms/step&lt;/code> (a reasonable value for a Python scheduler + ~40 kernels launched + sampling, without CUDA graphs). The real step:&lt;/p>
$$T_{\text{step}} = T_{\text{HBM}} + T_{\text{fixed}} = 6 + 2 = 8\ \text{ms} \;\Rightarrow\; \frac{1}{8\ \text{ms}} = 125\ \text{tok/s}$$
&lt;p>The overhead has eaten &lt;strong>41 tok/s out of the theoretical 166&lt;/strong>: &lt;code>T_fixed&lt;/code> is &lt;strong>25 % of the step&lt;/strong> (2 of 8 ms). Compare with the 70B: &lt;code>T_HBM ≈ 42 ms&lt;/code>, &lt;code>T_step ≈ 44 ms&lt;/code>, &lt;code>T_fixed&lt;/code> is 4.5 %. &lt;strong>Same absolute overhead, relative impact 5-6× larger in the SLM.&lt;/strong>&lt;/p>
&lt;p>&lt;strong>What happens if you apply CUDA graphs&lt;/strong> and take away, say, 1.5 of the 2 ms of &lt;code>T_fixed&lt;/code>:&lt;/p>
$$T_{\text{step}}^{\text{graphs}} = 6 + 0.5 = 6.5\ \text{ms} \;\Rightarrow\; 154\ \text{tok/s}$$
&lt;p>From 125 to 154 tok/s: &lt;strong>+23 %&lt;/strong> from orchestration alone, without touching the model or the memory hardware. In the 70B the same intervention would have gone from 44 to 42.5 ms, +3.5 %. There it is, in two numbers: &amp;ldquo;a different game&amp;rdquo;.&lt;/p>
&lt;p>&lt;strong>What happens if you quantise the weights to INT4&lt;/strong> (1.5 GB instead of 6 GB), with &lt;code>T_fixed&lt;/code> still at 2 ms:&lt;/p>
$$T_{\text{HBM}}^{\text{INT4}} = \frac{1.5 \times 10^{9}}{1 \times 10^{12}} = 1.5\ \text{ms};\quad T_{\text{step}} = 1.5 + 2 = 3.5\ \text{ms} \;\Rightarrow\; 285\ \text{tok/s}$$
&lt;p>The 4× weight quantisation did &lt;strong>not&lt;/strong> give 4× in latency: it went from 125 to 285 tok/s, a 2.3×, because the 2 ms of &lt;code>T_fixed&lt;/code> now dominates (it is 57 % of the step). In the 70B, quantising to INT4 gives almost the full 4× because &lt;code>T_fixed&lt;/code> is still noise. &lt;strong>The same quantisation delivers twice the speedup on the large model as on the small one&lt;/strong>, at batch 1. And if you also apply CUDA graphs on top of INT4 (&lt;code>T_fixed → 0.5 ms&lt;/code>): &lt;code>1.5 + 0.5 = 2 ms → 500 tok/s&lt;/code>. The order of the optimisations matters: in SLMs, &lt;strong>attacking &lt;code>T_fixed&lt;/code> first&lt;/strong> unlocks the rest.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Configuration (3B, 4090, batch 1)&lt;/th>
&lt;th>T_HBM&lt;/th>
&lt;th>T_fixed&lt;/th>
&lt;th>T_step&lt;/th>
&lt;th>tok/s&lt;/th>
&lt;th>vs. baseline&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>BF16, no graphs (baseline)&lt;/td>
&lt;td>6.0 ms&lt;/td>
&lt;td>2.0 ms&lt;/td>
&lt;td>8.0 ms&lt;/td>
&lt;td>125&lt;/td>
&lt;td>1.00×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>BF16 + CUDA graphs&lt;/td>
&lt;td>6.0 ms&lt;/td>
&lt;td>0.5 ms&lt;/td>
&lt;td>6.5 ms&lt;/td>
&lt;td>154&lt;/td>
&lt;td>1.23×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>INT4, no graphs&lt;/td>
&lt;td>1.5 ms&lt;/td>
&lt;td>2.0 ms&lt;/td>
&lt;td>3.5 ms&lt;/td>
&lt;td>285&lt;/td>
&lt;td>2.28×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>INT4 + CUDA graphs&lt;/td>
&lt;td>1.5 ms&lt;/td>
&lt;td>0.5 ms&lt;/td>
&lt;td>2.0 ms&lt;/td>
&lt;td>500&lt;/td>
&lt;td>4.00×&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;em>(Illustrative figures with &lt;code>T_fixed&lt;/code> rounded; the point is the pattern, not the decimal. The real &lt;code>T_fixed&lt;/code> depends on the stack, the PyTorch/CUDA version and whether there is tensor parallelism. Measure it in your own setup before believing any row.)&lt;/em>&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 780 300" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Per-step time breakdown: large model versus small model">
&lt;text x="390" y="24" text-anchor="middle" fill="currentColor" font-size="13" font-weight="600">Decode time breakdown per step (batch 1)&lt;/text>
&lt;!-- 70B -->
&lt;text x="40" y="78" fill="currentColor" font-size="12" font-weight="600">70B BF16&lt;/text>
&lt;text x="40" y="94" fill="currentColor" font-size="11">step ≈ 44 ms&lt;/text>
&lt;rect x="160" y="60" width="560" height="40" fill="#d4ecff" stroke="#1f5fa8" stroke-width="1.4"/>
&lt;rect x="704" y="60" width="16" height="40" fill="#f6caca" stroke="#a52a2a" stroke-width="1.4"/>
&lt;text x="440" y="85" text-anchor="middle" fill="#1f5fa8" font-size="12" font-weight="600">T_HBM (weights from HBM) ≈ 95 %&lt;/text>
&lt;text x="712" y="118" text-anchor="middle" fill="#a52a2a" font-size="10" font-weight="600">T_fixed ~5%&lt;/text>
&lt;!-- 3B -->
&lt;text x="40" y="190" fill="currentColor" font-size="12" font-weight="600">3B BF16&lt;/text>
&lt;text x="40" y="206" fill="currentColor" font-size="11">step ≈ 8 ms&lt;/text>
&lt;rect x="160" y="172" width="420" height="40" fill="#d4ecff" stroke="#1f5fa8" stroke-width="1.4"/>
&lt;rect x="580" y="172" width="140" height="40" fill="#f6caca" stroke="#a52a2a" stroke-width="1.4"/>
&lt;text x="370" y="197" text-anchor="middle" fill="#1f5fa8" font-size="12" font-weight="600">T_HBM ≈ 75 %&lt;/text>
&lt;text x="650" y="197" text-anchor="middle" fill="#a52a2a" font-size="11" font-weight="600">T_fixed ≈ 25 %&lt;/text>
&lt;!-- note -->
&lt;text x="160" y="252" fill="currentColor" font-size="11">Same absolute T_fixed (~2 ms): noise in the 70B, a quarter of the step in the 3B.&lt;/text>
&lt;text x="160" y="270" fill="currentColor" font-size="11">CUDA graphs attack the red band → disproportionate impact in the SLM.&lt;/text>
&lt;text x="160" y="288" fill="#5a2db0" font-size="11" font-weight="600">The roofline only models the blue band. The SLM bottleneck lives in the red one.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;h2 id="implications-per-optimisation">Implications per optimisation&lt;/h2>
&lt;p>With the model in hand, the blog&amp;rsquo;s levers reorder themselves once the regime changes.&lt;/p>
&lt;p>&lt;strong>Batching: far more headroom in SLMs.&lt;/strong> Remember that you cross the ridge at &lt;code>B ≈ ridge/2 ≈ 150&lt;/code> as an order of magnitude. In a large model, VRAM runs out long before you saturate compute (weights + KV do not let you reach batch 150). In an SLM the weights take up little space, so you can fit large batches in VRAM and stay memory-bound over a much wider range: the &lt;code>T_HBM&lt;/code> of the weights is amortised across the B requests (you load them once, they serve B), so aggregate throughput per GPU rises almost linearly with B until very high values. This is exactly the opposite of the 70B&amp;rsquo;s fear of saturating compute. In SLMs, &lt;strong>batching is the throughput lever par excellence&lt;/strong> because you saturate compute late; the &lt;a href="https://blog.lo0.es/en/posts/vllm-batch-sizing-two-hour-grid-search/">batch grid search in vLLM&lt;/a> has a much wider plateau of good behaviour. Careful: batching improves &lt;em>throughput&lt;/em>, not per-request &lt;em>latency&lt;/em>; for single-stream latency the prize is in &lt;code>T_fixed&lt;/code>.&lt;/p>
&lt;p>&lt;strong>Speculative decoding: a different crossover point.&lt;/strong> &lt;a href="https://blog.lo0.es/en/posts/speculative-decoding-fundamentals-maths-state-of-play/">Speculative&lt;/a> wins when verifying γ tokens is &amp;ldquo;almost free&amp;rdquo; because you are memory-bound. In an SLM the target is already cheap, so the draft has to be tiny for &lt;code>c = T_draft/T_target&lt;/code> to stay small, and the draft&amp;rsquo;s own &lt;code>T_fixed&lt;/code> (launching its kernels) bites harder. The crossover to compute-bound with batching also arrives earlier in absolute terms of tok/s served. The variant that fits best here avoids a separate draft: &lt;a href="https://blog.lo0.es/en/posts/self-speculative-decoding-model-gets-ahead-of-itself/">self-speculative / early-exit&lt;/a> reuses early layers of the model itself and saves the &lt;code>T_fixed&lt;/code> of orchestrating two models.&lt;/p>
&lt;p>&lt;strong>Quantisation: it helps for capacity, not for latency at batch 1.&lt;/strong> As the table showed, INT4 in an SLM at batch 1 gives diminishing returns in latency. Its real prize in SLMs is &lt;strong>capacity&lt;/strong>: weights 4× smaller free VRAM for more KV cache → more concurrency, and it is at high concurrency (aggregate throughput) that saving bytes pays off again. &lt;a href="https://blog.lo0.es/en/posts/aggressive-quantisation-4-bit-to-ternary/">Aggressive sub-4-bit and ternary quantisation&lt;/a> takes this to the extreme: in SLMs it makes sense above all for fitting more sessions per GPU, not for lowering the latency of a single one. And it is worth remembering (see &lt;a href="https://blog.lo0.es/en/posts/quantization-llm-inference-fp8-int4-gguf/">quantisation&lt;/a>) that at batch 1 the &lt;code>dequantize&lt;/code> adds compute work which, in a regime already grazed by &lt;code>T_fixed&lt;/code>, is not always free.&lt;/p>
&lt;p>&lt;strong>Architecture: fine-grained MoE changes which bytes you move.&lt;/strong> A &lt;a href="https://blog.lo0.es/en/posts/device-native-architectures-fine-grained-moe-pre-attention-router/">fine-grained device-native MoE&lt;/a> activates few parameters per token, so &lt;code>T_HBM&lt;/code> drops relative to a dense model of the same total size, but the &lt;code>T_fixed&lt;/code> fraction rises even further, and the router adds its own fixed overhead. It is the SLM regime taken to its limit: almost the whole game is played in orchestration.&lt;/p>
&lt;p>&lt;strong>Scheduler and CUDA graphs first.&lt;/strong> The operational conclusion, inverted with respect to the large-model posts: in SLMs, &lt;strong>before touching the model, kill &lt;code>T_fixed&lt;/code>&lt;/strong>. CUDA graphs (see &lt;a href="https://blog.lo0.es/en/posts/sms-cuda-streams-cuda-graphs-inference/">SMs, streams and graphs&lt;/a>), a &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">vLLM scheduler&lt;/a> with its Python part minimised or compiled, and kernel persistence are the first-order levers. In a 70B they would be marginal polish; in a 3B they are half the available speedup.&lt;/p>
&lt;h2 id="applied-to-on-premise-hardware">Applied to on-premise hardware&lt;/h2>
&lt;p>&lt;strong>On an RTX 4090 (24 GB, Ada Lovelace).&lt;/strong> This is the scenario where the flip is most visible, because the 4090 has ~1 TB/s (a third of the H100) but &lt;code>T_fixed&lt;/code> is the same in absolute terms. A 3B BF16 without CUDA graphs leaves ~125 tok/s on the table when the memory-bound ceiling is 166; enabling graphs and cleaning up the scheduler recovers most of that. The 4090 has plenty of VRAM room for an SLM, so the bottleneck is almost never total memory but orchestration and, at high concurrency, the KV cache. Rule of thumb: on a 4090 with an SLM, profile the per-step overhead first (Nsight Systems on the gap between kernels) before you quantise.&lt;/p>
&lt;p>&lt;strong>On a generic 4×H100 SXM cluster (320 GB, NVLink, native FP8).&lt;/strong> The H100 has 3.35 TB/s, so the &lt;code>T_HBM&lt;/code> of an SLM is even smaller (a 3B FP8 is ~3 GB → ~0.9 ms) and &lt;code>T_fixed&lt;/code> dominates even earlier: a badly orchestrated SLM on an H100 can spend more time in the Python scheduler than moving weights. Serving a single single-stream SLM on an H100 is close to a waste; the right mode is &lt;strong>aggressive batching&lt;/strong> (you saturate compute late, so you push large batches through and per-GPU throughput takes off) or multiplexing many SLMs/sessions per GPU via MPS/MIG. This connects with &lt;a href="https://blog.lo0.es/en/posts/capacity-planning-on-premise-llm-inference/">capacity planning&lt;/a>: for SLMs the capacity calculation is governed by concurrency and KV cache, not by the weights. And with the dilemma of &lt;a href="https://blog.lo0.es/en/posts/one-big-replica-or-many-small-ones-platform-decision/">one big versus N small&lt;/a>: replicating SLMs makes sense precisely because each replica saturates compute late and TP brings nothing (the model already fits; TP would only add communication &lt;code>T_fixed&lt;/code>).&lt;/p>
&lt;h2 id="what-we-have-not-covered">What we have not covered&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>The exact measured &lt;code>T_fixed&lt;/code>&lt;/strong>, kernel by kernel, with Nsight Systems: how much is launch, how much scheduler, how much sampling. That is the content of the next post in the series.&lt;/li>
&lt;li>&lt;strong>&lt;code>torch.compile&lt;/code> / partial captures&lt;/strong>: alternatives and complements to CUDA graphs when there is dynamic control flow.&lt;/li>
&lt;li>&lt;strong>The prefill regime in SLMs&lt;/strong>: prefill is compute-bound even in small models (it processes many tokens at once, high AI), so its roofline is the opposite of decode&amp;rsquo;s; see &lt;a href="https://blog.lo0.es/en/posts/optimising-prefill-vllm-knobs-ttft-will-not-forgive/">prefill&lt;/a>.&lt;/li>
&lt;li>&lt;strong>Attention and KV as the second term of &lt;code>T_HBM&lt;/code>&lt;/strong>: here we have folded them in implicitly; the fine-grained breakdown of attention (which scales with sequence length, not with the weights) deserves its own treatment.&lt;/li>
&lt;/ul>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache: the working memory of inference&lt;/a> — the memory-bound nature of decode is born in the KV cache; in SLMs the KV comes to dominate relative VRAM earlier than in large models.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-batch-sizing-two-hour-grid-search/">Batch sizing grid search in vLLM&lt;/a> — the plateau of good batch sizes is much wider in SLMs because you cross the ridge late; that post gives the empirical method.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/optimising-decode-vllm-squeezing-every-token-small-hardware/">Optimising decode in vLLM&lt;/a> — the concrete flags (CUDA graphs, eager vs captured) whose impact this post reorders for the SLM case.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/optimising-prefill-vllm-knobs-ttft-will-not-forgive/">Optimising prefill in vLLM&lt;/a> — the compute-bound flip side of the roofline: prefill already lives above the ridge even in small models.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/sms-cuda-streams-cuda-graphs-inference/">SMs, CUDA streams and CUDA graphs&lt;/a> — the mechanism that attacks &lt;code>T_fixed&lt;/code>; here we explain why its prize is disproportionate in SLMs.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">The vLLM scheduler step&lt;/a> — much of &lt;code>T_fixed&lt;/code> lives in this Python loop; in SLMs minimising it is a first-order lever.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/quantization-llm-inference-fp8-int4-gguf/">Quantisation for inference&lt;/a> — why weight quantisation yields less latency at batch 1 in SLMs (Amdahl&amp;rsquo;s law over &lt;code>T_HBM&lt;/code>) and more in capacity.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/speculative-decoding-fundamentals-maths-state-of-play/">Speculative decoding: fundamentals&lt;/a> — the memory/compute crossover point shifts in SLMs, changing when speculative pays off.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/capacity-planning-on-premise-llm-inference/">Capacity planning for on-premise inference&lt;/a> — for SLMs, capacity is governed by concurrency and KV, not by the weights; that post gives the formulas.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/one-big-replica-or-many-small-ones-platform-decision/">One big versus N small&lt;/a> — replicating SLMs beats TP because each replica saturates compute late and TP only adds communication &lt;code>T_fixed&lt;/code>.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/self-speculative-decoding-model-gets-ahead-of-itself/">Self-speculative decoding / early-exit&lt;/a> — sibling in the series: speeding up without a separate draft, avoiding the &lt;code>T_fixed&lt;/code> of orchestrating two models, a natural fit in SLMs.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/device-native-architectures-fine-grained-moe-pre-attention-router/">Fine-grained device-native MoE&lt;/a> — sibling in the series: the SLM regime taken to its limit, where the router and orchestration dominate over &lt;code>T_HBM&lt;/code>.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/aggressive-quantisation-4-bit-to-ternary/">Aggressive sub-4-bit and ternary quantisation&lt;/a> — sibling in the series: why in SLMs sub-4-bit pays off mostly in capacity/concurrency, not in latency at batch 1.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Williams, S., Waterman, A., Patterson, D. &lt;em>Roofline: An Insightful Visual Performance Model for Multicore Architectures&lt;/em>. Communications of the ACM, 52(4), 2009. &lt;a href="https://doi.org/10.1145/1498765.1498785">https://doi.org/10.1145/1498765.1498785&lt;/a>&lt;/li>
&lt;li>&lt;em>Mind the Memory Gap: Unveiling GPU Bottlenecks in Large-Batch LLM Inference&lt;/em>. arXiv:2503.08311, 2025. &lt;a href="https://arxiv.org/abs/2503.08311">https://arxiv.org/abs/2503.08311&lt;/a>&lt;/li>
&lt;li>Databricks. &lt;em>LLM Inference Performance Engineering: Best Practices&lt;/em>. &lt;a href="https://www.databricks.com/blog/llm-inference-performance-engineering-best-practices">https://www.databricks.com/blog/llm-inference-performance-engineering-best-practices&lt;/a>&lt;/li>
&lt;li>NVIDIA. &lt;em>NVIDIA H100 Tensor Core GPU Datasheet&lt;/em>. &lt;a href="https://resources.nvidia.com/en-us-tensor-core/nvidia-tensor-core-gpu-datasheet">https://resources.nvidia.com/en-us-tensor-core/nvidia-tensor-core-gpu-datasheet&lt;/a>&lt;/li>
&lt;li>NVIDIA. &lt;em>GeForce RTX 4090 — product specifications&lt;/em> (Ada Lovelace tensor core figures; treat as approximate, they mix dense/sparse).&lt;/li>
&lt;li>Yuan, Z. et al. &lt;em>LLM Inference Unveiled: Survey and Roofline Model Insights&lt;/em>. arXiv:2402.16363, 2024 — application of the roofline specifically to LLM inference.&lt;/li>
&lt;/ul></description></item></channel></rss>