Fix dwq: check for actual safetensors in target_dir#1173
Merged
angeloskath merged 2 commits intoml-explore:mainfrom Apr 21, 2026
Merged
Fix dwq: check for actual safetensors in target_dir#1173angeloskath merged 2 commits intoml-explore:mainfrom
angeloskath merged 2 commits intoml-explore:mainfrom
Conversation
angeloskath
approved these changes
Apr 21, 2026
Member
angeloskath
left a comment
There was a problem hiding this comment.
Looks good thanks!
I removed the test as it wasn't really testing the dwq code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
mlx_lm.dwqsilently skips target computation when--target-diris empty but exists.When the directory exists with no
.safetensorsfiles, the model is not loaded (model = None),target computation is skipped, and then
mx.load()crashes at runtime with:This happens when a user creates the target directory ahead of time, or when a previous run
was interrupted before writing targets.
Closes #1159
Root Cause
In
mlx_lm/quant/dwq.pyline 317, thehas_targetscheck usestarget_dir.exists():This returns
Truefor any existing directory, regardless of whether it contains target files.The subsequent code paths skip both model loading (line 334-335:
model = None) and targetcomputation (line 338), then try to load nonexistent files at line 356.
Fix
target_dir.exists()with a check that verifies actual.safetensorsfiles existin both
train/andvalid/subdirectorieshas_targets = target_dir.exists()Validation
6 new unit tests in
tests/test_dwq.py:has_targets = False(wasTrue)has_targets = False(wasTrue)has_targets = False(wasTrue)has_targets = True(unchanged)has_targets = False(unchanged)has_targets = False(wasTrue)