MCUNet and TinyML

MobileNetV2 needs 1,372 kB of working memory. A tiny chip has 256 kB. MCUNet cuts the need to 172 kB, 8 times less, by running the first layers one patch at a time.

Learn why deep learning does not fit on a microcontroller, how to count the memory it needs, and how TinyNAS and patch-based inference make it fit.

Pick a chip. Switch from whole layers to patches, then drag how many early blocks run patch by patch. Watch the tallest bar fall under the chip line. Then we build, piece by piece, the memory count, the search, the patches and the three tiny applications.

You need the idea of a convolution layer (a small filter slides over an image) and a little Python for the code. We build the rest from zero.

Based on Lecture 10 of MIT 6.5940 TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. The lecture slides are on the course page. Every idea is re-taught here in our own words and devices. It follows Lecture 9, Knowledge Distillation and leads into Lecture 11, TinyEngine.

Fit MobileNetV2 on the chip

5

Bars from MobileNetV2's layer sizes at 224 by 224, int8, 1 kB = 1,024 bytes: its 1,372 kB peak and its 172 kB result. The 256 kB and 320 kB chips are the lecture's boards, and 512 kB is for contrast. A patch bar is the block's memory divided by the patch count, a simplified view that skips the held output. The lecture shows about 10 percent more MACs for the full patch stage. Fewer blocks scale that down in a straight line, which is our guess.

Chapter 0

Tiny AI Starts With a Memory Gap of 100,000 Times

See why billions of tiny chips want deep learning, and why a model that fits a phone cannot fit them

A farmer clips a two dollar sensor board to a water pump. It runs on a coin battery for a year. Its job is to hear the pump rattle and send one message. Can that board run a neural network?

Three places a model can live

Cloud AI sends your data to GPUs or TPUs in a data center. Mobile AI runs the model on your phone. Tiny AI runs it on IoT devices and microcontrollers.

An IoT device (Internet of Things) is a small gadget with a sensor and a network link. A microcontroller (MCU) is a whole computer on one cheap chip, often with no operating system. The lecture's reasons to go tiny:

The gap in numbers

Two kinds of memory matter. Memory is the desk: fast working space. On a chip it is SRAM. Storage is the bookshelf: slow and large, and it keeps its contents with the power off. On a chip it is Flash.

TierMemory (desk)Storage (bookshelf)
Cloud AI32 GBterabytes to petabytes
Mobile AI4 GB256 GB
Tiny AI320 kB1 MB

Divide to see the gap. 32 GB is 32,000,000 kB, and 32,000,000 / 320 = 100,000. A phone gives 4,000,000 / 320 = 12,500, which the lecture rounds to 13,000 times.

Does the model fit? Try it

Hold the model against three bookshelves

Each bar is the storage of one tier, on a log scale. The vertical line is the size of the model's weights. A bar that reaches the line can hold the model.

Tier sizes from the lecture; cloud storage is drawn as 1 TB. GPT-3 and BERT sizes come from the lecture's growth chart, the others are the usual published counts. Weight size is parameters times bits / 8, weights only.

MobileNetV2 in int8 has 3.4 MB of weights. A phone holds that easily. The tiny chip's 1 MB of Flash is 3.4 times too small, and MobileNetV2 was built to be small. The lecture's rule: reduce both the weights and the activations. Chapter 1 defines activations.

A third wall

Mobile AI fights two limits: latency and energy. Tiny AI adds a third, memory, and all three bind at once. A fast, frugal model still fails if it does not fit.

  1. Count the two memories: Flash holds the model, SRAM holds the working data.
  2. Design together: why a better network or a better library alone is not enough.
  3. Choose the search space: input size and width before any search.
  4. Search with shared weights: one super network, many sub-networks.
  5. The imbalance: the early blocks set the peak.
  6. Patches: run the early layers one tile at a time.
  7. The halo: the price of tiles, and how to cut it.
  8. MCUNetV2: results and a look inside the winning network.
  9. Vision and audio: wake words, detection and keyword spotting.
  10. Anomalies: an autoencoder on a fan.
  11. Field guide: numbers, code and links.
MobileNetV2 in int8 needs 3.4 MB for its weights. Why can a phone run it but a tiny chip with 1 MB of Flash cannot?

Chapter 1

Count the Two Memories of a Chip: Flash and SRAM

Add up the stored model and the working memory of every layer, and find the one layer that sets the limit

Your tiny image model has 5 kB of weights. You load it on a chip with 256 kB of SRAM, and the program crashes. The weights are not the problem.

Two kinds of numbers

Weights are the numbers in the convolution kernels, the small filters that slide over the image. Training sets them, and they never change at run time, like a recipe. Activations are the grids that flow between layers, new for every input, like dough. Weights sit in Flash. Activations sit in SRAM.

The simple estimate

The lecture's count skips temporary buffers and code size. Call the bytes of the input activation of layer l inl and of its output outl. Each is height × width × channels × bytes per number.

Say it aloud

Peak SRAM equals the max over l of in-l plus out-l.

Peak SRAM
peak SRAM the working memory the chip must have, in bytes. Weights are left out: the chip fetches them from Flash in pieces.
maxl
the max over l the largest value over all layers l. One bad layer sets it, not the average.
inl
in-l the bytes of the input activation of layer l.
outl
out-l the bytes of the output activation of layer l.
In plain words

For each layer l, add in-l and out-l. Keep the largest sum. That is the peak SRAM.

With numbers

Below, layer 3 has in-3 = 221,184 B and out-3 = 55,296 B. The sum, 276,480 B, is the largest, so the peak is about 276 kB: over a 256 kB chip.

Flash is static: the chip must hold the whole model. Call the number of weights in layer l paramsl and the bytes per weight b.

Say it aloud

Flash equals the sum over l of params-l times b.

Flash
Flash the storage the model needs, in bytes.
Σl
the sum over l add one term for every layer l.
paramsl
params-l the number of weights in layer l.
b
b the bytes per weight: 1 in int8, 4 in 32 bit float.
In plain words

Count the weights params-l of every layer, add them, and multiply by b.

With numbers

The four layers below have 432, 1,536, 864 and 2,304 weights. With b = 1, Flash = 5,136 B, about 5 kB. The peak SRAM is 54 times larger.

One network, every number

Take a 96 × 96 input with 3 colour channels in int8, then four layers. Here 1 kB is 1,000 bytes.

  1. Layer 1, a 3×3 convolution with stride 2 (the filter moves two pixels at a time, so the grid halves), 3 to 16 channels. Input 96×96×3 = 27,648. Output 48×48×16 = 36,864. Sum: 64,512 B. Weights: 3×3×3×16 = 432.
  2. Layer 2, a 1×1 convolution that expands 16 channels to 96. Input 36,864. Output 48×48×96 = 221,184. Sum: 258,048 B. Weights: 16×96 = 1,536.
  3. Layer 3, a depthwise 3×3 convolution with stride 2, 96 channels. Input 221,184. Output 24×24×96 = 55,296. Sum: 276,480 B. Weights: 9×96 = 864.
  4. Layer 4, a 1×1 convolution that projects 96 channels to 24. Input 55,296. Output 24×24×24 = 13,824. Sum: 69,120 B. Weights: 96×24 = 2,304.
pythondef memory(layers, bytes_per=1):          # layers: [(in_shape, out_shape, n_weights), ...]
    size = lambda s: s[0] * s[1] * s[2] * bytes_per     # H x W x C numbers
    sram  = [size(i) + size(o) for i, o, _ in layers]     # per layer: input + output
    flash = sum(w for _, _, w in layers) * bytes_per   # static: every weight
    return flash, max(sram), sram.index(max(sram))  # Flash, peak SRAM, worst layer

Try it on a whole network

Find the layer that breaks the chip

Seven bars, one per layer: input activation (light) plus output (dark). The dashed line is the chip's SRAM, and a bar over it turns red.

96 × 96
1.00

A toy network made for this lesson: a 3×3 stride 2 stem, then expand, depthwise and project with expansion 6, int8.

Width 0.50 halves the channels, and the network fits. Doubling the input size quadruples the activations, so resolution is the strongest knob.

Real models against the real limit

ModelPeak SRAM over a 320 kB chip
ResNet-5023 times
MobileNetV222 times
MobileNetV2, int85 times

At about 70 percent ImageNet accuracy, MobileNetV2-0.75 has 4.6 times fewer parameters than ResNet-18, but only 1.8 times less peak activation. MCUNet cuts both: 6.1 and 3.4 times.

The failure: checking only the model size

Symptom: the model file is small, and the board still resets. Measure input plus output per layer: layer 3 needs 276 kB of a 256 kB chip. Fix: shrink the activations (a smaller input, narrower early layers), or change how the layers run.

A layer takes a 48×48×96 int8 input and gives a 24×24×96 output. Its weights are 864 bytes. How much SRAM does this layer need, by the lecture's simple rule?

Chapter 2

Design the Model and the Engine Together

Compare two one-sided fixes with the MCUNet loop, where the network and the runtime shape each other

You must furnish a small room. You can buy a smaller sofa, or rearrange the room so the old sofa fits. Often neither works alone. The lecture calls choosing both together system-algorithm co-design: the sofa is the network, and the room is the software that runs it.

Two one-sided fixes

Every network needs a library, the code that runs each layer on the chip. On a 256 kB chip they can take a third of the memory:

Fix (a) is neural architecture search (NAS): a program searches for a network on top of a fixed library. Fix (b) tunes the library for a fixed network.

ApproachFixedChangedExampleLimit
(a) Search the modelLibraryNetworkProxylessNAS, MnasNetCan only shrink the network until it squeezes in
(b) Tune the libraryNetworkLibraryTVM, a compilerCannot shrink an activation that is too large
(c) MCUNetNothingBothTinyNAS with TinyEngineEach side is shaped by the other

The MCUNet loop

TinyNAS designs the network for the chip's memory. TinyEngine compiles and runs it, and optimizes its code for that network. If the engine saves memory, the search can pick a wider network, and the design improves in turns. This lecture covers TinyNAS. Lecture 11 covers TinyEngine.

Call the model's peak SRAM from Chapter 1 peakmodel. Call the buffers and runtime data that the library adds overheadlibrary, and the chip's SRAM SRAMchip.

Say it aloud

Peak-model plus overhead-library is at most SRAM-chip.

peakmodel
peak-model the largest input plus output activation of any layer, from Chapter 1.
overheadlibrary
overhead-library temporary buffers and runtime data. The lecture's simple count leaves it out for now.
≤
is at most the left side must not be larger than the right side.
SRAMchip
SRAM-chip what the chip has: 256 kB or 320 kB in the lecture's boards.
In plain words

Add overhead-library to peak-model. If the sum is at most SRAM-chip, the model runs.

With numbers

With made-up numbers on a 256 kB chip: a generic library takes 100 kB, so peak-model can be 156 kB. A lean library takes 30 kB and leaves 226 kB, 70 kB more for the model.

Move the sofa, the room, or both

Fit the model and the engine into 256 kB

The tall bar is the chip. The yellow part is the library. The blue part is the model's peak. Pick an approach, then drag the sliders that approach can change.

200 kB
100 kB

Illustrative toy numbers, not from the lecture: libraries of 20 to 100 kB, a fixed 300 kB model for (b), and accuracy 45 + 17 log10(peak / 20) percent.

In (a) the library stays at 100 kB, so the model stops near 155 kB and 60 percent. In (b) the model stays at 300 kB, and even a 20 kB library makes 320 kB: nothing fits. In (c), 20 kB plus 235 kB reaches about 63.

