Skip to content

Speed up AVX2 inference with exact batched quantization and channel-major pointwise kernels - #22

Open
varyagnord wants to merge 4 commits into
ceva-ip:optimized-inferencefrom
varyagnord:perf/avx2-quantize4-cm64
Open

varyagnord wants to merge 4 commits into
ceva-ip:optimized-inferencefrom
varyagnord:perf/avx2-quantize4-cm64

Conversation

@varyagnord

@varyagnord varyagnord commented Nov 8, 2026 •

Copy link
Copy Markdown

AVX2 W7A8 inference currently computes K64 quantization parameters row by row and materializes channel-major/row-major float conversions around eight pointwise projections. This batches exact quantization parameters across four rows and adds a direct channel-major K64×N64 path, removing sixteen full float transposes per graph while preserving outputs and complete recurrent state bitwise.

This targets optimized-inference, on top of merged #21 (98df765). The implementation commits are 26c7a9c and cf16ba6; 41d0aa8 adds the direct cumulative measurement record.

Implementation

  • Batch the K64 min/max-derived scale, zero point and reciprocal calculations for four independent rows, using exact packed divisions and the original packing/rounding behavior. Zero-range groups retain the original algorithm.
  • Quantize eight frequency positions directly from channel-major input, compute four rows against two output tiles with a bounded AVX2 register schedule, and write channel-major results with a register 4×8 transpose. Avoid hot-loop accumulator spills.
  • Use the CM path only for eligible INT8 K64×N64 shapes and nonoverlapping input/output. Retain the original transpose/dense chain for other precisions, shapes, overlaps and VNNI selection.
  • Keep AVX2+FMA as the minimum, optional AVX-VNNI dispatch, unchanged weights/state/public ABI, seven public exports, and libc/libm-only release dependencies. All ten VNNI object files are byte-identical to the pre-i7 baseline in the matched builds. Shared graph improvements from Reduce native inference time on i7-7700T with per-model optimizations #21 still apply when VNNI is selected; the two new fast paths here are AVX2-specific.
  • Add direct quantization and CM contracts, guarded packed-weight/input checks, FP-environment cases and a decoder-skip regression. Preserve rejected experiments and inconclusive results in the measurement records.

Incremental measurements for the changes in this PR

Intel Core i7-7700T, GCC 14.2 with independently fresh model-8 PGO, performance governor/EPP and continuous neural calls. Each study uses 36 randomized mirrored ABBA/BAAB blocks, two fresh processes per version/block and 120 warmup hops/process.

Change / comparison Timed hops/process Model 2 time reduction Model 8 time reduction
Four-row quantization: 98df765 → 26c7a9c 500 1.274% [0.132, 2.403]% 1.128% [0.480, 1.772]%
Direct CM pointwise: 26c7a9c → cf16ba6 750 5.823% [5.222, 6.421]% 3.209% [2.709, 3.707]%

Intervals are multiplicity-adjusted: family four / 98.75% for quantization and family eight / 99.375% for CM. These are separate studies and their percentages must not be added or multiplied to claim a directly measured PR-only total. The quantization confirmation was separately fixed after its initial screens; all discovery/confirmation records remain available.

Original-power/10 ms results are reported separately. The larger 288-block model-8 quantization repeat remains inconclusive at +0.463% (95% interval [-0.345, +1.264]%). The separate 288-block CM repeat also remains inconclusive at +0.793% (adjusted interval [-0.453, +2.023]%).

Direct cumulative measurement, including already-merged #21

A new fixed-count study directly compares afa8292 (before #21 and these two optimizations) with cf16ba6. This table therefore describes the complete three-stage i7 result, including #21; it is not the incremental effect of this PR alone. The baseline already contains the earlier native W7A8 runtime and optional VNNI, rather than the original PyTorch FP32 model.

Condition Model Baseline mean ± run SD, ms Final mean ± run SD, ms Time reduction, 98.75% CI Throughput increase, 98.75% CI
Performance / continuous 2 0.775668 ± 0.010495 0.682981 ± 0.008152 11.948% [11.784, 12.112]% 13.569% [13.358, 13.781]%
Performance / continuous 8 1.823240 ± 0.020046 1.658830 ± 0.022045 9.019% [8.830, 9.207]% 9.913% [9.685, 10.141]%
Original powersave / 10 ms 2 3.310288 ± 0.195274 2.884951 ± 0.188570 12.881% [12.052, 13.702]% 14.786% [13.704, 15.878]%
Original powersave / 10 ms 8 4.667054 ± 0.288936 4.668449 ± 0.333109 0.009% [-0.947, 0.955]% 0.009% [-0.938, 0.965]%

Each model/condition has 288 blocks, 576 runs/version, six equally weighted recorded inputs, balanced orders within each input and randomized interleaving of models. Continuous runs use 600 timed hops, original-power paced runs 250; both have 120 warmup hops. Including the independent A/A controls, the new campaign contains 4,992 processes / 2,121,600 timed calls. No slow observations are discarded, no historical data are pooled, and collection does not stop on a favorable effect.

The inferential unit is the complete four-process block. Primary estimates use equally input-weighted paired log ratios, within-input variances and Welch–Satterthwaite t intervals. Bonferroni covers the four aggregate contrasts. Time reduction and throughput increase transform the same ratio; the arithmetic run means above are descriptive. Independent standard-library reconstruction matches the reported means, SD, SE and degrees of freedom. Stratified whole-block bootstrap, HAC lag 3 and chronological residual-block bootstrap lengths 4/8 support the same main conclusions. Original-power model 8 has no confirmed mean improvement.

The original-power model-8 A/A control has an apparent +2.996% effect and a t interval excluding zero; its prespecified conditional randomization test does not pass the corrected threshold (raw p=0.02723, adjusted p=0.10892). That discrepancy, including the post-plan sensitivity audit of all four A/A controls, is preserved explicitly. It was not subtracted as a fixed bias correction, and the collection/gating rules were unchanged.

Validation and scope

  • Reserve both logical CPUs of one physical core (CPU 2 and HT sibling CPU 6); workers run only on CPU 2 with UID 1000 and zero capabilities. Ordinary work is excluded from both; movable IRQ/workqueues/watchdog are steered away. Policy/cpuset monitoring and scheduler traces are retained. CPU 6 user/nice counters do not advance over the monitored intervals. No thermal-throttle counter increases occur. Residual bound kernel/interrupt/firmware/package effects remain. All three new campaign phases restore their saved settings and remove their temporary partition/timer.
  • Every spectrum and complete state match bitwise over 65 local EARS/stress streams / 147,711 hops per model, including four alias modes and reset replay. CM contracts cover 2,688 direct cases/model; the quantization oracle covers 16,384 cases. Full-graph FP32/FP16/INT8 × all 16 masks × eight-frame parity is also retained. No new perceptual scores are claimed.
  • Final local Release: 31 passed / 6 native-VNNI skips; ASan/UBSan: 31/6; AVX2-only: 31 passed; static: 30/6. CPU-mask checks preserve rejection below AVX2/FMA and execution without unrelated optional features. Final release SO SHA256: d52b21267579dc3a75c22c35dc13a3d55bb3e68ddc1300ec568110c45f26c80a, byte-identical to the measured CM implementation. Both cumulative-study builds receive one byte-identical measurement driver and identical weights/inputs.
  • The existing five-job native workflow exercises shared/static PGO generation and release, plain static, AVX2-only, and ASan/UBSan. CI is functional/build validation; performance figures come from the isolated local i7 campaign. Native VNNI performance is not measured by this PR.
  • Figures concern neural calls on this host and these inputs. FFT, synthesis, I/O, model creation and the unchanged algorithmic delay are excluded. The two conditions differ in cadence, timed length and power policy, so their difference is not solely a governor effect. Finite observed maxima do not establish a worst-case bound.

The performance summary describes the methods and results. The archived validation reports preserve the generated JSON and paired block observations at the original revision.

Verified CI for published head 41d0aa8f94fbd725f11b24a9b7482c17979d50e6

All five jobs passed in the upstream PR workflow and all five passed independently in the fork push workflow. All ten complete job logs were inspected and retained locally. Both workflows used GCC 11.4.0 on Ubuntu 22.04; performance figures above remain scoped to GCC 14.2.

Configuration Upstream Fork
Release shared (PGO) GENERATE: 31 passed, 6 skipped; release: 31 passed, 6 skipped GENERATE: 31 passed, 6 skipped; release: 31 passed, 6 skipped
Release static (PGO) GENERATE: 36 passed; release: 36 passed GENERATE: 30 passed, 6 skipped; release: 30 passed, 6 skipped
Release static 30 passed, 6 skipped 30 passed, 6 skipped
Release AVX2 fallback 31 passed 31 passed
ASan and UBSan 37 passed 31 passed, 6 skipped

The six direct VNNI contracts executed and passed in both upstream static-PGO phases and in the upstream sanitizer job. They explicitly skipped on runners without the required instruction. Both CM contracts and the four-row quantization oracle passed in every applicable configuration. There were no test failures, sanitizer diagnostics or PGO linkage failures. CI validates correctness and build portability; it does not supply VNNI speed measurements.

Quantize eight frequency positions directly and transpose outputs in registers,
avoiding sixteen full float transposes per graph. Preserve exact arithmetic,
AVX2/FMA requirements, original fallback paths, weights and state ABI.

Add guarded FP-mode and all-mask regression coverage, and preserve the paired
measurement records for the precision repeats and rejected optimization trials.
Compare the pre-i7 baseline with the final runtime in 288 paired blocks per model and power condition. Preserve SD, SE, adjusted intervals, A/A discrepancies, raw block observations and isolation verification.
@danielr55

Copy link
Copy Markdown
Collaborator

@varyagnord there are too many changes ~24K, can you make sure you didn't include unnecessary generated files? (this is also true for #23 which contains ~121K(!) additional lines...)

Keep the validation summary and link to the preserved reports at the original branch revision. Runtime and test sources are unchanged. Verified with a Release build and CTest.
@varyagnord

Copy link
Copy Markdown
Author

Thanks for pointing this out. I removed the generated benchmark JSON from the review diffs for both #22 and #23. That brings #22 down from 24,064 to 505 added lines and #23 from 121,308 to 3,242. The docs link to the original reports at pinned revisions, and both Release builds and CTest suites passed. #25 is available for independent review as the standalone model-8 AVX-VNNI change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants