diff --git a/diffsynth_engine/models/flux/flux_dit.py b/diffsynth_engine/models/flux/flux_dit.py index 6cc872a9..e9e50ad2 100644 --- a/diffsynth_engine/models/flux/flux_dit.py +++ b/diffsynth_engine/models/flux/flux_dit.py @@ -28,7 +28,7 @@ logger = logging.get_logger(__name__) -with open(FLUX_DIT_CONFIG_FILE, "r") as f: +with open(FLUX_DIT_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/flux/flux_text_encoder.py b/diffsynth_engine/models/flux/flux_text_encoder.py index e25cbe09..f93fba0c 100644 --- a/diffsynth_engine/models/flux/flux_text_encoder.py +++ b/diffsynth_engine/models/flux/flux_text_encoder.py @@ -10,7 +10,7 @@ logger = logging.get_logger(__name__) -with open(FLUX_TEXT_ENCODER_CONFIG_FILE, "r") as f: +with open(FLUX_TEXT_ENCODER_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/flux/flux_vae.py b/diffsynth_engine/models/flux/flux_vae.py index 9af50bc3..f733f0c7 100644 --- a/diffsynth_engine/models/flux/flux_vae.py +++ b/diffsynth_engine/models/flux/flux_vae.py @@ -8,7 +8,7 @@ logger = logging.get_logger(__name__) -with open(FLUX_VAE_CONFIG_FILE, "r") as f: +with open(FLUX_VAE_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/qwen_image/qwen_image_vae.py b/diffsynth_engine/models/qwen_image/qwen_image_vae.py index 838ac9f4..82102a57 100644 --- a/diffsynth_engine/models/qwen_image/qwen_image_vae.py +++ b/diffsynth_engine/models/qwen_image/qwen_image_vae.py @@ -12,7 +12,7 @@ CACHE_T = 2 -with open(QWEN_IMAGE_VAE_KEYMAP_FILE, "r") as f: +with open(QWEN_IMAGE_VAE_KEYMAP_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/sd/sd_text_encoder.py b/diffsynth_engine/models/sd/sd_text_encoder.py index eb7fea57..98bfc4bd 100644 --- a/diffsynth_engine/models/sd/sd_text_encoder.py +++ b/diffsynth_engine/models/sd/sd_text_encoder.py @@ -10,7 +10,7 @@ logger = logging.get_logger(__name__) -with open(SD_TEXT_ENCODER_CONFIG_FILE, "r") as f: +with open(SD_TEXT_ENCODER_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/sd/sd_unet.py b/diffsynth_engine/models/sd/sd_unet.py index 63c9de5e..0674e9d8 100644 --- a/diffsynth_engine/models/sd/sd_unet.py +++ b/diffsynth_engine/models/sd/sd_unet.py @@ -18,7 +18,7 @@ logger = logging.get_logger(__name__) -with open(SD_UNET_CONFIG_FILE) as f: +with open(SD_UNET_CONFIG_FILE, encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/sd3/sd3_dit.py b/diffsynth_engine/models/sd3/sd3_dit.py index d62fd6b7..c00cca06 100644 --- a/diffsynth_engine/models/sd3/sd3_dit.py +++ b/diffsynth_engine/models/sd3/sd3_dit.py @@ -13,7 +13,7 @@ logger = logging.get_logger(__name__) -with open(SD3_DIT_CONFIG_FILE, "r") as f: +with open(SD3_DIT_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/sd3/sd3_text_encoder.py b/diffsynth_engine/models/sd3/sd3_text_encoder.py index 286637e8..f72a0ea3 100644 --- a/diffsynth_engine/models/sd3/sd3_text_encoder.py +++ b/diffsynth_engine/models/sd3/sd3_text_encoder.py @@ -11,7 +11,7 @@ logger = logging.get_logger(__name__) -with open(SD3_TEXT_ENCODER_CONFIG_FILE, "r") as f: +with open(SD3_TEXT_ENCODER_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/sdxl/sdxl_text_encoder.py b/diffsynth_engine/models/sdxl/sdxl_text_encoder.py index a1d24853..0d0eadbc 100644 --- a/diffsynth_engine/models/sdxl/sdxl_text_encoder.py +++ b/diffsynth_engine/models/sdxl/sdxl_text_encoder.py @@ -10,7 +10,7 @@ logger = logging.get_logger(__name__) -with open(SDXL_TEXT_ENCODER_CONFIG_FILE, "r") as f: +with open(SDXL_TEXT_ENCODER_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/sdxl/sdxl_unet.py b/diffsynth_engine/models/sdxl/sdxl_unet.py index cb61c514..5ac8c1c8 100644 --- a/diffsynth_engine/models/sdxl/sdxl_unet.py +++ b/diffsynth_engine/models/sdxl/sdxl_unet.py @@ -18,7 +18,7 @@ logger = logging.get_logger(__name__) -with open(SDXL_UNET_CONFIG_FILE, "r") as f: +with open(SDXL_UNET_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/vae/vae.py b/diffsynth_engine/models/vae/vae.py index 0edce7df..dec71554 100644 --- a/diffsynth_engine/models/vae/vae.py +++ b/diffsynth_engine/models/vae/vae.py @@ -12,7 +12,7 @@ logger = logging.get_logger(__name__) -with open(VAE_CONFIG_FILE, "r") as f: +with open(VAE_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/models/wan/wan_dit.py b/diffsynth_engine/models/wan/wan_dit.py index a8b8b9c6..0c274836 100644 --- a/diffsynth_engine/models/wan/wan_dit.py +++ b/diffsynth_engine/models/wan/wan_dit.py @@ -398,7 +398,7 @@ def get_model_config(model_type: str): raise ValueError(f"Unsupported model type: {model_type}") config_file = MODEL_CONFIG_FILES[model_type] - with open(config_file, "r") as f: + with open(config_file, "r", encoding="utf-8") as f: config = json.load(f) return config diff --git a/diffsynth_engine/models/wan/wan_s2v_dit.py b/diffsynth_engine/models/wan/wan_s2v_dit.py index 2ceb36a4..d0d21c5a 100644 --- a/diffsynth_engine/models/wan/wan_s2v_dit.py +++ b/diffsynth_engine/models/wan/wan_s2v_dit.py @@ -360,7 +360,7 @@ def get_model_config(model_type: str): raise ValueError(f"Unsupported model type: {model_type}") config_file = MODEL_CONFIG_FILES[model_type] - with open(config_file, "r") as f: + with open(config_file, "r", encoding="utf-8") as f: config = json.load(f) return config diff --git a/diffsynth_engine/models/wan/wan_vae.py b/diffsynth_engine/models/wan/wan_vae.py index cf87908e..2b41f4eb 100644 --- a/diffsynth_engine/models/wan/wan_vae.py +++ b/diffsynth_engine/models/wan/wan_vae.py @@ -12,7 +12,7 @@ CACHE_T = 2 -with open(WAN_VAE_KEYMAP_FILE, "r") as f: +with open(WAN_VAE_KEYMAP_FILE, "r", encoding="utf-8") as f: config = json.load(f) @@ -855,7 +855,7 @@ def get_model_config(model_type: str) -> dict: raise ValueError(f"Unsupported model type: {model_type}") config_file = MODEL_CONFIG_FILES[model_type] - with open(config_file, "r") as f: + with open(config_file, "r", encoding="utf-8") as f: config = json.load(f) return config diff --git a/diffsynth_engine/pipelines/flux_image.py b/diffsynth_engine/pipelines/flux_image.py index 69128613..25d61c45 100644 --- a/diffsynth_engine/pipelines/flux_image.py +++ b/diffsynth_engine/pipelines/flux_image.py @@ -34,7 +34,7 @@ logger = logging.get_logger(__name__) -with open(FLUX_DIT_CONFIG_FILE, "r") as f: +with open(FLUX_DIT_CONFIG_FILE, "r", encoding="utf-8") as f: config = json.load(f) diff --git a/diffsynth_engine/pipelines/qwen_image.py b/diffsynth_engine/pipelines/qwen_image.py index d0b6e9ef..e30b1777 100644 --- a/diffsynth_engine/pipelines/qwen_image.py +++ b/diffsynth_engine/pipelines/qwen_image.py @@ -182,9 +182,9 @@ def _from_state_dict(cls, state_dicts: QwenImageStateDicts, config: QwenImagePip tokenizer_config_path=QWEN_IMAGE_TOKENIZER_CONF_PATH, image_processor_config_path=QWEN_IMAGE_PROCESSOR_CONFIG_FILE, ) - with open(QWEN_IMAGE_VISION_CONFIG_FILE, "r") as f: + with open(QWEN_IMAGE_VISION_CONFIG_FILE, "r", encoding="utf-8") as f: vision_config = Qwen2_5_VLVisionConfig(**json.load(f)) - with open(QWEN_IMAGE_CONFIG_FILE, "r") as f: + with open(QWEN_IMAGE_CONFIG_FILE, "r", encoding="utf-8") as f: text_config = Qwen2_5_VLConfig(**json.load(f)) encoder = Qwen2_5_VLForConditionalGeneration.from_state_dict( state_dicts.encoder, @@ -193,7 +193,7 @@ def _from_state_dict(cls, state_dicts: QwenImageStateDicts, config: QwenImagePip device=init_device, dtype=config.encoder_dtype, ) - with open(QWEN_IMAGE_VAE_CONFIG_FILE, "r") as f: + with open(QWEN_IMAGE_VAE_CONFIG_FILE, "r", encoding="utf-8") as f: vae_config = json.load(f) vae = QwenImageVAE.from_state_dict( state_dicts.vae, config=vae_config, device=init_device, dtype=config.vae_dtype diff --git a/diffsynth_engine/utils/memory/memory_predcit_model.py b/diffsynth_engine/utils/memory/memory_predcit_model.py index 147408c0..329e83f2 100644 --- a/diffsynth_engine/utils/memory/memory_predcit_model.py +++ b/diffsynth_engine/utils/memory/memory_predcit_model.py @@ -87,7 +87,7 @@ def train(self, records: List[dict]): return r2 def save_model(self, model_path): - with open(model_path, "wb") as f: + with open(model_path, "wb", encoding="utf-8") as f: torch.save( { "key_inputs": self.key_inputs, @@ -98,7 +98,7 @@ def save_model(self, model_path): @classmethod def from_pretrained(cls, model_path): - with open(model_path, "rb") as f: + with open(model_path, "rb", encoding="utf-8") as f: data = torch.load(f) model = cls(data["key_inputs"]) model.model = LinearRegression.deserialize(data["model"]) diff --git a/tests/test_models/qwen_image/test_qwen2_5_vl.py b/tests/test_models/qwen_image/test_qwen2_5_vl.py index accc7075..44452fc6 100644 --- a/tests/test_models/qwen_image/test_qwen2_5_vl.py +++ b/tests/test_models/qwen_image/test_qwen2_5_vl.py @@ -35,9 +35,9 @@ def setUpClass(cls): os.path.join(cls._model_path, file) for file in os.listdir(cls._model_path) if file.endswith(".safetensors") ] loaded_state_dict = load_model_checkpoint(ckpt_path, device="cpu", dtype=torch.bfloat16) - with open(QWEN_IMAGE_VISION_CONFIG_FILE, "r") as f: + with open(QWEN_IMAGE_VISION_CONFIG_FILE, "r", encoding="utf-8") as f: vision_config = Qwen2_5_VLVisionConfig(**json.load(f)) - with open(QWEN_IMAGE_CONFIG_FILE, "r") as f: + with open(QWEN_IMAGE_CONFIG_FILE, "r", encoding="utf-8") as f: text_config = Qwen2_5_VLConfig(**json.load(f)) cls.encoder = Qwen2_5_VLForConditionalGeneration.from_state_dict( loaded_state_dict,