Majid Al-RaimiSegmentation, generative models and LLMs

COE 592Lecture 01Part 02

Segmentation, generative models and LLMs

Promptable segmentation, diffusion models, 3D perception and large language models push computation and memory far beyond classification, and each has an efficient counterpart that recovers speed without losing quality.

Concepts
5
Slides
9-16
Reading
30 min
Understood
0/5 concepts

Why this part matters

Part 01 measured the price of accuracy on ImageNet. This part follows the same question into the models that define the field today: promptable segmentation, image and video diffusion, 3D perception in a moving car, and large language models. In every case the same move rescues the system: find the block that dominates the cost, then attack that block and only that block.

Every research direction in this course (quantisation, pruning, distillation, efficient attention, distributed inference) is motivated by one of the five cases here, and this is also how you scope a PhD project on embedded ML. Exam questions turn the slide numbers into arithmetic: bytes per parameter, speedup versus MAC ratio, frame budgets in milliseconds. Each concept below ends with that arithmetic worked out so you can do it from memory.

By the end you can

  1. Name SAM's three blocks, say which one dominates the cost, and explain what EfficientViT-SAM swaps to reach 48.9x.
  2. Explain why compute follows tokens and denoising steps rather than parameters, and why diffusion cost is super-quadratic in resolution.
  3. Compare naive patch parallelism with DistriFusion on MACs, latency and artifacts, and account for the gap between 4.0x less work and 3.0x speedup.
  4. Turn frames per second into a frame time and show which of Fast-LiDARNet's two levers crosses the 30 fps line.
  5. Convert parameters and precision into bytes and GPU counts, and give the three reasons LLMs must also run at the edge.

Picture a head-mounted camera looking at a door, a small label reading id 27, 52 cm, and a green mask painted over one region. A single click on the door produced that mask. That is what promptable means. The user supplies a hint, a point, a box or a phrase, and the model returns the object the hint refers to. The Segment Anything Model (SAM) from Kirillov et al. was trained on SA-1B, over one billion masks on 11 million images, so it can do this for objects it has never been told about.

The architecture matters more than the demo. SAM is three blocks. An image encoder, a ViT-H pre-trained with masked autoencoding, reads the image once and produces an image embedding. A prompt encoder turns sparse prompts (points, boxes, text) and dense prompts (masks) into prompt embeddings. A lightweight mask decoder combines the two and outputs a valid mask. The paper is explicit about the asymmetry: the image encoder runs once per image, and given a precomputed embedding, the prompt encoder and mask decoder run in a web browser, on a CPU, in about 50 ms. Encode once, expensively; prompt many times, cheaply.

The image encoder is the big block. It fills once per image, then the prompt encoder and decoder answer any number of prompts at almost no cost

SAM's three blocks

Image encoder
ViT-H, 641.1 M parameters, 2973 GMACs per image, runs once per image
Prompt encoder
Points, boxes and text (sparse), masks (dense); tiny
Mask decoder
Fuses image and prompt embeddings into a valid mask; with the prompt encoder, about 50 ms on a browser CPU

Attack the block that dominates

Once you see that the encoder holds 2973 GMACs and the rest is a 50 ms CPU job, the efficiency strategy writes itself. EfficientViT-SAM (Zhang, Cai and Han) keeps SAM's prompt encoder and mask decoder unchanged and replaces only the image encoder with EfficientViT, the multi-scale linear attention backbone from Cai et al. (ICCV 2023). Training happens in two stages: first the new encoder is distilled from SAM's ViT-H encoder as the teacher, then the whole model is trained end to end on SA-1B. Nothing else in the pipeline moves.

SimulatorSwap the block that dominates
Image encoder

Hover, tap or focus a block to see what it costs and whether EfficientViT-SAM touches it.

A100 TensorRT FP16 throughput11 img/s
SAM-ViT-H baseline 11 img/sscale to 800 img/s
Speedup1.0x11 ÷ 11 img/s
Encoder MACs cut1.0x2973 GMACs divided by the new encoder
Zero-shot COCO mAP46.5the baseline

Numbers from Table 1 of the EfficientViT-SAM paper. The prompt encoder and mask decoder are identical in every configuration, which is why swapping only the encoder moves the whole bar.

The fair way to judge the swap is accuracy against speed on the same hardware: zero-shot COCO mAP against A100 throughput with TensorRT in FP16. Zero-shot here has a precise meaning: the models were never trained on COCO, and they are evaluated with boxes from a ViTDet detector as prompts. Two speedups get quoted, and they belong to different models. The 16.5x figure is EfficientViT-SAM-XL1, which is faster and more accurate than SAM (47.8 versus 46.5 mAP). The 48.9x headline belongs to EfficientViT-SAM-L2, which matches SAM at 46.6 mAP while running 538 images per second instead of 11. The full table from the paper makes the families visible.

ModelEncoder paramsEncoder MACsThroughput (img/s)mAPSpeedup vs SAM-ViT-H
SAM-ViT-H641.1 M2973 G1146.51x
EfficientViT-SAM-XL1203.3 M322 G18247.816.5x
EfficientViT-SAM-XL0117.0 M185 G27847.525.3x
EfficientViT-SAM-L261.3 M69 G53846.648.9x
EfficientViT-SAM-L147.7 M49 G63846.258.0x
EfficientViT-SAM-L034.8 M35 G76245.769.3x
EfficientSAM25.3 M247 G18344.416.6x
EdgeSAM9.6 M20 G44942.140.8x
MobileSAM9.8 M39 G27838.725.3x
Zero-shot COCO instance segmentation, A100 with TensorRT FP16 (EfficientViT-SAM, Table 1)

Worked example

Compute reduction versus measured speedup

  1. MAC ratio

    SAM-ViT-H to L2: 2973 / 69 ≈ 43.1x fewer encoder MACs.
  2. Throughput ratio

    538 / 11 ≈ 48.9x more images per second.
  3. Compare

    The measured speedup is larger than the MAC ratio. MACs are a hardware-neutral proxy; the real number also depends on memory access patterns and how well TensorRT kernels run linear attention.
  4. Result

    43x less arithmetic bought 49x more throughput. MACs predict the direction, not the exact size, of a speedup.

The table carries a second lesson. EfficientSAM has 25.3 M encoder parameters, eight times fewer than XL1's 203.3 M, and yet the two run at the same throughput (183 versus 182 img/s), with EfficientSAM losing 3.4 mAP. Model size is about memory; speed is about MACs, memory traffic and kernels. Keep the three apart.

Quick check

Which block of SAM does EfficientViT-SAM replace to get its speedup?

Quick check

What does zero-shot mean for the COCO mAP on slide 10?

Recall

Name SAM's three blocks and say which one runs once per image.

Image encoder (runs once per image and dominates the cost), prompt encoder, lightweight mask decoder.

Recall

What does EfficientViT-SAM change, what does it keep, and what are the throughput and mAP of its 48.9x variant against SAM-ViT-H?

It replaces only the image encoder with EfficientViT and keeps the prompt encoder and mask decoder. L2 runs at 538 versus 11 img/s with 46.6 versus 46.5 zero-shot COCO mAP.

Type "teddy bears working as mad scientists", "a bowl of soup as a planet on a 1960s poster" or "an astronaut riding a horse on Mars" into Midjourney and a finished picture comes back. A diffusion model produced each one from a sentence, by starting from noise and removing a little of it at every step until an image appears. The results look effortless. The bill is not. Emad Mostaque, then CEO of Stability AI, said that training Stable Diffusion used 256 A100 GPUs for about 150,000 GPU-hours at a cost of about $600,000, the figure the lecture uses as Stable Diffusion's training cost.

Worked example

What $600,000 of training looks like

  1. Wall-clock time

    150,000 GPU-hours / 256 GPUs ≈ 586 hours, which is about 24.4 days with every GPU busy the whole time.
  2. Price per GPU-hour

    $600,000 / 150,000 GPU-hours = $4.00 per A100-hour.
  3. Cross-check

    256 GPUs × 24 h × 24.4 days ≈ 149,900 GPU-hours, matching the stated total.
  4. Result

    One training run: a rack of 256 accelerators for most of a month. Nobody iterates on that budget casually, which is why efficient training and inference are research topics rather than polish.

Stable Diffusion training run, 2022