The failure: the model passes the count and fails on the chip

Symptom: your count says 240 kB on a 256 kB chip, but the board runs out of memory. Measure the library's buffers: 40 kB, so the true need is 280 kB, 24 kB over. Fix: put the overhead into the search's memory limit, or make the engine leaner. TinyNAS and TinyEngine do both.

On a 256 kB chip, the library takes 100 kB and your model's peak is 200 kB. What does the co-design idea suggest?

Chapter 3

TinyNAS Stage One: Choose the Search Space First

Pick the input size and width that give the best models under your memory limit, before you search at all

With one hour to buy shoes, the shop you pick matters more than the shoe. In NAS the shop is the search space, the set of networks the search may look at. Its quality largely decides the quality of the model found.

Why the mobile space fails

Reuse a mobile space such as MnasNet, and even its smallest network cannot fit: a phone has 4 GB, a tiny chip 320 kB. The lecture builds a space for the chip instead.

Two knobs make a family of spaces

It scales a MobileNet-like space with two numbers. Resolution R is the side of the input image in pixels. Width multiplier W scales the channels of every layer. Each pair (R, W) is one sub-search space:

Kernel sizes, expansion ratios and blocks per stage stay open for the search in Chapter 4.

Score a space without training

Training every network would take years. The lecture's proxy: more FLOPs (here, multiply-adds) means more capacity, so higher accuracy is likely. Call one sampled network n, and the networks of a space that fit both chip limits fit(R, W). Among them, take p80, the FLOPs value that 80 percent stay at or under.

Say it aloud

Score of R, W equals p-eighty of FLOPs of n, over every n in fit of R, W.

score(R, W)
score of R, W how good this space is for this chip. The highest score wins.
p80
p-eighty the 80th percentile: 80 percent of the values are at or below it.
FLOPs(n)
FLOPs of n the multiply-adds of network n, a stand-in for capacity.
n in fit(R, W)
n in fit of R, W a network sampled from the space (R, W) whose peak SRAM and Flash are both within the chip's limits. This is where the chip enters.
In plain words

Sample networks n from the space. Drop any that break SRAM or Flash. Sort the rest by FLOPs of n and read the value 80 percent of the way up.

With numbers

With made-up numbers, 10 networks fit: 12, 15, 18, 21, 24, 27, 31, 33, 38 and 52 M FLOPs. Eight of ten are at or below 33, so the score is 33 M.

pythondef space_score(nets, sram_kb, flash_kb):        # nets: sampled networks of one (R, W) space
    fit = sorted(n.flops for n in nets
                 if n.peak_sram <= sram_kb * 1000 and n.flash <= flash_kb * 1000)
    if len(fit) < 15: return 0                    # too few fit: a bad space
    return fit[max(0, int(len(fit) * 0.8 + 0.999) - 1)]  # p80

Search the spaces yourself

Pick the best search space for your chip

Top: one cell per space, shaded by the p80 of 300 sampled networks, in M FLOPs. A cross means too few fit. Green outlines the best. Bottom: the curves of your tapped space (teal) and the best (green).

320 kB
1,024 kB

A toy made for this lesson: six stages, depth 1 to 4, expansion 3, 4 or 6, kernel 3, 5 or 7, int8, one fixed random seed. The lecture's curves use far more networks.

Slide the SRAM down: the best resolution drops, because big images make big activations. Slide the Flash up: the best width grows, because wide layers carry more weights. On the lecture's grid, more Flash favours more channels and a smaller resolution. More SRAM favours a larger resolution.

The failure: searching the wrong space

Symptom: the search ends with a mediocre model, or none fits. Measure p80. In the lecture, w0.3-r160 reaches 32.3 M FLOPs, and its best model 74.2 percent. w0.5-r144 reaches 50.3 M and 78.7 percent. Fix: score the spaces with no training, then search the best one.

Space A has p80 = 32 M FLOPs among the networks that fit the chip. Space B has p80 = 50 M. Which do you search, and why?

Chapter 4

TinyNAS Stage Two: Search Inside the Space With Shared Weights

Train one super network, sample sub-networks, reject any that break the memory limit, and keep the rest

A tailor cuts every suit from one bolt of cloth. TinyNAS trains one large network once, then cuts many smaller ones out of it. The lecture calls this stage resource-constrained model specialization, done by one-shot NAS with weight sharing.

One super network, many children

The super network is the biggest network in the space. Every candidate is a sub-network nested inside it, reusing part of its weights:

Training samples sub-networks at random and fine-tunes them together into the same weights. Lecture 8 covers this as Once-for-All.

Check the memory without running anything

Memory follows from shapes, so the chip limits become a hard rule. For each sample, compute peak SRAM and Flash with Chapter 1's count, and reject any that break a limit. Rank the survivors by accuracy with the borrowed weights. That score is an estimate, but it ranks candidates well enough.

One block, by hand: 16 channels at 48×48, expanded 6 times, a 5×5 depthwise filter with stride 2, then a projection to 24 channels.

  1. Expand: input 48×48×16 = 36,864 B. Output 48×48×96 = 221,184 B. Sum: 258,048 B.
  2. Depthwise, stride 2: input 221,184 B. Output 24×24×96 = 55,296 B. Sum: 276,480 B.
  3. Project: input 55,296 B. Output 24×24×24 = 13,824 B. Sum: 69,120 B.
  4. Block peak = 276,480 B, above 256,000 B. Reject. No run was needed.

With expansion 3 the block has 48 channels. Its sums are 147,456, 138,240 and 41,472 B, so its peak is 147,456 B and it survives.

pythondef specialize(supernet, sram, flash, val_set, n=1000):
    best = None
    for _ in range(n):
        net = supernet.sample()                       # kernel, expansion, depth per stage
        if net.peak_sram() > sram or net.flash() > flash:
            continue                                  # reject from shapes alone, no run
        acc = evaluate(net, val_set)                # uses the shared weights
        if best is None or acc > best[0]: best = (acc, net)
    return best

Sample sub-networks yourself

Cut networks from the super network

Top: every dot is a sub-network, placed by peak SRAM (across) and Flash (up), both on a log scale. Bottom: the memory of each block of the network you picked. The dashed line is the chip's SRAM.

0.5
144

The toy family of Chapter 3, not the lecture's space. FLOPs stand in for accuracy, since nothing is trained here.

At width 0.5 and size 144 on the 256 kB chip, about a quarter of the samples fit. A larger input slides the dots right. A wider network moves them up.

What the lecture measured

TinyNAS designs networks with more uniform peak memory per block. In the first two stages, MobileNetV2's tallest block is 2.2 times its average, and TinyNAS brings that to 1.6 times. No block spikes, so a larger model fits.

On Visual Wake Words (is a person in the picture?), MCUNet beats MobileNetV2 and ProxylessNAS in accuracy. It runs 2.4 and 3.4 times faster and needs 3.7 times less peak SRAM. One baseline runs out of memory on the 256 kB chip.

The failure: ranking before filtering

Symptom: the most accurate network, once exported, does not run. Measure: its widest block peaks at 276,480 B, 20,480 B over a 256,000 B chip. Fix: filter every candidate from shapes first, then rank only the survivors.

TinyNAS wants to know whether a sampled sub-network fits a 256 kB chip. How does it find out?

Chapter 5

The First Blocks Hold the Whole Memory Bill

Plot the memory of every block and see that one early block is 8 times too large while the tail is fine

A car park must hold the noon rush, not the quiet hours. Working memory is the same: only the peak counts. MCUNetV2, the second half of the lecture, asks where the noon hour of MobileNetV2 is.

Where the peak hides

A block here is one inverted residual block: three layers that expand the channels, filter them and project them back. MobileNetV2 has a first convolution (block 0) and 17 blocks after it.

The lecture's chart: block 2 needs 1,372 kB, its neighbours 500 to 600 kB, and every block from 5 on under 200 kB. On a 256 kB chip the first five cannot fit and the rest can. The lecture calls this the imbalanced memory distribution of CNNs: cut the first stage, and you cut the whole peak.

Why the head is heavy

Call the grid's height and width H and W, the input channels Cin, and the channels after the expand step Cexp. Each stride 2 step cuts H × W to a quarter, while the channels grow only 1.5 to 2 times.

Say it aloud

Mem is about H times W, times C-in plus C-exp.

mem
mem the block's SRAM need in int8 bytes: its input plus its expanded output. The depthwise step runs in place.
H × W
H times W the number of grid positions. A stride 2 layer cuts it to a quarter.
Cin
C-in the channels that enter the block.
Cexp
C-exp the channels after the expand step: 6 times C-in in MobileNetV2.
In plain words

Count the grid positions, H times W. Multiply by C-in plus C-exp. At one byte per number, that is mem.

With numbers

Block 2 of MobileNetV2: H = W = 112, C-in = 16, C-exp = 96. So 12,544 × 112 = 1,404,928 B. The lecture counts 1 kB as 1,024 B, so mem = 1,372 kB.

BlockGridChannelsInput plus outputMemory
2112 × 11216 to 96200,704 + 1,204,224 = 1,404,928 B1,372 kB
356 × 5624 to 14475,264 + 451,584 = 526,848 B515 kB
528 × 2832 to 19225,088 + 150,528 = 175,616 B172 kB
814 × 1464 to 38412,544 + 75,264 = 87,808 B86 kB

Each row has a grid 4 times smaller and channels 1.5 to 2 times larger, so memory falls 2 to 3 times per row. The tail is not the enemy.

Read the profile yourself

Find the noon hour of the network

Each bar is one block. Bars over the dashed chip line turn red. The outlined bar is the block you chose with the block slider.

2
256 kB

From MobileNetV2's published layer sizes, int8, 1 kB = 1,024 bytes. At 224 it gives the lecture's 1,372 kB peak and the 172 kB plateau at blocks 5 to 7. Accuracy is not modelled.

Drop the input to 96 × 96 and the whole network fits. That is not free: a smaller picture holds less detail, and accuracy falls. Chapter 8 returns to this cost.

The failure: shrinking the wrong thing

Symptom: you halve the channels and quantize to int8, and the model still does not fit. Measure block 2: 112×112×(8 + 48) = 702,464 B, about 686 kB, still 2.7 times the chip. Fix: aim at the block that sets the peak, and change how that stage runs.

In MobileNetV2 the early blocks need far more SRAM than the late blocks, even though the late blocks have more channels. Why?

Chapter 6

Run the Early Layers One Patch at a Time

Cut the image into tiles, push one tile through several layers, and watch the working memory fall

To copy a giant poster on a letter-size copier, you cut it into tiles and copy one at a time. MCUNetV2's patch-based inference does this for the first stage only. It cuts the input into patches (tiles) and runs each one through several layers before the next.

Per-layer against per-patch

Per-layer inference computes all of layer 1, keeps its full output, then computes layer 2. While layer 2 runs, a full input and a full output sit in SRAM together.

Per-patch inference swaps the loops. One tile goes through conv 1 and conv 2, and its small result goes into an output buffer. The big tensors in between never exist. The stage output must stay whole, since later layers need all of it. The lecture notes it is much smaller than the earlier layers.

The memory, with every number

Two layers on a 96×96×3 int8 input. Conv 1 is 3×3, stride 1, 3 to 16 channels. Conv 2 is 3×3, stride 2, 16 to 24 channels.

  1. Per-layer, conv 1: input 96×96×3 = 27,648 B plus output 96×96×16 = 147,456 B = 175,104 B.
  2. Per-layer, conv 2: input 147,456 B plus output 48×48×24 = 55,296 B = 202,752 B. This is the peak, about 203 kB.
  3. Per-patch with 3×3 patches: each patch produces a 16×16 piece of the final output. Conv 2 needs a 33×33 piece of conv 1's output (2 × 16 + 1). Conv 1 needs a 35×35 piece of the input (33 + 2).
  4. One patch, conv 1: 35×35×3 = 3,675 B plus 33×33×16 = 17,424 B = 21,099 B. Conv 2: 17,424 B plus 16×16×24 = 6,144 B = 23,568 B.

Call the bytes of the whole stage output outstage. For one tile, call the input and output of layer l tile-inl and tile-outl.

Say it aloud

Peak-patch equals out-stage plus the max over l of tile-in-l plus tile-out-l.

peakpatch
peak-patch the SRAM the patch stage needs, in bytes.
outstage
out-stage the full output buffer, held for the whole run. It is the floor.
maxl
the max over l the largest value over the layers of the stage.
tile-inl
tile-in-l the bytes of layer l's input for one tile, border included.
tile-outl
tile-out-l the bytes of layer l's output for one tile.
In plain words

Run Chapter 1's count on one tile, not the whole image. Then add out-stage, which stays in SRAM the whole time.

With numbers

From the steps above: out-stage = 55,296 B. The worst tile layer is conv 2, 17,424 + 6,144 = 23,568 B. So peak-patch = 78,864 B, about 79 kB, 2.6 times less than 203 kB.

pythondef patch_stage(x, layers, n, halo):            # x: (H, W, C) input; layers: functions on a tile
    H = x.shape[0]; s = H // n                   # each patch covers s x s input pixels
    out = None                                      # the one big buffer we must hold
    for i in range(n):
        for j in range(n):
            r0, r1 = max(0, i*s - halo), min(H, (i+1)*s + halo)   # tile plus its halo
            c0, c1 = max(0, j*s - halo), min(H, (j+1)*s + halo)
            t = x[r0:r1, c0:c1]
            for f in layers: t = f(t)               # tile through every layer of the stage
            out = write_tile(out, t, i, j, n)      # crop the halo away, place the result
    return out                                      # same tensor as per-layer inference

Cut the poster yourself

Run the stage tile by tile

Left: the input in patches. Purple runs now, and yellow is the border it borrows. Right: peak memory, whole against per patch.

3 × 3

The toy two-layer stage above, exact for inner patches. Border patches need slightly less halo. The real MCUNetV2 stage has several blocks.

At 1 × 1 nothing changes: 203 kB. At 2 × 2 the peak is 108 kB, at 3 × 3 it is 79 kB, and at 6 × 6 it is 61 kB. The bars flatten toward the 55 kB output floor.

What the lecture measured

For MobileNetV2, patching the first stage cuts the peak from 1,372 kB to 172 kB, 8 times less. On an STM32F746, with TinyEngine as the baseline, peak SRAM in kB:

ModelPer layer2 × 2 patches3 × 3 patchesReduction
MobileNetV2 (w0.5, r144)315113644.9 times
MobileNetV2-RD (w0.5, r144)30094515.9 times
FBNet-A (w0.45, r144)310132764.1 times
MCUNet (w1.0, r144)23485564.2 times

"RD" means redistributed (Chapter 7).

The failure: too many patches

Symptom: you add patches, and the peak stops falling while the run slows. Measure: in the toy, 4 × 4 to 6 × 6 lowers the peak only from 68.8 to 61.5 kB. Extra MACs rise from 2.8 to 4.3 percent. Fix: use the fewest patches that fit the chip.

With patch-based inference the peak SRAM of the first stage cannot fall below a floor, however many patches you use. What sets that floor?

Chapter 7

The Halo Costs Extra Work, So Reshape the Network

Measure how tile overlap grows with the receptive field, and shrink it by moving depth later

A convolution at a patch's edge needs pixels from the next patch. That borrowed border is the halo. Both neighbours compute it, so they repeat that work.

Why the halo grows

The receptive field is the area of the input that one output value depends on, like the circle of a torch beam. The lecture's rule: the overlap grows as the receptive field grows.

Walk backward from the output. For one layer, call the width of the output tile tout, the stride s and the kernel size k. The input tile width tin is:

Say it aloud

T-in equals t-out minus one, times s, plus k.

tin
t-in the input positions one patch must read in one direction, halo included.
tout
t-out the output positions the patch must make in that direction.
s
s the stride: one output step moves s steps in the input.
k
k the kernel size: how far one output looks.
In plain words

Step back t-out minus one strides of size s, then add one kernel width k. Repeat for each layer, back to the input.

With numbers

The lecture's pair, conv 3×3 stride 1 then conv 3×3 stride 2, with 12 outputs per side. Conv 2: (12 − 1) × 2 + 3 = 25. Conv 1: (25 − 1) × 1 + 3 = 27. A perfect split needs 24, so the halo is 3 pixels.

So conv 1 computes 25 × 25 = 625 outputs per patch, where a perfect split needs 24 × 24 = 576: 8.5 percent extra work. Each added layer widens the halo, and the early layers pay most.

pythondef halo_overhead(kernels, strides, chans, F, n):  # chans has one more entry than kernels
    L = len(kernels); t = [0] * (L + 1); f = [0] * (L + 1)
    t[L], f[L] = F // n, F                       # patch tile and full map at the stage output
    for l in range(L, 0, -1):                       # walk backward to the input
        t[l-1] = (t[l] - 1) * strides[l-1] + kernels[l-1]
        f[l-1] = f[l] * strides[l-1]
    macs = lambda l, size: size**2 * kernels[l-1]**2 * chans[l-1] * chans[l]
    patched = n*n * sum(macs(l, t[l]) for l in range(1, L+1))
    exact   = sum(macs(l, f[l]) for l in range(1, L+1))
    return patched / exact - 1                     # extra work as a fraction

