Majid Al-RaimiReference sheet

COE 592Lecture 01Reference

Reference sheet

Why efficient deep learning compressed onto one page: the definitions, formulas and numbers to have in your head before a quiz or exam.

The course question and the three pillars

Keep accuracy as high as possible under the budget the target device imposes. Progress comes from algorithm, hardware and data improving together; efficiency work reshapes the first two. Part 01: Accuracy at a cost

maxθ, A Acc(θ,A)s.t.MACsC,  MemoryM,  LatencyT,  EnergyE\max_{\theta,\ \mathcal{A}}\ \text{Acc}(\theta, \mathcal{A}) \quad \text{s.t.}\quad \text{MACs} \le C,\ \ \text{Memory} \le M,\ \ \text{Latency} \le T,\ \ \text{Energy} \le E
Efficient deep learning as a budgeted optimization
PillarAlexNet 2012Efficiency lever
AlgorithmDeep CNN, ReLU, dropout, SGDPruning, quantization, distillation, NAS
HardwareTwo GTX 580 GPUs, 3 GB each, about six daysAccelerators: cloud GPU, phone NPU, Jetson, microcontroller
DataImageNet, about 1.2 million images, 1000 classesData that stays on the device and drives local learning
Three pillars, what each gave AlexNet in 2012, and the efficiency lever
  • Privacy: raw data stays where it was collected.
  • Cost: fewer GPU hours, smaller cloud bills, less carbon (OFA: one specialized net per target emits the CO2 of five cars).
  • Connectivity: the model works where the network does not.
  • Energy: milliwatt devices need models sized for milliwatts.

ImageNet metrics and the winners

errtop-5=1Ni=1Nminj{1,,5}1[cijCi]\text{err}_{\text{top-5}} = \frac{1}{N}\sum_{i=1}^{N} \min_{j \in \{1,\dots,5\}} \mathbb{1}\big[c_{ij} \ne C_i\big]
Image i is wrong only if none of its five labels equals the true label
PropertyTop-5 errorTop-1 accuracy
Counts as correct whenAny of five returned labels matchesThe single top label matches
StrictnessLenient, always the better scoreStrict, always the worse score
Used on slide45, 6
Typical pairingabout 5% error75 to 80% accuracy
Top-5 error versus top-1 accuracy
YearWinnerTop-5 error (%)
2010NEC28.2
2011XRCE25.8
2012SuperVision (AlexNet), first deep CNN winner16.4
2013Clarifai11.7
2014GoogLeNet, 22 layers6.7
2015ResNet, 152 layers, first below human3.57
2016Trimps-Soushen2.99
2017SENet2.25
HumanOne trained annotator5.1
ILSVRC winning entries, top-5 error on the test set

MACs, parameters and diminishing returns

A MAC is one multiply plus one accumulate, counted per input, independent of hardware. Parameters count storage. One MAC is two FLOPs when a source counts them separately; the ResNet paper labels multiply-adds as FLOPs, so its 3.8 x 10^9 equals Sze's 3.9 GMACs. Part 01: Accuracy at a cost

MACsconv=HoutWoutCoutCinkhkw\text{MACs}_{\text{conv}} = H_{\text{out}} \cdot W_{\text{out}} \cdot C_{\text{out}} \cdot C_{\text{in}} \cdot k_h \cdot k_w
3 x 3, 64 in, 64 out, 56 x 56 map: 56 x 56 x 64 x 64 x 9 = 115.6 M MACs
ModelMACs (B)Top-1 (%)Parameters
MobileNetV10.5770.64.2 M
ResNet-503.976.025.5 M
InceptionV35.778.8about 24 M
ResNet-1017.676.444.5 M
Xception8.479.0about 23 M
Once-for-All (searched)0.59580.0about 7 M
Slide 5 and 6 anchors (x is MACs, y is top-1, bubble area is parameters, goal is the upper left)

Points of top-1 per extra billion MACs

MobileNetV1 to ResNet-50
(76.0 - 70.6) / (3.9 - 0.57) = 1.6 points per billion
ResNet-50 to Xception
(79.0 - 76.0) / (8.4 - 3.9) = 0.67 points per billion
ResNet-50 to ResNet-101
(76.4 - 76.0) / (7.6 - 3.9) = 0.11 points per billion

Efficient models and the Pareto frontier

Reduction ratio is reference MACs divided by new MACs in one unit. Once-for-All: 80.0% at 595 M MACs, inside the 600 M mobile setting. Part 01: Accuracy at a cost

