Go to Map Courses Lab Glossary How it works Troubleshooting Start →
ITEN
← Course 06 · From model to app (Lesson 06.03 · 16 minutes · No sensor · For everyone)

Pruning, distilling, choosing the architecture.

Besides using fewer bits, you can make a model lighter by removing the parts that do little, by having a smaller model imitate it, or by starting from a network built for the phone. Here you'll see the three routes, and the order to use them in.

What you learn
  1. What pruning is, and when it really makes the model faster
  2. How a small model learns from a big one
  3. Why it pays to start from an architecture designed for the phone
You need to know

If you don't remember one of these, the link takes you to the chapter that explains it.

How do you want to follow it
Preparing the scene…
  1. 01 Three routes

    There are three ways to get a smaller model.

    A model that's too heavy for the phone can be made lighter in other ways besides quantization01.05. You remove the parts that do little. You teach a small model to imitate a big one. Or you start from a network designed for the phone. The routes are often used together.

    In practice. Before you slim anything down, write down how big the model can be and how fast it has to be. Without a target, you keep trimming without knowing when to stop.

01 / 07
(Go deeper)

A few more numbers.


(01)

The winning lottery ticket

In 2019 Jonathan Frankle and Michael Carbin at MIT ran a curious experiment. They pruned a trained network, then took the small network that was left, reset it to its starting weights and trained it on its own. With 10 or 20 percent of the weights, it reached the same accuracy as the full network.

They called it the lottery ticket hypothesis. A big network contains many small networks, and training finds the lucky one. It doesn't tell you how to find it before training, but it explains why pruning works so well.

(02)

Distillation with temperature

Geoffrey Hinton and his colleagues described distillation in 2015. The trick is the temperature. Before the softmax, the teacher's scores are divided by a number greater than one, and the percentages get softer. Classes that are wrong but plausible get more weight, and the student sees the similarities better.

The student learns with two goals at once. It imitates the teacher's soft percentages, and it gives the right answer on the true labels, when there are any.

p_soft(i) = exp(z_i / T) / sum of exp(z_j / T)        with T between 2 and 10
(03)

How you design a network for the phone

The first networks for the phone were designed by hand. Since 2019, with MobileNetV3, Google has used automatic architecture search. A program tries thousands of variants and measures them on a real phone, keeping the ones with the best balance between accuracy and milliseconds.

MobileNetV4 took the idea further. The search looked for a network that works well on CPUs, GPUs, NPUs and other accelerators all at once, instead of on a single phone. The result is simple blocks that almost any chip runs well, which is why people use them outside Google too.

(Try it on your phone)

A plan to slim it down


Think of a model you want to bring to the phone, maybe the one from your own project. Write down the goals and the first step you'd try. The card stays saved in your browser.

The card saves itself as you type.

(Quiz)

4 questions to close the lesson.

When you have answered them all, the lesson counts as done and its stone on the map turns yellow. Answering is what counts, not the score.


  1. (01)

    You set half the weights to zero, but the model isn't any faster. Why?

  2. (02)

    In distillation, what does the student learn besides the right answer?

  3. (03)

    Where should you start for a model you want to bring to the phone?

  4. (04)

    In what order are the techniques usually used?

To close the lesson, answer the quiz

← Quantizing Back to the map
(Next lesson · 06.04) Formats and engines