Measure the halo yourself

Grow the halo, then shrink it

Left: one patch's input, drawn to scale. Purple is the tile's own area, yellow is the halo it borrows. Right: extra work in each layer of the stage, as a percent over a perfect split.

4

A toy stage made for this lesson with plain convolutions. Real MobileNet blocks use cheap depthwise layers, so the lecture's overhead is about 10 percent. Redistribute makes the first kernel 1×1.

With 3×3 kernels, 4 layers and 2 × 2 patches, the extra work is about 22 percent. With 7×7 kernels it is about 79 percent. Back at 3×3, turn on redistribute: the overhead falls to 15 percent.

Network redistribution

The lecture's fix is network redistribution: move receptive field out of the patch stage and into the later per-layer stage. That stage runs on small grids with no tiles, so extra receptive field there costs no halo.

MobileNetV2 does 301 M MACs, and 330 M when run per patch, 10 percent more. MobileNetV2-RD is back to 301 M, with the same performance on classification and detection. Its first patch block drops to a 1×1 kernel, and later blocks gain receptive field.

The failure: patching a deep, wide-kernel stage

Symptom: memory fits, but each prediction is much slower. Measure: in the toy, 5 layers of 5×5 kernels on a 3 × 3 grid do about 117 percent extra work. Fix: keep the patch stage shallow with small kernels, and move receptive field later.

A patch stage uses 7×7 kernels in every layer, and the extra work from overlapping tiles is large. Which change fits the lecture's redistribution idea?

Chapter 8

MCUNetV2 Searches the Network and the Patch Plan Together

Read the results on three tasks, then read what the winning architecture does in each of its stages

MCUNet is TinyNAS plus TinyEngine. MCUNetV2 adds patch-based inference, redistribution, and a joint search over two groups of knobs:

The two shape each other. So the search samples a network with its patch plan, computes peak SRAM from shapes, rejects pairs over the limit, and keeps the most accurate.

Three results

Each panel fixes the chip and changes only the method. ImageNet and VOC use int8. Visual Wake Words (VWW) asks if a person is in the picture. mAP (mean average precision) scores detection, and higher is better.

Task and chipBaselinesMCUNetMCUNetV2
VWW, peak SRAM at 90 percent accuracy (lower is better)none shown119 kB30 kB, 4 times less: fits a 32 kB chip
ImageNet top-1, STM32F412 (256 kB)MobileNetV2 0.35: 49.0; ProxylessNAS 0.3: 56.260.364.9 (+4.6)
ImageNet top-1, STM32F746 (320 kB)none shown68.571.8 (+3.3)
Pascal VOC mAP, STM32F746 (320 kB)MobileNetV2 with CMSIS: 31.651.468.3 (+16.9)

Detection gains most because it needs a larger input, and patches let the network read one in the same memory. Classification suffers less from a small picture, so its gains are smaller.

Read the report card yourself

Compare the methods on one chip

Pick a task. Each bar is one method on that chip. The purple bar is MCUNetV2. Compare bars inside one panel only, since each panel has a different chip or metric.

Figures from the lecture's result slides. The ImageNet bars start at 40 percent and the VOC bars at 20 mAP, as in the lecture's charts, so read the numbers, not the lengths.

Inside the winning network

The lecture opens a network that the joint search found for VWW. It runs per patch on grids of 160, 80, 40 and 20 positions per side, then per layer on 10 and 5. MB4_5×5 means expansion 4 and a 5×5 kernel.

WhereWhat the search choseWhy
Patch stageSmall kernelsSmall kernels keep the halo small, so tiles overlap less (Chapter 7)
Middle stageSmall expansion ratiosThe expand step is where memory spikes, so a small ratio lowers the peak (Chapter 5)
Later stageLarge expansion ratiosThe grids are small there, so a big ratio is cheap in memory and adds accuracy
InputA larger resolution for VWWVWW is resolution sensitive. MCUNet used 128×128

Nobody wrote these rules into the search. The memory limit and the halo cost taught them.

The failure: comparing across panels

Symptom: someone says MCUNet beats MCUNetV2, 68.5 against 64.9. Measure: 68.5 is on the 320 kB chip, and 64.9 on the 256 kB chip, where MCUNet scores 60.3. Fix: compare inside one panel, with the same chip and the same metric.

On the 320 kB chip, MCUNet scores 68.5 percent on ImageNet and MCUNetV2 scores 71.8. What is the correct reading?

Chapter 9

Tiny Vision and Tiny Audio: What Fits on the Chip

Wake a big model with a tiny one, detect at higher resolution, and spot a keyword in sound

A video doorbell watches an empty hallway all day. A large face recognition model would drain its battery. So a tiny model watches first and wakes the large one when a person appears.

Tiny vision: ImageNet on a chip

With int4 quantization (4 bits per number), MCUNet's ImageNet top-1 accuracy rises with chip memory:

ChipSRAM / FlashTop-1
STM32F412256 kB / 1 MB62.0
STM32F746320 kB / 1 MB63.5
STM32F765512 kB / 1 MB65.9
STM32H743512 kB / 2 MB70.7, the first above 70 percent on a commercial MCU
MobileNetV2 with CMSIS-NN, for contrast512 kB / 2 MB53.8

Visual wake words and detection

VWW is the vision version of "Hey Siri". The tiny model asks each camera frame one question: is a person here? Only then does the much larger face recognition model wake.

Detection is more sensitive to input resolution, because it makes a denser prediction. On the lecture's plot, VOC accuracy falls faster than ImageNet accuracy as the input shrinks to 160. Patches fit a larger input in the same memory, so face and person detection run on small boards.

Tiny audio: keyword spotting

Keyword spotting, the audio guard that hears "Hey Siri", runs in three steps. First, cut the sound into overlapping frames. Call the clip length L, the frame length l and the stride s, the gap between frame starts. The number of frames T is:

