feat(moe): FUSED3=1 opt-in AVX2 expert matmul — 40% less matmul time, bit-identical output, off by default - #1024
Open
outtodata wants to merge 2 commits into
Open
feat(moe): FUSED3=1 opt-in AVX2 expert matmul — 40% less matmul time, bit-identical output, off by default#1024outtodata wants to merge 2 commits into
outtodata wants to merge 2 commits into
Conversation
release: v1.6.1 — the first day of real users, fixed the same day
… quant + gate/up pair Adds c/fused_simd.h with exact-integer IDOT kernels (quant_x_q8_avx2, matmul_q_idot_v2/v3, matmul_q_idot_pair_v3) and a FUSED3 env-gated dispatch at the MoE expert FFN call site. OFF by default; with the flag unset the code path is byte-for-byte today's main. Loud when on: startup banner prints fused3=%d. Bit-exactness verified by memcmp harness in c/tests/bench_fused3.c and by identical greedy token streams vs main (flag off and on).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FUSED3: vectorized activation quantizer + 4-way IDOT + gate/up pair matmul — 40% less matmul time, bit-identical output, off by default
TL;DR. Three opt-in kernel upgrades in
c/fused_simd.h(envFUSED3=1, default off): (1) AVX2-vectorized activation quantization replacing the scalar tail ofquant_x_q8, (2) a 4-accumulator IDOT matmul variant with prefetch, (3) a paired gate/up matmul that shares the activation stream. On a Core i5-7300U (AVX2, 2C/4T), time inside expert matmul drops ~40%, greedy token streams are bit-identical to master, and end-to-end throughput on our production config goes 2.08 → 2.38 tok/s. No change to file formats, no approximation anywhere: all arithmetic is still exact integer IDOT.Setting. OLMoE-1B-7B Q8_0 snapshot, our production flags, Windows + WSL pipes (i.e. the noisy setting — numbers below are conservative; on a quiet machine the deltas are larger). MoE weights streamed from disk via the async expert pipe.
What changes (all under
FUSED3, default OFF)quant_x_q8quant_x_q8_avx2: vector abs-max + quant, exact same round-to-nearest-even semanticsmatmul_q_idot_v2matmul_q_idot_v3: 4 independent int32 accumulators +_mm_prefetchof the next weight rowmatmul_q_idot_pair_v3: single pass, both outputs, shared activation cache trafficDispatch is a single
if (g_fused3)inolmoe.cat the MoE FFN call site; nothing else is touched.Measured (bench_fused3_inproc, in-process, isolated kernels; medians of ≥10)
Output equivalence: md5 of the 200-token greedy stream identical with and without the flag across three independent runs (
d6cb4e151fa83994d62982f3cbba4190), and identical to a separately-built reference binary. This is expected — every path is exact integer arithmetic; the flag only changes instruction scheduling, never values.How this answers the review gates from #906
FUSED3defaults to 0; when set, startup printsMODE FUSED3 ...banner plus per-layer[PROF]counters already present in the build.What this is NOT
EXPERT_WORKERS=2) in the same series: it is a NO-GO from us (pipe interference eats the gain, and it introduces thread-count-dependent scheduling). Not proposed.Caveats
#if defined(__AVX2__)around v3, scalar/v2 fallback otherwise).Diff is ~200 lines in
c/fused_simd.h+ a dispatch flag + a bench binary. Happy to open the PR if the direction looks right, or to carve it differently (e.g. three separate flags) if you prefer finer-grained gating.Related
c/tests/bench_fused3.c(v3_quant_bitexact=yes,v3_output_bitidentical_v2=yeson this branch).