GPUs
256 × A100
GPU-hours
about 150,000
Wall clock
about 24 days
Cost
about $600,000
Implied price
about $4 per GPU-hour
RunA100sGPU-hoursWall clockCost
Stable Diffusion, 2022256about 150,000about 24 daysabout $600,000
MosaicML SD2 base, 2023128about 21,0006.8 daysunder $42,000
The original run next to MosaicML's SD2 base run

Why parameters are not the cost

Training is paid once. Inference is paid on every request, so compare what one forward pass costs in MACs across four very different models. The natural expectation is that the biggest model costs the most. The numbers say otherwise, and the reason is the most important idea in this concept.

ModelParametersWorkloadMACsRatio
ViT-H0.6 B518 x 518 image, one forward pass1.02 Tbaseline
Llama 3 8B8 B1,024-token context, 512 output tokens11.2 T11x ViT-H
FLUX.112 B1K x 1K image, one denoising step37.2 T36x ViT-H, 3.3x Llama 3
CogVideoX5.6 B480 x 720, 49 frames, one denoising step332 T8.9x FLUX.1, 326x ViT-H
MACs for one pass, from slide 12 (log axis on the slide)

FLUX.1 has 12 B parameters and CogVideoX has 5.6 B, yet CogVideoX needs 8.9x the MACs per step. Llama 3 8B has more parameters than ViT-H by a factor of thirteen but costs eleven times more, not thirteen, and FLUX.1 with 1.5x the parameters of Llama 3 costs 3.3x as much. Parameters alone predict none of these ratios. What predicts them is how many tokens each model pushes through those parameters. A dense transformer spends roughly one multiply-accumulate (two FLOPs) per parameter per token in its linear layers, and on top of that attention compares every token with every other token.

MACs per passNparamsNtokens+cNtokens2d\text{MACs per pass} \approx N_{\text{params}}\,N_{\text{tokens}} + c\,N_{\text{tokens}}^{2}\,d
Why tokens, not parameters, set the bill: a linear term and a quadratic attention term

Now the numbers make sense. ViT-H sees one 518 × 518 image cut into 14-pixel patches, 37 × 37 = 1,369 tokens: 632 M × 1,370 ≈ 0.87 T for the linear layers, and the attention term adds the rest of the 1.02 T. Llama 3 processes about 1,500 tokens. FLUX.1 works on the latent of a 1K × 1K image, about 4,000 tokens. CogVideoX compresses 49 frames of 480 × 720 video into 13 latent frames and denoises them all at once, about 17,500 tokens, roughly four times FLUX.1. Because the attention term grows with the square of that count, the bill grows far more than four times, and the smaller parameter count cannot save it. Read the linear term as the weights each token actually passes through, not the headline parameter count: for FLUX.1 the naive 12 B × 4,096 ≈ 49 T overshoots the 37.2 T bar because image and text tokens use separate weights in its double-stream blocks. One accounting rule explains the ordering of the chart: compute is parameters times tokens, plus attention.

One more multiplier hides in the words "single step" under the FLUX.1 and CogVideoX bars. A diffusion model repeats its forward pass once per denoising step. With a 50-step sampler, one 1K FLUX.1 image costs 37.2 T × 50 = 1,860 T MACs, and a CogVideoX clip costs 332 T × 50 = 16,600 T. A classifier pays its bar once; a generator pays it fifty times.

Resolution is worse than quadratic

Now hold the model fixed and vary only the image side length for FLUX.1, from 1024 to 4096. Going four times wider makes the image sixteen times larger in pixels, so a quadratic law would predict sixteen times the MACs. From the slide's left chart, one step at 1K x 1K costs 37.2 T, and the curve on the right ends near 1,950 T at 4096: a factor of about 52, far above the 16x a quadratic law predicts. This is what the lecture calls super-quadratic scaling, and the formula above explains it. Tokens grow with pixels (16x), the linear term grows with tokens (16x), and the attention term grows with tokens squared (256x). The blend lands at about 52x.