Say it aloud

T equals L minus small l, over s, plus one.

T
T the number of frames: the columns of the feature grid.
L
big L the length of the clip, in ms.
l
small l the length of one frame, in ms.
s
s the stride: how far the window moves each time, in ms.
In plain words

Take one frame length l from the clip length L. Count how many strides s fit in the rest. Add one for the first frame.

With numbers

A 1,000 ms clip with 40 ms frames and a 20 ms stride: T = (1000 − 40) / 20 + 1 = 49 frames.

Second, turn each frame into spectral coefficients: the energy in each band of pitch, a step designed by hand. With 10 bands the grid is 49 × 10 = 490 numbers. Third, a network gives each word a probability, such as 0.91 for "Yes".

Turn a sound into a grid

Top: a made-up spoken word, with your frame in purple. Bottom: the feature grid, one column per frame, one row per pitch band.

40 ms
20 ms
20

A synthetic sound made for this lesson: two gliding tones from 0.30 s to 0.70 s, read by a Goertzel filter at 10 centres. Real spotters use MFCC features with the same frame logic.

Why a CNN, and how MCUNet helps

A Google study the lecture cites: speech grids have strong links in time and pitch, which a dense network ignores. A CNN slides one filter over the grid, so it also handles speech that shifts with speaking style. It wins at matched multiplies. On Speech Commands, MCUNet's hardware-aware search gives 2 percent higher accuracy, 2.8 times faster inference and 4.1 times less peak memory.

The failure: a stride that is too small

Symptom: keyword spotting works, but the battery drains. Measure: with a 5 ms stride, T = (1000 − 40) / 5 + 1 = 193 frames, 3.9 times the work of a 20 ms stride. Fix: use a stride near half the frame length.

A clip is 1,000 ms. Frames are 50 ms long and start every 25 ms. How many frames does the network read?

Chapter 10

Tiny Anomaly Detection: Learn What Normal Looks Like

Train a small autoencoder on normal data only, then flag any input it rebuilds badly

A factory fan's bearing wears, and its hum changes. There are no labels, only hours of healthy hum. Teach the chip what normal looks like and flag the rest. That is anomaly detection, used in surveillance, health care and fraud prevention.

The autoencoder

An autoencoder is a network that predicts its own input through a narrow middle. The encoder squeezes the input into a short code vector. The decoder rebuilds the input from it, like an artist who draws a face from five words. The lecture lists three properties:

Every number, in four samples

In a tiny world every normal window has four equal samples, so one code number is enough. The direction is v = (1, 1, 1, 1) / 2. Encoding is a dot product, and decoding multiplies the code by v.

  1. Normal x = (0.9, 1.1, 1.0, 1.0). Code c = v · x = (0.9 + 1.1 + 1.0 + 1.0) / 2 = 2.0. Rebuild x′ = c × v = (1, 1, 1, 1).
  2. Odd x = (1.5, −1, 1, −1). Code c = (1.5 − 1 + 1 − 1) / 2 = 0.25. Rebuild x′ = (0.125, 0.125, 0.125, 0.125).

Train on normal data only. Call the live window x, with D samples xi, and its rebuild x′i. The reconstruction error e is:

Say it aloud

E equals the square root of: the sum over i of x-i minus x-prime-i, squared, over D.

e
e the reconstruction error of one window.
√
the square root of undoes the squaring, so e is in the units of the signal.
Σi
the sum over i one term for each sample of the window.
xi
x-i sample i of the live window.
x′i
x-prime-i the decoder's rebuild of sample i.
D
D the samples per window: 4 here, 24 in the device.
In plain words

Subtract each x-prime-i from x-i and square it. Average over the D samples and take the root. If e passes the threshold, flag an anomaly.

With numbers

Normal: squares 0.01, 0.01, 0, 0, so e = √(0.02 / 4) = 0.07. Odd: squares 1.89, 1.27, 0.77, 1.27, so e = √(5.19 / 4) = 1.14. With a made-up threshold of 0.3, the first passes and the second raises the alarm.

pythondef train(normal, k):                         # normal: (N, D) windows of healthy data
    C = normal.T @ normal / len(normal)         # (D, D) covariance
    _, vecs = np.linalg.eigh(C)
    return vecs[:, -k:]                         # (D, k): the k directions that matter

def score(x, V):                              # x: (D,) one live window
    code = V.T @ x                            # encoder: (k,) numbers
    xhat = V @ code                           # decoder: (D,) rebuilt window
    return np.sqrt(np.mean((x - xhat) ** 2))   # reconstruction error

alarm = score(window, V) > threshold             # one number against one number

Hear the fan

Set the alarm for the fan

Top: a window (blue) and its rebuild (purple). Bottom: errors of 100 healthy (blue) and 100 faulty (warm) windows against your threshold. Red bars are mistakes.

2
0.08

Synthetic data: 200 healthy windows of 24 samples, 3 cycles, random size and phase, noise 0.05. Faults: 4.5 cycles, three spikes, or an added 6 cycle wave of 0.35 or 0.12. The model is a linear autoencoder, which equals PCA.

At code size 2 and threshold 0.08 with the faint hum, no healthy window alarms and 97 of 100 hums are caught. A healthy window has two degrees of freedom, size and phase.

The lecture's fan runs on an Arduino Nano 33 BLE Sense: 256 kB SRAM, 1 MB Flash, a Cortex-M4 at 64 MHz. A 24 to 2 to 24 autoencoder has 24×2 + 2 + 2×24 + 24 = 122 weights, 122 bytes in int8. K-means and Gaussian mixture models are other common choices.

The failure: a code that is too big

Symptom: the detector stays quiet when the fan is faulty. Measure: at code size 12 and threshold 0.08, only 4 of 100 faint hums are caught, because the big code rebuilds the fault too. Fix: keep the code small, and set the threshold just above the largest healthy error.

