Skip to content

Commit

Permalink
[Bump version] 0.13.0dev0 & Deprecate predict_epsilon (huggingface#…
Browse files Browse the repository at this point in the history
…2109)

* [Bump version] 0.13

* Bump model up

* up
  • Loading branch information
patrickvonplaten authored Jan 25, 2023
1 parent b0cc7c2 commit 09779cb
Show file tree
Hide file tree
Showing 33 changed files with 28 additions and 212 deletions.
2 changes: 1 addition & 1 deletion examples/community/imagic_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def train(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

accelerator = Accelerator(
Expand Down
2 changes: 1 addition & 1 deletion examples/community/lpw_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

# 0. Default height and width to unet
Expand Down
2 changes: 1 addition & 1 deletion examples/community/lpw_stable_diffusion_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

# 0. Default height and width to unet
Expand Down
2 changes: 1 addition & 1 deletion examples/dreambooth/train_dreambooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion examples/dreambooth/train_dreambooth_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

# Cache compiled models across invocations of this script.
cc.initialize_cache(os.path.expanduser("~/.cache/jax/compilation_cache"))
Expand Down
2 changes: 1 addition & 1 deletion examples/dreambooth/train_dreambooth_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion examples/text_to_image/train_text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__, log_level="INFO")

Expand Down
2 changes: 1 addition & 1 deletion examples/text_to_image/train_text_to_image_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion examples/text_to_image/train_text_to_image_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__, log_level="INFO")

Expand Down
2 changes: 1 addition & 1 deletion examples/textual_inversion/textual_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion examples/textual_inversion/textual_inversion_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
# ------------------------------------------------------------------------------

# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__, log_level="INFO")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.12.0")
check_min_version("0.13.0.dev0")

logger = get_logger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def run(self):

