Knowledge / Artificial Intelligence and Data Science / Edge AI and model optimisation

Edge AI and model optimisation

Artificial Intelligence and Data Science (B.E./B.Tech) · AI applications · free study notes for exams, placements and interviews

In short

Edge AI means running a trained model on or near the device that produces the data - a phone, camera, microcontroller, car ECU, POS terminal or factory gateway - instead of sending data to a cloud GPU. It matters because edge hardware has a fraction of the memory, compute and power of a server, so the model must be compressed and the runtime tuned: quantisation, pruning, distillation and graph optimisation typically cut size 4x and latency 2-4x with under 1% accuracy loss. Indian syllabuses examine it under AI/ML hardware, embedded AI and TinyML electives, with numericals on model size, FLOPs, memory bandwidth and latency budgets. It is a live hiring area at Qualcomm India, Samsung R&D, Bosch, Nvidia Bengaluru, Tata Elxsi, Niramai, Wadhwani AI, Ather and almost every Indian computer-vision startup, and is pushed by the DPDP Act, 2023 preference for keeping personal data local.

Explained

What edge AI is and why it is used

Hardware for edge inference

Quantisation

Pruning, distillation and architecture choices

Runtime and graph optimisation

Measurement, trade-offs and Indian context

Key points

Formulas and examples

Affine quantisation: r = S (q − Z) ; q = round(r/S) + Z, clipped to [qmin, qmax]
r = real value, q = integer code, S = scale (real units per step), Z = zero-point (integer mapping to r = 0)
Scale for asymmetric INT8 (qmin = 0, qmax = 255): S = (rmax − rmin)/255 ; Z = round(−rmin/S)
Scale for symmetric INT8 (range −127…127): S = max(|r|)/127 , Z = 0
Model size (bytes) ≈ number of parameters × bits per parameter / 8
Compression ratio = original bits per weight / new bits per weight (sparsity adds a further 1/(1 − s) factor on stored non-zeros)
Standard convolution MACs = K² × Cin × Cout × Hout × Wout ; FLOPs ≈ 2 × MACs
Depthwise separable MACs = (K² × Cin + Cin × Cout) × Hout × Wout
Cost ratio (separable/standard) = 1/Cout + 1/K²
Fully connected layer MACs = Cin × Cout ; parameters = Cin × Cout + Cout
Arithmetic intensity I = FLOPs / bytes moved ; roofline: attainable FLOP/s = min(peak FLOP/s, I × bandwidth)
Latency-bound throughput: FPS = 1000 / latency_ms (batch 1) ; with pipelining, FPS = 1000 / slowest_stage_ms
Energy per inference E (mJ) = average power (W) × latency (ms)
Distillation loss: L = α·CE(y, student) + (1 − α)·T²·KL(softmax(zt/T) ‖ softmax(zs/T))
Pruned parameter count = N × (1 − s), where s = sparsity fraction
Amdahl-style speedup when a fraction f of the model is accelerated by factor k: speedup = 1/((1 − f) + f/k)

Example 1 - INT8 quantisation parameters and round-trip error. A layer's activations after calibration lie in [−4.0, 12.0]. Quantise to asymmetric UINT8 (0-255).

Example 2 - Model size, memory bandwidth and the real bottleneck. A 25.6-million-parameter ResNet-50 is deployed on a board with 25 GB/s memory bandwidth and 1.3 TFLOPS of FP16 compute. The model needs 8.2 GFLOPs per 224×224 image.

Example 3 - Depthwise separable convolution saving. Layer: input 56×56×128, 3×3 convolution, 256 output channels, stride 1, same padding (output 56×56×256).

Example 4 - Latency budget for an Indian retail camera. A shelf-monitoring camera must process 15 fps. Measured per frame: capture+resize 4 ms, normalise 2 ms, inference 48 ms (FP32 on CPU), NMS+decode 6 ms.

Example 5 - Pruning plus quantisation for a TinyML microcontroller. A 1.2-million-parameter keyword-spotting model must fit 256 kB of flash on a Cortex-M4.

TechniqueSize gainSpeed gainAccuracy costNeeds retraining
FP16 / BF162x1.5-2x on GPU/NPUNegligibleNo
PTQ dynamic INT8~4x1.5-2x0-1%No
PTQ static INT84x2-4x0.5-2%No (calibration only)
QAT INT84x2-4x<0.5%Yes
INT4 weight-only (LLM)8x2-3x (memory-bound)1-3% perplexityNo (GPTQ/AWQ)
Unstructured pruning 80%2-5x stored~1x without sparse kernels0-2%Yes (fine-tune)
Structured pruning 50%2x1.8-2x1-3%Yes (fine-tune)
Knowledge distillation3-10x3-10x1-4%Yes (full training)
Efficient architecture5-20x5-20xDepends on targetYes (train from scratch)
DeploymentLatencyPrivacyOfflineRecurring costModel size limit
Cloud GPU100-500 ms (network)Data leaves deviceNoHigh, per hourEffectively none
Edge box (Jetson)5-50 msLocalYesOne-time hardware~1-8 GB
Mobile SoC NPU5-30 msLocalYesNone~100 MB-2 GB
MCU (TinyML)1-100 msLocalYesNone20-500 kB
# TFLite/LiteRT full-integer post-training quantisation with a calibration generator
import tensorflow as tf, numpy as np

def rep_data():                      # 100-500 real samples, same pre-processing as deployment
    for img in calib_images[:300]:
        yield [np.expand_dims(img.astype(np.float32), 0)]

conv = tf.lite.TFLiteConverter.from_saved_model("saved_model/")
conv.optimizations = [tf.lite.Optimize.DEFAULT]
conv.representative_dataset = rep_data
conv.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
conv.inference_input_type  = tf.int8   # fully integer in/out -> no float ops on the MCU
conv.inference_output_type = tf.int8
open("model_int8.tflite", "wb").write(conv.convert())
# PyTorch structured pruning + export, then measure on-device (never trust FLOPs alone)
import torch, torch.nn.utils.prune as prune
for m in model.modules():
    if isinstance(m, torch.nn.Conv2d):
        prune.ln_structured(m, name="weight", amount=0.3, n=2, dim=0)  # drop 30% of filters
        prune.remove(m, "weight")          # make the sparsity permanent before export
# fine-tune here, then: torch.onnx.export(...) and benchmark p50/p95 after warm-up

Where it is used

Interview questions

Common mistakes

Related topics

Computer vision basics · Object detection and segmentation · Speech recognition and audio AI · Large language models and prompt engineering · Embedded systems and microcontrollers · MLOps and model deployment

Open in the Knowledge reader →Find jobs →