Skip to content

tools: gemma4_e4b_convert.py, an E4B BF16 checkpoint to MLX affine 4-bit g64 under mlx-lm's names - #1403

Closed
Mirrdhyn wants to merge 1 commit into
ashhart:mainfrom
hygurlabs:e4b-family-convert
Closed

Mirrdhyn wants to merge 1 commit into
ashhart:mainfrom
hygurlabs:e4b-family-convert

Conversation

@Mirrdhyn

Copy link
Copy Markdown
Contributor

What this changes

Part of #1222. Independent of #1400, #1401 and #1402.

tools/zig/gemma4_e4b_convert.py writes an MLX affine 4/64 checkpoint from the BF16 E4B, under mlx-lm's names (language_model.model.) and its per-module quantization table; it leaves out the shared layers' unread k_proj, v_proj, k_norm. Options: --dense-ple keeps the per-layer input linears and table BF16 (marked false), --attn-bits 8 puts the attention projections at 8 bits. --check-mlx compares every quantized block with mx.quantize, byte for byte, on MLX's CPU device: its Metal quantize rounds a few scales differently (7 of 10,240 groups on a synthetic matrix, MLX 0.30.0 to 0.32.4).

KL against BF16, forced tokens, 14 French prompts, 358 positions (measured on our Intel Arc prototype engine with these checkpoints): 4/64 with BF16 per-layer linears 0.0409, top-1 97.2 %; plus 8-bit attention 0.0176, top-1 98.9 %, at a cost of about 10 % decode and 40 % prompt speed there.

Receipt

  • --dense-ple --check-mlx on nvidia/NVIDIA-Nemotron-3.5-Bolt-E4B-BF16 49843eed, MLX 0.32.4, M4 Max: 1,185 tensors, 260 quantized, 0 blocks differ.
  • python -m unittest tools/zig/gemma4_e4b_convert_test.py: 11 passed (numpy), skipped cleanly without numpy.
  • Not run: decode and prompt speed, no engine serves E4B yet.

@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thank you for this, and for the byte check against mx.quantize. We're not going to take it, though.

TensorFold doesn't ship lossy conversions of a release, and this tool requantizes the BF16 E4B to 4 bits. Your own KL
is 0.041, or 0.018 with 8-bit attention. The --dense-ple and --attn-bits 8 recipes would make checkpoints of our
own, which is what we most want to avoid.

The engine doesn't need the tool either. The family reads MLX affine checkpoints under mlx-lm's names, so a published
MLX conversion, or one made with mlx_lm.convert, loads the same way. For the per-layer work, the seeded oracle in
#1402 already avoids needing a converted checkpoint. Main does still carry two older converters of this kind (tools/zig/gemma4_12b_convert.py and spark25_convert.py). They predate this rule, and we'll retire them rather than add more.

Thanks again for the careful work across #1222.

@ashhart ashhart closed this Oct 27, 2026
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