ktransformers icon indicating copy to clipboard operation
ktransformers copied to clipboard

Intel Consumer Level AVX-VNNI Support

Open callmegaga opened this issue 8 months ago • 7 comments

Reminder

  • [x] I have read the above rules and searched the existing issues.

System Info

I am not sure.Does kt support the intel consumer level avx-vnni instructions whitch is 256 bit, it is different with server side avx-vnni which is 512 bit.Do you assess whether doing this is worthwhile? If so, I can do this work.I'm also trying to make the NPU, iGPU, and CPU work together on Intel processors.Can you give me some advice?

Reproduction

Put your message here.

Others

No response

callmegaga avatar Mar 23 '26 03:03 callmegaga

Hey, thanks so much for reaching out — and for being willing to contribute!

To clarify the current state: kt-kernel supports AVX2 for consumer CPUs, but AVX2-VNNI (the 256-bit VNNI variant on Alder/Raptor Lake P-cores) is not yet explicitly supported. So there's a real opportunity here!

Adding AVX2-VNNI support would be a meaningful contribution — it would unlock better INT8 performance on a wide range of consumer hardware without needing AMX or AVX512. If you're up for it, we'd love to see what you can do. A good starting point would be the kernel dispatch logic in ktransformers/operators/cpu_backend/.

For the NPU+iGPU+CPU direction — that's a really cool idea and something we find genuinely interesting. It's not our current focus, but we'd be excited to see experiments in that direction from the community.

Looking forward to seeing your work!


This reply was co-authored by an AI agent and a human.

ErvinXie avatar Mar 31 '26 02:03 ErvinXie

Okay, if these two points are technically feasible, then I will complete the relevant development. Thank you.

callmegaga avatar Mar 31 '26 05:03 callmegaga

LOOKING FORWARD TO THE IMPROVEMENT ON SUPPORTING VNNI !

wqshmzh avatar Apr 10 '26 12:04 wqshmzh

VNNI int8 does not work that effectively due to the quantization range for Q4_K_M will not all be within int8, but vnni int16 is the best thing intel ever implemented, despite only a side product of vnni int8-- expect a 2x acceleration from it though, that's still a lot.

NukePeace avatar Apr 16 '26 11:04 NukePeace

I have been working in exactly this lane: RAWINT4 serving on consumer CPUs with the 256-bit AVX-VNNI (here an Arrow Lake Core Ultra 5 225: AVX2 + AVX-VNNI, no AVX512, no AMX).

First result is a correctness fix. The AVX-VNNI-256 RAWINT4 backend could not load weights through the serving path at all, because its TP wrapper only accepted flat weight buffers while NativeMoEWrapper always passes per-expert pointers. Fixed in #2092 together with per-commit equivalence tests over the RAWINT4 load paths.

On performance there is real headroom in the current kernel. Cycle-counted microbenchmarks of the AVX-VNNI-256 RAWINT4 GEMM on this machine (rdtscp, arms interleaved per round, min over rounds; kernel level, not end to end): reworking the accumulator scheme gives 1.4x to 1.8x on decode shapes depending on shape and group size, and streaming the weights as packed nibbles instead of the load-time-unpacked int8 reaches about 2.2x on large prefill shapes. The packed-nibble direction also halves resident expert weight memory, since the backend currently unpacks int4 to int8 at load time. I plan to send these incrementally, each with the same equivalence-test treatment.

blazingphoenix7 avatar Jul 18 '26 04:07 blazingphoenix7

The performance follow-up is up: #2095.

Since the kernel-level numbers above, I measured both changes end to end through the operator path, and the picture is sharper than those microbenchmarks: at production thread counts decode is memory-bandwidth bound, so the win that actually transfers is streaming half the bytes. That is the packed weight storage mode in the PR, opt-in, which halves resident expert weight memory and speeds single-token decode up to 1.40x at large MoE dims. The accumulator restructure underneath is bitwise identical to the current kernel and carries the kernel-level headroom. Batched qlen-16 pays about 10 to 13 percent in packed mode, which is why it is opt-in; the full operator-level tables and the evidence are in the PR.

blazingphoenix7 avatar Jul 19 '26 15:07 blazingphoenix7

The remaining gap in this lane is MXFP4 (the DeepSeek-V4 native format): operators/avx2/ has AVX-VNNI-256 variants for RAWINT4 and GPTQ INT4, but AVX2MXFP4_MOE still runs FP32 FMAs on PSHUFB-decoded weights. I'd like to take that one.

Plan, following the structure of #2187:

  • Weights stay in the existing packed-nibble + per-group scale layout (no loader or buffer changes). The 16 E2M1 codepoints times 2 are exact int8 values (0, ±1, ±2, ±3, ±4, ±6, ±8, ±12), so the per-group PSHUFB decode emits int8 directly instead of BF16→FP32.
  • Activations are quantized once per expert to biased u8 per 32-value group (matching the weight group), stored in BufferA next to the BF16 rows the way the packed GPTQ backend does, so the GEMM never re-quantizes.
  • One vpdpbusd per 32-value group per token (vs 4 FMAs + 4 FP32 loads today), per-group rescale into FP32 accumulators, +128 bias removed with the integer weight-sum computed from the same decoded group.
  • New backend class AVXVNNI256MXFP4_MOE, gated on avx_vnni like the existing ones, selectable from the Python side; the AVX2 backend stays the default until numbers justify switching.

Precision trade-off is the same one the RAWINT4 / GPTQ VNNI backends already make (int8 activations per group instead of BF16); I'll report rel-L1 against the dequantized reference alongside GMAC/s. Dev box is an i7-14650HX (AVX2 + AVX-VNNI, no AVX-512), so kernel-level numbers only, as in #2212.

If you'd rather see this as an opt-in path inside the existing AVX2 MXFP4 class instead of a separate backend, tell me before I get far.

sakurahello1 avatar Sep 17 '26 16:09 sakurahello1