ReferenceMACsTop-1 (%)Reduction
Xception8400 M79.08400 / 595 = 14.1x
ResNet-503900 M76.03900 / 595 = 6.6x
MobileNetV1569 M70.60.96x, 9.4 points less accurate
Once-for-All against handcrafted references
AB    AccAAccB  MACsAMACsB, with at least one strictA \succ B \iff \text{Acc}_A \ge \text{Acc}_B \ \wedge\ \text{MACs}_A \le \text{MACs}_B,\ \text{with at least one strict}
Dominance; the frontier is the set of undominated models, and NAS moves it to the upper left

TinyML and on-device learning

MCUNet runs mask and person detection on an OpenMV Cam (Cortex-M7). Reference MCU STM32F746: 320 kB SRAM, 1 MB flash, no OS, no DRAM. TinyNAS searches under the memory limits; TinyEngine runs without interpreter overhead. Part 01: Accuracy at a cost

TierMemoryStorageGap from the tier above
Cloud AI (V100)16 GBTB to PBreference
Mobile AI (iPhone 11)4 GBmore than 64 GB4x memory, 1000x storage
Tiny AI (STM32F746)320 kB1 MB3100x memory, 64000x storage
MCUNet Table 1

Why nothing off the shelf fits

ResNet-50 FP32 weights
25.5 M x 4 B = 102 MB, 102x over 1 MB flash
ResNet-50 INT8 weights
25.5 MB, still 25x over
MobileNetV2 peak activation
6.8 MB FP32 (22x), 1.7 MB INT8 (5.3x) over 320 kB SRAM
MCUNet result
3.5x less SRAM, 5.7x less flash; 70.7% top-1 on STM32H743
ResourceInferenceTraining
Compute per exampleOne forward passforward + backward, about 3x
ActivationsFreed layer by layerAll kept until the backward pass returns
Extra stateWeights onlyWeights, gradients, optimizer moments
Memory scalingLargest single layerGrows with depth and batch size
Inference versus training

Naive training state on a microcontroller

MobileNetV1 weights, FP32
4.2 M x 4 B = 16.8 MB
Gradients and momentum
2 more copies = 33.6 MB
Total before activations
50.4 MB, about 157x over 320 kB SRAM
Lin et al. 2022
training under 256 kB

SAM and EfficientViT-SAM

SAM is an image encoder (ViT-H, runs once per image, dominates cost), a prompt encoder and a lightweight mask decoder (together about 50 ms on a browser CPU). EfficientViT-SAM replaces only the encoder. Zero-shot means COCO was never in training; prompts are ViTDet boxes. Part 02: Generative and large models

ModelEncoder paramsEncoder MACsimg/smAPSpeedup
SAM-ViT-H641.1 M2973 G1146.51x
EfficientViT-SAM-XL1203.3 M322 G18247.816.5x
EfficientViT-SAM-L261.3 M69 G53846.648.9x
EfficientSAM25.3 M247 G18344.416.6x
MobileSAM9.8 M39 G27838.725.3x
Zero-shot COCO, A100 TensorRT FP16 (EfficientViT-SAM Table 1, selected rows)

Generative compute: tokens times steps

MACs per passNparamsNtokens+cNtokens2d\text{MACs per pass} \approx N_{\text{params}}\,N_{\text{tokens}} + c\,N_{\text{tokens}}^{2}\,d
A linear term in tokens plus a quadratic attention term; multiply by the denoising step count
ModelParametersWorkloadMACs
ViT-H0.6 B518 x 518 image, about 1,370 tokens1.02 T
Llama 3 8B8 B1024 context + 512 output, about 1,500 tokens11.2 T
FLUX.1 (one step)12 B1K x 1K latent, about 4,000 tokens37.2 T
CogVideoX (one step)5.6 B49 frames, 13 latent frames, about 17,500 tokens332 T
Slide 12, MACs for one forward pass

Stable Diffusion training run, 2022

GPUs
256 x A100
GPU-hours
about 150,000
Wall clock
150,000 / 256 = 586 h, about 24 days
Cost
about $600,000, so $4 per GPU-hour
MosaicML 2023 rerun
21,000 A100-hours, under $50,000
SidePixelsMACs per stepMACs ratio
10241xabout 30 T1x
20484xabout 200 T6.7x
30729xabout 720 T24x
409616xabout 1,950 T65x
FLUX.1 per-step MACs against image side (super-quadratic: 16x pixels gives 65x MACs, close to 4^3)

DistriFusion

Each GPU denoises one patch but attends to its neighbours' activations from the previous step (displaced patch parallelism); the first step is synchronous, later communication is asynchronous and hidden. Part 02: Generative and large models

SetupMACs per deviceWork per deviceLatencySpeedupQuality
Original, 1 GPU907 T1x12.3 s1xreference
Naive patches, 4 GPUs190 T4.8x less3.14 s3.9xduplicated subjects
DistriFusion, 4 GPUs227 T4.0x less4.16 s3.0xno artifacts
DistriFusion, 8 GPUs113 T8.0x less2.74 s4.5xno artifacts
SDXL at 1280 x 1920, 50 Euler steps, A100s
parallel efficiency=speedupdevices=3.04=75%\text{parallel efficiency} = \frac{\text{speedup}}{\text{devices}} = \frac{3.0}{4} = 75\%
Naive patches reach 98% by skipping 147 T of cross-patch attention (190 x 4 = 760 T versus 907 T); DistriFusion keeps 227 x 4 = 908 T

Fast-LiDARNet and the frame budget

tframe=1000 msfpst_{\text{frame}} = \frac{1000\ \text{ms}}{\text{fps}}
30 fps is 33.3 ms per frame
ConfigurationRateFrame timeLeverAgainst 33.3 ms
MinkowskiNet5 fps200 msnone167 ms over
Optimised sparse kernels18 fps55.6 mssystem, 3.6x22 ms over
Fast-LiDARNet47 fps21.3 msalgorithm, 2.6x more (9.4x total)12 ms to spare
Three configurations on slide 14 (GTX 1080Ti; the in-car Jetson AGX Xavier runs 11 fps)

LLMs outgrow GPU memory

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
PrecisionBytes per paramWeightsGPUs
FP3242,120 GB27
FP16 or BF1621,060 GB14
INT81530 GB7
INT40.5265 GB4
MT-NLG (530 B) by precision on A100 80 GB cards
ModelYearParametersFP16 weights
Transformer20170.05 B0.1 GB
GPT-220191.5 B3 GB
Megatron-LM20198.3 B16.6 GB
GPT-32020175 B350 GB
MT-NLG2022530 B1,060 GB
Slide 15 models, FP16 weights

Cloud GPUs and the memory wall

TOPS=2×MACs per second1012,TOPS/W=peak TOPSboard power (W)\text{TOPS} = \frac{2 \times \text{MACs per second}}{10^{12}}, \qquad \text{TOPS/W} = \frac{\text{peak TOPS}}{\text{board power (W)}}
Dense figures; NVIDIA's 2:4 sparse figure is exactly double
PartDense FP16 TOPSBandwidth GB/sPower WMemory GBTOPS/W
P100 (2016), PCIe18.7732250160.075
V100 SXM (2017)125900300320.42
A100 SXM (2020)3122,039400800.78
H100 SXM (2022)9903,430700961.41
B100 SXM (2024)1,7508,1927001922.5
Slide 18 values, TOPS per watt computed

Growth from P100 to B100

Dense FP16 TOPS
18.7 to 1,750, about 94x
Board power
250 to 700 W, 2.8x
Memory capacity
16 to 192 GB, 12x
Memory bandwidth
732 to 8,192 GB/s, about 11x
TOPS per watt
0.075 to 2.5, about 33x

Memory wall on an H100

H100 compute
990 x 10^12 dense FP16 ops/s
H100 bandwidth
3.35 x 10^12 bytes/s
Break-even intensity
990 / 3.35 = 295 ops per byte
LLM decoding, batch 1
2 ops per 2-byte weight = 1 op per byte
Trend (Gholami et al.)
FLOPS 3.0x, DRAM bandwidth 1.6x, interconnect 1.4x per 2 years

Edge accelerator families

FamilyPerformancePowerTOPS/WShape
Snapdragon 845 to 8 Gen 13 to 52 TOPS, 17x9 to 10 W, 1.1x0.33 to 5.2fixed thermal lid
Apple A11 to A17 Pro0.6 to 35 TOPS, 58x6 to 8 W, about 1x0.075 to 2.63 (A15)fixed thermal lid
Jetson Nano to AGX Orin 64GB0.5 to 275 TOPS, 550x10 to 60 W, 6x0.05 to 4.6ladder of power tiers
Slides 19 to 21: fixed lid versus power ladder

Which tier for which power budget

Microcontroller
milliwatts (STM32F746 about 360 mW)
Phone SoC
about 10 W, fixed by heat
Robot module (Jetson)
10 to 60 W, configurable
Cloud GPU
250 to 700 W

The microcontroller tier

A microcontroller is a compact integrated circuit for embedded systems that puts a processor, memory and I/O peripherals on a single chip: no OS, no DRAM, milliwatts and kilobytes. Part 03: Hardware gap

DMIPS=Dhrystones per second1757=(DMIPS/MHz)×fclock\text{DMIPS} = \frac{\text{Dhrystones per second}}{1757} = (\text{DMIPS/MHz}) \times f_{\text{clock}}
Integer benchmark normalized to the VAX 11/780; contains no MACs
BoardCoreMHzDMIPSmWSRAMFlash
Arduino ZeroCortex-M0+4845632 kB256 kB
Arduino DueCortex-M3841582696 kB512 kB
STM32F407VGCortex-M4168210132192 kB1 MB
STM32F746NGCortex-M7216462360320 kB1 MB
Slide 22 boards

DMIPS arithmetic

Arm DMIPS/MHz
M0+ 0.95, M3 and M4 1.25, M7 2.14
STM32F746
2.14 x 216 = 462
STM32F407
1.25 x 168 = 210
MCU TOPS upper bound
216 MHz x 2 MACs x 2 ops = 0.0009 TOPS

Cloud, mobile and tiny AI

TierDeviceActivation memoryWeight storageMemory vs tinyStorage vs tiny
Cloud AIA100-class GPU80 GB HBMabout 1 TB or more250,000xabout 1,000,000x
Mobile AIFlagship phone4 GB DRAM256 GB flash12,500x256,000x
Tiny AISTM32F746320 kB SRAM1 MB flash1x1x
Slide 23, with ratios to the tiny tier
80 GB320 kB=80×106 kB320 kB=250,000\frac{80\ \text{GB}}{320\ \text{kB}} = \frac{80 \times 10^{6}\ \text{kB}}{320\ \text{kB}} = 250{,}000
1 GB = 10^6 kB, 1 GB = 10^3 MB

Ratios to have ready

Cloud to mobile, activation
80 GB / 4 GB = 20x
Mobile to tiny, activation
4 GB / 320 kB = 12,500x
Cloud to tiny, activation
80 x 10^6 kB / 320 kB = 250,000x
Mobile to tiny, storage
256 GB / 1 MB = 256,000x
530 B FP16 against tiny
1.06 TB / 1 MB = 1,060,000x
QuantitySizeCloud, 80 GBMobile, 256 GB and 4 GBTiny, 1 MB and 320 kB
FP32 weights102.2 MByes, 783x headroomyesno, 102x over flash
INT8 weights25.6 MByesyesno, 25.6x over flash
Peak activation7.2 MByesyesno, 22.5x over SRAM
Does ResNet-50 (25,557,032 parameters) fit? Two budgets checked separately

Slide errata

Answer with the corrected fact, and name the slide version if a question depends on it. Part 01, Part 02, Part 03

What the slides get wrong

Slide 2
"without loosing accuracy" should read "without losing accuracy".
Slide 5
Legend bubbles 2M to 64M are parameter counts, not MACs. "ResNetXt" means ResNeXt. The chart is Figure 2 of the Once-for-All paper, credited to Deng et al.
Slide 6
"ResNetXt-50" and "ResNetXt-101" are again ResNeXt.
Slide 10
The citation is the EfficientViT backbone paper (Cai et al., ICCV 2023). The 48.9x result is Zhang, Cai and Han, arXiv 2402.05008. "EfficientVIT" should read EfficientViT.
Slide 15
The x axis skips 2019 with uneven spacing, so slopes are distorted. "MegatronLM" is Megatron-LM (8.3 B). The 2017 Transformer has 65 M (base) and 213 M (big), rounded to 0.05 B.
Slide 18
"Memory Bendwidth" means Bandwidth. H100 96 GB is an OEM SXM5 SKU, and 3,430 GB/s matches neither the 80 GB (3.35 TB/s) nor the 96 GB part. P100 values are the PCIe card (SXM2 was 300 W). B100 1,750 is the dense half of 3.5 PFLOPS sparse.
Slide 20
No A17 power is plotted, so its TOPS/W cannot be computed. The A13 6 TOPS is NanoReview's figure; the A17 Pro 35 TOPS comes from Apple's 2023 event.
Slide 21
Standard TX2 has 8 GB (4 GB is the TX2 4GB variant). The series mixes precisions: Nano and TX2 in FP16, Xavier INT8, Orin sparse INT8. The caption credits NanoReview but the URL is Connect Tech.
Slide 22
"on a single" is missing "chip". "KB" should be kB. STM32F407VG has 192 kB SRAM plus 4 kB backup, not 196 kB. Due's 158 DMIPS implies 1.88 DMIPS/MHz; Arm rates the M3 at 1.25 (105).
Slide 23
Cloud and mobile columns were updated from MCUNet's 2020 table (V100 16 GB, iPhone 11 more than 64 GB) to 80 GB and 256 GB; the tiny column is unchanged, so the columns are not one dated snapshot.
Slide 24
The MIT course is 6.5940, "TinyML and Efficient Deep Learning Computing" (Fall 2024 page), now "TinyML and Efficient AI Computing". The slide omits year and URL.