今天在執行 run.bat 啟動 Stable Diffusion 時出現 no module 'xformers' 訊息 :
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.10.1
Commit hash: 82a973c04367123ae98bd9abdf80d9eda9b910e2
Launching Web UI with arguments:
2025-04-18 21:19:25.116834: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
C:\Users\USER\Downloads\sd.webui\system\python\lib\site-packages\timm\models\layers\__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Loading weights [6ce0161689] from C:\Users\USER\Downloads\sd.webui\webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Creating model from config: C:\Users\USER\Downloads\sd.webui\webui\configs\v1-inference.yaml
Running on local URL: http://127.0.0.1:7860
To create a public link, set share=True in launch().
Startup time: 22.2s (prepare environment: 5.9s, import torch: 8.2s, import gradio: 2.7s, setup paths: 3.1s, import ldm: 0.1s, initialize shared: 0.2s, other imports: 0.7s, load scripts: 0.7s, create ui: 0.5s, gradio launch: 0.2s).
Applying attention optimization: Doggettx... done.
Model loaded in 7.1s (load weights from disk: 0.3s, create model: 0.5s, apply weights to model: 5.6s, apply dtype to VAE: 0.2s, calculate empty prompt: 0.3s).
雖然 webui 網站介面有順利開啟, 但很好奇 no module 'xformers' 是甚麼意思, 就將上面訊息貼給 ChatGPT 去查, 原來 xformers 是 Facebook 開發的一套高效的注意力 (attention) 加速模組, 用來優化 Transformer 模型的運算, 可降低記憶體用量並加速模型的推理速度, 對 SD 來說就是使生成圖片更順暢速度更快.
這讓我想起在本系列第一篇, 更新完 webui 時我漏掉一個步驟 (編輯 webui-user.bat 檔), 只要補做此步驟即可. 先按 Ctrl+C 按 Y 關閉命令提示字元視窗後, 到 webui 資料夾用記事本編輯 webui-user.bat 批次檔 :
然後在 set COMMANDLINE_ARGS= 後面添加 --xformers :
然後重新執行 run.bat 就會安裝 xformers 模組, 不會再出現 no module 'xformers' 了 :
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.10.1
Commit hash: 82a973c04367123ae98bd9abdf80d9eda9b910e2
Installing xformers
Launching Web UI with arguments: --xformers
2025-04-18 21:41:59.937638: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
C:\Users\USER\Downloads\sd.webui\system\python\lib\site-packages\timm\models\layers\__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
Loading weights [6ce0161689] from C:\Users\USER\Downloads\sd.webui\webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Creating model from config: C:\Users\USER\Downloads\sd.webui\webui\configs\v1-inference.yaml
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 85.1s (prepare environment: 77.9s, import torch: 3.4s, import gradio: 0.8s, setup paths: 1.1s, initialize shared: 0.2s, other imports: 0.3s, load scripts: 0.6s, create ui: 0.5s, gradio launch: 0.2s).
Applying attention optimization: xformers... done.
Model loaded in 2.8s (create model: 0.7s, apply weights to model: 1.8s, calculate empty prompt: 0.1s).
所以不按圖施工自作聰明, 結果就會有瑕疵.
沒有留言 :
張貼留言