Commit 3dafa1b
[GGUF FE] Fix dequant/op correctness bugs and Q2_K/Q3_K packing
Correctness fixes found in code review:
- Q4_0 requant read u4 nibbles as unsigned, ignoring the 0x88 XOR sign
encoding; token_embd/output Q4_0 weights were corrupted. Read as signed
i4 when there is no zero-point.
- GELU/GEGLU used OpenVINO's default (ERF) Gelu; ggml uses the tanh
approximation. Pass GeluApproximationMode::TANH.
- MUL_MAT type-mismatch Convert re-read the original input(0), discarding
the op_case 2/3 reprocessing of B and targeting the wrong element type.
- SCALE aborted when the "bias" attribute was absent; give scale/bias
defaults like SOFT_MAX.
- IMROPE read data_node->get_shape()[3], throwing on a dynamic dim; use the
decoder output_shape like the NORMAL/NEOX branches.
- VIEW op_case 3 could leave slice_dim == -1 and index the shape at
SIZE_MAX; return the input unchanged for an identity view.
- SetRows stateless lowering only guarded dim 2 against dynamic; emit -1 for
any dynamic batch/n_seq/emb dim.
- FLASH_ATTN_EXT did not convert k/v to f16, so f32 K/V hit SDPA's
mixed-type check; convert explicitly.
- Q4_K integer zero-point (u8) was unclamped and could wrap mod 256; clamp
to [0,255] via a shared helper.
Q2_K / Q3_K dequant (previously DISABLED as known-failing):
- Q2_K: block layout is scales-first then qs (offsets were swapped), and qs
is not in element order, so replace the memcpy with a per-element unpack
into LSB-packed u2 matching ggml's dequantize_row_q2_K.
- Q3_K: rebuild the 16 signed 6-bit sub-scales with ggml's kmask1/kmask2
interleave (-32 bias) and unpack qs/hmask in ggml's strided element order.
- dequant_extracted_to_f32 (Q8_0_C requant path) gains a u2 branch for Q2_K
and reads no-zp 4-bit weights as signed (Q3_K centered i4 / Q4_0).
- Re-enable the Q2_K/Q3_K dequant and weight tests; both now match the ggml
reference within f16 tolerance.
Infra / hygiene:
- Drop the duplicate ov::WeightlessCacheAttribute definition and include the
canonical core dev_api header (matches the ONNX frontend), fixing an ODR
hazard.
- Rename public headers frontend.h/decoder.h to .hpp so ov_add_frontend
(which installs *.hpp only) ships them for direct linkers.
- Parallelize fill_q6_k (the only serial fill) and reuse the requant flag
instead of recomputing needs_q8_0_c_requant.
- Correct the stale features.cmake / src CMakeLists comments (the FE is
installed and exports entry points; it is hidden via m_hidden), and remove
leftover commented-out debug code.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent b18361b commit 3dafa1b
22 files changed
Lines changed: 187 additions & 106 deletions
File tree
- cmake
- src/frontends/gguf
- include/openvino/frontend/gguf
- src
- op
- pass
- quant
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
159 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
160 | 162 | | |
161 | 163 | | |
162 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
83 | 93 | | |
84 | 94 | | |
85 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
0 commit comments