What you will learn
- What a weight and an activation are, in plain words.
- Why weights mostly cost storage and activations mostly cost working memory.
- Why a wider number can make the same arithmetic slower, even when the number of operations stays the same.
- How to check which step causes an error before you change it.
- Why you must check a model's output on the device before you time it.
1. Start with one spoken word
Say the word for mute to a voice-command device. Here is what happens, in order:
you speak → microphone → audio samples
→ audio features (1,950 numbers)
→ neural network → 13 scores, one per command
→ highest score wins → "mute" event sent to the product
A neural network is a long chain of multiply-and-add steps. Two kinds of numbers flow through it, and they are easy to mix up.
| Term | What it is | Analogy | When it changes |
|---|---|---|---|
| Weight | A number the model learned during training. It says how much each input matters. | Years of experience: what a sound engineer knows about voices. | Never, while the device runs. |
| Activation | A number the model computes from the current input, and passes to the next step. | What the engineer hears right now, and how they interpret it. | Every time you speak. |
The weights are fixed. The activations change with every sound. So weights are stored knowledge, and activations are work in progress.
2. A tiny example you can check by hand
Imagine a neuron that looks at only four audio features. Its score is the sum of activation times weight for each feature. Here the weights are illustrative, not taken from our model:
| Feature | Activation (sound "mute") | Weight | Product |
|---|---|---|---|
| 1 | 0.8 | 0.9 | 0.72 |
| 2 | 0.7 | 0.8 | 0.56 |
| 3 | 0.2 | −0.5 | −0.10 |
| 4 | 0.9 | 0.7 | 0.63 |
| Score | 1.81 | ||
Now say up instead. The weights stay the same, but the activations change: 0.2, 0.3, 0.9, 0.1. The score becomes 0.18 + 0.24 − 0.45 + 0.07 = 0.04. Same weights, different inputs, different answer. That is inference.
Each multiply-and-add is a MAC (multiply-accumulate). Counting MACs is the simplest way to estimate how much work a model does.
3. Our real model in numbers
The voice-command model has three layers:
| Layer | Values | Weights into this layer |
|---|---|---|
| Input (audio features) | 1,950 | – |
| Hidden layer, 128 neurons | 128 | 1,950 × 128 = 249,600 |
| Output, 13 command scores | 13 | 128 × 13 = 1,664 |
| Total | 251,264 weights (plus 141 biases) |
Every hidden neuron looks at all 1,950 inputs. That single fact drives most of the story below.
4. Where the memory goes: flash versus RAM
The weights are stored in flash, the device's program memory, built into the firmware. The activations are held in RAM, in a working buffer that the runtime reuses on every inference.
Weights: storage grows with precision
| Weight format | Bytes per weight | Weight storage |
|---|---|---|
| 8-bit integer (INT8) | 1 | 251,264 B |
| 16-bit integer (INT16) | 2 | 502,528 B |
| 32-bit float (FP32) | 4 | 1,005,056 B |
Activations: the working set is small
The input buffer holds 1,950 values. Its size depends on the number format:
| Input format | Input buffer (RAM) |
|---|---|
| 8-bit (INT8) | 1,950 B |
| 16-bit (INT16) | 3,900 B |
| 32-bit float (FP32) | 7,800 B |
A word of caution: the sum of all activation values (2,104 logical values for this model) is not the peak RAM your runtime needs. Scratch buffers, alignment and the runtime's own bookkeeping all add to it. Always measure the arena.
5. Memory is capacity; computation is recurring work
Memory is a one-time reservation. Computation is paid again on every inference. Our model runs about ten times per second (a new window every 100 ms), and each run performs the same 251,264 MACs:
| Duration | MAC operations, if inference keeps up | Extra input RAM from 16-bit input |
|---|---|---|
| One inference | 251,264 | 1,950 B (fixed) |
| One second | 2,512,640 | 1,950 B |
| One minute | 150,758,400 | 1,950 B |
| One hour | 9,045,504,000 | 1,950 B |
The memory cost stays flat, while the work keeps adding up. A small change in how each number is stored can therefore change a very large number of operations.
Here is one way to see why. In the hidden layer, each of the 1,950 inputs is used by all 128 neurons. The input is stored once but used 128 times. The computation, not the storage, is where precision costs you.
6. Why a wider number can be slower
Think of a warehouse. An INT8 forklift can carry several small boxes in one trip. If the boxes are bigger, the forklift attachment does not fit, and the same boxes need more trips. The number of boxes has not changed. The time has.
Three things decide how fast the same arithmetic runs:
- Packing (SIMD). A 32-bit register holds four 8-bit values but only two 16-bit values. Chip instructions that work on several values at once are most efficient when the data is packed tightly.
- The kernel. A kernel is the code that does the arithmetic. Chip vendors often provide optimized kernels for common formats. If no optimized kernel exists for your format, the runtime falls back to a general one.
- The accumulator. A neuron adds up 1,950 products. Wider inputs produce wider products, and the running total needs more bits.
The accumulator example makes the last point concrete. Two extreme cases, each repeated 1,950 times:
| Format | One product (worst case) | Sum of 1,950 products | Fits in 32 bits? |
|---|---|---|---|
| 8-bit input × 8-bit weight | 127 × 127 = 16,129 | 31,451,550 | Yes (limit 2,147,483,647) |
| 16-bit input × 8-bit weight | 32,767 × 127 = 4,161,409 | 8,114,747,550 | No |
A 16-bit path therefore needs a 64-bit accumulator. The extra cost is in the arithmetic, not in memory: one accumulator is reused for all 1,950 products of a neuron, so it adds only a few bytes of state.
7. Does more precision help? Find the error before you fix it
Our first idea was simple. The model's inputs are 1,950 numbers rounded to 8 bits. The words mute and up can produce similar numbers, and rounding may merge them. With a made-up scale of 0.01 for illustration, two features of 10.2 and 10.5 would become 1,020 and 1,050, and stay different. At 8 bits with our real input scale of about 0.8669, both round to the same value.
That idea is reasonable, but it is a hypothesis, so we measured each quantization step separately:
| Step that is quantized | Accuracy cost on the test windows |
|---|---|
| Input features only | 0.03 points |
| Output scores (logits) only | 3.16 points |
The input rounding costs almost nothing. The output scores hold most of the loss. A 16-bit candidate helped because it kept the output in higher precision, not because its input was wider. Our first explanation was wrong, and the measurement showed where the error really lived.
8. What happened on the board
The 16-bit candidate passed the checks we ran on the PC. On the ESP32-S3 it failed in a way that was easy to miss. For a silent input, all 13 output classes came back with the same probability, 0.07693 (one in thirteen). With every score equal, the code picks the first class, and that looked like a correct "silence" result.
Our boot self-test had the same blind spot. It checked only that the top class was silence, so the tie passed. We then changed the test to require a clear margin between silence and the next class, and the 16-bit build now fails the test as it should.
- A correct model file does not guarantee correct output. The runtime and its kernels decide what really runs.
- A check that looks only at the winning label can be fooled by a tie. Check the margin, or check that the outputs are not all the same.
- Do not time a build whose output is wrong. Its speed describes a different computation. The 16-bit timing from that build is not a valid comparison.
The cause was not found. The runtime version we use does not let us read internal tensors, so the problem is still open. The 2× and 3× slowdown figures in the next sections are scenarios, not measurements.
9. The real-time budget: a 100 ms loop
A new window arrives every 100 ms. If one inference takes longer than that, windows wait in a queue, and when the queue is full, new windows are dropped. A late or missing window means a late or missing command.
On an earlier instrumented INT8 build, the median inference took 33.5 ms. Here is what that means for the budget:
| Scenario | Inference time | Share of the 100 ms window | Status |
|---|---|---|---|
| INT8, measured median | 33.5 ms | 33.5% | 66.5 ms left for other work |
| Scenario: 2× slower | 67 ms | 67% | 33 ms left |
| Scenario: 3× slower | 100.5 ms | 100.5% | 0.5 ms overrun, queue starts to build |
These percentages are elapsed time, not measured CPU use, because the real-time scheduler can interrupt inference to run other tasks. Latency, queues and CPU use all have to be measured on the device.
10. The other way to change a model: add neurons
Suppose the team doubles the hidden layer from 128 to 256 neurons to tell mute from up more clearly. That is a different kind of change: the architecture changes, so the work changes.
| Resource | Now | 256 neurons | 16-bit activations |
|---|---|---|---|
| Weights | 251,264 | 502,528 | 251,264 |
| Weight storage | 251,264 B | 502,528 B | 251,264 B |
| Input RAM | 1,950 B | 1,950 B | 3,900 B |
| Multiply-accumulates | 251,264 | 502,528 | 251,264 |
More neurons means more storage and more arithmetic. A wider number means a little more RAM and possibly a slower kernel, with the same arithmetic. Two different reasons for a slower model, and two different fixes.
11. The mental model to keep
| Question | What it controls |
|---|---|
| How much knowledge must I store? | Weight count and weight precision (flash) |
| How much working memory do I need? | Activation count and precision (RAM) |
| How much arithmetic must I do? | Operation count (MACs), set by the architecture |
| How fast can my processor do that arithmetic? | Kernel efficiency, packing and accumulator width |
These four are related but not interchangeable. A model can barely change in flash size and still take much longer to run, because it changed its computation path. Measure all four.
Knowledge check
Try the questions first, then open the answer.
Why is the 16-bit-activation model only about 2 KB bigger than the INT8 one?
Because the 251,264 weights stay 8-bit. Only the input buffer and a few small items grow.
Does a 16-bit input use more RAM?
Yes. The input grows from 1,950 to 3,900 bytes. The total arena must still be measured, because scratch buffers and bookkeeping add to it.
Does a 16-bit input change the number of multiply-accumulates?
No, if the architecture stays the same. The count stays at 251,264. What can change is how much time each operation takes.
Our first guess was that 8-bit input rounding confused mute and up. What did the measurement say?
Input quantization cost only 0.03 accuracy points. Output score quantization cost 3.16 points. The output was the larger source of error.
Why could the 16-bit build's timing not be used?
Its output was wrong on the device: every class had the same score for silence. A fast wrong answer is not a valid timing.
Is a 2× slowdown guaranteed for 16-bit activations?
No. It is a scenario. The actual cost depends on the kernel, and it was not measured on a correct build.
Why does a wider accumulator not need much extra RAM?
One accumulator is reused for all products of a neuron. It is state, not a buffer for each product.
Glossary
| Term | Plain meaning |
|---|---|
| Activation | A number the network computes from the current input, layer by layer. |
| Arena | The block of RAM the TensorFlow Lite Micro runtime reserves for activations and scratch space. |
| Bias | A learned number added to a neuron's sum before the output is used. |
| Cadence | How often inference runs. Here, one window every 100 ms. |
| Flash | Non-volatile program memory. Model weights live here in our firmware. |
| Kernel | The code that performs one operation, such as a fully connected layer. |
| Logit | A raw output score before it is turned into a probability. |
| MAC | Multiply-accumulate: one multiplication and one addition into a running total. |
| Quantization | Storing numbers with fewer bits, using a scale and a zero point to map them to integers. |
| Weight | A learned number in the model. It stays fixed while the device runs. |
Keep going
More lessons are planned in this series. If you want the full method behind building an embedded ML product, the book is the reference: The Embedded Engineer's Guide to Edge AI. For a guided path from reading to building, see Learning. Questions or corrections are welcome through Connect.