SimulatorFLUX.1 cost versus resolution
1024 × 1024
05001000150020001024153620482560307235844096MACs (T), one denoising stepdashed: quadratic in side lengthsolid: fit to the slide, dots: slide readings
Pixels1,048,5761024 squared, 1.0x the 1024 image
Latent tokens4,096(side ÷ 16) squared, typical latent patching
MACs per step37.2T1.0x the 1024 cost
Quadratic reference37.2Tif cost only followed pixel count
Token-linear share31.6Tlinear layers, grows with tokens
Attention share5.6Tgrows with tokens squared
50-step image1,860Tper-step MACs times sampler steps

The solid curve is 31.6 (s/1024)^2 + 5.6 (s/1024)^4 trillion MACs, fitted to the two end points of the slide chart. It is a teaching model of the slide curve, not a profile of FLUX.1 itself.

FLUX.1 MACs per step read off the slide chart, by image side

1024
about 37 T
1536
about 94 T
2048
about 207 T
2560
about 406 T
3072
about 728 T
3584
about 1,226 T
4096
about 1,950 T

Worked example

Fitting the slide curve

  1. Model

    Let r = side / 1024 and write MACs(r) = A r² + B r⁴: a token-linear part and an attention part.
  2. Fit the end points

    A + B = 37.2 at r = 1 and 16A + 256B = 1950 at r = 4, so B ≈ 5.6 T and A ≈ 31.6 T.
  3. Check the middle

    At 2048: 4 × 31.6 + 16 × 5.6 ≈ 216 T (chart about 207 T). At 3072: 9 × 31.6 + 81 × 5.6 ≈ 741 T (chart about 728 T).
  4. Result

    At 1024 attention is about 15% of the cost. At 4096 it is about three quarters. This is why efficient attention (the EfficientViT backbone from the previous concept, FlashAttention, linear attention) is a research area of its own.

Quick check

Why does one CogVideoX step cost more MACs than one FLUX.1 step?

Quick check

FLUX.1 MACs rise from about 37 T at 1024 to about 1,950 T at 4096, roughly 52x, while pixels grow 16x. What best explains that?

Recall

256 A100s for 150,000 GPU-hours: how many days is that, and what price per GPU-hour does $600,000 imply?

150,000 / 256 ≈ 586 hours, about 24 days. $600,000 / 150,000 = $4 per GPU-hour.

Recall

Why does CogVideoX with 5.6 B parameters need 8.9x the MACs of FLUX.1 with 12 B parameters?

It denoises a stack of latent frames per step, about four times FLUX.1's token count. Compute follows tokens (and tokens squared for attention), not parameter count.

Recall

From 1024 to 4096, how much do pixels grow and how much do FLUX.1 MACs grow, and why the difference?

Pixels grow 16x, MACs about 52x. The linear layers scale with tokens, but attention scales with tokens squared, so the total is super-quadratic in side length.

Ask SDXL for a "Romantic painting of a ship sailing in a stormy sea" at high resolution. One GPU paints one ship in 12.3 s. The obvious way to go faster is to cut the canvas into four vertical strips, hand each strip to its own GPU, and let them work without talking. The result is 3.9x faster and wrong: four strips, four ships, four different skies. Each patch generated its own picture because no patch could see the others.

Four isolated patches each paint their own ship. Let each patch read its neighbours' activations from the previous step and one ship spans the frame

DistriFusion (Li et al., CVPR 2024) keeps the split and restores the context. The trick rests on a property of diffusion: consecutive denoising steps produce similar activations, because each step removes only a little noise. So a patch can attend to its neighbours' activations from the previous step instead of waiting for the current one. The paper calls this displaced patch parallelism. The first few denoising steps (the warm-up: the first step plus four more in the paper) run synchronous patch parallelism so everyone starts from the same picture; after that, communication runs asynchronously and hides behind computation. No retraining is needed. The latency drops to 4.16 s, 3.0x faster than one GPU, and the ship is one ship.

SetupMACs per deviceWork per deviceLatencySpeedupQuality
Original, 1 GPU907 T1x12.3 s1xreference image
Naive patches, 4 GPUs190 T4.8x less3.14 s3.9xduplicated subjects
DistriFusion, 4 GPUs227 T4.0x less4.16 s3.0xno artifacts
DistriFusion, 8 GPUs (paper, not on the slide)113 T8.0x less2.74 s4.5xno artifacts
SDXL at 1280 x 1920, 50-step Euler sampler, A100 GPUs (DistriFusion teaser; slide 13 shows the first three rows)

