---
title: Prediction Difference Metrics (PD-Quant)
url: https://www.emergentmind.com/topics/prediction-difference-metrics-pd-quant
type: topic
---

# Prediction Difference Metrics (PD-Quant)

Prediction Difference Metrics (PD-Quant) are a class of post-training quantization (PTQ) techniques that employ global measures of prediction shift to optimize quantization parameters in deep neural networks. Unlike conventional PTQ approaches based on local feature or activation distance, PD-Quant determines quantization parameters by explicitly minimizing the difference between the predicted distributions of a full-precision network and its quantized counterpart over a calibration set. This method aims to reduce accuracy degradation in aggressive (e.g., 2-bit) quantization regimes by leveraging a global prediction difference metric, typically instantiated via the Kullback–Leibler (KL) divergence between output softmax distributions [2212.07048]. PD-Quant further incorporates techniques to counteract overfitting with limited calibration data, notably via distribution correction of activations.

## 1. Formal Definition of the Prediction Difference Metric

Let $f(\cdot)$ denote a full-precision neural network and $f^q(\cdot)$ its quantized version. Given a calibration dataset $\{x_i\}_{i=1}^N$, define:

- $p_i = f(x_i) \in \mathbb{R}^C$: Softmax output of $f$ on input $x_i$
- $q_i = f^q(x_i) \in \mathbb{R}^C$: Softmax output of $f^q$ on $x_i$

The Prediction Difference Metric (PDM) is the average KL divergence between the predictions:
\[
\mathrm{PDM}(f, f^q) = \frac{1}{N}\sum_{i=1}^N D_{\mathrm{KL}}(p_i \Vert q_i) = \frac{1}{N}\sum_{i=1}^N \sum_{c=1}^C p_i(c) \log \frac{p_i(c)}{q_i(c)}
\]

PDM quantifies the shift in predicted distributions resulting from quantization noise, serving as a global criterion for PTQ parameter search.

## 2. Optimization of Quantization Parameters via PDM

PD-Quant simultaneously optimizes per-layer/block activation scales ($S_a$) and per-weight rounding offsets ($\theta$). For block $l$, given quantized output $\tilde A_l = B^q_l(\tilde A_{l-1}; S_a, \theta)$ and original prediction $O_{fp} = f(x)$, the optimization problem is:

\[
\min_{S_a, \theta}~ D_{\mathrm{KL}}\Big(O_{fp}\Vert f_{l+1}(\tilde{A}_l)\Big) + \lambda_r \|A_l - \tilde{A}_l\|_2^2
\]

- $\mathcal{L}_{PD}$: Global loss (prediction difference)
- $\mathcal{L}_{\mathrm{reg}}$: Blockwise output MSE regularizer
- $\lambda_r$: Regularization coefficient (typ. $0.05$–$0.5$)

The quantizer for each value $x$ is:
\[
\tilde x = \mathrm{clamp}\left(\left\lfloor \frac{x + \theta}{S} \right\rceil + Z; q_{\min}, q_{\max}\right)
\]
with scale $S$, zero-point $Z$, and round offset $\theta$.

## 3. Algorithmic Description and Workflow

PD-Quant is implemented as a blockwise, calibration-driven algorithm. The standard workflow is:

1. Initialize $f^q \leftarrow f$; set all $\theta \leftarrow 0$; set all $S_a$ via min–max.
2. For $l=1\ldots L$ (blocks):
   a. Propagate calibration samples through blocks $1\ldots l-1$ to obtain inputs $\{A_{l-1}^q\}$.
   b. (Optional) Apply Distribution Correction (DC) to match batch statistics.
   c. Jointly optimize $(S_a, \theta)$ by minimizing the sum of PDM loss and local regularizer for $\sim 20,000$ iterations.
   d. Freeze parameters and proceed to the next block.
3. Output the fully quantized network $f^q$.

The pseudocode structure is as follows:

