Quantization interview question

MLOps & ProductionQuantizationModel Compressionmedium

What does this symmetric INT8 quantization snippet print, and which statement about using an asymmetric (zero-point) scheme for ReLU outputs is correct?

python
import numpy as np

x = np.array([-0.62, 0.013, 0.733, 2.54], dtype=np.float32)
scale = np.abs(x).max() / 127                      # symmetric INT8
q = np.clip(np.round(x / scale), -127, 127).astype(np.int8)
x_hat = q.astype(np.float32) * scale               # dequantize
print(q.tolist())
print(round(float(x_hat[2]), 3))
  1. A[-31, 1, 37, 127] and 0.74. ReLU outputs are never negative, so a zero-point lets all 256 codes cover [0, max] and gives a step about half as large as the symmetric one.
  2. B[-31, 1, 37, 127] and 0.74. ReLU outputs need a zero-point because symmetric INT8 has no exact code for zero, which would turn every inactive ReLU unit into a small non-zero value.
  3. C[-31, 0, 37, 127] and 0.733. Values inside the range dequantize back exactly, and for ReLU outputs a zero-point mainly helps by keeping the rare negative values accurate.
  4. D[-31, 1, 36, 127] and 0.72. Casting to int8 truncates 36.65 down to 36, and for ReLU outputs a zero-point centres the grid on the mean activation, which lowers the error.
Show the answer and explanation

Correct answer: A, [-31, 1, 37, 127] and 0.74. ReLU outputs are never negative, so a zero-point lets all 256 codes cover [0, max] and gives a step about half as large as the symmetric one.

Explanation Quantization

Symmetric quantization maps [−max|x|, +max|x|] onto the integers −127…127 with zero at code 0: scale = max|x| / 127, q = round(x / scale), x̂ = q × scale.

Here scale = 2.54 / 127 = 0.02:

xx / scaleqx̂error
−0.62−31.0−31−0.620
0.0130.6510.020.007 (54% relative)
0.73336.65370.740.007
2.54127.01272.540

np.round runs before the cast, so 36.65 becomes 37, not 36. The maximum rounding error is scale / 2 = 0.01, and small values lose the most relative precision.

Asymmetric quantization adds a zero-point z: q = round(x / scale) + z, with scale = (max − min) / 255 for UINT8. It pays off when the range is lopsided. ReLU outputs in [0, 6]:

  • symmetric: scale = 6 / 127 ≈ 0.047, and the 127 negative codes are never used
  • asymmetric: scale = 6 / 255 ≈ 0.024, about half the step, so half the rounding error

Why the distractors fail: symmetric schemes represent zero exactly (code 0); ReLU outputs have no negative values to protect; and a zero-point aligns the grid with the min–max range, not with the mean.

Interview tip: the common recipe is symmetric per-channel for weights (centred near zero) and asymmetric or calibrated per-tensor for activations, whose ranges are often one-sided.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More MLOps & Production questions

  1. A telecom team adds a new feature, dropped_calls_7d, produced by a streaming job from network events starting today. To train on 18 months of history, past…
  2. A retailer's progressive-delivery pipeline shifts traffic to a new recommendation-API version in steps of 5% → 25% → 50% → 100%. At each step, automated…
  3. A telecom support bot on a self-hosted vLLM server sends a 3,000-token system prompt plus the growing chat history on every turn. After you enable automatic…
  4. A security review of a retail client's Google Cloud project finds that the Vertex AI training pipeline, a GKE scoring service and a nightly export job all run…
  5. On a GKE cluster you deploy a model server as a Deployment with 3 replicas and expose it with a Service. Which statement correctly describes these Kubernetes…