Skip to content

Commit

Permalink
Check k-diffusion version is at least 0.0.12 (#2022)
Browse files Browse the repository at this point in the history
* Check k-diffusion version is at least 0.0.12

* make style
  • Loading branch information
pcuenca authored Jan 17, 2023
1 parent a43bdd0 commit 7e29b74
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"isort>=5.5.4",
"jax>=0.2.8,!=0.3.2",
"jaxlib>=0.1.65",
"k-diffusion",
"k-diffusion>=0.0.12",
"librosa",
"modelcards>=0.1.4",
"numpy",
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
is_flax_available,
is_inflect_available,
is_k_diffusion_available,
is_k_diffusion_version,
is_librosa_available,
is_onnx_available,
is_scipy_available,
Expand Down
4 changes: 2 additions & 2 deletions src/diffusers/dependency_versions_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
deps = {
"Pillow": "Pillow",
"accelerate": "accelerate>=0.11.0",
"black": "black==22.8",
"black": "black==22.12",
"datasets": "datasets",
"filelock": "filelock",
"flake8": "flake8>=3.8.3",
Expand All @@ -15,7 +15,7 @@
"isort": "isort>=5.5.4",
"jax": "jax>=0.2.8,!=0.3.2",
"jaxlib": "jaxlib>=0.1.65",
"k-diffusion": "k-diffusion",
"k-diffusion": "k-diffusion>=0.0.12",
"librosa": "librosa",
"modelcards": "modelcards>=0.1.4",
"numpy": "numpy",
Expand Down
3 changes: 2 additions & 1 deletion src/diffusers/pipelines/stable_diffusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
OptionalDependencyNotAvailable,
is_flax_available,
is_k_diffusion_available,
is_k_diffusion_version,
is_onnx_available,
is_torch_available,
is_transformers_available,
Expand Down Expand Up @@ -64,7 +65,7 @@ class StableDiffusionPipelineOutput(BaseOutput):


try:
if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
if not (is_torch_available() and is_transformers_available() and is_k_diffusion_version(">=", "0.0.12")):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from ...utils.dummy_torch_and_transformers_and_k_diffusion_objects import * # noqa F403
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
is_flax_available,
is_inflect_available,
is_k_diffusion_available,
is_k_diffusion_version,
is_librosa_available,
is_modelcards_available,
is_onnx_available,
Expand Down
16 changes: 15 additions & 1 deletion src/diffusers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,26 @@ def is_transformers_version(operation: str, version: str):
operation (`str`):
A string representation of an operator, such as `">"` or `"<="`
version (`str`):
A string version of PyTorch
A version string
"""
if not _transformers_available:
return False
return compare_versions(parse(_transformers_version), operation, version)


def is_k_diffusion_version(operation: str, version: str):
"""
Args:
Compares the current k-diffusion version to a given reference with an operation.
operation (`str`):
A string representation of an operator, such as `">"` or `"<="`
version (`str`):
A version string
"""
if not _k_diffusion_available:
return False
return compare_versions(parse(_k_diffusion_version), operation, version)


class OptionalDependencyNotAvailable(BaseException):
"""An error indicating that an optional dependency of Diffusers was not found in the environment."""

0 comments on commit 7e29b74

Please sign in to comment.