```python
# Pseudocode for PD-Quant
Input: f (FP network), X (calibration set)
Output: f^q (Quantized network)

for l in 1...L:
    if l > 1:
        compute {A_{l-1}^q}
    optionally: {A_{l-1}^{DC}} = DC({A_{l-1}^q})
    optimize S_a, θ for block l:
        for each step:
            compute softmax outputs
            compute L_PD = (1/N) ∑ D_KL
            compute L_reg = (1/N) ∑ ||A_l - B^q_l(A_{l-1})||^2
            update S_a, θ via gradient
    freeze block l
return f^q
```

## 4. Overfitting Mitigation: Distribution Correction

With limited calibration data, PTQ can overfit to idiosyncratic activation statistics. PD-Quant addresses this by remapping block inputs to match the mean/variance recorded in BatchNorm layers:

Let block $l$ have $n$ BatchNorm layers with statistics $\{\mu_{(i,l)}, \sigma_{(i,l)}\}_{i=1}^n$. For sample batch statistics $\{\hat{\mu}_{(i,l)}, \hat{\sigma}_{(i,l)}\}$, solve

\[
A_{l-1}^{DC} = \arg\min_{A} \lambda_c \sum_{i=1}^n \big[ (\hat{\mu}_{(i,l)} - \mu_{(i,l)})^2 + (\hat{\sigma}_{(i,l)} - \sigma_{(i,l)})^2 \big] + \|A - A_{l-1}^{FP}\|^2
\]

Here, $\lambda_c$ tunes the correction's strength ($0$ corresponds to no correction). Correction is performed using a few steps of gradient descent and is activated when the calibration set is small ($\lesssim 2$K).

## 5. Empirical Performance and Benchmarking

PD-Quant demonstrates consistent improvements in accuracy over established PTQ baselines, particularly in low-bit regimes. Selected results include:

| Model            | Bit | Baseline QDrop | PD-Quant |
|------------------|-----|---------------|----------|
| ResNet-18        | 2/2 | 51.42%        | 53.14%   |
| RegNetX-600MF    | 2/2 | 39.01%        | 40.67%   |

Wider 4-bit/2-bit (W4A2) or 2-bit/4-bit (W2A4) configurations see $1$–$3\%$ improvements. At 256 calibration images, gains over QDrop remain $0.5$–$1\%$; the benefit of DC diminishes with calibration set size.

Relative quantization time (ResNet-18, RTX A6000):

- QDrop: $\sim 0.4$ h
- PD-Quant (no DC): $\sim 0.9$ h
- PD-Quant ($+$DC): $\sim 1.1$ h

This is substantially faster than quantization-aware training (QAT; e.g., LSQ, $\sim 120$ h).

## 6. Hyperparameters, Calibration, and Implementation Details

Hyperparameters are found robust across model architectures:

- $\lambda_r$ (regularization): $[0.05, 0.5]$
- $\lambda_c$ (DC strength): $[0, 0.02]$

Calibration sets of $1$K–$2$K in-domain images yield optimal results; even at $256$ samples, performance exceeds QDrop. Notably, scale optimization for weights via PDM does not provide further benefit, as weight scale search per channel is discrete; MSE or per-channel min–max is preferred for this aspect.

## 7. Limitations, Methodological Extensions, and Best Practices

PD-Quant incurs additional fine-tuning cost (typically $\sim1$ h per model), contrasting with search-only approaches. Application to Vision Transformers (ViT/DeiT) shows $1$–$2\%$ improvements at W4A6 and W2A6. Other potential metrics (e.g., Earth Mover’s Distance) may be substituted for KL, and mixed-precision bitwidth selection can be informed by PDM sensitivity.

Best practices include quantizing blocks in order, utilizing $1,000$–$2,000$ in-domain calibration samples, tuning $\lambda_r$ on a single block, always incorporating the local $\mathcal{L}_{\mathrm{reg}}$, and applying DC for small calibration sizes.

A plausible implication is that layer-local MSE alone insufficiently captures prediction robustness under quantization, and global output-centric metrics such as PDM provide a superior quantization protocol for aggressive precision reduction [2212.07048].

Source: https://www.emergentmind.com/topics/prediction-difference-metrics-pd-quant