Repository navigation
fix(studio): record the bit widths of prequantized MLX models - #11940
danielhanchen merged 3 commits into
Conversation
eb0658f to
a174070
Compare
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
522b59b to
711918f
Compare
|
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. |
|
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
|
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_quantizationanswered "declares uniform 4-bit", andprequantized_4bitwas the only prequantized load mode. So for an 8-bit or mixed-width prequantized snapshot (common inmlx-communityrepos):unquantizedalthough 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_.prequantized_4bit(unchanged)prequantized_8bitprequantized_4_8bitruntime_4bit(unchanged)unquantized(unchanged)prequantized_4bitis exactly the{4}case, so existing v1 markers keep their meaning andRESOURCE_PROVENANCE_VERSIONstays at 1. The mode is still one string, so it flows throughroutes/training.py,core/training/training.pyand the resume cache key without changes._snapshot_declares_quantization→_snapshot_quantization_widths, which returns the declared width set, orNonefor widths it cannot describe (outside 1..16, or more than 8 of them); those do not attest.normalize_worker_provenance_eventandvalidate_exact_model_pinrequire 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_modeproduces is accepted.unquantizedmarkers keep resuming without a width check, exactly as before.exact_model_snapshot_path/exact_model_snapshot_for_commitlose theirrequire_quantizedparameter.validate_exact_model_pinwas its only user and now compares widths itself._loaded_model_is_4bit, themlx_configexclusion pinned bytest_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_8bitrefuses 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:incompletenow assertprequantized_8bit/prequantized_4_8bitand a resumable marker.prequantized_8bit.prequantized_8bitpin refuses resume once the snapshot declares 4-bit.unquantizedmarker still resumes.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.studio/backend/tests/test_training_cached_start.py: the runtime-4-bit resume propagation test is parametrized to also carryprequantized_8bitthrough to the worker config.Run from
studio/backendon macOS (Apple M1 Pro): the provenance, cached-start, history-update and resume-reason suites give 368 passed and 3 failed. The same 3test_training_cached_start.pytests (MLX dataset-streaming rejection message/status) also fail on unmodifiedmainon this machine.ruff checkandscripts/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, isolatedUNSLOTH_STUDIO_HOME) and trained through/api/train/startwithyahma/alpaca-cleaned, then read each run's storedresource_provenance:model_load_modemlx-community/Qwen3.5-0.8B-8bitprequantized_8bitmlx-community/Qwen3.5-0.8B-8bitresume_from_checkpointprequantized_8bitcan_resume: true; the resume returned 200 and ran only steps 16–20mlx-community/Qwen3.5-0.8B-8bitprequantized_8bit(wasunquantized)mlx-community/Qwen2.5-0.5B-Instruct-4bitprequantized_4bit(unchanged)