You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit eec8e3f
Browse filesBrowse the repository at this point in the historyBrowse files
authored
feat(gguf): support Q6_K, fix byte-level tokenizers, emit loadable packages (#543)
Three defects blocked running a Q4_K_M GGUF (`tencent/Hy-MT2-1.8B`) end
to end.
## 1. Q6_K was unsupported
Q4_K_M is a **mixed** preset. This file is 192 × Q4_K, 33 × Q6_K, 129 ×
F32, and the Q6_K third is not a rounding error — it holds **34% of the
bytes**, including the 193 MB `token_embd.weight` that this model also
uses as its `lm_head` (there is no `output.weight`).
`repack_dequantized_tensor` already named Q6_K as an expected input for
exactly this reason, but no unpacker existed, so the build failed
outright.
Adds `_repack_q6_k`, following ggml's `dequantize_row_q6_K` interleave:
each 128-element half consumes 64 `ql` bytes, 32 `qh` bytes and 8
scales, emitting four 32-element groups with `is = l // 16`.
**Verified bit-for-bit** against `gguf`'s own dequantizer on six real
tensors, ~1M elements each — zero differing elements. This matters
because every plausible-but-wrong permutation of that interleave still
yields finite values of the right magnitude; only exact comparison
distinguishes correct from subtly transposed.
## 2. Byte-level tokenizers were decoded as SentencePiece
The reconstructor applied Metaspace (`▁`) unconditionally. This model
declares `tokenizer.ggml.model = gpt2`, whose vocabulary spells a
leading space as `Ġ` — a different alphabet. Every inter-word space was
dropped:
```
"Hello, world!" -> "Hello,!world!"
```
The code detected the bad round-trip, **warned, and emitted the broken
tokenizer anyway**. Now it dispatches on the declared family.
Fixing the alphabet alone was not enough. `tokenizer.ggml.pre` names the
*split* rule, which the byte-level model does not imply — llama.cpp
keeps per-family regexes because families disagree on how digits, CJK
and punctuation group. A mismatch **still round-trips**, so it is
invisible to a round-trip check and only shows at the id level: a tab
sample decomposed as `[184, 25056]` where the reference gives `[20061,
421]`.
Adds the family split table. All six samples — ASCII, CJK, emoji,
repeated spaces, tabs/newlines — now match the HF tokenizer
**id-for-id** as well as round-tripping exactly.
## 3. The Python API could not produce a loadable package
`mobius build-gguf --runtime onnx-genai` emitted tokenizer + inference
metadata, but `build_from_gguf` callers got a bare graph that loads
nowhere — the model directory was missing both artifacts.
Rather than document a second call sequence for API users,
`write_gguf_runtime_package` now owns the full artifact set, and the CLI
routes through it. One function knows what a complete package is, so the
two paths cannot drift.
## Incidental
Q6_K was missing from `type_can_omit_zero_points`, which raised
`KeyError` — caught by the existing suite. That test asserted Q6_K was
*unsupported*, which is no longer true, so it is retargeted to Q5_K
(still unsupported), preserving the "no silent float fallback" guarantee
it was written to protect. A new test covers Q6_K selecting the
asymmetric 4-bit target.
## Validation
`python -m pytest src/mobius/integrations/gguf/ -q` — **330 passed, 0
failed**.
End-to-end, the Python API now emits a complete package with no
tokenizer warning:
```
tokenizer: ...\tokenizer.json
inference_metadata: ...\inference_metadata.yaml
model.onnx.data 989.74 MB
```
---------
Co-authored-by: Copilot <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: justinchuby <[email protected]>
Copilot-Session: d60eb808-7cc6-4abc-b48d-2a6dd3841624
0 commit comments