Getting a ImportError while go though the Train a diffuser model tutorial

Hi, I am running a notebook on paperspace. it says i a import error when I’m trying to import the UNet2DModel.
I’m running python 3.9.16
Any ideas on what i could do to fix this.
Thanks in advance
This is the error

ImportError                               Traceback (most recent call last)
File /usr/local/lib/python3.9/dist-packages/diffusers/utils/import_utils.py:710, in _LazyModule._get_module(self, module_name)
    709 try:
--> 710     return importlib.import_module("." + module_name, self.__name__)
    711 except Exception as e:

File /usr/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:986, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:680, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:850, in exec_module(self, module)

File <frozen importlib._bootstrap>:228, in _call_with_frames_removed(f, *args, **kwds)

File /usr/local/lib/python3.9/dist-packages/diffusers/models/unet_2d.py:22
     21 from ..utils import BaseOutput
---> 22 from .embeddings import GaussianFourierProjection, TimestepEmbedding, Timesteps
     23 from .modeling_utils import ModelMixin

File /usr/local/lib/python3.9/dist-packages/diffusers/models/embeddings.py:22
     21 from ..utils import USE_PEFT_BACKEND
---> 22 from .activations import get_activation
     23 from .attention_processor import Attention

File /usr/local/lib/python3.9/dist-packages/diffusers/models/activations.py:21
     20 from ..utils import USE_PEFT_BACKEND
---> 21 from .lora import LoRACompatibleLinear
     24 ACTIVATION_FUNCTIONS = {
     25     "swish": nn.SiLU(),
     26     "silu": nn.SiLU(),
   (...)
     29     "relu": nn.ReLU(),
     30 }

File /usr/local/lib/python3.9/dist-packages/diffusers/models/lora.py:35
     34 if is_transformers_available():
---> 35     from transformers import CLIPTextModel, CLIPTextModelWithProjection
     38 logger = logging.get_logger(__name__)  # pylint: disable=invalid-name

ImportError: cannot import name 'CLIPTextModelWithProjection' from 'transformers' (/usr/local/lib/python3.9/dist-packages/transformers/__init__.py)

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In [14], line 1
----> 1 from diffusers import UNet2DModel
      3 model = UNet2DModel(
      4     sample_size=config.image_size,  # the target image resolution
      5     in_channels=3,  # the number of input channels, 3 for RGB images
   (...)
     24     ),
     25 )

File <frozen importlib._bootstrap>:1055, in _handle_fromlist(module, fromlist, import_, recursive)

File /usr/local/lib/python3.9/dist-packages/diffusers/utils/import_utils.py:701, in _LazyModule.__getattr__(self, name)
    699 elif name in self._class_to_module.keys():
    700     module = self._get_module(self._class_to_module[name])
--> 701     value = getattr(module, name)
    702 else:
    703     raise AttributeError(f"module {self.__name__} has no attribute {name}")

File /usr/local/lib/python3.9/dist-packages/diffusers/utils/import_utils.py:700, in _LazyModule.__getattr__(self, name)
    698     value = self._get_module(name)
    699 elif name in self._class_to_module.keys():
--> 700     module = self._get_module(self._class_to_module[name])
    701     value = getattr(module, name)
    702 else:

File /usr/local/lib/python3.9/dist-packages/diffusers/utils/import_utils.py:712, in _LazyModule._get_module(self, module_name)
    710     return importlib.import_module("." + module_name, self.__name__)
    711 except Exception as e:
--> 712     raise RuntimeError(
    713         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
    714         f" traceback):\n{e}"
    715     ) from e

RuntimeError: Failed to import diffusers.models.unet_2d because of the following error (look up to see its traceback):
cannot import name 'CLIPTextModelWithProjection' from 'transformers' (/usr/local/lib/python3.9/dist-packages/transformers/__init__.py)

Hi @mattlocke, you probably need to upgrade transformers

pip install --upgrade transformers

2 Likes

Thanks it worked. Really appreciate the help. Hope you have a amazing day.

1 Like

command :sh inference.sh
The following values were not passed to accelerate launch and had defaults used instead:
--num_processes was set to a value of 1
--num_machines was set to a value of 1
--mixed_precision was set to a value of 'no'
--dynamo_backend was set to a value of 'no'
To avoid this warning pass in values for each of the problematic parameters or run accelerate config.
Traceback (most recent call last):
File “/home/lenovo/Documents/outfit/IDM-VTON/inference.py”, line 15, in
from ip_adapter.ip_adapter import Resampler
File “/home/lenovo/Documents/outfit/IDM-VTON/ip_adapter/init.py”, line 1, in
from .ip_adapter import IPAdapter, IPAdapterPlus, IPAdapterPlusXL, IPAdapterXL, IPAdapterFull,IPAdapterPlus_Lora,IPAdapterPlus_Lora_up
File “/home/lenovo/Documents/outfit/IDM-VTON/ip_adapter/ip_adapter.py”, line 5, in
from diffusers import StableDiffusionPipeline
File “/home/lenovo/Documents/outfit/otenv/lib/python3.10/site-packages/diffusers/init.py”, line 4, in
from diffusers.utils import USE_PEFT_BACKEND
ImportError: cannot import name ‘USE_PEFT_BACKEND’ from ‘diffusers.utils’ (/home/lenovo/Documents/outfit/otenv/lib/python3.10/site-packages/diffusers/utils/init.py)
Traceback (most recent call last):
File “/home/lenovo/Documents/outfit/otenv/bin/accelerate”, line 8, in
sys.exit(main())
File “/home/lenovo/Documents/outfit/otenv/lib/python3.10/site-packages/accelerate/commands/accelerate_cli.py”, line 45, in main
args.func(args)
File “/home/lenovo/Documents/outfit/otenv/lib/python3.10/site-packages/accelerate/commands/launch.py”, line 986, in launch_command
simple_launcher(args)
File “/home/lenovo/Documents/outfit/otenv/lib/python3.10/site-packages/accelerate/commands/launch.py”, line 628, in simple_launcher
raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command ‘[’/home/lenovo/Documents/outfit/otenv/bin/python3.10’, ‘inference.py’, ‘–width’, ‘768’, ‘–height’, ‘1024’, ‘–num_inference_steps’, ‘30’, ‘–output_dir’, ‘result’, ‘–unpaired’, ‘–data_dir’, ‘/home/lenovo/Documents/outfit/IDM-VTON/test’, ‘–seed’, ‘42’, ‘–test_batch_size’, ‘2’, ‘–guidance_scale’, ‘2.0’]’ returned non-zero exit status 1.
my file structure is same as guided but still i got this error,help me out to solve this