Worked example

Where the work went

  1. Naive total

    190 T × 4 = 760 T, less than the original 907 T. Naive patches skip all cross-patch attention, so the total work drops. The missing 147 T is exactly the missing context.
  2. DistriFusion total

    227 T × 4 = 908 T ≈ 907 T. The full computation is preserved and simply divided by four.
  3. Ideal latency

    12.3 s / 4 ≈ 3.08 s if four GPUs were perfectly parallel. Naive lands at 3.14 s, DistriFusion at 4.16 s.
  4. Result

    DistriFusion does 4.0x less work per GPU but runs only 3.0x faster. The difference is the cost of exchanging activations between GPUs and of the synchronous warm-up steps.
parallel efficiency=speedupdevices=3.04=75%\text{parallel efficiency} = \frac{\text{speedup}}{\text{devices}} = \frac{3.0}{4} = 75\%
Naive patches reach 3.9 / 4 = 98% by skipping work; DistriFusion pays 25% for keeping the picture whole

The pattern is general in distributed systems: splitting work across machines helps only when the compute you save exceeds the communication you add. Here the saving is large because a high-resolution diffusion step is enormous (MACs in the hundreds of trillions), and the communication is hidden behind it. The paper also runs a scaling study on a larger image, 3840 × 3840, shown in the table below. Read down the efficiency column: every added GPU still helps, but each device contributes less than the last, because the communication grows while the per-device work shrinks.

A100sSpeedup over one GPUMarginal speedupParallel efficiency
11xreference100%
21.8x1.8x90%
43.4x1.9x85%
86.1x1.8x76%
DistriFusion on SDXL at 3840 x 3840, A100s (paper; same 50-step Euler sampler as the table above, a larger image). Marginal column divides each speedup by the one above it

Quick check

DistriFusion cuts MACs per GPU 4.0x but latency only 3.0x. What explains the gap?

Quick check

Where does a DistriFusion patch get context about its neighbours?

Recall

What artifact does naive patch parallelism produce, and why?

Duplicated subjects (four ships for one prompt), because the patches never see each other and each generates its own composition.

Recall

Why is 190 T times 4 less than the original 907 T?

Naive patches skip the cross-patch attention, so they do less total work. DistriFusion's 227 T × 4 = 908 T preserves the whole computation.

A 2015 Toyota Prius V with a roof-mounted Velodyne LiDAR drives a wooded test track. A network reads raw 3D point clouds and produces steering. A car does not care how elegant the network is; it cares whether the answer arrives before the deadline the system sets. Three measurements tell the story: MinkowskiNet at 5 fps is "too slow to drive", the same network with optimised kernels reaches 18 fps, and Fast-LiDARNet reaches 47 fps, above the 30 fps line the slide marks as real time.

Kernel optimisation lifts 5 fps to 18 fps and still misses the 30 fps line. Only the redesigned model crosses it

The most useful way to read fps is to invert it into a frame time. A stream at 30 fps gives you 33.3 ms per frame, and everything the model does must fit inside that budget.

tframe=1000 msfpst_{\text{frame}} = \frac{1000\ \text{ms}}{\text{fps}}
Frame time from frame rate

Frame times behind the bars

Budget at 30 fps
33.3 ms
MinkowskiNet, 5 fps
200 ms, 167 ms over budget
Optimised kernels, 18 fps
55.6 ms, 22 ms over budget
Fast-LiDARNet, 47 fps
21.3 ms, 12 ms to spare

The paper (Liu, Amini, Zhu, Karaman, Han and Rus, ICRA 2021) is explicit about the two levers. Their optimised sparse convolution kernel gives a 3.6x acceleration, and their hardware-aware model design reduces latency by another 2.6x. The two multiply: 3.6 × 2.6 ≈ 9.4, which is 47 / 5. The first lever is pure systems work: the same network, the same accuracy, better code for the sparse operations point clouds need. The second is algorithmic: a smaller architecture chosen with the hardware in mind. This pairing is what the lecture means by algorithm and system co-design. Neither lever alone reaches the line. Kernels take the network from 200 ms to 55.6 ms and still miss by 22 ms; the redesign brings it to 21.3 ms.

