No module ‘xformers’ 原因与解决方法

今天,一位朋友在用“Stable Diffusion”的时候,打开提示错误如下:

No module 'xformers'. Proceeding without it.

中文翻译

没有模块“xformers”。在没有它的情况下继续。

No module 'xformers'. Proceeding without it.

 

原因:

通过报错,其实也能知道一个大概的原因,主要就是:没有模块“xformers“。

 

什么是“xformers”模块?

该模块xformers能对GPU有一定优化,加快了出图的速度。

 

Xformers 应该是社区目前知名度最高的优化加速方案了,名字 Xformers 指的是该库将各种transformer架构的模型囊括其中。该库仅适用于NVIDIA 显卡,特点是加速图片生成并降低显存占用,代价是输出图像不稳定,有可能比不开Xformers略差。

 

xformers可以大大节省AI图片生成时间,节省GPU缓存!有xformer可以给你使用stable-diffusion软件时,节省大量时间和显存,时间就是生命,时间能省就是增加生命的时间!

 

例如:

xformers没有开启的话,会使的AI图片的生成时间变长,GPU显存占用量变大,如果你有100GB的显存(一张4090显卡只有24GB显存),那么不用xformers也无所谓了。

但是你的显存真的有100GB吗?如果有的话,恭喜你,你可以开启100GB显存的强大GPU世界了。

 

我向朋友又要来了控制台整个调试代码如下:

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Commit hash: 22bcc7be428c94e9408f589966c2040187245d81
Installing requirements for Web UI

Launching Web UI with arguments: --use-cpu all --skip-torch-cuda-test --theme dark --precision full --no-half --api --autolaunch
Warning: caught exception 'No CUDA GPUs are available', memory monitor disabled
No module 'xformers'. Proceeding without it.
AUTOMATIC1111/stable-diffusion-webui packed by bilibili@秋葉aaaki 
本整合包完全免费,严禁倒卖。若您付费获得本软件请立刻举报商家。
[AddNet] Updating model hashes...
[AddNet] Updating model hashes...
Loading weights [7f96a1a9ca] from G:\20230629李晓明AI\AI绘画\Ai绘画软件\sd-webui-aki-v4\models\Stable-diffusion\anything-v5-PrtRE.safetensors
Creating model from config: G:\20230629李晓明AI\AI绘画\Ai绘画软件\sd-webui-aki-v4\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading VAE weights specified in settings: G:\20230629李晓明AI\AI绘画\Ai绘画软件\sd-webui-aki-v4\models\VAE\animevae.pt
Applying cross attention optimization (InvokeAI).
Textual inversion embeddings loaded(1): EasyNegative
Model loaded in 93.5s (load weights from disk: 1.0s, create model: 1.5s, apply weights to model: 59.9s, apply dtype to VAE: 0.6s, load VAE: 28.7s, hijack: 0.2s, load textual inversion embeddings: 1.4s, scripts callbacks: 0.1s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 154.9s (import torch: 11.6s, import gradio: 7.1s, import ldm: 2.9s, other imports: 10.9s, setup codeformer: 0.5s, load scripts: 5.5s, load SD checkpoint: 93.7s, create ui: 20.5s, gradio launch: 1.7s, scripts app_started_callback: 0.2s).

 

解决方法

由于“No module 'xformers'”这个不能算是真正的错误。

缺少xformers模块AI绘画软件照样还是可以正常运行的,只需要浏览器直接打开网址“http://127.0.0.1:7860”照样能成功启动。

 

如果你实在是不想它报“No module 'xformers'”这个错误,想要解决这个提示,想要开启xformers模块,有以下两种方法:

 

第一种:

1、用以下命令运行

./webui-user.bat --xformers

 

第二种:

1、打开项目目录下launch.py文件,

 

2、找到:

commandline_args = os.environ.get('COMMANDLINE_ARGS', "")

 

3、修改为

commandline_args = os.environ.get('COMMANDLINE_ARGS', "--xformers")

 

4、保存并以正常方式启动webui即可!

 

第三种:安装xformers模块

github地址:https://github.com/facebookresearch/xformers

可参考:xformers下载+安装+使用教程

 

1、可以单独pip安装xformers模块,命令:

pip install xformer

用pip安装,这里的版本需要注意,如果安装的版本不对,会卸载你的原安装正常的pytorch版本,导致你的环境变得无法使用。

比如我安装的torch-2.0.1+cu118,对应的是xformer0.0.19等都是错误的,导致需要重新卸载,重新安装。

torch-2.0.1+cu118,对应的是xformer0.0.21。

 

2、我推荐大家直接用“A启动器 -  高级选项 - 环境维护 - 安装PyTorch - 选择版本”,例如:Torch 2.0.1(CUDA 11.8)+ xFormers 0.0.21Torch 2.0.1(CUDA 11.8)+ xFormers 0.0.21

付杰
  • ¥ 89.0元
  • 市场价:129.0元
  • ¥ 598.0元
  • 市场价:2980.0元
  • ¥ 79.0元
  • 市场价:99.0元
  • ¥ 199.0元
  • 市场价:299.0元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: