TCS Pune

TinyML Model Deployment and Memory Profiler

Intermediate · 4–6 hours

TinyML Model Deployment and Memory Profiler

Deploy a known model reproducibly and measure model bytes, runtime flash, tensor arena, stack, heap and inference timing.

ESP32 / nRF52 / STM32 / RP2040Existing classification model and representative test vectorsTensorFlow Lite Micro C++

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

  1. Export immutable representative test vectors
  2. Record model hash and conversion settings
  3. Keep expected outputs with tolerances
  4. Use test vectors not present in training

Training and validation pipeline

  1. Inspect model input/output type and quantisation
  2. List required operators and versions
  3. Compile minimal resolver build
  4. Compare desktop and target outputs
  5. Measure flash delta with and without model
  6. Measure arena, stack, heap and latency repeatedly

Model deployment procedure

  1. Convert model to a const byte array or supported file container
  2. Align model storage as required by target
  3. Allocate arena statically and fail clearly if allocation fails
  4. Run golden vectors before enabling live sensors
  5. Measure cold and warm inference timing
  6. Record compiler, optimisation, board and clock settings

Memory and performance targets

MetricTargetUnitWhy it matters
Validation accuracy>= 80%Confirms exported model behaviour
Flash usage<= 1200KBPreserves application/update capacity
Peak RAM / arena<= 300KBPrevents runtime collision
Inference latency<= 80msEstablishes scheduling feasibility

Deployment checkpoints

CheckExpected resultEvidence
SchemaModel schema is supported by runtimeBoot log
Golden vectorsTarget predictions match approved tolerancesComparison table
Arena searchMinimum stable arena plus safety margin recordedProfiling log
Repeated inferenceNo growth, corruption or timing driftLong-run evidence
Build traceabilityModel hash and tool versions recordedRelease 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

SymptomLikely causeCorrective action
Didn't find opResolver excludes model operatorAdd only the named required operator
AllocateTensors failsArena too small or wrong alignmentProfile allocation and add measured margin
Target differs from desktopQuantisation/preprocessing mismatchCompare tensor values stage by stage
Latency varies widelyInterrupt/task contention or clock scalingProfile 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 measurements

Interview and viva questions

  1. Why is model file size not equal to total flash cost?
  2. What lives in the tensor arena?
  3. Why use golden test vectors before live sensors?
  4. How do compiler optimisation flags affect comparison?
  5. 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.

Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA