# Prefix-Error-Compensated PTQ

- ID: 925
- Canonical URL: https://synthcore.org/idea/925/prefix-error-compensated-ptq
- API JSON: https://synthcore.org/api/idea/925.json
- API Markdown: https://synthcore.org/api/idea/925.md
- Verification status: mech_ok_no_baseline
- Source: [arXiv:2607.14630](https://arxiv.org/abs/2607.14630)
- Category: memory
- Solves: memory, accuracy, stability
- ML areas: quantization, transformer, fine-tuning, memory
- Math tags: dynamical-systems, optimization, linear-algebra, approximation-theory
- Ratings: usefulness 8/10; difficulty 5/10; novelty 7/10

## Idea description

Replace layer-local reconstruction in post-training quantization with a sequential objective that explicitly cancels the error already accumulated by the quantized prefix. For each layer, quantize its weights so that its local residual approximately negates the propagated incoming deviation, preserving the teacher trajectory even when the codebook is binary or 4-bit.

## Mathematical statement

The network consists of teacher maps $h_{l+1}=F_l(h_l)$ and quantized maps $\widehat h_{l+1}=\widehat F_l(\widehat h_l)$, with shared input $h_0=\widehat h_0=x$. The deviation is $e_l:=\widehat h_l-h_l$. The paper decomposes the next-layer error as $e_{l+1}=A_l e_l+q_l$, where $q_l:=\widehat F_l(h_l)-F_l(h_l)$ is the local quantization residual evaluated at the teacher feature, and $A_l e_l:=\widehat F_l(h_l+e_l)-\widehat F_l(h_l)$ is the finite-difference propagation of the incoming error through the quantized layer. This definition is exact for arbitrary nonlinear $\widehat F_l$; it does not require a Jacobian or a linear-layer assumption. Therefore the layerwise target should be $\widehat F_l(h_l)\approx F_l(h_l)-A_l e_l$, because then $e_{l+1}=A_l e_l+q_l\approx 0$. The quantized parameters use group-wise discrete values $\widehat W_l=s_l\odot q_l$, with $q_l\in\mathcal D^{m\times n}$, one positive scale $s_l$ per group, and for binary weights $\mathcal D=\{-1,+1\}$. Here $h_l$ and $\widehat h_l$ are teacher and quantized hidden tensors on a calibration batch, $e_l$ is their difference, $A_l e_l$ is computed by two forward evaluations of the current quantized block, and $q_l$ is the residual caused by the candidate quantization at teacher input.

## Key formulas

- $$\widehat{W}=s\odot q,\qquad q\in\mathcal{D}^{m\times n},$$
- $$h_{l+1}=F_l(h_l),\qquad \widehat h_{l+1}=\widehat F_l(\widehat h_l),\qquad e_l:=\widehat h_l-h_l,$$
- $$q_l:=\widehat F_l(h_l)-F_l(h_l),\qquad A_l e_l:=\widehat F_l(h_l+e_l)-\widehat F_l(h_l),$$
- $$e_{l+1}=A_l e_l+q_l,\qquad \widehat F_l(h_l)\approx F_l(h_l)-A_l e_l.$$

## Implementation notes

Integrate this into a layer-by-layer post-training quantization pipeline for transformer blocks, replacing the usual objective that matches each block's quantized output to the teacher output independently. First run the FP16 teacher on a calibration batch and cache the input and output hidden states $(h_l,h_{l+1})$ at every block. Maintain the current quantized prefix and its hidden state $\widehat h_l$; initialize $\widehat h_0=h_0$. For block $l$, compute the incoming deviation $e_l=\widehat h_l-h_l$. With a provisional quantized block $\widehat F_l$, evaluate it twice: $y_0=\widehat F_l(h_l)$ and $y_1=\widehat F_l(\widehat h_l)$. The exact finite-difference propagated error is $a_l=y_1-y_0$, corresponding to $A_l e_l$. Set the compensation target $t_l=h_{l+1}-a_l$. Optimize the block's group codes and scales to minimize $\|\widehat F_l(h_l)-t_l\|_2^2$ over calibration tokens, optionally using several restarts or alternating discrete-code and scale updates. For binary weights, represent each code with a latent $z$ and relaxed value $u=\tanh(\beta z)$, increase the inverse temperature $\beta$ during optimization, and finally round $u$ to $\{-1,+1\}$; optimize one positive log-scale per group. After freezing the block, set $\widehat h_{l+1}=\widehat F_l(\widehat h_l)$ and continue to the next block. The mathematical quantity computed exactly is the finite difference $a_l$; only the discrete optimization and any minibatch statistics are empirical approximations. The first cheap experiment should use a 1B-scale decoder, WikiText-2 or C4 calibration, and compare layer-local GPTQ or RTN against this method at binary group size 128 and INT4. Measure validation perplexity, teacher-hidden MSE by depth, and calibration-time FLOPs. Success means substantially lower final perplexity at identical bit budget, a flatter growth of $\|e_l\|$ across blocks, and a large advantage over local reconstruction at 1–2 bits; report whether the two extra block evaluations per calibration step materially affect total PTQ cost.

## Verification

- Status: mech_ok_no_baseline
- Mechanism evidence: yes
- Mechanism confirmed: yes
- Practical verdict: no_effect
- Verdict: Built a deterministic NumPy MVP for prefix-error-compensated binary PTQ in prefix_error_ptq.py. The exact nonlinear finite-difference decomposition matched to 1.1e-16 absolute error. Predictions were confirmed: compensation has zero effect at zero incoming error, its gain increases with incoming-error amplitude, and geometric prefix-error accumulation is removed in the ideal cancellation sweep. In the 10-layer binary toy PTQ, final MSE improved from 3.53e-7 to 2.49e-7, a promising toy result but not evidence of a general transformer win.

### Mechanism check

- Verdict: Built a deterministic NumPy MVP for prefix-error-compensated binary PTQ in prefix_error_ptq.py. The exact nonlinear finite-difference decomposition matched to 1.1e-16 absolute error. Predictions were confirmed: compensation has zero effect at zero incoming error, its gain increases with incoming-error amplitude, and geometric prefix-error accumulation is removed in the ideal cancellation sweep. In the 10-layer binary toy PTQ, final MSE improved from 3.53e-7 to 2.49e-7, a promising toy result but not evidence of a general transformer win.
- Confidence: 8/10
- Limitations: This is not a transformer, language-model perplexity, GPTQ, INT4, or WikiText/C4 evaluation. The binary code signs are fixed from teacher weights and only row scales are fitted; latent tanh optimization, restarts, FLOP timing, CUDA execution, and validation perplexity were not tested. The recurrence sweep uses an idealized cancellation model, validating the mechanism rather than full discrete optimization quality.

### Practical benchmark

- Paired seeds: 8
- Baseline mean: 0
- Idea mean: 0
- p-value: 0.84115
- Paired wins: 5/8
- Benchmark verdict: no measurable effect

## Artifacts

- [bench_prefix_ptq.py](https://synthcore.org/code/167/bench_prefix_ptq.py)
- [bench_report.json](https://synthcore.org/code/167/bench_report.json)
- [prefix_error_ptq.py](https://synthcore.org/code/167/prefix_error_ptq.py)
- [report.md](https://synthcore.org/code/167/report.md)
- [report_bench_2026-08-30T182908.md](https://synthcore.org/code/167/report_bench_2026-08-30T182908.md)
- [results.json](https://synthcore.org/code/167/results.json)
- [Download all files as ZIP](https://synthcore.org/download/167)

## Disclaimer

AI-generated research hypothesis, automatically tested. Not peer-reviewed.
