Pulse Data Hub

Edge Computing in Data Science: Shrinking Models, Tested

Edge Computing in Data Science: Shrinking Models, Tested

Edge computing in data science means running a trained model on the device that collects the data, such as a phone, camera or sensor, instead of sending everything to a server. That puts hard limits on model size, speed and power. This article measures those trade-offs on a real task: we trained several models on 1,797 handwritten digits, then compared size on disk, accuracy and single-prediction latency, and tried compressing a neural network with 8-bit quantization. One result went against the usual advice. Measured with torch 2.15 and scikit-learn 1.9.1 on a 2-core cloud CPU with one thread.

Bar chart of model size in KB: random forest 4,644, float32 neural net 656, small forest 589, SVM 350, float16 net 329, int8 net 170, logistic regression 6
Size on disk of each trained model (test accuracy in brackets).

Why the edge

Running locally cuts the round trip to a server (latency), keeps raw data on the device (privacy), and works without a network. The price is a small memory budget and a weak processor, so a model needs to be small and fast enough, not just accurate.

The task and the models

We used the digits dataset bundled with scikit-learn (1,797 images, 8×8 pixels; 1,347 for training, 450 for testing). We trained a neural network with 167,178 weights (64-512-256-10), logistic regression, an RBF SVM and two random forests. Everything was measured on the same split.

import torch, torch.nn as nn

net = nn.Sequential(nn.Linear(64, 512), nn.ReLU(), nn.Linear(512, 256), nn.ReLU(), nn.Linear(256, 10))
# ... trained 30 epochs with Adam ...

# 8-bit dynamic quantization of the Linear layers
quantized = torch.ao.quantization.quantize_dynamic(net, {nn.Linear}, dtype=torch.qint8)
half = net.half()                               # 16-bit weights

Size and accuracy

ModelTest accuracySize on disk
Random forest, 100 trees0.9824,644 KB
Neural network, float320.978656 KB
Random forest, 20 trees, depth 80.956589 KB
SVM, RBF kernel0.989350 KB
Neural network, float16 weights0.978329 KB
Neural network, int8 quantized0.978170 KB
Logistic regression0.9696 KB

Quantization worked as advertised on size: converting the weights to 8 bits cut the neural network from 656 KB to 170 KB (3.9 times smaller) with exactly the same test accuracy (0.978), and 16-bit weights halved it to 329 KB, also with no accuracy change. The 100-tree forest was the largest at 4.6 MB; a small forest was 8 times smaller but lost 2.7 points of accuracy. And the logistic regression was only 6 KB with 96.9% accuracy, which is hard to beat for a tight budget.

The surprise: smaller was not faster

ModelMedian latency, one image
Neural network, float3230 microseconds
Neural network, int8 quantized63 microseconds
Logistic regression (scikit-learn)92 microseconds
SVM (scikit-learn)120 microseconds
Random forest, 20 trees1,206 microseconds
Random forest, 100 trees5,267 microseconds

On this CPU, the quantized network was twice as slow as the float32 one (63 versus 30 microseconds; the 95th percentile was 92 versus 43). A network this small is dominated by overhead, and dynamic quantization adds work to convert the activations on each call. Quantization usually pays off for latency on larger models and on hardware with fast integer instructions, but we did not test those, so check on your own device. Note that the scikit-learn timings include Python call overhead, so they are not directly comparable with the PyTorch ones; the gap between the 100-tree forest and the other models (more than 40 times slower than the SVM) is large enough to hold regardless.

What this means for edge projects

Start with the simplest model that meets the accuracy requirement (here logistic regression or a small network), then shrink: quantize, prune or reduce the forest. Always measure size, accuracy and latency on the target hardware, because a compression that wins on one axis can lose on another, as ours did on speed. For model-building background see neural networks in Python, support vector machines, random forests and how to deploy a model with Flask when a server is fine. The official PyTorch quantization documentation describes the methods.

Limits of this test

A toy dataset and a small network; one cloud CPU, not a phone or microcontroller; single-thread timings; one training run per model; no power or battery measurement. Results on real edge hardware may differ, especially for latency.

FAQ

What is edge computing in data science?

Running trained models on the device that produces the data, for low latency, privacy and offline use.

Does quantization hurt accuracy?

Not in our test: int8 and float16 versions of the network both scored 0.978, same as float32. Larger models can lose accuracy, so test each one.

Is a quantized model always faster?

No. Ours was about twice as slow at one prediction on this CPU, though 3.9 times smaller.

Which model suits a tiny device?

Logistic regression was only 6 KB and 96.9% accurate on this task. Start there and move up only if the accuracy is not enough.

Newsletter Signup Form

Latest tutorials

Latest articles

On this page
Verified by MonsterInsights