Intuition What this page is
The parent Edge deployment and ONNX note gave you the formulas . Here we stress-test them against every kind of input a real deployment throws at you: normal numbers, zero-width ranges, negative-only ranges, saturating outliers, the latency break-even, and an exam twist. If a scenario exists, you should meet it below.
We reuse only two engines from the parent:
Latency: edge wins when t infer edge < t up + t infer cloud + t down + t queue .
Quantization: the affine map r = S ( q − Z ) with S = q m a x − q m i n r m a x − r m i n , Z = q m i n − S r m i n , and round-trip error ∣ r ^ − r ∣ ≤ S /2 .
Every worked example below is tagged with the cell it covers.
Cell
Scenario class
What can go wrong
A
Symmetric range [ − a , a ]
zero-point should land on 0
B
Asymmetric / positive-only range [ 0 , r m a x ] (post-ReLU)
zero-point shifts off centre
C
Negative-only range [ r m i n , 0 ]
sign of Z , does real-0 still map to an integer?
D
Value outside the range (outlier)
saturation / clamping at q m i n , q m a x
E
Degenerate range r m i n = r m a x
division by zero in S
F
Error bound as a limit
shrink range → shrink error
G
Latency break-even (real-world word problem)
edge-vs-cloud decision
H
Latency at the boundary (tie)
equality case, degenerate bandwidth
I
Exam-style twist: 4× size vs accuracy trade
reasoning, not just plugging
r = 0.5 with range [ − 1 , 1 ] into int8 [ − 128 , 127 ] .
Forecast: guess the integer q before reading. Closer to 0 or closer to 127 ?
Step 1. Compute the scale S = 127 − ( − 128 ) 1 − ( − 1 ) = 255 2 ≈ 0.007843 .
Why this step? S is "how many real units per integer tick" — we need it before anything else.
Step 2. Zero-point Z = − 128 − 0.007843 − 1 = − 128 + 127.5 = − 0.5 → round to 0 .
Why this step? Z is the integer that represents real 0 ; for a symmetric range it should sit near 0 .
Step 3. Quantize: q = round ( 0.5/0.007843 ) + 0 = round ( 63.75 ) = 64 .
Why this step? apply q = round ( r / S ) + Z — the forward map.
Step 4. Dequantize back: r ^ = 0.007843 × 64 = 0.5019 .
Why this step? to measure the rounding damage.
Verify: error = ∣0.5019 − 0.5∣ = 0.0019 ≤ S /2 = 0.0039 . Inside the guaranteed bound. ✓ Related tools: Model Quantization and Pruning .
Worked example A ReLU output lives in
[ 0 , 6 ] (a "ReLU6" clamp). Quantize r = 4.5 into uint8 [ 0 , 255 ] .
Forecast: since the range starts at 0 , will the zero-point be 0 or something else?
Step 1. S = 255 − 0 6 − 0 = 255 6 ≈ 0.023529 .
Why this step? activations are never negative here, so we spend all 256 codes on [ 0 , 6 ] .
Step 2. Z = 0 − S 0 = 0 .
Why this step? the low endpoint is real 0 , so real 0 maps to integer 0 — the zero-point sits at the very bottom.
Step 3. q = round ( 4.5/0.023529 ) + 0 = round ( 191.25 ) = 191 .
Why this step? forward map again.
Step 4. r ^ = 0.023529 × 191 = 4.494 .
Why this step? round-trip check.
Verify: error = 0.006 ≤ S /2 = 0.01176 . ✓ Zero-point landing exactly on 0 is why ReLU/padding stay exact after quantization.
Worked example Weights of a layer live in
[ − 3 , 0 ] . Quantize r = − 1.2 into int8 [ − 128 , 127 ] .
Forecast: the range's top is real 0 . Which integer will represent 0 ?
Step 1. S = 127 − ( − 128 ) 0 − ( − 3 ) = 255 3 ≈ 0.011765 .
Step 2. Z = q m i n − S r m i n = − 128 − 0.011765 − 3 = − 128 + 255 = 127 .
Why this step? here real 0 is the top endpoint, so real 0 maps to q m a x = 127 — the zero-point slides to the top.
Step 3. q = round ( − 1.2/0.011765 ) + 127 = round ( − 102 ) + 127 = − 102 + 127 = 25 .
Why this step? forward map; note the negative r / S pulls q below the zero-point.
Step 4. r ^ = 0.011765 × ( 25 − 127 ) = 0.011765 × ( − 102 ) = − 1.2 .
Why this step? round-trip.
Verify: error = ∣ − 1.2 − ( − 1.2 ) ∣ = 0.0 ≤ S /2 . ✓ (Exact here because − 1.2/ S hit a whole number.)
Worked example Range calibrated to
[ − 1 , 1 ] , int8 [ − 128 , 127 ] . A rare outlier r = 3.0 arrives. What happens?
Forecast: does q keep climbing past 127 , or stop?
Step 1. S = 2/255 ≈ 0.007843 , Z = 0 (same as Example 1).
Why this step? calibration was done earlier; new inputs reuse the frozen S , Z .
Step 2. Raw forward map: q raw = round ( 3.0/0.007843 ) + 0 = round ( 382.5 ) = 382 .
Why this step? the formula doesn't know about limits — it just computes.
Step 3. Clamp to the representable range: q = min ( 127 , max ( − 128 , 382 )) = 127 .
Why this step? an 8-bit integer physically cannot exceed 127 ; hardware saturates. Look at the red flat cap in the figure — every value above r m a x collapses onto the same code.
Step 4. r ^ = 0.007843 × ( 127 − 0 ) = 0.9961 .
Why this step? to see the huge error the outlier causes.
Verify: error = ∣0.9961 − 3.0∣ = 2.0039 ≫ S /2 . The bound S /2 only holds inside the range — this is exactly why calibration and QAT matter (parent's "quantizing is free accuracy" mistake).
Worked example A "dead" channel has all weights equal to
2.0 , so r m i n = r m a x = 2.0 . Quantize it.
Forecast: what does S do when the numerator is 0 ?
Step 1. S = q m a x − q m i n r m a x − r m i n = 255 2.0 − 2.0 = 255 0 = 0 .
Why this step? a zero-width range needs zero real units per tick.
Step 2. Z = q m i n − r m i n / S → division by zero . The formula breaks.
Why this step? to expose the degeneracy rather than crash silently.
Step 3. Fix / convention: when r m i n = r m a x , set S = 1 (or any nonzero) and store the constant directly; every input dequantizes to the single value 2.0 .
Why this step? real quantization libraries special-case zero-width ranges to avoid NaN.
Verify: with the fix, any q gives r ^ = 2.0 exactly (the channel is constant), error = 0 . ✓ Degenerate inputs must be caught , never fed to the raw formula.
Worked example Same value
r = 0.5 , but we tighten the range from [ − 1 , 1 ] to [ − 0.5 , 0.6 ] (per-channel calibration). How much does the worst-case error shrink?
Forecast: halving-ish the range — does the error bound roughly halve too?
Step 1. Old bound: S old = 2/255 , so S old /2 = 1/255 ≈ 0.003922 .
Why this step? baseline worst case.
Step 2. New scale: S new = 255 0.6 − ( − 0.5 ) = 255 1.1 ≈ 0.004314 .
Why this step? tighter real span ⇒ smaller S .
Step 3. New bound S new /2 = 0.55/255 ≈ 0.002157 .
Why this step? error scales linearly with S ; ∣ r ^ − r ∣ ≤ S /2 .
Step 4. Ratio: S old /2 S new /2 = 1.0 0.55 = 0.55 .
Why this step? the limiting behaviour — as range span → 0 , worst-case error → 0 proportionally.
Verify: 0.002157 ≈ 0.55 × 0.003922 . ✓ This is the mathematical reason per-channel ranges beat one global range .
Worked example A phone must classify a
150 KB image. Upload+download bandwidth B = 1 MB/s (so ≈ 1000 KB/s ). Cloud inference = 10 ms , queue = 30 ms . The phone's own model runs in t infer edge = 120 ms . Edge or cloud?
Forecast: cloud's chip is 12× faster at compute — but does that win overall?
Step 1. Transfer time each way: t up = t down = 1000 KB/s 150 KB = 0.15 s = 150 ms .
Why this step? t ≈ bytes / B — the parent's transfer model. (Result label ≈ 0.5 KB, i.e. logits, is tiny; we keep 150 ms as a conservative symmetric estimate.)
Step 2. T cloud = t up + t infer cloud + t down + t queue = 150 + 10 + 150 + 30 = 340 ms .
Why this step? sum every term the cloud path pays.
Step 3. T edge = 120 ms .
Why this step? edge pays only its own compute — no transfer, no queue (look at the two stacked bars in the figure).
Step 4. Compare: 120 < 340 ⇒ edge wins by 220 ms .
Why this step? the decision rule: edge wins when network+queue (150 + 150 + 30 = 330 ) exceeds the compute penalty (120 − 10 = 110 ). 330 > 110 . ✓
Verify: compute penalty 110 ms < network+queue 330 ms , consistent with T edge < T cloud . ✓ See Model Serving and Inference Latency .
Worked example Same numbers as Example 7, but bandwidth drops so that we ask:
at what t infer edge do edge and cloud tie , and what does the tie mean?
Forecast: the tie edge-time equals cloud's total , right?
Step 1. Set T edge = T cloud : t ⋆ = 150 + 10 + 150 + 30 = 340 ms .
Why this step? the break-even is defined by equality.
Step 2. Interpretation: if the edge model took exactly 340 ms , both paths finish together — pick edge for privacy/offline as a tiebreaker.
Why this step? equality cases still need a decision; non-latency forces break the tie.
Step 3. Degenerate sub-case: if bandwidth B → ∞ , then t up , t down → 0 and T cloud → 10 + 30 = 40 ms ; now edge (120 ) loses .
Why this step? the limiting behaviour — infinite bandwidth kills the edge advantage, leaving only queue+compute.
Verify: at B → ∞ , T cloud = 40 ms < 120 ms , so cloud wins. The crossover bandwidth is exactly where 150 KB / B × 2 = 340 − 40 = 300 ms ⇒ B = 1000 KB/s , matching Example 7. ✓
Worked example "Int8 quantization makes a
40 MB float32 model 4 × smaller. A teammate claims that means exactly 4 × faster inference AND identical accuracy. Which claim(s) are wrong, and what is the true new size?"
Forecast: how many of the two claims survive?
Step 1. New size = 40 MB /4 = 10 MB (float32 = 4 bytes → int8 = 1 byte).
Why this step? size scales exactly with bytes-per-weight; this part is true.
Step 2. "4 × faster" — false in general. Speedup depends on whether the chip has fast int8 kernels and whether the model is memory-bound or compute-bound; often 2 –3 × , sometimes near 1 × .
Why this step? size ratio ≠ latency ratio (see TensorRT and GPU Optimization ).
Step 3. "Identical accuracy" — false. Rounding error ∣ r ^ − r ∣ ≤ S /2 per weight accumulates; outlier-sensitive layers can drop accuracy (Example 4). Fix: calibration or QAT.
Why this step? connects to the parent's "quantizing is free accuracy" mistake.
Verify: only the size claim (10 MB ) is exact; the speed and accuracy claims are approximations. 40/4 = 10 . ✓
Recall Did every cell get covered?
Which example handles a value outside the calibrated range? ::: Example 4 (Cell D, saturation).
Which example breaks the scale formula and why? ::: Example 5 — zero-width range gives S = 0 , dividing by zero in Z .
In the latency rule, edge wins when what exceeds what? ::: network+queue cost exceeds the compute penalty of the smaller chip.
What makes per-channel ranges beat a global range mathematically? ::: smaller S ⇒ smaller error bound S /2 (Example 6).
When does infinite bandwidth flip the decision to cloud? ::: transfer terms vanish, so only queue+compute remain (Example 8).
Mnemonic The three quant landmarks
"Sym-0, Pos-bottom, Neg-top" — for a sym metric range Z ≈ 0 ; for a pos itive-only range Z sits at the bottom (q m i n ); for a neg ative-only range Z sits at the top (q m a x ).