Skip to content

Commit

Permalink
Adapt to forced transformers version in some dependent libraries (hug…
Browse files Browse the repository at this point in the history
…gingface#1638)

* Adapt to forced transformers version in some dependent libraries

* style

* Update __init__.py

* update requires_backends
  • Loading branch information
anton-l authored Dec 9, 2022
1 parent 0892525 commit 3ebe40f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
12 changes: 0 additions & 12 deletions src/diffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
)


# Make sure `transformers` is up to date
if is_transformers_available():
import transformers

if is_transformers_version("<", "4.25.1"):
raise ImportError(
f"`diffusers` requires transformers >= 4.25.1 to function correctly, but {transformers.__version__} was"
" found in your environment. You can upgrade it with pip: `pip install transformers --upgrade`"
)
else:
pass

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/pipelines/stable_diffusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StableDiffusionPipelineOutput(BaseOutput):
from .safety_checker import StableDiffusionSafetyChecker

try:
if not (is_transformers_available() and is_torch_available()):
if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from ...utils.dummy_torch_and_transformers_objects import StableDiffusionImageVariationPipeline
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/pipelines/versatile_diffusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


try:
if not (is_transformers_available() and is_torch_available()):
if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from ...utils.dummy_torch_and_transformers_objects import (
Expand Down
15 changes: 14 additions & 1 deletion src/diffusers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,20 @@ def requires_backends(obj, backends):
if failed:
raise ImportError("".join(failed))

if name in ["StableDiffusionDepth2ImgPipeline"] and is_transformers_version("<", "4.26.0.dev0"):
if name in [
"VersatileDiffusionTextToImagePipeline",
"VersatileDiffusionPipeline",
"VersatileDiffusionDualGuidedPipeline",
"StableDiffusionImageVariationPipeline",
] and is_transformers_version("<", "4.25.0"):
raise ImportError(
f"You need to install `transformers>=4.25` in order to use {name}: \n```\n pip install"
" --upgrade transformers \n```"
)

if name in [
"StableDiffusionDepth2ImgPipeline",
] and is_transformers_version("<", "4.26.0.dev0"):
raise ImportError(
f"You need to install `transformers` from 'main' in order to use {name}: \n```\n pip install"
" git+https://github.com/huggingface/transformers \n```"
Expand Down

0 comments on commit 3ebe40f

Please sign in to comment.