From 999044596aa5118308753a3b77b97403378f0b3d Mon Sep 17 00:00:00 2001 From: Anton Lozhkov Date: Wed, 30 Nov 2022 15:27:56 +0100 Subject: [PATCH] Bump to 0.10.0.dev0 + deprecations (#1490) --- .../train_unconditional.py | 7 +- setup.py | 2 +- src/diffusers/__init__.py | 2 +- src/diffusers/hub_utils.py | 120 +----------------- src/diffusers/modeling_utils.py | 14 -- src/diffusers/pipelines/ddpm/pipeline_ddpm.py | 2 +- src/diffusers/schedulers/scheduling_ddim.py | 2 +- .../schedulers/scheduling_ddim_flax.py | 2 +- src/diffusers/schedulers/scheduling_ddpm.py | 4 +- .../schedulers/scheduling_ddpm_flax.py | 4 +- .../scheduling_dpmsolver_multistep.py | 2 +- .../scheduling_dpmsolver_multistep_flax.py | 2 +- tests/pipelines/ddpm/test_ddpm.py | 2 +- tests/test_config.py | 2 +- tests/test_scheduler.py | 4 +- tests/test_scheduler_flax.py | 4 +- 16 files changed, 20 insertions(+), 155 deletions(-) diff --git a/examples/unconditional_image_generation/train_unconditional.py b/examples/unconditional_image_generation/train_unconditional.py index fc5be82b6a63..492c25d02b38 100644 --- a/examples/unconditional_image_generation/train_unconditional.py +++ b/examples/unconditional_image_generation/train_unconditional.py @@ -14,7 +14,6 @@ from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel, __version__ from diffusers.optimization import get_scheduler from diffusers.training_utils import EMAModel -from diffusers.utils import deprecate from huggingface_hub import HfFolder, Repository, whoami from packaging import version from torchvision.transforms import ( @@ -417,11 +416,7 @@ def transforms(examples): scheduler=noise_scheduler, ) - deprecate("todo: remove this check", "0.10.0", "when the most used version is >= 0.8.0") - if diffusers_version < version.parse("0.8.0"): - generator = torch.manual_seed(0) - else: - generator = torch.Generator(device=pipeline.device).manual_seed(0) + generator = torch.Generator(device=pipeline.device).manual_seed(0) # run pipeline in inference (sample random noise and denoise) images = pipeline( generator=generator, diff --git a/setup.py b/setup.py index 4ebec8692752..ee27b620ddae 100644 --- a/setup.py +++ b/setup.py @@ -214,7 +214,7 @@ def run(self): setup( name="diffusers", - version="0.9.0", # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots) + version="0.10.0.dev0", # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots) description="Diffusers", long_description=open("README.md", "r", encoding="utf-8").read(), long_description_content_type="text/markdown", diff --git a/src/diffusers/__init__.py b/src/diffusers/__init__.py index 93f2f3a13af2..6d470cb0e65b 100644 --- a/src/diffusers/__init__.py +++ b/src/diffusers/__init__.py @@ -9,7 +9,7 @@ ) -__version__ = "0.9.0" +__version__ = "0.10.0.dev0" from .configuration_utils import ConfigMixin from .onnx_utils import OnnxRuntimeModel diff --git a/src/diffusers/hub_utils.py b/src/diffusers/hub_utils.py index 8bf0933a1dce..a1772d8f70bf 100644 --- a/src/diffusers/hub_utils.py +++ b/src/diffusers/hub_utils.py @@ -15,16 +15,15 @@ import os -import shutil import sys from pathlib import Path from typing import Dict, Optional, Union from uuid import uuid4 -from huggingface_hub import HfFolder, Repository, whoami +from huggingface_hub import HfFolder, whoami from . import __version__ -from .utils import ENV_VARS_TRUE_VALUES, deprecate, logging +from .utils import ENV_VARS_TRUE_VALUES, logging from .utils.import_utils import ( _flax_version, _jax_version, @@ -83,121 +82,6 @@ def get_full_repo_name(model_id: str, organization: Optional[str] = None, token: return f"{organization}/{model_id}" -def init_git_repo(args, at_init: bool = False): - """ - Args: - Initializes a git repo in `args.hub_model_id`. - at_init (`bool`, *optional*, defaults to `False`): - Whether this function is called before any training or not. If `self.args.overwrite_output_dir` is `True` - and `at_init` is `True`, the path to the repo (which is `self.args.output_dir`) might be wiped out. - """ - deprecation_message = ( - "Please use `huggingface_hub.Repository`. " - "See `examples/unconditional_image_generation/train_unconditional.py` for an example." - ) - deprecate("init_git_repo()", "0.10.0", deprecation_message) - - if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]: - return - hub_token = args.hub_token if hasattr(args, "hub_token") else None - use_auth_token = True if hub_token is None else hub_token - if not hasattr(args, "hub_model_id") or args.hub_model_id is None: - repo_name = Path(args.output_dir).absolute().name - else: - repo_name = args.hub_model_id - if "/" not in repo_name: - repo_name = get_full_repo_name(repo_name, token=hub_token) - - try: - repo = Repository( - args.output_dir, - clone_from=repo_name, - use_auth_token=use_auth_token, - private=args.hub_private_repo, - ) - except EnvironmentError: - if args.overwrite_output_dir and at_init: - # Try again after wiping output_dir - shutil.rmtree(args.output_dir) - repo = Repository( - args.output_dir, - clone_from=repo_name, - use_auth_token=use_auth_token, - ) - else: - raise - - repo.git_pull() - - # By default, ignore the checkpoint folders - if not os.path.exists(os.path.join(args.output_dir, ".gitignore")): - with open(os.path.join(args.output_dir, ".gitignore"), "w", encoding="utf-8") as writer: - writer.writelines(["checkpoint-*/"]) - - return repo - - -def push_to_hub( - args, - pipeline, - repo: Repository, - commit_message: Optional[str] = "End of training", - blocking: bool = True, - **kwargs, -) -> str: - """ - Parameters: - Upload *self.model* and *self.tokenizer* to the 🤗 model hub on the repo *self.args.hub_model_id*. - commit_message (`str`, *optional*, defaults to `"End of training"`): - Message to commit while pushing. - blocking (`bool`, *optional*, defaults to `True`): - Whether the function should return only when the `git push` has finished. - kwargs: - Additional keyword arguments passed along to [`create_model_card`]. - Returns: - The url of the commit of your model in the given repository if `blocking=False`, a tuple with the url of the - commit and an object to track the progress of the commit if `blocking=True` - """ - deprecation_message = ( - "Please use `huggingface_hub.Repository` and `Repository.push_to_hub()`. " - "See `examples/unconditional_image_generation/train_unconditional.py` for an example." - ) - deprecate("push_to_hub()", "0.10.0", deprecation_message) - - if not hasattr(args, "hub_model_id") or args.hub_model_id is None: - model_name = Path(args.output_dir).name - else: - model_name = args.hub_model_id.split("/")[-1] - - output_dir = args.output_dir - os.makedirs(output_dir, exist_ok=True) - logger.info(f"Saving pipeline checkpoint to {output_dir}") - pipeline.save_pretrained(output_dir) - - # Only push from one node. - if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]: - return - - # Cancel any async push in progress if blocking=True. The commits will all be pushed together. - if ( - blocking - and len(repo.command_queue) > 0 - and repo.command_queue[-1] is not None - and not repo.command_queue[-1].is_done - ): - repo.command_queue[-1]._process.kill() - - git_head_commit_url = repo.push_to_hub(commit_message=commit_message, blocking=blocking, auto_lfs_prune=True) - # push separately the model card to be independent from the rest of the model - create_model_card(args, model_name=model_name) - try: - repo.push_to_hub(commit_message="update model card README.md", blocking=blocking, auto_lfs_prune=True) - except EnvironmentError as exc: - logger.error(f"Error pushing update to the model card. Please read logs and retry.\n${exc}") - - return git_head_commit_url - - def create_model_card(args, model_name): if not is_modelcards_available: raise ValueError( diff --git a/src/diffusers/modeling_utils.py b/src/diffusers/modeling_utils.py index bfcba2916a6b..8f0222957a53 100644 --- a/src/diffusers/modeling_utils.py +++ b/src/diffusers/modeling_utils.py @@ -666,20 +666,6 @@ def num_parameters(self, only_trainable: bool = False, exclude_embeddings: bool return sum(p.numel() for p in self.parameters() if p.requires_grad or not only_trainable) -def unwrap_model(model: torch.nn.Module) -> torch.nn.Module: - """ - Recursively unwraps a model from potential containers (as used in distributed training). - - Args: - model (`torch.nn.Module`): The model to unwrap. - """ - # since there could be multiple levels of wrapping, unwrap recursively - if hasattr(model, "module"): - return unwrap_model(model.module) - else: - return model - - def _get_model_file( pretrained_model_name_or_path, *, diff --git a/src/diffusers/pipelines/ddpm/pipeline_ddpm.py b/src/diffusers/pipelines/ddpm/pipeline_ddpm.py index 31791caf9ebe..114a38a5fec7 100644 --- a/src/diffusers/pipelines/ddpm/pipeline_ddpm.py +++ b/src/diffusers/pipelines/ddpm/pipeline_ddpm.py @@ -73,7 +73,7 @@ def __call__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " DDPMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: new_config = dict(self.scheduler.config) diff --git a/src/diffusers/schedulers/scheduling_ddim.py b/src/diffusers/schedulers/scheduling_ddim.py index b1f765a7284e..7a805dd5a4f2 100644 --- a/src/diffusers/schedulers/scheduling_ddim.py +++ b/src/diffusers/schedulers/scheduling_ddim.py @@ -134,7 +134,7 @@ def __init__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " DDIMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample") diff --git a/src/diffusers/schedulers/scheduling_ddim_flax.py b/src/diffusers/schedulers/scheduling_ddim_flax.py index f98d9770043f..157321d46816 100644 --- a/src/diffusers/schedulers/scheduling_ddim_flax.py +++ b/src/diffusers/schedulers/scheduling_ddim_flax.py @@ -138,7 +138,7 @@ def __init__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " FlaxDDIMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample") diff --git a/src/diffusers/schedulers/scheduling_ddpm.py b/src/diffusers/schedulers/scheduling_ddpm.py index a9522c5ab4bc..62a13c33cd89 100644 --- a/src/diffusers/schedulers/scheduling_ddpm.py +++ b/src/diffusers/schedulers/scheduling_ddpm.py @@ -125,7 +125,7 @@ def __init__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " DDPMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample") @@ -255,7 +255,7 @@ def step( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " DDPMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: new_config = dict(self.config) new_config["prediction_type"] = "epsilon" if predict_epsilon else "sample" diff --git a/src/diffusers/schedulers/scheduling_ddpm_flax.py b/src/diffusers/schedulers/scheduling_ddpm_flax.py index 97b38fd3a17e..e716ea0abaad 100644 --- a/src/diffusers/schedulers/scheduling_ddpm_flax.py +++ b/src/diffusers/schedulers/scheduling_ddpm_flax.py @@ -132,7 +132,7 @@ def __init__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " FlaxDDPMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample") @@ -239,7 +239,7 @@ def step( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " FlaxDDPMScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: new_config = dict(self.config) new_config["prediction_type"] = "epsilon" if predict_epsilon else "sample" diff --git a/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py b/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py index c28f40d44c16..25d80ec5f560 100644 --- a/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py +++ b/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py @@ -142,7 +142,7 @@ def __init__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " DPMSolverMultistepScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample") diff --git a/src/diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py b/src/diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py index 78b611ae2721..a44070d1d2aa 100644 --- a/src/diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py +++ b/src/diffusers/schedulers/scheduling_dpmsolver_multistep_flax.py @@ -177,7 +177,7 @@ def __init__( "Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler =" " FlaxDPMSolverMultistepScheduler.from_pretrained(, prediction_type='epsilon')`." ) - predict_epsilon = deprecate("predict_epsilon", "0.10.0", message, take_from=kwargs) + predict_epsilon = deprecate("predict_epsilon", "0.11.0", message, take_from=kwargs) if predict_epsilon is not None: self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample") diff --git a/tests/pipelines/ddpm/test_ddpm.py b/tests/pipelines/ddpm/test_ddpm.py index 6656fb738d51..0f7ca86273e0 100644 --- a/tests/pipelines/ddpm/test_ddpm.py +++ b/tests/pipelines/ddpm/test_ddpm.py @@ -69,7 +69,7 @@ def test_inference(self): assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 def test_inference_deprecated_predict_epsilon(self): - deprecate("remove this test", "0.10.0", "remove") + deprecate("remove this test", "0.11.0", "remove") unet = self.dummy_uncond_unet scheduler = DDPMScheduler(predict_epsilon=False) diff --git a/tests/test_config.py b/tests/test_config.py index 2a021c4ced5f..1aefbad4d1a3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -203,7 +203,7 @@ def test_overwrite_config_on_load(self): ddpm_2 = DDPMScheduler.from_pretrained("google/ddpm-celebahq-256", beta_start=88) with CaptureLogger(logger) as cap_logger: - deprecate("remove this case", "0.10.0", "remove") + deprecate("remove this case", "0.11.0", "remove") ddpm_3 = DDPMScheduler.from_pretrained( "hf-internal-testing/tiny-stable-diffusion-torch", subfolder="scheduler", diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index e53ab049c0a5..621fbfe1253b 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -639,12 +639,12 @@ def test_prediction_type(self): self.check_over_configs(prediction_type=prediction_type) def test_deprecated_predict_epsilon(self): - deprecate("remove this test", "0.10.0", "remove") + deprecate("remove this test", "0.11.0", "remove") for predict_epsilon in [True, False]: self.check_over_configs(predict_epsilon=predict_epsilon) def test_deprecated_epsilon(self): - deprecate("remove this test", "0.10.0", "remove") + deprecate("remove this test", "0.11.0", "remove") scheduler_class = self.scheduler_classes[0] scheduler_config = self.get_scheduler_config() diff --git a/tests/test_scheduler_flax.py b/tests/test_scheduler_flax.py index da1042f3d698..ac4f726e828a 100644 --- a/tests/test_scheduler_flax.py +++ b/tests/test_scheduler_flax.py @@ -626,12 +626,12 @@ def test_prediction_type(self): self.check_over_configs(prediction_type=prediction_type) def test_deprecated_predict_epsilon(self): - deprecate("remove this test", "0.10.0", "remove") + deprecate("remove this test", "0.11.0", "remove") for predict_epsilon in [True, False]: self.check_over_configs(predict_epsilon=predict_epsilon) def test_deprecated_predict_epsilon_to_prediction_type(self): - deprecate("remove this test", "0.10.0", "remove") + deprecate("remove this test", "0.11.0", "remove") for scheduler_class in self.scheduler_classes: scheduler_config = self.get_scheduler_config(predict_epsilon=True) scheduler = scheduler_class.from_config(scheduler_config)