setup(
name="diffusers",
version="0.12.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.13.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",
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.12.0"
__version__ = "0.13.0.dev0"

from .configuration_utils import ConfigMixin
from .utils import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

# 1. Check inputs. Raise error if not correct
Expand Down
28 changes: 1 addition & 27 deletions src/diffusers/pipelines/ddpm/pipeline_ddpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import torch

from ...configuration_utils import FrozenDict
from ...utils import deprecate, randn_tensor
from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput


Expand Down Expand Up @@ -46,7 +45,6 @@ def __call__(
num_inference_steps: int = 1000,
output_type: Optional[str] = "pil",
return_dict: bool = True,
**kwargs,
) -> Union[ImagePipelineOutput, Tuple]:
r"""
Args:
Expand All @@ -68,30 +66,6 @@ def __call__(
[`~pipelines.ImagePipelineOutput`] or `tuple`: [`~pipelines.utils.ImagePipelineOutput`] if `return_dict` is
True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images.
"""
message = (
"Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler ="
" DDPMScheduler.from_pretrained(<model_id>, prediction_type='epsilon')`."
)
predict_epsilon = deprecate("predict_epsilon", "0.13.0", message, take_from=kwargs)

if predict_epsilon is not None:
new_config = dict(self.scheduler.config)
new_config["prediction_type"] = "epsilon" if predict_epsilon else "sample"
self.scheduler._internal_dict = FrozenDict(new_config)

if generator is not None and generator.device.type != self.device.type and self.device.type != "mps":
message = (
f"The `generator` device is `{generator.device}` and does not match the pipeline "
f"device `{self.device}`, so the `generator` will be ignored. "
f'Please use `torch.Generator(device="{self.device}")` instead.'
)
deprecate(
"generator.device == 'cpu'",
"0.13.0",
message,
)
generator = None

# Sample gaussian noise to begin loop
if isinstance(self.unet.sample_size, int):
image_shape = (batch_size, self.unet.in_channels, self.unet.sample_size, self.unet.sample_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __call__(
True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

if isinstance(image, PIL.Image.Image):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

# 1. Check inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

if isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

if isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

# 1. Check inputs. Raise error if not correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def __call__(
(nsfw) content, according to the `safety_checker`.
"""
message = "Please use `image` instead of `init_image`."
init_image = deprecate("init_image", "0.13.0", message, take_from=kwargs)
init_image = deprecate("init_image", "0.14.0", message, take_from=kwargs)
image = init_image or image

# 1. Check inputs
Expand Down
12 changes: 1 addition & 11 deletions src/diffusers/schedulers/scheduling_ddim.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, deprecate, randn_tensor
from ..utils import BaseOutput, randn_tensor
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin


Expand Down Expand Up @@ -113,7 +113,6 @@ class DDIMScheduler(SchedulerMixin, ConfigMixin):
"""

_compatibles = [e.name for e in KarrasDiffusionSchedulers]
_deprecated_kwargs = ["predict_epsilon"]
order = 1

@register_to_config
Expand All @@ -128,16 +127,7 @@ def __init__(
set_alpha_to_one: bool = True,
steps_offset: int = 0,
prediction_type: str = "epsilon",
**kwargs,
):
message = (
"Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler ="
" DDIMScheduler.from_pretrained(<model_id>, prediction_type='epsilon')`."
)
predict_epsilon = deprecate("predict_epsilon", "0.13.0", message, take_from=kwargs)
if predict_epsilon is not None:
self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample")

if trained_betas is not None:
self.betas = torch.tensor(trained_betas, dtype=torch.float32)
elif beta_schedule == "linear":
Expand Down
11 changes: 0 additions & 11 deletions src/diffusers/schedulers/scheduling_ddim_flax.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import jax.numpy as jnp

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import deprecate
from .scheduling_utils_flax import (
CommonSchedulerState,
FlaxKarrasDiffusionSchedulers,
Expand Down Expand Up @@ -103,7 +102,6 @@ class FlaxDDIMScheduler(FlaxSchedulerMixin, ConfigMixin):
"""

_compatibles = [e.name for e in FlaxKarrasDiffusionSchedulers]
_deprecated_kwargs = ["predict_epsilon"]

dtype: jnp.dtype

Expand All @@ -123,16 +121,7 @@ def __init__(
steps_offset: int = 0,
prediction_type: str = "epsilon",
dtype: jnp.dtype = jnp.float32,
**kwargs,
):
message = (
"Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler ="
f" {self.__class__.__name__}.from_pretrained(<model_id>, prediction_type='epsilon')`."
)
predict_epsilon = deprecate("predict_epsilon", "0.13.0", message, take_from=kwargs)
if predict_epsilon is not None:
self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample")

self.dtype = dtype

def create_state(self, common: Optional[CommonSchedulerState] = None) -> DDIMSchedulerState:
Expand Down
25 changes: 2 additions & 23 deletions src/diffusers/schedulers/scheduling_ddpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import numpy as np
import torch

from ..configuration_utils import ConfigMixin, FrozenDict, register_to_config
from ..utils import BaseOutput, deprecate, randn_tensor
from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, randn_tensor
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin


Expand Down Expand Up @@ -106,7 +106,6 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
"""

_compatibles = [e.name for e in KarrasDiffusionSchedulers]
_deprecated_kwargs = ["predict_epsilon"]
order = 1

@register_to_config
Expand All @@ -120,16 +119,7 @@ def __init__(
variance_type: str = "fixed_small",
clip_sample: bool = True,
prediction_type: str = "epsilon",
**kwargs,
):
message = (
"Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler ="
" DDPMScheduler.from_pretrained(<model_id>, prediction_type='epsilon')`."
)
predict_epsilon = deprecate("predict_epsilon", "0.13.0", message, take_from=kwargs)
if predict_epsilon is not None:
self.register_to_config(prediction_type="epsilon" if predict_epsilon else "sample")

if trained_betas is not None:
self.betas = torch.tensor(trained_betas, dtype=torch.float32)
elif beta_schedule == "linear":
Expand Down Expand Up @@ -239,7 +229,6 @@ def step(
sample: torch.FloatTensor,
generator=None,
return_dict: bool = True,
**kwargs,
) -> Union[DDPMSchedulerOutput, Tuple]:
"""
Predict the sample at the previous timestep by reversing the SDE. Core function to propagate the diffusion
Expand All @@ -259,16 +248,6 @@ def step(
returning a tuple, the first element is the sample tensor.
"""
message = (
"Please make sure to instantiate your scheduler with `prediction_type` instead. E.g. `scheduler ="
" DDPMScheduler.from_pretrained(<model_id>, prediction_type='epsilon')`."
)
predict_epsilon = deprecate("predict_epsilon", "0.13.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"
self._internal_dict = FrozenDict(new_config)

t = timestep

if model_output.shape[1] == sample.shape[1] * 2 and self.variance_type in ["learned", "learned_range"]:
Expand Down
Loading

0 comments on commit 09779cb

Please sign in to comment.