Skip to content

fix(split-mtp): fix refusal text, --force shards, --q-bits validation - #1778

Merged
inureyes merged 3 commits into
mainfrom
fix/issue-1763-split-mtp-guards
Sep 10, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/issue-1763-split-mtp-guards

Conversation

@inureyes

@inureyes inureyes commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Summary

The PR #1753 technical report listed three defects in split-mtp among its follow-ups. This PR fixes all three. Review of the first version found five more gaps in the same guards, and those are fixed here as well.

  • Refusal text. The MAX_BLOCK_SIZE refusal rendered with two runs of 14 literal spaces. It is now one sentence with single spaces.
  • --force never deletes weight files. prepare_output_dir(dir, force) refuses and names the file when the output directory holds any *.safetensors other than the drafter's own model.safetensors. The loader's glob_safetensors reads every *.safetensors in a directory, so a stale model-0000N-of-... or consolidated.safetensors would otherwise be loaded as part of the drafter. A stale model.safetensors.index.json is still cleared when no foreign file remains. An unreadable directory fails closed.
  • Quantization parameters are checked before any tensor work. SUPPORTED_AFFINE_BITS (2, 3, 4, 5, 6, 8) and SUPPORTED_AFFINE_GROUP_SIZES (32, 64, 128) now live in mlxcel-core::layers, next to validate_affine_quantization_bits and validate_affine_quantization_group_size. Before this PR, --q-bits 1 or --q-group-size 16 did the tensor work and then aborted the process inside MLX's quantize. Gemma 4's private copy of the bit set now reads the shared constant. validate_quantization_params still accepts 1..=32 at load time (fix(core): an unvalidated config.json quantization block reaches MLX and terminates the process #929).
  • Checks run before mutation. preflight_checks (bits, group size, output equals source) runs before prepare_output_dir. A bad flag or -o pointing at the source can no longer touch the directory first.

Validation

  • Workspace gate on 059ea43: exit 0, 123 binaries, 11,038 passed, 0 failed. Clippy, fmt, verify-versions, verify-kernel-dtype-keys and verify-llama-compat are clean. CI is green.
  • Every new or strengthened test was run with its fix reverted and failed by name. With only the load-time 1..=32 check left, --q-bits 1 aborts the test binary (std::invalid_argument: [quantize] The requested number of bits 1 is not supported, SIGABRT).
  • Real run with a release binary at 059ea43 against glm-4.7-flash-bf16:
    • --q-bits 4 writes the drafter: 54 tensors, 0.72 GB, glm4_moe_lite_mtp, 4-bit affine, group size 64. model.safetensors and config.json are byte-identical to the output of the pre-PR binary (the fix(mlx): bump MLX pin to 81ba1c6a so mxfp8 block scales round up #1772 merge).
    • --force over a planted model-00001-of-00003.safetensors exits 1 and names that file. Every file's name, size, mtime and inode is unchanged.
    • --q-bits 7 exits 1 within a second with quantization bits (7) must be one of 2, 3, 4, 5, 6, 8, and no drafter2 is created.

Closes #1763.

The PR #1753 technical report recorded three small defects in its own follow-up section: a wrapped string literal in the MAX_BLOCK_SIZE refusal lost its `\` continuations and rustfmt joined the line, leaving two runs of 14 literal spaces in the rendered message; `--force` removed a stale safetensors index but left orphan `model-*.safetensors` shards beside the drafter's single-file output, which the loader could then read as one checkpoint; and the `--q-bits` help text advertised `{2, 3, 4, 5, 6, 8}` while the only pre-quantize check was the shared `validate_quantization_params` bounds check (`1..=32`), so an unsupported width like 7 quantized and crashed the process later with an uncatchable MLX abort.

Restored the `\` continuations and added a no-double-space assertion to the block-size test. Extracted the output-directory guard into `prepare_output_dir`, which now refuses rather than deletes when a previously sharded checkpoint's shards are still present, naming one shard and leaving every file on disk; it still clears a stale index when no shards remain. Promoted the affine bit-width literal in `infer_quantization_bits` to `pub const SUPPORTED_AFFINE_BITS`, added `validate_affine_quantization_bits`, and call it from `split_mtp` alongside `resolve_block_size` so a bad width fails before any tensor work; the shared load-time bounds check is unchanged.

Marked all three follow-up bullets resolved in both technical report translations for PR #1753.

Closes #1763.
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:cli Command-line interface / CLI flags status:review Under review labels Sep 10, 2026
PR #1778 review found five gaps in the previous split-mtp fixes. gemma4 kept its own `SUPPORTED_OVERRIDE_BITS` copy of the affine bit set instead of the shared `SUPPORTED_AFFINE_BITS`, so the two could drift silently; it now reads the shared constant. `--q-group-size` had no producer-side check, so `--q-bits 4 --q-group-size 16` passed validation and aborted the process inside MLX's affine quantize call after doing the tensor work; added `SUPPORTED_AFFINE_GROUP_SIZES` and `validate_affine_quantization_group_size`, verified against the pinned MLX `mlx/ops.cpp` (`group_size != 32 && != 64 && != 128`), wired next to the bits check. The CLI's non-mutating checks (bits, group_size, output-equals-source) ran after `prepare_output_dir`, which could already mutate the directory or misname the source as the output; extracted `preflight_checks` and `refuse_output_is_source` and moved them before any mutation. The shard guard only matched `model-*.safetensors`, so `consolidated.safetensors` bypassed it entirely and would then be silently read alongside the drafter by the loader's `glob_safetensors`; broadened the predicate to any `*.safetensors` other than the drafter's own `model.safetensors`, shared between both call sites, and made the directory-listing helper fail closed instead of treating an unreadable directory as shard-free.

Also corrected doc/error text claiming MLX's affine packing "only has an integer solution" for the six supported bit widths: the packing invariant has a solution for 7 too, it is simply not a width MLX's kernel implements. The core validators now say "quantization bits"/"quantization group_size" rather than naming `--q-bits`; split-mtp adds the flag name around the error. Strengthened `split_refuses_an_unsupported_q_bits` to use an empty `WeightMap`, proving the refusal precedes tensor work, and to match `(bits)` rather than a bare substring.

Every reworked guard was verified failing with its fix reverted, then passing restored.
Records the split-mtp guard fixes: the refusal text, the --force contract that refuses beside any foreign safetensors file, and the producer-side bits and group-size validators, with the real-run result that the drafter output is byte-identical to the pre-PR binary's.

Updates the PR #1753 report's resolved follow-up bullets to the final guard scope (any foreign *.safetensors, group size validated too), and corrects twelve doc comments that cited the PR #1778 review as "issue #1778".
@inureyes inureyes added status:done Completed and removed status:review Under review labels Sep 10, 2026
@inureyes
inureyes merged commit 33cd41d into main Sep 10, 2026
13 checks passed
@inureyes
inureyes deleted the fix/issue-1763-split-mtp-guards branch September 10, 2026 23:27
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Command-line interface / CLI flags area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:low Low priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(split-mtp): tidy the block-size refusal text, clear stale shards under --force, and align the --q-bits help with the validator

1 participant