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

**URL:** <https://discuss.huggingface.co/t/getting-a-importerror-while-go-though-the-train-a-diffuser-model-tutorial/67564>\
**Category:** Beginners\
**Created:** [December 31, 2023, 4:46pm UTC](https://discuss.huggingface.co/t/getting-a-importerror-while-go-though-the-train-a-diffuser-model-tutorial/67564 "2023-12-31T16:46:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattlocke](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mattlocke](https://discuss.huggingface.co/u/mattlocke)\
**Post date:** [December 31, 2023, 4:46pm UTC](https://discuss.huggingface.co/t/getting-a-importerror-while-go-though-the-train-a-diffuser-model-tutorial/67564/1 "2023-12-31T16:46:17Z")

</div>

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![dblakely](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dblakely](https://discuss.huggingface.co/u/dblakely)\
**Post date:** [December 31, 2023, 6:02pm UTC](https://discuss.huggingface.co/t/getting-a-importerror-while-go-though-the-train-a-diffuser-model-tutorial/67564/2 "2023-12-31T18:02:29Z")

</div>

Hi @mattlocke, you probably need to upgrade `transformers`

`pip install --upgrade transformers`

---

<div class="post-metadata">

**Author:** ![mattlocke](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mattlocke](https://discuss.huggingface.co/u/mattlocke)\
**Post date:** [January 1, 2024, 10:12am UTC](https://discuss.huggingface.co/t/getting-a-importerror-while-go-though-the-train-a-diffuser-model-tutorial/67564/3 "2024-01-01T10:12:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SaiLochana](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@SaiLochana](https://discuss.huggingface.co/u/SaiLochana)\
**Post date:** [May 10, 2024, 12:46pm UTC](https://discuss.huggingface.co/t/getting-a-importerror-while-go-though-the-train-a-diffuser-model-tutorial/67564/4 "2024-05-10T12:46:59Z")

</div>

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
