Skip to content

Commit 1547720

Browse files
yiyixuxuyiyixuxu
authored andcommitted
add is_torchvision_available (#6800)
* add * remove transformer --------- Co-authored-by: yiyixuxu <yixu310@gmail,com>
1 parent 674d43f commit 1547720

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/diffusers/training_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import numpy as np
77
import torch
8-
from transformers import is_torchvision_available
98

109
from .models import UNet2DConditionModel
1110
from .utils import (
1211
convert_state_dict_to_diffusers,
1312
convert_state_dict_to_peft,
1413
deprecate,
1514
is_peft_available,
15+
is_torchvision_available,
1616
is_transformers_available,
1717
)
1818

src/diffusers/utils/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
is_torch_version,
7676
is_torch_xla_available,
7777
is_torchsde_available,
78+
is_torchvision_available,
7879
is_transformers_available,
7980
is_transformers_version,
8081
is_unidecode_available,

src/diffusers/utils/import_utils.py

+11
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@
278278
except importlib_metadata.PackageNotFoundError:
279279
_peft_available = False
280280

281+
_torchvision_available = importlib.util.find_spec("torchvision") is not None
282+
try:
283+
_torchvision_version = importlib_metadata.version("torchvision")
284+
logger.debug(f"Successfully imported torchvision version {_torchvision_version}")
285+
except importlib_metadata.PackageNotFoundError:
286+
_torchvision_available = False
287+
281288

282289
def is_torch_available():
283290
return _torch_available
@@ -367,6 +374,10 @@ def is_peft_available():
367374
return _peft_available
368375

369376

377+
def is_torchvision_available():
378+
return _torchvision_available
379+
380+
370381
# docstyle-ignore
371382
FLAX_IMPORT_ERROR = """
372383
{0} requires the FLAX library but it was not found in your environment. Checkout the instructions on the

0 commit comments

Comments
 (0)