liveBook · Manning

Max absolute difference

As explained in Quantization and Fast Inference

The largest absolute element-wise difference between two numerical outputs.

Max absolute difference is the largest element-wise absolute difference between two outputs: max(|baseline − variant|). For logits, it reports the worst single-logit divergence. section 6.5

Quantized ResNet-18 logits

Against a PyTorch FP32 baseline, ORT Static INT8 has a max absolute difference of 1.119 across 100 ImageNette samples; ONNX FP32 has 0.00007. section 6.5

Listing 6.8 Tensor-level equivalence metrics
def compute_equivalence_metrics(baseline, variant, labels=None):
    diff = baseline - variant                                     #A
    abs_diff = np.abs(diff)
 
    # Per-sample cosine similarity, then average
    dot = np.sum(baseline * variant, axis=1)
    norm_b = np.linalg.norm(baseline, axis=1)
    norm_v = np.linalg.norm(variant, axis=1)
    cos_sim = dot / (norm_b * norm_v + 1e-12)                    #B
 
    preds_base = np.argmax(baseline, axis=1)
    preds_var = np.argmax(variant, axis=1)
    agreement = np.mean(preds_base == preds_var)                  #C
 
    return {
        "max_abs_diff": float(abs_diff.max()),
        "mean_abs_diff": float(abs_diff.mean()),
        "cosine_sim": float(np.mean(cos_sim)),
        "top1_agreement": float(agreement),
    }

The equivalence-metrics listing computes the value by taking the maximum of the element-wise absolute differences. section 6.5

How Quantization and Fast Inference covers it

How deep it goes
Defines the worst-case logit error and implements it as the maximum element-wise absolute difference.
Examples
Uses ResNet-18 comparisons showing 1.119 for ORT Static INT8 and 0.00007 for ONNX FP32.
What you can do after
Evaluate the worst single-logit divergence between a baseline and a model variant.
How it connects
Connects to mean absolute difference, mean squared error, cosine similarity, top-1 prediction agreement, and quantization.

This explainer was generated by Manning's knowledge graph from the text of Quantization and Fast Inference. The section links point to the parts of the book it draws on.