Commit ea87e78
K3 Step 4 phase 1: bug4 fingerprint for Gemma 4 tokenizer + patch script
User-side evidence 2026-06-09 (commit e56303d on main):
results/research/k3_mlx_verifier_diag_1781021396.json
PR #99's mlx_lm.load diagnostic captured the failure with:
error_type: AttributeError
error_message: 'list' object has no attribute 'keys'
matched_fingerprint: bug1_quant_config_list_vs_dict
mlx_lm_version: 0.31.3
But the traceback shows the actual failure is in transformers' tokenizer
load path, NOT in mlx_lm's quantization handling:
transformers/tokenization_utils_base.py:1210
self.SPECIAL_TOKENS_ATTRIBUTES = ... + list(special_tokens.keys())
↑ list has no .keys()
Where special_tokens = self.extra_special_tokens, set during
GemmaTokenizerFast.__init__ from tokenizer_config.json.
So bug1's fingerprint was a string-match false positive (matched the
error message text but mis-attributed the root cause to quantization
config). The real bug is the Gemma 4 multimodal tokenizer's
extra_special_tokens being a list when transformers 5.x expects a dict.
Two changes:
1. NEW scripts/research/k3_patch_gemma4_tokenizer_config.py (~200 LOC)
Reads <verifier_dir>/tokenizer_config.json, inspects
extra_special_tokens shape, and converts list → dict.
Three list shapes handled:
a. Empty list → return empty dict (no-op semantics, shape-correct
for transformers)
b. List of strings → positional mapping using known Gemma 4
token names (audio_token, image_token, video_token, boi_token,
eoi_token, boa_token, eoa_token); surplus entries auto-named
extra_token_N
c. List of dicts {name, content/value} → reduce to flat dict
Idempotent (already-dict → no-op exit 0). Backs up original to
tokenizer_config.json.pre-k3-patch.bak (only on first patch). Has
--dry-run flag.
Exit codes:
0 patched (or already a dict)
1 tokenizer_config.json missing
2 not parseable JSON
3 list shape unrecognised — manual fix needed; full content
printed to stderr with Gemma 4 token-name reference
Unit-tested all three shape conversions plus the unrecognised-
mixed-list error path.
2. UPDATED _diagnose_mlx_load_failure in k3_feasibility_smoke.py:
* Now also captures tokenizer_config.json + processor_config.json
content under diag.tokenizer_config_json / diag.processor_config_json
(so the next iteration's diagnostic includes the file content,
not just file size from the directory listing)
* NEW bug4_gemma4_extra_special_tokens_list_shape fingerprint:
- Matches when traceback contains '_set_model_specific_special_tokens'
OR 'tokenization_utils_base' (the call site)
- OR when tokenizer_config.json's extra_special_tokens is observed
to be a list directly
- Suggested workaround points at the patch script
* REFINED bug1_quant_config_list_vs_dict: now requires
NOT bug4_traceback_match. Prevents string-match false positives
when the real cause is the tokenizer path. Both fingerprints
can fire only if the traceback genuinely points at quantization
code (which bug1's signature is meant to cover).
Tests: 307/307 v04 pass (no v04 code changes; only smoke script +
new patch script in scripts/research/).
User's next step:
cd Kakeya-LLM-Inference-engine
git pull --ff-only origin main # after this PR merges
# Patch the local checkpoint (one-time, idempotent):
python3 scripts/research/k3_patch_gemma4_tokenizer_config.py \
models/gemma-4-26B-A4B-it-mlx-4bit
# Re-run the smoke:
bash scripts/research/k3_feasibility_smoke.py \
--platform mac \
--verifier-path models/gemma-4-26B-A4B-it-mlx-4bit \
--skip-drafter
# If smoke succeeds → push the new evidence (proves Step 4 unblocked
# the verifier load path)
# If it fails again → the new diagnostic captures the next layer's
# error with tokenizer_config_json content; push for analysis
What this PR does NOT yet do:
* Doesn't fix the verifier load itself if extra_special_tokens has an
unrecognised shape — the patch script exits 3 in that case with full
diagnostic. We then write phase 2 of Step 4 based on what shape it
actually has.
* Doesn't address other potential mlx_lm Gemma 4 MoE bugs that may
surface AFTER the tokenizer load path is unblocked. The five known-
bug fingerprints in the diagnostic are designed to catch those
surgically too.
Stack: off main, parallel to PR #100 (Step 3a). Both can land
independently; both unblock the Mac MLX critical path.
Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>1 parent e56303d commit ea87e78
2 files changed
Lines changed: 322 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
258 | 276 | | |
259 | 277 | | |
260 | 278 | | |
| |||
291 | 309 | | |
292 | 310 | | |
293 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
294 | 358 | | |
295 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
296 | 363 | | |
297 | 364 | | |
298 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 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 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
0 commit comments