kohya-ss / sd-scripts

Apache License 2.0
5.12k stars 853 forks source link

ModuleNotFoundError: No module named 'xformers' #420

Open jonathanhecl opened 1 year ago

jonathanhecl commented 1 year ago

I can't train a model with LoRA...

.....
[Dataset 0]
loading image sizes.
100%|████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 1537.39it/s]
make buckets
min_bucket_reso and max_bucket_reso are ignored if bucket_no_upscale is set, because bucket reso is defined by image size automatically / bucket_no_upscaleが指定された場合は、bucketの解像度は画像サイズから自動計算されるため、min_bucket_resoとmax_bucket_resoは無視されます
number of images (including repeats) / 各bucketの画像枚数(繰り返し回数を含む)
bucket 0: resolution (512, 512), count: 1500
mean ar error (without repeats): 0.0
prepare accelerator
Using accelerator 0.15.0 or above.
loading model for process 0/1
load StableDiffusion checkpoint
loading u-net: <All keys matched successfully>
loading vae: <All keys matched successfully>
loading text encoder: <All keys matched successfully>
Replace CrossAttention.forward to use xformers
Traceback (most recent call last):
  File "H:\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 1764, in replace_unet_cross_attn_to_xformers
    import xformers.ops
ModuleNotFoundError: No module named 'xformers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:\StableDiffusion\Kohya\kohya_ss\train_network.py", line 760, in <module>
    train(args)
  File "H:\StableDiffusion\Kohya\kohya_ss\train_network.py", line 167, in train
    train_util.replace_unet_modules(unet, args.mem_eff_attn, args.xformers)
  File "H:\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 1718, in replace_unet_modules
    replace_unet_cross_attn_to_xformers()
  File "H:\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 1766, in replace_unet_cross_attn_to_xformers
    raise ImportError("No xformers / xformersがインストールされていないようです")
ImportError: No xformers / xformersがインストールされていないようです
Traceback (most recent call last):
  File "C:\Users\GS\miniconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\GS\miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "H:\StableDiffusion\Kohya\kohya_ss\venv\Scripts\accelerate.exe\__main__.py", line 7, in <module>
  File "h:\stablediffusion\kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\accelerate_cli.py", line 45, in main
    args.func(args)
  File "h:\stablediffusion\kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\launch.py", line 1104, in launch_command
    simple_launcher(args)
  File "h:\stablediffusion\kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\launch.py", line 567, in simple_launcher
    raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['h:\\stablediffusion\\kohya\\kohya_ss\\venv\\scripts\\python.exe', 'train_network.py', '--enable_bucket', '--pretrained_model_name_or_path=H:/StableDiffusion/SD-Models/v1-5-pruned-emaonly.ckpt', '--train_data_dir=H:/StableDiffusion/Kohya/image', '--resolution=512,512', '--output_dir=H:/StableDiffusion/Kohya/models', '--logging_dir=H:/StableDiffusion/Kohya/logs', '--network_alpha=1', '--save_model_as=safetensors', '--network_module=networks.lora', '--text_encoder_lr=5e-5', '--unet_lr=0.0001', '--network_dim=8', '--output_name=hidezone', '--lr_scheduler_num_cycles=1', '--learning_rate=0.0001', '--lr_scheduler=constant', '--train_batch_size=1', '--max_train_steps=1500', '--save_every_n_epochs=1', '--mixed_precision=fp16', '--save_precision=fp16', '--cache_latents', '--optimizer_type=AdamW', '--max_data_loader_n_workers=0', '--bucket_reso_steps=64', '--xformers', '--bucket_no_upscale']' returned non-zero exit status 1.
usamaa-saleem commented 1 year ago

try pip install xformers

jonathanhecl commented 1 year ago

I did it, and it didn't work

TingTingin commented 1 year ago
cd sd-scripts

python -m venv venv
venv\Scripts\activate

pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install --upgrade -r requirements.txt
pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl

copy .\bitsandbytes_windows\*.dll .\venv\Lib\site-packages\bitsandbytes\
copy .\bitsandbytes_windows\cextension.py .\venv\Lib\site-packages\bitsandbytes\cextension.py
copy .\bitsandbytes_windows\main.py .\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py

accelerate config 

Did you run the code in here? I changed the commands to work with windows

weginszhang commented 1 year ago

Is this problem solved? I'm having the same issue too

TingTingin commented 1 year ago

You need to install xformers using the code above the mainline xformers doesn't work I believe unless your on pytorch 2.0

TingTingin commented 1 year ago

You can however disable xformers if you have enough vram

weginszhang commented 1 year ago

Not solved yet, my training environment is M1 - macos, I have installed it,But the error is still reported

您需要使用主线上方的代码安装 xformers 我相信 xformers 不起作用,除非您使用 pytorch 2.0

mianayo commented 1 year ago

hi,how can I disable xformers?

Tays-s commented 1 year ago

hi,how can I disable xformers?

training parameters - advanced configuration - use xformers

kingsdy commented 1 year ago

I can't train a model with LoRA...

.....
[Dataset 0]
loading image sizes.
100%|████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 1537.39it/s]
make buckets
min_bucket_reso and max_bucket_reso are ignored if bucket_no_upscale is set, because bucket reso is defined by image size automatically / bucket_no_upscaleが指定された場合は、bucketの解像度は画像サイズから自動計算されるため、min_bucket_resoとmax_bucket_resoは無視されます
number of images (including repeats) / 各bucketの画像枚数(繰り返し回数を含む)
bucket 0: resolution (512, 512), count: 1500
mean ar error (without repeats): 0.0
prepare accelerator
Using accelerator 0.15.0 or above.
loading model for process 0/1
load StableDiffusion checkpoint
loading u-net: <All keys matched successfully>
loading vae: <All keys matched successfully>
loading text encoder: <All keys matched successfully>
Replace CrossAttention.forward to use xformers
Traceback (most recent call last):
  File "H:\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 1764, in replace_unet_cross_attn_to_xformers
    import xformers.ops
ModuleNotFoundError: No module named 'xformers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:\StableDiffusion\Kohya\kohya_ss\train_network.py", line 760, in <module>
    train(args)
  File "H:\StableDiffusion\Kohya\kohya_ss\train_network.py", line 167, in train
    train_util.replace_unet_modules(unet, args.mem_eff_attn, args.xformers)
  File "H:\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 1718, in replace_unet_modules
    replace_unet_cross_attn_to_xformers()
  File "H:\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 1766, in replace_unet_cross_attn_to_xformers
    raise ImportError("No xformers / xformersがインストールされていないようです")
ImportError: No xformers / xformersがインストールされていないようです
Traceback (most recent call last):
  File "C:\Users\GS\miniconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\GS\miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "H:\StableDiffusion\Kohya\kohya_ss\venv\Scripts\accelerate.exe\__main__.py", line 7, in <module>
  File "h:\stablediffusion\kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\accelerate_cli.py", line 45, in main
    args.func(args)
  File "h:\stablediffusion\kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\launch.py", line 1104, in launch_command
    simple_launcher(args)
  File "h:\stablediffusion\kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\launch.py", line 567, in simple_launcher
    raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['h:\\stablediffusion\\kohya\\kohya_ss\\venv\\scripts\\python.exe', 'train_network.py', '--enable_bucket', '--pretrained_model_name_or_path=H:/StableDiffusion/SD-Models/v1-5-pruned-emaonly.ckpt', '--train_data_dir=H:/StableDiffusion/Kohya/image', '--resolution=512,512', '--output_dir=H:/StableDiffusion/Kohya/models', '--logging_dir=H:/StableDiffusion/Kohya/logs', '--network_alpha=1', '--save_model_as=safetensors', '--network_module=networks.lora', '--text_encoder_lr=5e-5', '--unet_lr=0.0001', '--network_dim=8', '--output_name=hidezone', '--lr_scheduler_num_cycles=1', '--learning_rate=0.0001', '--lr_scheduler=constant', '--train_batch_size=1', '--max_train_steps=1500', '--save_every_n_epochs=1', '--mixed_precision=fp16', '--save_precision=fp16', '--cache_latents', '--optimizer_type=AdamW', '--max_data_loader_n_workers=0', '--bucket_reso_steps=64', '--xformers', '--bucket_no_upscale']' returned non-zero exit status 1.

Hi friend, I have the same troblem. Have you solve it, if do, please tell me how you solve it.

TingTingin commented 1 year ago

Remove - -xformers from your command or install xformers with this command

pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
kingsdy commented 1 year ago

Thanks a lot, it worked, finally.

从 Windows 版邮件https://go.microsoft.com/fwlink/?LinkId=550986发送


发件人: TingTingin @.> 发送时间: Tuesday, May 16, 2023 4:26:56 PM 收件人: kohya-ss/sd-scripts @.> 抄送: kingsdy @.>; Comment @.> 主题: Re: [kohya-ss/sd-scripts] ModuleNotFoundError: No module named 'xformers' (Issue #420)

Remove - -xformers from your command

― Reply to this email directly, view it on GitHubhttps://github.com/kohya-ss/sd-scripts/issues/420#issuecomment-1549224034, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7LBQ6VOYKNREETBLTEFHY3XGM25BANCNFSM6AAAAAAW74IAQ4. You are receiving this because you commented.Message ID: @.***>

pix33l commented 1 year ago

hi,how can I disable xformers?

training parameters - advanced configuration - use xformers

it's woking for me, thanks!

My training environment: Macbook Pro M1 Pro

xarthurx commented 1 year ago

Same issue here. I'm using kohya_ss. Training Dreambooth is good with xformers, and the package is actually there. But training LoRA will have this error...

It seems the script is not using the venv:

 python -V                                                                                 
Python 3.10.11

but the output shows it is using my base environment python:

System Information:
System: Windows, Release: 10, Version: 10.0.22621, Machine: AMD64, Processor: Intel64 Family 6 Model 165 Stepping 5, GenuineIntel

Python Information:
Version: 3.10.10, Implementation: CPython, Compiler: MSC v.1934 64 bit (AMD64)

Virtual Environment Information:
Path: C:\xLibraries\kohya_ss\venv

GPU Information:
Name: NVIDIA GeForce RTX 3090, VRAM: 24576 MiB