From eb214f3d87fda961ff16b4cc91c6fec30eeba67d Mon Sep 17 00:00:00 2001 From: Osamaali313 Date: Fri, 17 Jul 2026 22:40:53 +0300 Subject: [PATCH] Fix safetensors detection in try_collect_weight_map (missing dot in glob) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- optimum/fx/parallelization/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimum/fx/parallelization/utils.py b/optimum/fx/parallelization/utils.py index e1d6120628..70df18f8f1 100644 --- a/optimum/fx/parallelization/utils.py +++ b/optimum/fx/parallelization/utils.py @@ -464,7 +464,7 @@ def try_collect_weight_map(model_name_or_path: str, cache_dir: Optional[str], fo from transformers.utils import SAFE_WEIGHTS_INDEX_NAME, WEIGHTS_INDEX_NAME weight_map = {} - use_safetensors, weight_patterns = False, ["*safetensors", "*.bin"] + use_safetensors, weight_patterns = False, ["*.safetensors", "*.bin"] for pattern in weight_patterns: if len(glob.glob(os.path.join(folder_path, pattern))) > 0: use_safetensors = pattern == "*.safetensors"