Log inStart free
LESSON 36.04 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

On-device inference

Watch an 8B model fit and run on a laptop, a phone and a board.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 36.04 · INFERENCE BAYINT4 · NEEDS 4.83 GB · FITS 4 OF 4
01
Stage 1 of 5 · Fit in memory
In INT4 the on-device copy needs 4.83 GB. It fits in the free memory of all four machines.
Explain it simply

Each bar is one machine's memory, all on the same scale. The ochre part is the weights. The dashed part at the end is kept by the operating system and other apps. If the weights do not fit in what is left, the model cannot load at all.

Four memory bars. The cloud needs 16.38 GB and has 80.00 GB free: it fits. The laptop needs 4.83 GB and has 12.00 GB free: it fits. The phone needs 4.83 GB and has 5.00 GB free: it fits. The board needs 4.83 GB and has 6.50 GB free: it fits.

weights, compute unitsprompt, prefill, KV cachedecode, tokens backdoes not fit, network waitOS and apps, your device
memory of each machineweight bytes per formatcloud H10080 GB · 3.35 TB/s · in a data centerBF16 needs 16.38 GB of 80.00 GB free · fitsweights 16.06 GB · KV cache 0.068 GB · buffers 0.25 GBlaptop16 GB · 120 GB/sOS 4 GBINT4 needs 4.83 GB of 12.00 GB free · fitsweights 4.52 GB · KV cache 0.068 GB · buffers 0.25 GBphone8 GB · 60 GB/sOS 3 GBINT4 needs 4.83 GB of 5.00 GB free · fitsweights 4.52 GB · KV cache 0.068 GB · buffers 0.25 GBembedded board8 GB · 68 GB/s · edge deviceOSINT4 needs 4.83 GB of 6.50 GB free · fitsweights 4.52 GB · KV cache 0.068 GB · buffers 0.25 GBBF16 · 16 bits a weight · 16.06 GB8.03 G weights × 16 bits ÷ 8INT8 · 8.5 bits a weight · 8.53 GB8.03 G weights × 8.5 bits ÷ 8 (code + a 16-bit scale per 32)INT4 · 4.5 bits a weight · 4.52 GB8.03 G weights × 4.5 bits ÷ 8 (code + a 16-bit scale per 32)on-device need = weights + KV cache + buffers4.52 + 0.068 + 0.25 ≈ 4.83 GBthe cloud keeps BF16: 16.38 GBmemory of each machineweight bytes per formatcloud H10080 GB · 3.35 TB/s · in a data centerBF16 needs 16.38 GB of 80.00 GB free · fitsweights 16.06 GB · KV cache 0.068 GB · buffers 0.25 GBlaptop16 GB · 120 GB/sOS 4 GBINT4 needs 4.83 GB of 12.00 GB free · fitsweights 4.52 GB · KV cache 0.068 GB · buffers 0.25 GBphone8 GB · 60 GB/sOS 3 GBINT4 needs 4.83 GB of 5.00 GB free · fitsweights 4.52 GB · KV cache 0.068 GB · buffers 0.25 GBembedded board8 GB · 68 GB/s · edge deviceOSINT4 needs 4.83 GB of 6.50 GB free · fitsweights 4.52 GB · KV cache 0.068 GB · buffers 0.25 GBBF16 · 16 bits a weight · 16.06 GB8.03 G weights × 16 bits ÷ 8INT8 · 8.5 bits a weight · 8.53 GB8.03 G weights × 8.5 bits ÷ 8 (code + a 16-bit scale per 32)INT4 · 4.5 bits a weight · 4.52 GB8.03 G weights × 4.5 bits ÷ 8 (code + a 16-bit scale per 32)on-device need = weights + KV cache + buffers4.52 + 0.068 + 0.25 ≈ 4.83 GBthe cloud keeps BF16: 16.38 GB
Toy: 29.C6's 8B model and chat request (512 + 8 tokens); four machines with round specs
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
M=N⋅b/8+KV+buf\sy{m}{out}{M} = \sy{w}{param}{N \cdot b / 8} + \sy{kv}{data}{\text{KV}} + \text{buf}
M=8.03 G⋅4.5/8+0.068+0.25≈4.83 GBM = 8.03\,\text{G} \cdot 4.5 / 8 + 0.068 + 0.25 \approx 4.83\,\text{GB}

Memory is the weights plus the KV cache plus the buffers.

Common mix-ups

MYTHIf the model downloads, a laptop or a phone can run it.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01In INT8, does the 8B model still fit in the phone's free memory?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.