Exercises — Edge deployment and ONNX
Before we start, one symbol we reuse everywhere:
L1 — Recognition
Q1.1
Match each pain to whether it is solved by edge or cloud: (a) raw camera frames must never leave the device, (b) the model needs 40 GB of GPU memory, (c) the robot must react in 5 ms with no Wi-Fi.
Recall Solution
(a) Edge — data never leaves the device solves privacy. (b) Cloud — a tiny edge chip cannot hold a 40 GB model; only cloud GPUs can. (c) Edge — 5 ms with no network means the round-trip terms don't even exist; must compute locally.
Q1.2
Name the four things ONNX stores inside its graph file.
Recall Solution
nodes (operators like Conv, MatMul, Relu), initializers (the weights), typed inputs, and typed outputs. Mnemonic from the parent: N-O-R-I = Nodes, Operators, Runtime-Inputs.
Q1.3
In providers=["CPUExecutionProvider"], what is an Execution Provider (EP) in one sentence?
Recall Solution
An EP is the backend that actually computes the graph's operations — the swappable engine (CPU, CUDA, TensorRT, CoreML, NNAPI) that ONNX Runtime hands each operator to. Related: TensorRT and GPU Optimization, Mobile ML - CoreML and TFLite.
L2 — Application
Q2.1
A model has weights stored as float32. How many megabytes (1 MB bytes) does it occupy? After int8 quantization?
Recall Solution
float32 = 4 bytes/weight: bytes MB. int8 = 1 byte/weight: bytes MB. Exactly a 4× shrink — the "80/20 win" from the parent.
Q2.2
Weights fall in . Target signed int8 . Compute the scale .
Recall Solution
Why this formula: it stretches the 10-wide real range to fit the 255-wide integer range so both endpoints line up.
Q2.3
Using from Q2.2, find the zero-point (rounded to nearest integer).
Recall Solution
Why: is the integer that decodes back to exactly real . Because the range is asymmetric, is not — it slides toward the crowded side.
Q2.4
Quantize with . Then dequantize and report the error.
Recall Solution
Error . ✓ within the theoretical bound.
L3 — Analysis
Q3.1
Two quantization schemes for weights in : A — one global range . B — per-channel; the busy channel is . Compare the worst-case rounding error for a value inside the busy channel. Why does per-channel win?
Recall Solution
Scheme A: , so . Scheme B: , so . Per-channel error is 10× smaller ( vs ). Why: the busy channel's true values only span ; a global range wastes most of its 255 integer steps on empty space , making each step coarse. Tighter range ⇒ smaller ⇒ smaller error. See Model Quantization and Pruning.
Q3.2
Cloud path: ms, ms, ms, ms. Edge inference ms. Which wins, and by how much?

Recall Solution
Edge wins by ms. Check the parent's rearranged inequality — compute penalty ms; network+queue ms. Since , edge wins. ✓ See Model Serving and Inference Latency.
Q3.3
The same edge chip gets a firmware bug and now takes ms. Recompute. What flipped and why?
Recall Solution
ms vs ms. Cloud now wins by ms. The compute penalty ms now exceeds network+queue ms, so the inequality flips. Lesson: the winner is not a property of "edge vs cloud" but of the numbers — always evaluate the inequality.
L4 — Synthesis
Q4.1
You export a PyTorch classifier that (i) is fed variable batch sizes in production and (ii) uses an operator only defined in opset 16+. Write the three torch.onnx.export arguments that matter and justify each.
Recall Solution
torch.onnx.export(model, dummy, "m.onnx",
input_names=["img"], output_names=["logits"],
dynamic_axes={"img": {0: "batch"}}, # variable batch → mark axis 0 dynamic
opset_version=16) # lowest opset that has the opdummy(real-shaped tensor): export traces the actual ops; no input ⇒ no trace ⇒ no graph.dynamic_axes: without it, batch is frozen at the dummy's size and production feeds cause shape-mismatch errors.opset_version=16: pick the lowest opset that still supports your op, so the widest set of runtimes can load it. Higher-than-needed opset risks "unsupported opset" load failures.
Q4.2
Cloud output and edge output differ by max element . You call np.allclose(a, b, atol=1e-4). Does it pass? Should you "fix" the mismatch? Explain in terms of Execution Providers.
Recall Solution
, so allclose returns True — it passes. You should not try to force bit-identical output: different EPs use different kernels, operator fusion, and floating-point summation order, so results agree only to a tolerance, never exactly. Validating agreement (not equality) is the correct engineering check.
L5 — Mastery
Q5.1
Design a decision rule in one inequality for whether to deploy on edge, given data size bytes, bandwidth bytes/s (uplink+downlink combined), queue , and the two inference times. Then apply it: B, B/s, s, s, s.
Recall Solution
Transfer time (bytes over bytes-per-second). Deploy on edge when: Left = compute penalty of the smaller chip; right = network + queue cost saved. Plug in: penalty s. Network+queue s. Since → deploy on edge (saves s per call). Ties to Data Privacy and Federated Learning when privacy also forbids the round-trip.
Q5.2
Build a full quantize→dequantize round-trip for the value in range into int8, then state the exact reconstruction error. (Reuse from L2.)
Recall Solution
, (from Q2.2–Q2.3). Clamp check: ✓ (no saturation). Error . ✓ Round-trip lands inside the guaranteed error box.
Q5.3
A value is quantized with the same scheme. Show what breaks and name the standard fix.
Recall Solution
. But int8 max is , so must clamp (saturate) to 127. Dequantized: — the true is crushed to , a huge error of . Why: lies outside the calibrated range . Fix: choose the range with a calibration dataset that actually covers such outliers, or use quantization-aware training (QAT) so the network learns to avoid out-of-range activations. See Model Quantization and Pruning.
Connections
- Model Quantization and Pruning
- Model Serving and Inference Latency
- TensorRT and GPU Optimization
- Computational Graphs
- Data Privacy and Federated Learning
- Mobile ML - CoreML and TFLite