Skip to content

fix(studio): record the bit widths of prequantized MLX models - #11940

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
Mathews-Tom:studio/prequantized-width-provenance
Sep 30, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
Mathews-Tom:studio/prequantized-width-provenance

Conversation

@Mathews-Tom

@Mathews-Tom Mathews-Tom commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #8134

Thanks to BardiaKoopah for the analysis in #8134. This takes the width-aware direction the issue proposed, choosing the variant that needs no marker migration.

Problem

_snapshot_declares_quantization answered "declares uniform 4-bit", and prequantized_4bit was the only prequantized load mode. So for an 8-bit or mixed-width prequantized snapshot (common in mlx-community repos):

  • with the 4-bit toggle on, the model never attested, and the run was never resumable;
  • with the toggle off, it attested as unquantized although its weights are 8-bit.

Change

Prequantized load modes now name the snapshot's declared widths: prequantized_{widths}bit, with widths sorted, unique and joined by _.

Snapshot declares Recorded mode
4-bit throughout prequantized_4bit (unchanged)
8-bit prequantized_8bit
4-bit and 8-bit layers prequantized_4_8bit
nothing, 4-bit toggle on, runtime 4-bit policy runtime_4bit (unchanged)
nothing, toggle off unquantized (unchanged)
  • prequantized_4bit is exactly the {4} case, so existing v1 markers keep their meaning and RESOURCE_PROVENANCE_VERSION stays at 1. The mode is still one string, so it flows through routes/training.py, core/training/training.py and the resume cache key without changes.
  • _snapshot_declares_quantization → _snapshot_quantization_widths, which returns the declared width set, or None for widths it cannot describe (outside 1..16, or more than 8 of them); those do not attest.
  • Attestation records any declared width whatever the toggle says, since the weights on disk are what loaded.
  • normalize_worker_provenance_event and validate_exact_model_pin require the snapshot's current widths to equal the recorded ones, so a snapshot whose widths changed refuses to resume. Stored modes are parsed strictly: only the canonical form that _prequantized_mode produces is accepted.
  • Existing unquantized markers keep resuming without a width check, exactly as before.
  • exact_model_snapshot_path / exact_model_snapshot_for_commit lose their require_quantized parameter. validate_exact_model_pin was its only user and now compares widths itself.
  • The runtime-4-bit policy (_loaded_model_is_4bit, the mlx_config exclusion pinned by test_mlx_runtime_4bit_attestation_requires_exact_runtime_policy) is untouched.

Question for maintainers

The issue left the marker contract to you. I kept version 1 because the new values extend the vocabulary without changing any existing value. An older build that meets prequantized_8bit refuses the resume ("exact model snapshot … no longer available") rather than misreading it. If you'd rather bump to v2 with explicit v1 readers, it's a small follow-up on this branch.

Tests

studio/backend/tests/test_training_provenance.py:

  • The two tests that pinned 8-bit and mixed 4+8 as incomplete now assert prequantized_8bit / prequantized_4_8bit and a resumable marker.
  • New: 8-bit with the toggle off attests prequantized_8bit.
  • New: a prequantized_8bit pin refuses resume once the snapshot declares 4-bit.
  • New: a legacy unquantized marker still resumes.
  • New: non-canonical stored modes (prequantized_8_8bit, prequantized_8_4bit, prequantized_08bit, prequantized_bit) are refused on a snapshot whose widths they would otherwise match, while the canonical spelling resumes. Removing the canonical-order check makes this test fail.
  • New: an out-of-range width does not attest.

studio/backend/tests/test_training_cached_start.py: the runtime-4-bit resume propagation test is parametrized to also carry prequantized_8bit through to the worker config.

Run from studio/backend on macOS (Apple M1 Pro): the provenance, cached-start, history-update and resume-reason suites give 368 passed and 3 failed. The same 3 test_training_cached_start.py tests (MLX dataset-streaming rejection message/status) also fail on unmodified main on this machine. ruff check and scripts/run_ruff_format.py (pinned ruff 0.6.9) are clean.

Real-model check (Apple M1 Pro)

Ran this branch's backend (run.py --api-only, isolated UNSLOTH_STUDIO_HOME) and trained through /api/train/start with yahma/alpaca-cleaned, then read each run's stored resource_provenance:

Model 4-bit toggle Outcome model_load_mode Marker
mlx-community/Qwen3.5-0.8B-8bit on completed 6/6 steps prequantized_8bit complete, attested
mlx-community/Qwen3.5-0.8B-8bit on stopped at step 15/20 with save, then resumed via resume_from_checkpoint prequantized_8bit can_resume: true; the resume returned 200 and ran only steps 16–20
mlx-community/Qwen3.5-0.8B-8bit off completed 4/4 steps prequantized_8bit (was unquantized) complete, attested
mlx-community/Qwen2.5-0.5B-Instruct-4bit on completed 4/4 steps prequantized_4bit (unchanged) complete, attested

@Mathews-Tom
Mathews-Tom force-pushed the studio/prequantized-width-provenance branch from eb0658f to a174070 Compare September 25, 2026 17:43
@Mathews-Tom Mathews-Tom changed the title Studio: record the real bit width of prequantized models so 8-bit and mixed MLX runs resume fix(studio): record the bit widths of prequantized MLX models Sep 25, 2026
Resource provenance only recognised uniformly 4-bit snapshots. An 8-bit or mixed-width prequantized model (common in mlx-community repos) never attested with the 4-bit toggle on, so its runs were never resumable, and with the toggle off it attested as `unquantized` although its weights are quantized.

Prequantized load modes now name the snapshot's declared widths: `prequantized_{widths}bit`, sorted, unique and joined by `_` (`prequantized_8bit`, `prequantized_4_8bit`). The existing `prequantized_4bit` is exactly the `{4}` case, so v1 markers keep their meaning without a RESOURCE_PROVENANCE_VERSION bump, and the value flows through the existing resume plumbing unchanged.

`_snapshot_declares_quantization` becomes `_snapshot_quantization_widths`, which returns the declared width set, or None for widths it cannot describe (outside 1..16, or more than 8), which do not attest. Attestation records any declared width regardless of the toggle. Event normalisation and `validate_exact_model_pin` require the snapshot's current widths to match the recorded mode, so a snapshot whose widths changed refuses to resume. Legacy `unquantized` markers keep resuming without a width check, as before. `exact_model_snapshot_path` and `exact_model_snapshot_for_commit` lose their now-unused `require_quantized` parameter.

Closes unslothai#8134
@Mathews-Tom
Mathews-Tom force-pushed the studio/prequantized-width-provenance branch from 522b59b to 711918f Compare September 25, 2026 19:39
@danielhanchen

Copy link
Copy Markdown
Member

Confirmed main still only attests uniform 4-bit snapshots in _snapshot_declares_quantization, so 8-bit and mixed-width MLX runs either cannot resume or get recorded as unquantized, and the width-aware mode fixes both. Will get this reviewed, thanks for the real-model check.

@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #11940, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#254.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror b4792d7b3a (this PR's f503d59c4)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b4792d7b3a

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror b4792d7b3a (this PR's f503d59c4).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit 6f70f90 into unslothai:main Sep 30, 2026
42 of 46 checks passed
@Mathews-Tom
Mathews-Tom deleted the studio/prequantized-width-provenance branch October 1, 2026 12:28
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.

Studio: prequantized MLX models that are not uniformly 4-bit cannot attest, so their runs are never resumable

3 participants