TinyML Model Deployment and Memory Profiler
Deploy a known model reproducibly and measure model bytes, runtime flash, tensor arena, stack, heap and inference timing.
Learning objectives
- Explain static and runtime memory costs
- Build a minimal operator resolver
- Measure rather than guess tensor arena size
- Create a repeatable deployment report
Prerequisites
- Embedded C/C++ build and serial logging
- Linker-map basics
- One trained int8 .tflite model
Dataset and labelling plan
- Export immutable representative test vectors
- Record model hash and conversion settings
- Keep expected outputs with tolerances
- Use test vectors not present in training
Training and validation pipeline
- Inspect model input/output type and quantisation
- List required operators and versions
- Compile minimal resolver build
- Compare desktop and target outputs
- Measure flash delta with and without model
- Measure arena, stack, heap and latency repeatedly
Model deployment procedure
- Convert model to a const byte array or supported file container
- Align model storage as required by target
- Allocate arena statically and fail clearly if allocation fails
- Run golden vectors before enabling live sensors
- Measure cold and warm inference timing
- Record compiler, optimisation, board and clock settings
Memory and performance targets
| Metric | Target | Unit | Why it matters |
|---|---|---|---|
| Validation accuracy | >= 80 | % | Confirms exported model behaviour |
| Flash usage | <= 1200 | KB | Preserves application/update capacity |
| Peak RAM / arena | <= 300 | KB | Prevents runtime collision |
| Inference latency | <= 80 | ms | Establishes scheduling feasibility |
Deployment checkpoints
| Check | Expected result | Evidence |
|---|---|---|
| Schema | Model schema is supported by runtime | Boot log |
| Golden vectors | Target predictions match approved tolerances | Comparison table |
| Arena search | Minimum stable arena plus safety margin recorded | Profiling log |
| Repeated inference | No growth, corruption or timing drift | Long-run evidence |
| Build traceability | Model hash and tool versions recorded | Release manifest |
Inference code
const tflite::Model* model = GetModel(g_model);
if (model->version() != TFLITE_SCHEMA_VERSION) fail_safe();
static uint8_t arena[ARENA_BYTES];
allocate_interpreter(model, resolver, arena);
for (test : golden_vectors) compare(invoke(test), test.expected);
profile_repeated_inference();Troubleshooting
| Symptom | Likely cause | Corrective action |
|---|---|---|
| Didn't find op | Resolver excludes model operator | Add only the named required operator |
| AllocateTensors fails | Arena too small or wrong alignment | Profile allocation and add measured margin |
| Target differs from desktop | Quantisation/preprocessing mismatch | Compare tensor values stage by stage |
| Latency varies widely | Interrupt/task contention or clock scaling | Profile worst case under real workload |
Safety, privacy and model limits
- Never download an untrusted model into production firmware without provenance and integrity checks.
- Profiling must use the final compiler flags and representative concurrent workload.
- Do not log sensitive input tensors in production.
- A model that fits once may still fail without stack and update margins.
Measured deployment profile
Log in to record deployment measurementsInterview and viva questions
- Why is model file size not equal to total flash cost?
- What lives in the tensor arena?
- Why use golden test vectors before live sensors?
- How do compiler optimisation flags affect comparison?
- Why report worst-case as well as average latency?
Lesson notes
Responsible TinyML workflow
Keep raw data, preprocessing, model version, compiler options and measured device results together. A desktop accuracy score does not prove embedded performance. Validate representative unseen samples on the actual target and define an explicit fallback for low confidence or out-of-distribution input.
Deployment evidence
Record the dataset split, confusion matrix, exported model hash, firmware build, board revision, peak memory, average and worst-case latency, power conditions and failures. Never treat an educational classifier as a safety-certified decision system.
