Skip to content

cpu_moe: integer IQ4_NL dot product (scalar + AVX2) - #47

Merged
Vasyl-Trefilov merged 1 commit into
RustingStudio:mainfrom
Saul5662:iq4nl-cpu-dot
Nov 17, 2026
Merged

Vasyl-Trefilov merged 1 commit into
RustingStudio:mainfrom
Saul5662:iq4nl-cpu-dot

Conversation

@Saul5662

Copy link
Copy Markdown
Contributor

Issue

cpu_moe::int_dot had no IQ4_NL case, so routed experts stored as IQ4_NL fell back to f32 row dequantization in the CPU expert worker. In OrcaRouter Qwen3.8-Flash-Next-Uncensored-IQ3_XXS every ffn_down_exps tensor is IQ4_NL, so this fallback dominated decode.

Results

RTX 3060 12 GB, Ryzen 7 5800XT, on top of 3355cbb, bench --gpu --mtp 0 --ctx 16384 --pp 8192 --tg 64 --reps 3 --chunk 8192:

before after
decode 10.9 tok/s 31.6 tok/s
CPU worker 75.6 ms/token 15.9 ms/token

Patch (src/cpu_moe.rs)

  • Scalar dot_iq4nl and AVX2 avx2::dot_iq4nl (pshufb lookup of KVALUES_IQ4NL, maddubs/madd, two blocks per step plus an odd tail) against the Q8_K activations, like dot_iq4xs.
  • int_dot returns them for GgmlType::IQ4NL.
  • int_dots_match_dequant covers IQ4_NL (672 values, so the odd tail runs).

This patch was written by AI (Claude Code). Please check the code fully before merging.

int_dot had no IQ4_NL entry, so routed experts stored as IQ4_NL (the
ffn_down_exps of OrcaRouter Qwen3.8-Flash-Next-Uncensored IQ3_XXS) fell
back to f32 row dequantization in the CPU expert worker.

Add dot_iq4nl against the Q8_K activations like dot_iq4xs: 18-byte
blocks, eight per Q8_K block. The AVX2 version looks up KVALUES_IQ4NL
with pshufb and handles two blocks per step plus an odd tail.
int_dots_match_dequant covers it at 672 values (21 blocks, odd tail).

RTX 3060 + Ryzen 7 5800XT, 8K prompt: CPU worker 75.6 -> 15.9 ms/token,
decode 10.9 -> 31.6 tok/s.
@Saul5662

Copy link
Copy Markdown
Contributor Author

I have been doing a TON of patches with claude code and currently have decode & prefill at 34.5 t/s and 974 t/s at 62k. 8k is at 40.2 t/s and 1012 t/s.

This is all without MTP.

I am happy to PR the mess if you'd like after its all complete but it is a hot mess and only really been tested on my Orca model since its mainly a personal patch.

@Vasyl-Trefilov
Vasyl-Trefilov merged commit f72485a into RustingStudio:main Nov 17, 2026
@Vasyl-Trefilov

Copy link
Copy Markdown
Member

@Saul5662 I tested it and merged, tysm for contribute!

Vasyl-Trefilov added a commit that referenced this pull request Nov 17, 2026
…duct, MTP for Flash-Next and layer splits

- chat page: MCP tools from an mcp.json file (serve --mcp), per-tool switches, confirm step before each call (#18)
- cpu_moe: integer IQ4_NL dot product, scalar and AVX2 (#47)
- experts: a long prompt no longer freezes the placement for the reply (#44)
- mtp: draft head for Qwen3.8-Flash-Next on the GPU (--mtp-model), drafts with a multi-GPU layer split (#38)
- vision: faster CPU encoder, image prompts prefill on the GPU with M-RoPE
- startup warning when the binary has no AVX2 but the CPU does (#44)
- cuda: size_t pointer offsets in moe_combine, STRATA_NVRTC_OPTS (#34)
- docs: LORA.md rewritten for users (#15)
Vasyl-Trefilov added a commit that referenced this pull request Nov 18, 2026
Co-authored-by: Andrew Pavlov <100561417+andrew-pavlov-ua@users.noreply.github.com>
Vasyl-Trefilov added a commit that referenced this pull request Nov 18, 2026
…duct, MTP for Flash-Next and layer splits

- chat page: MCP tools from an mcp.json file (serve --mcp), per-tool switches, confirm step before each call (#18)
- cpu_moe: integer IQ4_NL dot product, scalar and AVX2 (#47)
- experts: a long prompt no longer freezes the placement for the reply (#44)
- mtp: draft head for Qwen3.8-Flash-Next on the GPU (--mtp-model), drafts with a multi-GPU layer split (#38)
- vision: faster CPU encoder, image prompts prefill on the GPU with M-RoPE
- startup warning when the binary has no AVX2 but the CPU does (#44)
- cuda: size_t pointer offsets in moe_combine, STRATA_NVRTC_OPTS (#34)
- docs: LORA.md rewritten for users (#15)
Vasyl-Trefilov added a commit that referenced this pull request Nov 20, 2026
…duct, MTP for Flash-Next and layer splits

- chat page: MCP tools from an mcp.json file (serve --mcp), per-tool switches, confirm step before each call (#18)
- cpu_moe: integer IQ4_NL dot product, scalar and AVX2 (#47)
- experts: a long prompt no longer freezes the placement for the reply (#44)
- mtp: draft head for Qwen3.8-Flash-Next on the GPU (--mtp-model), drafts with a multi-GPU layer split (#38)
- vision: faster CPU encoder, image prompts prefill on the GPU with M-RoPE
- startup warning when the binary has no AVX2 but the CPU does (#44)
- cuda: size_t pointer offsets in moe_combine, STRATA_NVRTC_OPTS (#34)
- docs: LORA.md rewritten for users (#15)
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