Skip to content

quant: AVX2 kernel for int3-g64 matmul (cherry-pick from #601) - #926

Merged
JustVugg merged 1 commit into
devfrom
quant/avx2-matmul-i3
Aug 10, 2026
Merged

quant: AVX2 kernel for int3-g64 matmul (cherry-pick from #601)#926
JustVugg merged 1 commit into
devfrom
quant/avx2-matmul-i3

Conversation

@JustVugg

Copy link
Copy Markdown
Owner

Cherry-pick of 3ab405d from #601, as suggested in the closing discussion of #452: the fmt=5 int3 matmul had NEON and AVX-512 arms but fell to scalar on x86 CPUs without AVX-512 β€” which is most consumer hardware (Zen2/Zen3, recent Intel consumer chips).

Authorship preserved: the commit lands exactly as @steve-m wrote it (author field intact); the only conflict against current dev was the doc comment above matmul_i3, where #661's AVX-512 description and this commit's AVX2 description both live now. Dispatch order after the merge: AVX-512 β†’ NEON β†’ AVX2 β†’ scalar.

Verified on an AVX2-only 12-core (no AVX-512, so the new arm is the one exercised, not skipped):

  • tests/test_int3 β€” numeric check green, including the outlier-rows RMS comparison
  • tests/test_int3_load β€” container inference green
  • engine builds clean with -march=native

πŸ€– Generated with Claude Code

matmul_i3 shipped with a NEON path only; on x86 every 3-bit weight went
through the scalar bit-extraction tail. Measured on the Zen2 12-core box
(MiniMax-M3 int3-g64 routed experts): routed-CPU effective bandwidth
3.7-3.9 GB/s vs 27 GB/s for the int4 IDOT path β€” expert-matmul at 88%
of decode time, 0.95 tok/s where int4 does 2.8.

Low plane reuses matmul_i2's 2-bit unpack (shift/mask + unpacklo into
16 ordered bytes); high plane broadcasts the two mask bytes with
pshufb, bit-tests against per-lane masks, and adds 4 where set; the
[0,7] byte then drops to [-4,3] at the epi32 widen, two FMAs per 16
weights, one hsum per 64-input group. Ragged tails stay scalar.

Verified against a double-precision scalar reference over S=1/S>1,
multiple-of-64 and ragged shapes: max rel err 5.4e-6.
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