From b8bbc4a1f8728103bd5ca6ded83387a76be88921 Mon Sep 17 00:00:00 2001 From: Stepheni12 Date: Wed, 31 Jan 2024 02:22:29 -0500 Subject: [PATCH 1/3] Change path to posix --- src/diffusers/models/modeling_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/diffusers/models/modeling_utils.py b/src/diffusers/models/modeling_utils.py index aab4d16172d9..599da73682ae 100644 --- a/src/diffusers/models/modeling_utils.py +++ b/src/diffusers/models/modeling_utils.py @@ -21,6 +21,7 @@ from collections import OrderedDict from functools import partial from typing import Any, Callable, List, Optional, Tuple, Union +from pathlib import Path import safetensors import torch @@ -369,18 +370,18 @@ def save_pretrained( # Save the model if safe_serialization: safetensors.torch.save_file( - state_dict, os.path.join(save_directory, weights_name), metadata={"format": "pt"} + state_dict, Path(save_directory, weights_name).as_posix(), metadata={"format": "pt"} ) else: - torch.save(state_dict, os.path.join(save_directory, weights_name)) + torch.save(state_dict, Path(save_directory, weights_name).as_posix()) - logger.info(f"Model weights saved in {os.path.join(save_directory, weights_name)}") + logger.info(f"Model weights saved in {Path(save_directory, weights_name).as_posix()}") if push_to_hub: # Create a new empty model card and eventually tag it model_card = load_or_create_model_card(repo_id, token=token) model_card = populate_model_card(model_card) - model_card.save(os.path.join(save_directory, "README.md")) + model_card.save(Path(save_directory, "README.md").as_posix()) self._upload_folder( save_directory, From 36a7aa505c11adb29e11d70c7366e9f8242d4c50 Mon Sep 17 00:00:00 2001 From: Stepheni12 Date: Mon, 12 Feb 2024 18:13:14 -0500 Subject: [PATCH 2/3] running isort --- src/diffusers/models/modeling_utils.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/diffusers/models/modeling_utils.py b/src/diffusers/models/modeling_utils.py index 599da73682ae..c1d119bef3f4 100644 --- a/src/diffusers/models/modeling_utils.py +++ b/src/diffusers/models/modeling_utils.py @@ -20,8 +20,8 @@ import re from collections import OrderedDict from functools import partial -from typing import Any, Callable, List, Optional, Tuple, Union from pathlib import Path +from typing import Any, Callable, List, Optional, Tuple, Union import safetensors import torch @@ -30,21 +30,12 @@ from torch import Tensor, nn from .. import __version__ -from ..utils import ( - CONFIG_NAME, - FLAX_WEIGHTS_NAME, - SAFETENSORS_FILE_EXTENSION, - SAFETENSORS_WEIGHTS_NAME, - WEIGHTS_NAME, - _add_variant, - _get_model_file, - deprecate, - is_accelerate_available, - is_torch_version, - logging, -) -from ..utils.hub_utils import PushToHubMixin, load_or_create_model_card, populate_model_card - +from ..utils import (CONFIG_NAME, FLAX_WEIGHTS_NAME, + SAFETENSORS_FILE_EXTENSION, SAFETENSORS_WEIGHTS_NAME, + WEIGHTS_NAME, _add_variant, _get_model_file, deprecate, + is_accelerate_available, is_torch_version, logging) +from ..utils.hub_utils import (PushToHubMixin, load_or_create_model_card, + populate_model_card) logger = logging.get_logger(__name__) @@ -607,7 +598,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P model = cls.from_config(config, **unused_kwargs) # Convert the weights - from .modeling_pytorch_flax_utils import load_flax_checkpoint_in_pytorch_model + from .modeling_pytorch_flax_utils import \ + load_flax_checkpoint_in_pytorch_model model = load_flax_checkpoint_in_pytorch_model(model, model_file) else: From 2f5017fe4155a22a1fb24a0349d18514ebb016cd Mon Sep 17 00:00:00 2001 From: Stepheni12 Date: Fri, 8 Mar 2024 18:42:11 -0500 Subject: [PATCH 3/3] run style and quality checks --- src/diffusers/models/modeling_utils.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/diffusers/models/modeling_utils.py b/src/diffusers/models/modeling_utils.py index 1453af86ea8f..ccc3536079c6 100644 --- a/src/diffusers/models/modeling_utils.py +++ b/src/diffusers/models/modeling_utils.py @@ -30,12 +30,21 @@ from torch import Tensor, nn from .. import __version__ -from ..utils import (CONFIG_NAME, FLAX_WEIGHTS_NAME, - SAFETENSORS_FILE_EXTENSION, SAFETENSORS_WEIGHTS_NAME, - WEIGHTS_NAME, _add_variant, _get_model_file, deprecate, - is_accelerate_available, is_torch_version, logging) -from ..utils.hub_utils import (PushToHubMixin, load_or_create_model_card, - populate_model_card) +from ..utils import ( + CONFIG_NAME, + FLAX_WEIGHTS_NAME, + SAFETENSORS_FILE_EXTENSION, + SAFETENSORS_WEIGHTS_NAME, + WEIGHTS_NAME, + _add_variant, + _get_model_file, + deprecate, + is_accelerate_available, + is_torch_version, + logging, +) +from ..utils.hub_utils import PushToHubMixin, load_or_create_model_card, populate_model_card + logger = logging.get_logger(__name__) @@ -598,8 +607,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P model = cls.from_config(config, **unused_kwargs) # Convert the weights - from .modeling_pytorch_flax_utils import \ - load_flax_checkpoint_in_pytorch_model + from .modeling_pytorch_flax_utils import load_flax_checkpoint_in_pytorch_model model = load_flax_checkpoint_in_pytorch_model(model, model_file) else: