Repository navigation
v16.7 — The requantizer, proved UB-free
v16.7 — The requantizer, proved UB-free
A new CBMC proof covers the step that turns every int8 layer's int32 accumulator back into a narrow output: Requantizer::apply (int8, uint8, int16 and int32 storage) and multiplyByQuantizedMultiplier. Writing it found two cases of undefined behaviour, and both are fixed in this release. The SMLAD dot-product proof now runs on every pull request as a required check.
Fixes
quantizeMultipliershift out of range. For a scale ratio below 2^-32 it returned a shift of 32 or more, andRequantizer::applythen shifted a 32-bit value by that amount, which is undefined behaviour. Such a ratio rounds every int32 accumulator to 0, so it now returns multiplier 0. The left side is clamped at -31, beyond which every non-zero accumulator saturates anyway. No result changes. The shift contract, -31 <= shift <= 31, is now documented onRequantizer.- 32-bit storage zero-point overflow. With
int32_toutput storage, the one-rounding path added the zero point in int32 without the clamp the saturating path had, so a zero point near the rails overflowed. 32-bit storage now adds and clamps in int64 on both paths. - The int8, uint8 and int16 instantiations compile to byte-identical machine code before and after (Cortex-M0+ and Cortex-M4, -O3), so no deployed int8 model and no benchmark changes. Two regression tests in
unit_test/quantizationfail on the old header and pass now.
Formal verification
- Requantizer proof (
unit_test/formal/requantizer, opt-in): for every accumulator, multiplier, zero point and clamp bound at every shift from -31 to 31, the library is free of undefined behaviour and equals gemmlowp's two-step definition computed exactly in int64. That is 317 proofs, about 11 CPU-hours, and 5 planted defects that must each be caught. The reference uses gemmlowp's original forms rather than the library's derivations, so the proof also covers the one-rounding fast path and the ±2^30 rail.FastRequantizeris not covered, because CBMC 5.95's C++ front end cannot type-check it. - SMLAD proof in CI: the proof that the Cortex-M SMLAD int8 dot product equals the scalar reference for every input now runs on every pull request as the required check "CBMC proof (SMLAD dot product)". It runs 15 proofs and 4 planted defects with Bitwuzla 0.9.1 pinned by hash, so every run also shows the proof can fail. master now requires 22 checks.
Documentation, architecture guides, and example gallery: https://danmcleran.github.io/tinymind/
Full changelog: v16.6...v16.7