Commit 1ab1661
Emit MatMulNBits accuracy_level=4 (int8 path) — 2.3x CPU decode (#402)
**Root cause of onnx-genai being ~3.6x slower than llama.cpp on CPU:
MatMulNBits was emitted with no `accuracy_level`**, so ORT's MLAS kernel
ran the fp32 dequant+GEMM path instead of the int8 dynamic-quant + int8
dot-product path (ARM SDOT / x86 AVX-VNNI) — the same class of kernel
llama.cpp uses. ORT's parity claim holds; we just weren't opting in.
`default_int4_accuracy_level=4` already existed on the cpu/webgpu
`EpCapabilities` but was **dead config**. This plumbs it via a new
`_accuracy_level_attrs()` helper into both `MatMulNBits` emission sites
in `components/_quantized_linear.py` (Q/K/V/O, MLP, tied + non-tied
head). Emits when `>0`, omits at `0` (portable default preserved).
### Measured (Qwen2.5-0.5B Q4, CPU EP, decode tok/s, all coherent)
| config | tok/s |
|---|---:|
| baseline (accuracy_level missing) | 39.3 |
| **accuracy_level=4 (int8)** | **91.8** (2.33x) |
| quantized head + acc4 | **194.7** |
| ref: LM Studio CPU | 157 |
fp16/bf16 levels regress on M1 (no native GEMM). End-to-end verified:
`--ep cpu` stamps all 168 nodes with accuracy_level=4; `--ep default`
omits it.
lintrunner clean; pytest 518 passed (+2 tests).
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 57177b7 commit 1ab1661
2 files changed
Lines changed: 82 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
29 | 54 | | |
30 | 55 | | |
31 | 56 | | |
| |||
126 | 151 | | |
127 | 152 | | |
128 | 153 | | |
| 154 | + | |
129 | 155 | | |
130 | 156 | | |
131 | 157 | | |
| |||
309 | 335 | | |
310 | 336 | | |
311 | 337 | | |
| 338 | + | |
312 | 339 | | |
313 | 340 | | |
314 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
128 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
129 | 184 | | |
130 | 185 | | |
131 | 186 | | |
| |||
0 commit comments