An autoencoder trained only on healthy fan data rebuilds a new window with a large error. What is the right reading?

Chapter 11

Field Guide: Numbers, Checklist, Code and Where Next

Keep the whole lecture on one page, then take the memory count with you

On a tiny chip, the working memory of the worst layer sets the limit. MCUNet designs the network and the engine together. TinyNAS scores spaces by p80, then searches with shared weights and a memory filter. MCUNetV2 runs the first blocks patch by patch, and redistribution keeps the halo cheap.

The numbers

NumberWhat it isWhere
32 GB, 4 GB, 320 kBMemory of cloud, phone and tiny chip. 100,000 and 13,000 times smaller0
256 kB, 320 kBSRAM of the Arduino Nano 33 BLE Sense and the STM32 F746ZG, each with 1 MB Flash1
23x, 22x, 5xPeak SRAM over a 320 kB chip: ResNet-50, MobileNetV2, MobileNetV2 int81
4.6x and 1.8x; 6.1x and 3.4xSmaller parameters and peak activation: MobileNetV2-0.75, then MCUNet, against ResNet-181
32.3 M and 50.3 M FLOPsp80 of a bad space (w0.3-r160) and a good space (w0.5-r144). Best accuracy 74.2 and 78.7 percent3
2.2x to 1.6xTallest block over the average, first two stages: MobileNetV2 to TinyNAS4
1,372 kB to 172 kBMobileNetV2 peak SRAM, per layer to per patch. 8 times less5, 6
4.1x to 5.9xPeak SRAM reduction from patches on four models, STM32F7466
301 M, 330 M, 301 M MACsMobileNetV2, with patches, then redistributed7
119 kB to 30 kBVWW peak SRAM at 90 percent accuracy, MCUNet to MCUNetV28
64.9, 71.8, 68.3MCUNetV2: ImageNet on 256 kB, ImageNet on 320 kB, VOC mAP on 320 kB8
70.7 percentFirst ImageNet top-1 above 70 percent on a commercial MCU (int4)9
T = (L − l) / s + 1Frames in a keyword spotting clip9

The terms

TermMeaningCh
SRAM, FlashThe working memory (desk) and the storage (bookshelf) of a chip0, 1
Peak SRAMThe largest input plus output activation over all layers1
Co-designShape the network and the runtime together2
Search space, p80The set of networks searched, scored by the 80th percentile FLOPs of the fitting ones3
Super network, weight sharingOne large network whose weights every sub-network reuses4
Imbalanced memoryThe early blocks use far more SRAM than the later ones5
Patch-based inferenceRun the first stage tile by tile, then hold only the stage output6
Halo, receptive fieldThe border a tile borrows, set by how far one output looks7
RedistributionMove receptive field from the patch stage to the later stage7
Autoencoder, code vectorA network that rebuilds its input through a narrow middle10

A checklist before you deploy

The core as code

The lecture's formulas fit in a few lines of Python. Shapes are in the comments.

pythonimport numpy as np

def memory(layers, b=1):                     # layers: [(in_shape, out_shape, n_weights)]
    sz = lambda s: s[0] * s[1] * s[2] * b
    sram = [sz(i) + sz(o) for i, o, _ in layers]
    return sum(w for _, _, w in layers) * b, max(sram)   # Flash, peak SRAM

def space_score(nets, sram, flash):          # p80 FLOPs among networks that fit
    fit = sorted(n.flops for n in nets if n.peak <= sram and n.flash <= flash)
    return fit[max(0, int(len(fit) * 0.8 + 0.999) - 1)] if len(fit) >= 15 else 0

def tile_in(t_out, k, s):                    # input tile for an output tile: (t - 1) * s + k
    return (t_out - 1) * s + k

def patch_peak(out_bytes, tile_in_bytes, tile_out_bytes):
    return out_bytes + tile_in_bytes + tile_out_bytes   # held output + one tile's working memory

def n_frames(L, l, s):                       # keyword spotting: frames in a clip
    return (L - l) // s + 1

def anomaly(x, V, threshold):               # V: (D, k) trained on healthy data only
    xhat = V @ (V.T @ x)                   # encode (k,), decode (D,)
    return np.sqrt(np.mean((x - xhat) ** 2)) > threshold

Run these on the worked examples. Chapter 1 gives 276,480 B for layer 3. Chapter 3 gives p80 = 33 M. Chapter 6 gives 78,864 B for 3 × 3 patches. Chapter 7 gives a 27-wide input tile. Chapter 9 gives 49 frames.

Where this sits

Earlier lectures made models small: pruning, quantization, architecture search and distillation. This lecture adds the missing question: where does the working memory go? The next lecture, TinyEngine, covers the runtime that makes the plan real. Later lectures return to the same chips for training on the device.

Keep going

The takeaway. On a tiny chip, the working memory of the single worst layer sets the limit, not the model size. Find that layer, then change how it runs: design the space, search with a memory filter, and run the early blocks patch by patch.
A model has 200 kB of weights and a block that needs 1,372 kB of activations. The chip has 1 MB of Flash and 256 kB of SRAM. What is the best next step?

Credit

This lesson follows Lecture 10 of MIT 6.5940, TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Read the lecture slides on the course page. The papers the lecture cites include MCUNet, MCUNetV2, ProxylessNAS, MnasNet, TVM, Once-for-All, Visual Wake Words, Hello Edge and the Google study on small-footprint keyword spotting. All explanations, devices and examples here are our own. Toy numbers are labelled as such, and the lecture's numbers are cited from its slides.

Now press Teach and explain, from memory, how to count the peak SRAM of a network, why patches lower it, and what the halo costs. Then go back to the instrument at the top and fit MobileNetV2 on the 256 kB chip.

MCUNet and TinyML, MIT 6.5940 Lecture 10
The course page and slides · Back to Lecture 9 · On to Lecture 11 · Back to Gleams