ConfigurationRateFrame timeLeverInside 33.3 ms?
MinkowskiNet5 fps200 msnoneno, 167 ms over
MinkowskiNet, optimised sparse kernels18 fps55.6 mssystem: 3.6xno, 22 ms over
Fast-LiDARNet47 fps21.3 msalgorithm: 2.6x more, 9.4x totalyes, 12 ms to spare
Three configurations from slide 14

Quick check

Kernel optimisation lifts MinkowskiNet to 18 fps. Why is that still not enough?

Recall

Name Fast-LiDARNet's two levers with their multipliers and the resulting frame rates.

Sparse-convolution kernel optimisation, 3.6x (5 to 18 fps), and hardware-aware model design, 2.6x (18 to 47 fps), 9.4x in total.

Recall

What is the frame budget at 30 fps, and what is MinkowskiNet's frame time at 5 fps?

1000 / 30 ≈ 33.3 ms budget; 1000 / 5 = 200 ms per frame.

MT-NLG, the largest model on the lecture's chart, has 530 billion parameters. Store each one in FP16, two bytes, and the weights alone occupy 530 × 10⁹ × 2 = 1,060 GB. The largest GPU of that period, an A100 with 80 GB, holds 40 billion FP16 parameters. The gap between the two is 1,060 / 80 = 13.25, so 14 GPUs of weights before a single activation is computed.

To compare a model with a chip, put both on one log axis of model size by converting GPU bytes into a parameter count at FP16, which is what the lecture's assumption "data are FP16" means. 16 GB becomes 8 B parameters, 32 GB becomes 16 B, 80 GB becomes 40 B. On that shared axis the two curves tell the story of the large language model era: model size climbs from 0.05 B to 530 B, about 10,000x in roughly four years, while GPU memory climbs from 16 GB to 80 GB, 5x. Models have outgrown the chips they run on, and the distance keeps widening.

Model parameters climb about 10,000x while GPU memory climbs about 5x on the same FP16 axis. The gap at 2022 is 13x
ModelYearParametersFP16 weightsA100 80 GB GPUs
Transformer20170.05 B0.1 GB1
GPT20180.11 B0.22 GB1
BERT-Large20180.34 B0.68 GB1
GPT-220191.5 B3 GB1
Megatron-LM20198.3 B16.6 GB1
T-NLG202017 B34 GB1
GPT-32020175 B350 GB5
MT-NLG2021 (paper 2022)530 B1,060 GB14
Models on the chart, FP16 weight memory and A100 80 GB count for weights alone
AcceleratorMemoryFP16 parameters it holds
TPU v216 GB8 B
V10032 GB16 B
TPU v332 GB16 B
A10040 GB20 B
A10080 GB40 B
Accelerators on the chart

Parameters to bytes to GPUs

Every memory question in this course starts with one multiplication. Parameters times bytes per parameter gives the weight memory; divide by the memory of one device and round up to get the device count. The bytes per parameter depend on the numeric format: 4 for FP32, 2 for FP16 or BF16, 1 for INT8, 0.5 for INT4. Quantisation, which later lectures cover in depth, is simply the art of moving down that list without losing accuracy.

weight bytes=Nparams×bytes per param,GPUs=weight bytesGPU bytes\text{weight bytes} = N_{\text{params}} \times \text{bytes per param}, \qquad \text{GPUs} = \left\lceil \frac{\text{weight bytes}}{\text{GPU bytes}} \right\rceil
Weights only; activations and the KV cache come on top

Worked example

MT-NLG on A100 80 GB GPUs

  1. FP16

    530 B × 2 bytes = 1,060 GB; 1,060 / 80 = 13.25, so 14 GPUs for the weights alone.
  2. INT8

    530 B × 1 byte = 530 GB; 530 / 80 = 6.6, so 7 GPUs.
  3. INT4

    530 B × 0.5 byte = 265 GB; 265 / 80 = 3.3, so 4 GPUs.
  4. Result

    Every halving of precision halves the shelf. The same rule says an 80 GB card holds at most 40 B FP16 parameters, and that leaves zero room for anything else.
SimulatorParameters to bytes to GPUs
Precision
Weight memory1,060 GB530 B × 2 bytes per parameter
A100 80 GB GPUs14ceil of GB ÷ 80, weights only
A100 40 GB GPUs27ceil of GB ÷ 40, weights only
One A100 80 GBDoes not fit
needs 1,060 GBof 80 GB
Phone, 4 GB RAM: 265 phonesDoes not fit
Microcontroller, 1 MB weight storageDoes not fit

Weights only. Activations and the KV cache add memory that grows with batch size and context length, so a model that just fits here does not run. GB means 10^9 bytes. The 4 GB is the RAM slide 23 gives mobile AI (its activation-memory row), which holds weights and activations together; the 1 MB is the flash weight storage it gives a microcontroller.

Try Llama 3 8B in the calculator. In FP16 it needs 16 GB, four times the 4 GB of RAM slide 23 gives a phone. Slide 23 lists that 4 GB as activation memory and 256 GB as weight storage; in practice LLM inference loads the weights into that same RAM, so the 4 GB is the binding limit. In INT4 the model needs 4 GB, exactly at the line, with nothing left for activations. Now try the 2017 Transformer at 0.05 B against a microcontroller's 1 MB of weight storage: 100 MB in FP16, a hundred times over. The gap between what models need and what edge hardware has is the subject of part 03.

Why run them at the edge anyway

If LLMs barely fit in a rack of cloud GPUs, why does the lecture insist on running them on laptops, cars and robots? Three reasons, each one a research direction in this course.

  1. Copilot services, such as code completion, office assistants and in-game chat, running locally on the machine that uses them. Latency drops, and the service works in a car or a robot far from any data center.
  2. Resource-constrained, low-power devices that are not always connected. An edge LLM must work when the link is slow or absent.
  3. Privacy of user data. Prompts contain code, documents and conversations, and a local model never uploads them.

This is the design space for an on-device assistant, and it is why the rest of the course is about shrinking the memory (quantisation, pruning), the compute (efficient attention, distillation) and the deployment (compilers, kernels) of exactly the models on this chart. For a PhD project on embedded ML, the two-slope chart is the problem statement.

Quick check

A 175 B parameter model is stored in INT8. What is its weight memory?

Quick check

Why can 16 GB of GPU memory be drawn as 8 B parameters?

Recall

What is the FP16 weight memory of MT-NLG, and how many A100 80 GB GPUs does it need for weights alone?

530 B × 2 bytes = 1,060 GB; 1,060 / 80 = 13.25, so 14 GPUs before activations or the KV cache.

Recall

How many FP16 parameters fit in 16 GB, and how much did model size and GPU memory grow over the chart?

8 B parameters. Model size grew about 10,000x and GPU memory about 5x.

Recall

Give the three reasons on slide 16 for running LLMs at the edge.

Local copilot services on laptops, cars and robots; resource-constrained low-power devices that are not always connected; privacy of personal data that should not be uploaded.

Recap

If you remember nothing else

  • SAM is an image encoder that runs once per image and dominates the cost, plus a prompt encoder and a lightweight mask decoder that together run in about 50 ms on a CPU.
  • EfficientViT-SAM replaces only the image encoder: 538 versus 11 img/s (48.9x) at 46.6 versus 46.5 zero-shot COCO mAP.
  • Training Stable Diffusion took 256 A100s for 150k GPU-hours, about 24 days and about $600,000, so about $4 per GPU-hour.
  • Compute follows tokens times steps: CogVideoX with 5.6 B parameters needs 332 T MACs per step, 8.9x FLUX.1's 37.2 T with 12 B parameters.
  • FLUX.1 MACs grow about 52x from 1024 to 4096 while pixels grow 16x, because attention is quadratic in token count.
  • DistriFusion on 4 GPUs: 227 T MACs per device (4.0x less), 4.16 s (3.0x faster), no duplicated subjects. Naive patches are 3.9x faster but fragment the image.
  • Fast-LiDARNet: kernel optimisation 3.6x, model redesign 2.6x, 5 to 47 fps against a 30 fps (33.3 ms) budget.
  • Model size grew about 10,000x in four years while GPU memory grew about 5x; 530 B FP16 parameters are 1,060 GB, or 14 A100 80 GB GPUs for weights alone.
  • Edge LLMs exist for local copilots on laptops, cars and robots, for low-power devices that are not always connected, and for privacy.

Sources