From 697afd805b62da7e3cf1c29fc647be0906d79979 Mon Sep 17 00:00:00 2001 From: dltsum Date: Sun, 20 Sep 2026 22:43:52 +0800 Subject: [PATCH] Pin UTF-8 encoding when reading user-provided config files `fetch_original_config` reads the user-supplied original config file and the fp16_safetensors command reads `model_index.json` without specifying an encoding, so both fall back to the locale encoding. On Windows with a non-UTF-8 locale (e.g. cp936) any non-ASCII content (CJK comments, emoji) crashes with a UnicodeDecodeError. Co-Authored-By: Claude Code --- src/diffusers/commands/fp16_safetensors.py | 2 +- src/diffusers/loaders/single_file_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/commands/fp16_safetensors.py b/src/diffusers/commands/fp16_safetensors.py index ec91bba357a0..c8f3d9ed0a0b 100644 --- a/src/diffusers/commands/fp16_safetensors.py +++ b/src/diffusers/commands/fp16_safetensors.py @@ -99,7 +99,7 @@ def run(self): from huggingface_hub._commit_api import CommitOperationAdd model_index = hf_hub_download(repo_id=self.ckpt_id, filename="model_index.json") - with open(model_index, "r") as f: + with open(model_index, "r", encoding="utf-8") as f: pipeline_class_name = json.load(f)["_class_name"] pipeline_class = getattr(import_module("diffusers"), pipeline_class_name) self.logger.info(f"Pipeline class imported: {pipeline_class_name}.") diff --git a/src/diffusers/loaders/single_file_utils.py b/src/diffusers/loaders/single_file_utils.py index ac707947d491..2526ffdd1dd0 100644 --- a/src/diffusers/loaders/single_file_utils.py +++ b/src/diffusers/loaders/single_file_utils.py @@ -500,7 +500,7 @@ def load_single_file_checkpoint( def fetch_original_config(original_config_file, local_files_only=False): if os.path.isfile(original_config_file): - with open(original_config_file, "r") as fp: + with open(original_config_file, "r", encoding="utf-8") as fp: original_config_file = fp.read() elif is_valid_url(original_config_file):