Network Instance Size Comparison
Every number on this page is generated by tools/size_report/size_report.py: python3 tools/size_report/size_report.py instances prints the instance-size tables (seconds), and python3 tools/size_report/size_report.py code rebuilds the unit tests and examples under GCC and Clang for the code-size comparison at the end (minutes; it overwrites the build products in each output/). Last regenerated on 2026-11-10, after the training fixes in #260-#265; the instance sizes were unchanged by those fixes.
All Architectures: MLP vs LSTM vs GRU vs KAN
Using double (2->N->1)
Instance sizes in bytes for XOR-class network configurations using double as the value type.
| Architecture | Hidden Neurons | Trainable | Non-trainable | Training Overhead |
|---|---|---|---|---|
| MLP (2->3->1) | 3 | 704 bytes | 264 bytes | +440 bytes (+167%) |
| MLP (2->5->1) | 5 | 1,008 bytes | 360 bytes | +648 bytes (+180%) |
| Elman RNN (2->3->1) | 3 | 1,056 bytes | 384 bytes | +672 bytes (+175%) |
| LSTM (2->3->1) | 3 | 3,024 bytes | 960 bytes | +2,064 bytes (+215%) |
| GRU (2->3->1) | 3 | 2,400 bytes | 792 bytes | +1,608 bytes (+203%) |
| KAN (2->5->1, G=5, k=1) | 5 | 4,208 bytes | 1,256 bytes | +2,952 bytes (+235%) |
Using Q8.8 Fixed-Point (XOR Configuration)
Instance sizes in bytes for XOR network configurations using QValue<8,8,true> (signed Q8.8 fixed-point, 2 bytes per value).
| Architecture | Hidden Neurons | Trainable | Non-trainable | Training Overhead |
|---|---|---|---|---|
| MLP (2->3->1) | 3 | 328 bytes | 144 bytes | +184 bytes (+128%) |
| MLP (2->5->1) | 5 | 440 bytes | 200 bytes | +240 bytes (+120%) |
| Elman RNN (2->3->1) | 3 | 472 bytes | 192 bytes | +280 bytes (+146%) |
| LSTM (2->3->1) | 3 | 952 bytes | 384 bytes | +568 bytes (+148%) |
| GRU (2->3->1) | 3 | 808 bytes | 336 bytes | +472 bytes (+140%) |
| KAN (2->5->1, G=5, k=1) | 5 | 1,200 bytes | 416 bytes | +784 bytes (+188%) |
The KAN row is a 5-neuron hidden layer, so the matched comparison is the MLP (2->5->1) row, not the 3-neuron row used for the recurrent architectures.
Relative Size (vs MLP)
| Trainable | Non-trainable | |
|---|---|---|
| double | ||
| Elman / MLP | 1.5x | 1.5x |
| LSTM / MLP | 4.3x | 3.6x |
| GRU / MLP | 3.4x | 3.0x |
| KAN / MLP | 4.2x | 3.5x |
| Q8.8 | ||
| Elman / MLP | 1.4x | 1.3x |
| LSTM / MLP | 2.9x | 2.7x |
| GRU / MLP | 2.5x | 2.3x |
| KAN / MLP | 2.7x | 2.1x |
Each ratio is against the MLP of the same hidden width: the Elman / LSTM / GRU rows divide by MLP (2->3->1), the KAN rows by MLP (2->5->1).
GRU vs LSTM
| Trainable | Non-trainable | |
|---|---|---|
| double: GRU / LSTM | 79% | 83% |
| Q8.8: GRU / LSTM | 85% | 88% |
GRU uses 3 gates (update, reset, candidate) versus LSTM’s 4 gates (input, forget, output, cell candidate), saving ~15-21% memory per hidden neuron.
Why Each Architecture is Larger
- MLP: One weight per connection. Minimal storage.
- Elman RNN: Same connection weights as MLP, plus a recurrent layer that stores previous hidden outputs and feeds them back as additional inputs.
- LSTM: 4 gates (input, forget, output, cell) multiply connection weights by 4x, plus recurrent state and cell memory.
- GRU: 3 gates (update, reset, candidate) multiply connection weights by 3x, plus recurrent state. ~20% smaller than LSTM.
- KAN: Each edge stores B-spline coefficients (
GridSize + SplineDegree= 6 per edge with G=5, k=1), plus a base weight and spline weight. Training adds gradient, delta weight, and previous delta weight for every learnable parameter.
All architectures remain under 1.25 KB in Q8.8 fixed-point even in trainable form, making them suitable for embedded deployment.
Liquid Cells (Continuous-Time): LTC & CfC
The liquid cells (LtcCell, CfCCell) are measured on a different basis from the rows above. The MLP/LSTM/GRU/KAN figures are sizeof(network object) — self-contained objects that embed weights and training state. The liquid cells are pointer-shaped structs over a caller-owned flat parameter array; the trainable footprint is the parameter array itself (NumParams × sizeof(ValueType)), and the optimizer state (momentum velocity, the host-only autodiff tape) lives outside the cell. The numbers below are therefore parameter bytes — the weights you store and ship — not object sizeof, so they are not directly comparable to the LSTM/GRU rows.
Each configuration below includes a small linear readout (NumState -> 1, NumState + 1 params) so the totals match a usable sequence-to-scalar model.
| Cell (config) | Cell params | + readout | Total params | Q8.8 | double |
|---|---|---|---|---|---|
LTC LtcCell<2,3> | 24 | 4 | 28 | 56 bytes | 224 bytes |
CfC CfCCell<2,3,4> | 84 | 4 | 88 | 176 bytes | 704 bytes |
LTC LtcCell<4,8> | 120 | 9 | 129 | 258 bytes | 1,032 bytes |
CfC CfCCell<4,8,16> | 752 | 9 | 761 | 1,522 bytes | 6,088 bytes |
- LTC
NumParams = W_in (NumState·NumInputs) + W_rec (NumState²) + b/tau/A (3·NumState). For<2,3>: 6 + 9 + 9 = 24. - CfC
NumParams = W_bx (BackboneDim·NumInputs) + W_bh (BackboneDim·NumState) + b_b (BackboneDim) + 4·(NumState·BackboneDim + NumState)for the two tanh heads plus the time-gate A/B. For<2,3,4>: 8 + 12 + 4 + 4·15 = 84. The backbone trunk and four heads make CfC heavier than a same-width LTC or GRU — it buys the closed-form (solver-free) rollout and the per-steptstime-gate.
int8 deployable CfC (QCfCCell)
For the pure-integer deployment path the weights are int8 (1 byte each) and the biases are int32. For QCfCCell<...,2,3,4>: 68 weight bytes (8 + 12 + 48) + 52 bias bytes (13 × int32) = 120 bytes of caller-owned parameters, plus the two 256-entry int8 sigmoid/tanh LUTs (512 bytes) that are shared across every cell and layer in the model. No <cmath>, no float state on the inference path.
Signal Processing Pipeline Sizes
Instance sizes in bytes for Conv1D, Pool1D, and Dropout layers. These are standalone composable layers that sit outside the neural network template.

examples/kws_cortex_m (make csv && make plot): per-layer compute cost and stacked weight/activation footprint for a keyword-spotting pipeline.
Conv1D
| Configuration | double | Q8.8 |
|---|---|---|
| Conv1D (100, kernel=5, stride=2, 8 filters) | 768 bytes | 192 bytes |
| Conv1D (100, kernel=5, stride=1, 4 filters) | 384 bytes | 96 bytes |
MaxPool1D
| Configuration | Size (bytes) |
|---|---|
| MaxPool1D (96 input, pool=2, stride=2, 4 channels) | 1,536 bytes |
| MaxPool1D (48 input, pool=2, stride=2, 1 channel) | 192 bytes |
| MaxPool1D (6 input, pool=2, stride=2, 1 channel) | 24 bytes |
MaxPool1D stores argmax indices (size_t per output) for backpropagation gradient routing. Size is independent of value type.
AvgPool1D
AvgPool1D is stateless (1 byte). It has no per-instance storage since average gradients are computed directly from the pool size.
Dropout
| Configuration | Size (bytes) |
|---|---|
| Dropout (192 elements, 50%) | 193 bytes |
| Dropout (32 elements, 50%) | 33 bytes |
| Dropout (5 elements, 50%) | 6 bytes |
Full Pipeline: Conv1D -> MaxPool1D -> Dropout
| Value Type | Conv1D (100, k=5, s=1, 4 filters) | MaxPool1D (96, p=2, s=2, 4 ch) | Dropout (192, 50%) | Total |
|---|---|---|---|---|
double | 384 bytes | 1,536 bytes | 193 bytes | 2,113 bytes |
| Q8.8 | 96 bytes | 1,536 bytes | 193 bytes | 1,825 bytes |
2D Layers
All 2D layers use NHWC layout. Sizes below are in float (the type used by the examples/kws_cortex_m/ runner). Q8.8 sizes are ~4x smaller.
| Configuration | float |
|---|---|
| Conv2D (20x20x1, k=3, s=1, 8 filters) | 640 bytes |
| DepthwiseConv2D (9x9x8, k=3) | 640 bytes |
| PointwiseConv2D (7x7, 8 -> 16) | 1,152 bytes |
| PointwiseConv2D (1x1, 16 -> 10; dense classifier) | 1,360 bytes |
| MaxPool2D (18x18x8, pool=2, stride=2) | 5,184 bytes |
| GlobalAvgPool2D (7x7x16) | 1 byte |
Conv2D / DepthwiseConv2D / PointwiseConv2D store both weights and gradients (2x overhead) to support on-device training. MaxPool2D stores size_t argmax indices per output. GlobalAvgPool2D is stateless.
Full Pipeline: Conv2D -> MaxPool2D -> DepthwiseConv2D -> PointwiseConv2D -> GlobalAvgPool2D -> Dense
Running the pipeline in examples/kws_cortex_m/ (20x20x1 input, 10 output classes, all float):
| Section | Bytes |
|---|---|
| Total weight + state bytes | 8,976 |
| Peak activation buffer | 10,368 (first conv output) |
Swapping the layer value type from float to Q8.8 roughly quarters the Conv / DW / PW / Dense storage and halves each activation buffer. The MaxPool2D argmax array is size_t-indexed and is independent of value type – on a tight MCU target it becomes the dominant term and is the best candidate for the next round of footprint work.
Binary and Ternary Dense Layer Sizes
BinaryDense (Trainable)
| Configuration | double | Q8.8 |
|---|---|---|
| BinaryDense (4, 2) | 168 bytes | 44 bytes |
| BinaryDense (16, 8) | 2,192 bytes | 560 bytes |
| BinaryDense (64, 16) | 16,768 bytes | 4,288 bytes |
TernaryDense (Trainable)
| Configuration | double | Q8.8 |
|---|---|---|
| TernaryDense (4, 2, 50%) | 168 bytes | 44 bytes |
| TernaryDense (16, 8, 50%) | 2,208 bytes | 576 bytes |
| TernaryDense (64, 16, 50%) | 16,896 bytes | 4,416 bytes |
Inference-Only Packed Weight Storage
| Configuration | Binary (packed) | Ternary (packed) | Full double | Full Q8.8 |
|---|---|---|---|---|
| 64x16 weights + biases | 256 bytes | 384 bytes | 8,320 bytes | 2,080 bytes |
| 32x32 weights + biases | 384 bytes | 512 bytes | 8,448 bytes | 2,112 bytes |
Weight Storage Compression Ratios (64x16 layer)
| Storage | Bytes | vs double | vs Q8.8 |
|---|---|---|---|
Full double | 8,192 bytes | 1x | – |
| Full Q8.8 | 2,048 bytes | 4x | 1x |
| Packed binary (1-bit) | 128 bytes | 64x | 16x |
| Packed ternary (2-bit) | 256 bytes | 32x | 8x |
GCC vs Clang Code Size
Both toolchains are built and tested in CI (see the Quality Gates table in the README). This section records how much code each one generates for the same sources, measured as the .text section via size --format=sysv — not total file size, which for the unit tests is dominated by debug information and would say more about DWARF encoding than about code generation.
Measured on 2026-11-10 with GCC 13.3.0 and Clang 18.1.3 on x86-64 Linux. Examples are built with their release target (-O3); unit tests use their default build. Each row compares like with like, since both compilers run through the same Makefile.
These are host binaries and are not a deployable footprint. The unit-test figures include Boost.Test, libstdc++ and the C runtime, which is why they run to megabytes. For what tinymind actually costs on a target, see the instance sizes above, plus the heapfree and stack_usage gates and the arm_crosscompile build in unit_test/embedded.
Totals
| Group | Binaries | GCC .text | Clang .text | Delta |
|---|---|---|---|---|
| Unit tests | 20 | 14,265,015 | 13,898,814 | -2.6% |
| Examples | 43 | 1,258,893 | 1,359,151 | +8.0% |
| All | 63 | 15,523,908 | 15,257,965 | -1.7% |
In aggregate the two are within 2% of each other, and the split is close to even — Clang emits less code for 35 of the 63 binaries and more for 28. The aggregate hides a very wide per-binary spread, from -60.6% to +105.6%, so neither compiler is uniformly better on size and there is no basis for picking one on that alone.
The pattern in the outliers is inlining appetite. The examples where Clang is much larger are deeply templated pipelines — anfis_mackey_glass, kws_cortex_m, mobilenetv2_int8 — where it inlines layer bodies GCC keeps as calls. Where the hot code is a smaller loop nest, Clang often comes out well ahead (dqn_maze, maze, lstm_sinusoid_float). If you are size-constrained on a target, measure your own shape rather than generalizing from either column.
The unit-test group covers every suite with a C++ binary except unit_test/exhaustive (a long-running sweep), plus the eight unit_test/embedded gate-matrix binaries; the example group is every example with a release target.
Unit tests
| Binary | GCC .text | Clang .text | Delta |
|---|---|---|---|
qformat_oracle/qformat_oracle_unit_test | 783,496 | 694,626 | -11.3% |
nn/nn_unit_test | 4,176,625 | 3,972,348 | -4.9% |
qlearn/qlearn_unit_test | 940,199 | 916,868 | -2.5% |
ltc/ltc_unit_test | 754,355 | 736,348 | -2.4% |
cfc/cfc_unit_test | 751,027 | 736,060 | -2.0% |
kan/kan_unit_test | 852,537 | 837,264 | -1.8% |
integration/integration_unit_test | 730,349 | 718,322 | -1.6% |
lookuptable/lookuptable_unit_test | 815,885 | 804,996 | -1.3% |
quantization/quantization_unit_test | 1,777,885 | 1,758,720 | -1.1% |
embedded/embedded_smoke_freestanding | 26,568 | 26,295 | -1.0% |
embedded/embedded_smoke_no_fpu | 26,568 | 26,295 | -1.0% |
dual/dual_unit_test | 849,355 | 842,568 | -0.8% |
embedded/embedded_smoke_int16_accum_freestanding | 69,386 | 68,871 | -0.7% |
embedded/embedded_smoke_hosted | 30,234 | 30,103 | -0.4% |
embedded/embedded_smoke_no_stdlib | 30,234 | 30,103 | -0.4% |
embedded/embedded_smoke_quant_freestanding | 67,462 | 67,175 | -0.4% |
embedded/embedded_smoke_simd_disabled | 67,462 | 67,175 | -0.4% |
embedded/embedded_smoke_fp16_freestanding | 72,700 | 72,615 | -0.1% |
qformat/qformat_unit_test | 1,040,771 | 1,039,634 | -0.1% |
pinn/pinn_unit_test | 401,917 | 452,428 | +12.6% |
Examples
| Example | GCC .text | Clang .text | Delta |
|---|---|---|---|
dqn_maze | 67,804 | 26,712 | -60.6% |
pytorch_quant/xor (xor_quant) | 7,895 | 3,879 | -50.9% |
maze | 22,599 | 12,036 | -46.7% |
lstm_sinusoid_float | 55,830 | 33,076 | -40.8% |
gbdt_tabular_int8 | 5,529 | 3,551 | -35.8% |
qcfc_liquid_int8 | 20,338 | 14,236 | -30.0% |
import_demo | 30,219 | 21,415 | -29.1% |
lstm_sinusoid | 25,190 | 19,748 | -21.6% |
kws_cortex_m_int8 | 37,691 | 32,166 | -14.7% |
air_quality | 27,663 | 24,828 | -10.2% |
tiny_generate_int8 | 53,325 | 48,621 | -8.8% |
elman_temporal_xor | 21,373 | 19,488 | -8.8% |
pytorch/gru (gru_parity) | 7,015 | 6,448 | -8.1% |
elman_vowels | 76,813 | 74,132 | -3.5% |
state_space_int8 | 16,327 | 16,039 | -1.8% |
mixed_precision_mlp_int8_qformat | 23,917 | 23,847 | -0.3% |
moe_regimes_int8 | 6,819 | 6,871 | +0.8% |
iris | 19,630 | 20,628 | +5.1% |
resnet_block_int8 | 20,829 | 22,103 | +6.1% |
seq2seq_softmax_int8 | 84,989 | 90,581 | +6.6% |
energy_efficiency | 19,430 | 20,892 | +7.5% |
transformer_encoder_int8 | 49,613 | 53,533 | +7.9% |
import_moe_demo | 3,305 | 3,639 | +10.1% |
seq2seq_int8 | 84,045 | 92,965 | +10.6% |
xor | 12,005 | 13,780 | +14.8% |
anfis_mackey_glass_int8 | 19,924 | 23,095 | +15.9% |
pinn_heat1d | 63,774 | 74,168 | +16.3% |
cfc_sequence | 22,349 | 26,037 | +16.5% |
optical_digits | 17,797 | 22,024 | +23.8% |
resnet18_block_int8 | 36,621 | 46,402 | +26.7% |
gas_sensor_drift | 13,899 | 17,768 | +27.8% |
har_activity | 39,290 | 50,368 | +28.2% |
gru_xor | 18,972 | 24,732 | +30.4% |
kan_xor | 15,206 | 20,120 | +32.3% |
pytorch/xor | 4,134 | 5,512 | +33.3% |
transformer_encoder_stack_softmax_int8 | 47,493 | 66,593 | +40.2% |
predictive_maintenance | 22,081 | 31,672 | +43.4% |
ltc_sequence | 12,764 | 19,697 | +54.3% |
transformer_encoder_stack_int8 | 46,181 | 74,801 | +62.0% |
mixed_precision_kws | 20,893 | 34,231 | +63.8% |
mobilenetv2_int8 | 42,717 | 86,787 | +103.2% |
kws_cortex_m | 6,683 | 13,644 | +104.2% |
anfis_mackey_glass | 7,922 | 16,286 | +105.6% |
Regenerate with python3 tools/size_report/size_report.py code, which builds each directory under both compilers and reads size --format=sysv. make check-clang runs the Clang side of the unit tests as a test gate.