From 070d70b7e83ace24c945b570f84acb19d9f5bc7f Mon Sep 17 00:00:00 2001 From: Functionhx <2994114386@qq.com> Date: Fri, 10 Jul 2026 03:34:08 +0800 Subject: [PATCH] Fix DiffusionPipeline.download() on Windows: os.path.join produces backslash paths On Windows, os.path.join(k, "config.json") produces paths with backslash separators (e.g. text_encoder\config.json). These patterns are later passed to fnmatch, which does not normalize path separators, causing the pattern mismatch on Windows. The result: subfolder config.json files are silently excluded from allow_patterns and never downloaded by snapshot_download on Windows, but downloading works fine on Linux/macOS. Fix: use an f-string (f"{k}/config.json") to always produce forward-slash paths, consistent with how other patterns are already constructed in the same function (f"{k}/*", f"{k}/{f}.py", etc.). Same bug in FlaxDiffusionPipeline.download(): os.path.join(k, "*") on line 339 of pipeline_flax_utils.py. Fixed identically (f"{k}/*"). Test Plan: No behavioral change on Linux/macOS (forward slash already used). On Windows, subfolder config.json files and Flax subfolder wildcards will now be included in allow_patterns and matched correctly. Fixes huggingface/diffusers#14142 Signed-off-by: Yuchen Fan --- src/diffusers/pipelines/pipeline_flax_utils.py | 2 +- src/diffusers/pipelines/pipeline_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/pipelines/pipeline_flax_utils.py b/src/diffusers/pipelines/pipeline_flax_utils.py index 8c29db8aa45e..b81d81265bf5 100644 --- a/src/diffusers/pipelines/pipeline_flax_utils.py +++ b/src/diffusers/pipelines/pipeline_flax_utils.py @@ -336,7 +336,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike | None ) # make sure we only download sub-folders and `diffusers` filenames folder_names = [k for k in config_dict.keys() if not k.startswith("_")] - allow_patterns = [os.path.join(k, "*") for k in folder_names] + allow_patterns = [f"{k}/*" for k in folder_names] allow_patterns += [FLAX_WEIGHTS_NAME, SCHEDULER_CONFIG_NAME, CONFIG_NAME, cls.config_name] ignore_patterns = ["*.bin", "*.safetensors"] if not from_pt else [] diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 7b653caa0657..867a85683339 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -1738,7 +1738,7 @@ def download(cls, pretrained_model_name, **kwargs) -> str | os.PathLike: # add custom pipeline file allow_patterns += [f"{custom_pipeline}.py"] if f"{custom_pipeline}.py" in filenames else [] # also allow downloading config.json files with the model - allow_patterns += [os.path.join(k, "config.json") for k in model_folder_names] + allow_patterns += [f"{k}/config.json" for k in model_folder_names] allow_patterns += [ SCHEDULER_CONFIG_NAME, CONFIG_NAME,