Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion diffsynth_engine/models/flux/flux_dit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/flux/flux_text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/flux/flux_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/qwen_image/qwen_image_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/sd/sd_text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/sd/sd_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/sd3/sd3_dit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/sd3/sd3_text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/sdxl/sdxl_text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/sdxl/sdxl_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/vae/vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/wan/wan_dit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/models/wan/wan_s2v_dit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions diffsynth_engine/models/wan/wan_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/pipelines/flux_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions diffsynth_engine/pipelines/qwen_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions diffsynth_engine/utils/memory/memory_predcit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The encoding parameter should not be used when opening a file in binary mode ('wb'). torch.save writes binary data, and specifying an encoding for a binary file will raise a ValueError. Please remove the encoding argument.

Suggested change
with open(model_path, "wb", encoding="utf-8") as f:
with open(model_path, "wb") as f:

torch.save(
{
"key_inputs": self.key_inputs,
Expand All @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The encoding parameter should not be used when opening a file in binary mode ('rb'). torch.load reads binary data, and specifying an encoding for a binary file will raise a ValueError. Please remove the encoding argument.

Suggested change
with open(model_path, "rb", encoding="utf-8") as f:
with open(model_path, "rb") as f:

data = torch.load(f)
model = cls(data["key_inputs"])
model.model = LinearRegression.deserialize(data["model"])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/qwen_image/test_qwen2_5_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down