Fix safetensors detection in try_collect_weight_map (missing dot in glob)#2463
Open
Osamaali313 wants to merge 1 commit into
Open
Fix safetensors detection in try_collect_weight_map (missing dot in glob)#2463Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
…lob)
`try_collect_weight_map` builds its weight-file patterns as
`["*safetensors", "*.bin"]` — the safetensors entry is missing its dot.
The pattern still matches real files (`glob("*safetensors")` matches
`model.safetensors`), so the loop breaks on it, but the next line sets
use_safetensors = pattern == "*.safetensors"
which compares against the dotted form and is therefore always False, even
for a safetensors-only model.
With `use_safetensors` stuck False, the code reads `WEIGHTS_INDEX_NAME`
(`pytorch_model.bin.index.json`) instead of `SAFE_WEIGHTS_INDEX_NAME`,
globs `*.bin` (empty for a safetensors model), and runs
`convert_bin_to_safetensors` needlessly. The three sibling references in the
same function (the `== "*.safetensors"` comparison and the `*.safetensors`
globs) all use the dotted form, confirming the intended pattern. Add the
missing dot.
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.
Problem
try_collect_weight_map(optimum/fx/parallelization/utils.py) builds its weight-file glob patterns with the safetensors dot missing:"*safetensors"still matches real files (glob("*safetensors")matchesmodel.safetensors), so the loop breaks on it — butuse_safetensors = ("*safetensors" == "*.safetensors")is always False, even for a safetensors-only model.Impact
With
use_safetensorsstuck False, for a safetensors model:index_pathusesWEIGHTS_INDEX_NAME(pytorch_model.bin.index.json) instead ofSAFE_WEIGHTS_INDEX_NAME→ the realmodel.safetensors.index.jsonis never read.weight_filesglobs*.bin→ empty for a safetensors model.convert_bin_to_safetensorsruns on every call (acquires a file lock; no-op with no bin files).try_collect_weight_mapis called fromoptimum/fx/parallelization/api.pyin the FX tensor-parallelismparallelize_modelflow.Evidence (siblings prove intent)
The three other references in the same function all use the dotted
"*.safetensors":use_safetensors = pattern == "*.safetensors"glob.glob(os.path.join(folder_path, "*.safetensors" if use_safetensors else "*.bin"))glob.glob(os.path.join(folder_path, "*.safetensors"))The sibling
"*.bin"entry in the same list has its dot; only the safetensors entry is missing it.Reproduction
Synthetic sharded-safetensors dir (
model-0000{1,2}-of-00002.safetensors+model.safetensors.index.json):*safetensors)False❌pytorch_model.bin.index.json[]*.safetensors)True✅model.safetensors.index.jsonFix