在 stable diffusion webui 的开发过程中,许多开源工作者为项目做出了巨大的贡献, 他们的工作使得我们普通人能够以最简单的方式接触到最前沿的人工智能技术, 在此向他们致以最崇高的敬意!
Stable Diffusion Webui 使用了git作为自己的数据文件下载工具, 这样既能保证插件和脚本的下载, 也可以通过版本控制丝滑的更新和回滚版本
所以, 让我们先来安装git!
GitForWindows的安装过程基本没有什么难度, 选择组件时我一般是全安装的(虽然有的暂时用不上), 特别需要注意的是, 安装时需要将Git LFS安装上, 如图所示:
下一步的默认编辑器可以改成自己喜欢的, 例如VSCode, 然后后面一路Next就可以了(你仔细研究这些选项会发现没啥可改的, 搞不好会出兼容性问题)
安装完成git后, "重新打开Cmd命令行", 输入git lfs install, 安装并激活LFS功能, 成功会返回Git LFS initialized.
强烈建议配置git的proxy, 不然stable自己在下载东西时会发生很多错误Connection_Reset或者速度极慢到1.4KB/s, 配置方法如下:
HTTP类型 PROXY:
设置:`git config --global http.proxy http://<proxy服务器>:<proxy端口>`
取消:`git config --global --unset http.proxy`
SOCKS5类型 PROXY:
设置:`git config --global socks.proxy socks5://<proxy服务器>:<proxy端口>`
取消:`git config --global --unset socks.proxy`
如果没有PROXY服务器, 可以下载Steam++(Watt Toolkit)并开启Github加速
另外一种是只能加速Github的Clone和Raw以及Release等http内容, 而且无法做到不修改stable diffusion webui 源代码实现加速, 所以容易破坏后续升级兼容性, 详细使用方法见官网:https://ghproxy.com
AUTOMATIC1111特别提醒:Newer version of Python does not support torch
Python版本建议选择官方的 3.10.6 版本!
下载地址:https://www.python.org/downloads/release/python-3106/
安装过程如下:
接下来pip和py启动器必选:
高级选项中, 勾选安装给所有用户后, 会自动更改安装路径, 一般默认即可, 然后勾选红框内必须选项:
根据安装程序提示解锁PATH变量最大长度限制, 然后Close即可:
重新启动电脑, 打开cmd命令行, 输入python, 不是报未知程序, 也不是打开Microsoft Store让你下载Python 3.11就可以了, 标准输出如下:
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
※安装之前请确保驱动程序安装并且正常, 可以通过win+r -> 输入 'dxdiag' 回车-> 是(验证签名)-> 上面的显示选项卡 -> 驱动程序 -> 确保驱动程序模型为WDDM
※cuDNN本质就是一堆编译好的DLL, 没啥事不建议动, 因为pytorch的支持程度有限, 为了稳定建议不要私自替换文件
先下载, 官网:https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64
然后打开安装程序, 释放到一个临时目录, 启动安装向导, 选择上CUDA组件, 我是偷懒全选上了:
然后等待安装成功后重启即可
找个文件名短一点的, 没有空格的, 纯英文名称的文件夹(最好在磁盘根目录), 例如C:\PySrc
然后进入这个目录后, 按住Shift后不松开, 右键, 会多出一个在此处打开Powershell窗口或在此处打开命令行窗口, 哪个都一样, 只是语法略有区别, 二者可以在打开后互转, 转powershell 就输入powershell, 转cmd就输入cmd
Windows 11 上可能默认换成了终端, 不用按Shift右键文件夹内空白处就有在终端中打开, 这个默认是pwsh(新版 Windows Powershell), 用法和旧版相同
打开命令行后, 输入git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git, Clone 项目到当前文件夹
※如果遇到报错, 请检查proxy是否连通
由于我是4060TI16G, 所以内存和显存我没有做任何限制, 只求速度, 我的配置参数如下:
@echo off
set PYTHON="C:\Program Files\Python310\Python.exe"
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--skip-torch-cuda-test --enable-insecure-extension-access --opt-sdp-attention --opt-channelslast --no-half-vae --upcast-sampling --xformers --precision full --listen --port 8888
call webui.bat
WebUI中所有关于内存和显存基本上都是限制的, 也就是想全速别加上LowVRAM之类的参数
所有参数列表参考(官方wiki):https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Command-Line-Arguments-and-Settings#webui-user
为了方便各位直接查看, 我复制了一份在附加内容部分
国内为了方便大家调通webui, 建议先去liblibai:https://www.liblibai.com, 国内之恋直接下, 很快, 然后放入models\Stable-Diffusion\文件夹内就可以了, LoRA同理, embedding则是直接放到embeddings\文件夹下
运行webui-user.bat即可
这一步运行上一步保存的bat文件就可以了, 但是如果遇到CUDA相关问题, 请往下看:
一般来说, 都会加上Skip CUDA test来减少启动时间, 而且部分机型必须加上这个参数, 因为检测不到CUDA但是却可以正常用
如果遇到CUDA不可用, 请打开cmd, 输入Python后进入交互式编程, 运行以下代码:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
他将会输出类似如下内容:
PS C:\Users\Administrator> python
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.0.1+cu118
>>> print(torch.cuda.is_available())
True
>>>
2.0.1+cu118代表pytorch版本和CUDA版本,True代表python可以正常调用CUDA代码
如果你在任何时候看到torch报错提示你torch.cuda.is_available()返回False, 这时候你需要重装正确版本的torch, 所有pytorch的whl独立包都可以在官方网站手动下载:https://download.pytorch.org/whl/torch/, 然后使用pip install <whl文件位置> -I强制安装, 即可解决此问题
例如:pip install ./torch-2.0.1+cu118-cp310-cp310-win_amd64.whl -I
安装插件是从WebUI中的extensions中安装, 安装插件必须添加启动参数--enable-insecure-extension-access, 通过Git URL完成安装, 一般只需填写Git仓库地址即可
个人推荐4个必备插件, 具体使用和安装说明每个仓库自己都有说明(另外controlnet模型和部分放大模型需要huggingface, 必须使用proxy):
| 插件名称 | 用途 | Github仓库|
| ControlNet| 使得输出结果更加稳定, 可以自定义各种预处理器对模型进行微调| https://github.com/Mikubill/sd-webui-controlnet.git|
| 简体中文语言包| 基本汉化 | https://github.com/dtlnor/stable-diffusion-webui-localization-zh_CN.git|
| 双语对照翻译插件 | 中英对照 | https://github.com/journey-ad/sd-webui-bilingual-localization.git|
| sd-webui-prompt-all-in-one| All in one 大杂烩, 各种提示词翻译, 界面美化等等 | https://github.com/Physton/sd-webui-prompt-all-in-one.git|
其实这个问题不用太担心, 也不用多想, Stable Diffusion必须要大显存, 位宽和显存速度对推理影响不大, CUDA和Tensor Core以及RT Core影响出图速度, 鉴于性价比, 我推荐4060TI16GB, 当然我不打游戏, 所以这个还得自己综合考虑, 毕竟这张卡满载才165w, 待机平时2w, winserver2022 + dell R730XD 也容易安装(就是这个riser卡的cpu 8pin 转 gpu 8pin 的线还得单独买), 加上MSI Afterburner调个风扇转速就能压下来好多温度, 而且这个卡玩ChatGLM2也是很快的, 回车2s内就开始输出了, 需要 13.2GB 左右, 所以4070/4070TI是玩不了的, 因为内存跑的话非常慢, 慢的不是像Stable Diffusion那样人类可以接受的等待时间
性能测试:
参数(完整版详见附加内容):
模型: nsfwMultiUseModel_nonSpecific.ckpt [c028c00615] 7.5GB
步数: 50
提示词 积极: nature,Dreamy forest,Alps,ocean,hills,in a meadow,on the beach,field,rice paddy,flower field,flower sea,starry sky,lake,river,onsen,flowers meadows,mountain,the top of the hill,outdoors,sunset,sky,golden hour lighting,in winter,dusk,sunset,meteor shower,stars,disney movie,azur lane,genshin impact,((abstract art)),((futurism)),wide_shot,panorama,((Monet style)),waterpark,fountain,convenience store,concert,theater,gothic architecture,gothic architecture,chinese style architecture,railroad tracks,museum,planetarium,modern,Europe,in_the_movie_theatre,east_asian_architecture,rubble_ruins,under_bridge,bridge,bridge,railroad,reservoir,tombstone,Disney_land,Disney_land,notebook,pencil,open_book,book_stack,school_bag,backpack,bookshelf,plant,flower,vase,bouquet,tree,cherry_blossoms,hydrangea,cherry_blossoms,hibiscus,maple_tree,palm_tree,Gelatin,fruit,teacup,music,guitar,piano,cello,playing_instrument,wind_chime,macro_shot,close-up,vehicle_focus,between_legs,between_fingers,solo_focus,x-ray,cross-section,peeping,eyes_focus,uchiwa,transparent_umbrella
消极: altostratus_opacus,cumulonimbus,Cumulonimbus,cumulus,Stratocumulus FastNegativeV2
大小: 1200x1200
高清修复: 关
ControlNet: SoftEdge
测试结果(可以读取出元数据):
图片:
4060TI 512x512 最快可以稳定在9its/s, 因为太高分辨率容易崩, 所以一般不建议直接拉满分辨率, 数据集原来就是512x512的
界面效果:
nature,Dreamy forest,Alps,ocean,hills,in a meadow,on the beach,field,rice paddy,flower field,flower sea,starry sky,lake,river,onsen,flowers meadows,mountain,the top of the hill,outdoors,sunset,sky,golden hour lighting,in winter,dusk,sunset,meteor shower,stars,disney movie,azur lane,genshin impact,((abstract art)),((futurism)),wide_shot,panorama,((Monet style)),waterpark,fountain,convenience store,concert,theater,gothic architecture,gothic architecture,chinese style architecture,railroad tracks,museum,planetarium,modern,Europe,in_the_movie_theatre,east_asian_architecture,rubble_ruins,under_bridge,bridge,bridge,railroad,reservoir,tombstone,Disney_land,Disney_land,notebook,pencil,open_book,book_stack,school_bag,backpack,bookshelf,plant,flower,vase,bouquet,tree,cherry_blossoms,hydrangea,cherry_blossoms,hibiscus,maple_tree,palm_tree,Gelatin,fruit,teacup,music,guitar,piano,cello,playing_instrument,wind_chime,macro_shot,close-up,vehicle_focus,between_legs,between_fingers,solo_focus,x-ray,cross-section,peeping,eyes_focus,uchiwa,transparent_umbrella
Negative prompt: altostratus_opacus,cumulonimbus,Cumulonimbus,cumulus,Stratocumulus FastNegativeV2
Steps: 50, Sampler: DPM++ 2M Karras, CFG scale: 10, Seed: 1439573177, Size: 1200x1200, Model hash: c028c00615, Model: nsfwMultiUseModel_nonSpecific, ControlNet 0: "preprocessor: softedge_pidinet, model: control_v11p_sd15_softedge [a8575a2a], weight: 1.25, starting/ending: (0.2, 1), resize mode: Crop and Resize, pixel perfect: True, control mode: Balanced, preprocessor params: (512, -1, -1)", TI hashes: "FastNegativeV2: a7465e7cc2a2", Version: v1.5.1
Saved: 00203-1439573177.png
Argument Command | Value | Default | Description | |
---|---|---|---|---|
CONFIGURATION | ||||
-h, --help | None | False | Show this help message and exit. | |
--exit | Terminate after installation | |||
--data-dir | DATA_DIR | ./ | base path where all user data is stored | |
--config | CONFIG | configs/stable-diffusion/v1-inference.yaml | Path to config which constructs model. | |
--ckpt | CKPT | model.ckpt | Path to checkpoint of Stable Diffusion model; if specified, this checkpoint will be added to the list of checkpoints and loaded. | |
--ckpt-dir | CKPT_DIR | None | Path to directory with Stable Diffusion checkpoints. | |
--no-download-sd-model | None | False | Don't download SD1.5 model even if no model is found. | |
--vae-dir | VAE_PATH | None | Path to Variational Autoencoders model | disables all settings related to VAE. |
--vae-path | VAE_PATH | None | Checkpoint to use as VAE; setting this argument | |
--gfpgan-dir | GFPGAN_DIR | GFPGAN/ | GFPGAN directory. | |
--gfpgan-model | GFPGAN_MODEL | GFPGAN model file name. | ||
--codeformer-models-path | CODEFORMER_MODELS_PATH | models/Codeformer/ | Path to directory with codeformer model file(s). | |
--gfpgan-models-path | GFPGAN_MODELS_PATH | models/GFPGAN | Path to directory with GFPGAN model file(s). | |
--esrgan-models-path | ESRGAN_MODELS_PATH | models/ESRGAN | Path to directory with ESRGAN model file(s). | |
--bsrgan-models-path | BSRGAN_MODELS_PATH | models/BSRGAN | Path to directory with BSRGAN model file(s). | |
--realesrgan-models-path | REALESRGAN_MODELS_PATH | models/RealESRGAN | Path to directory with RealESRGAN model file(s). | |
--scunet-models-path | SCUNET_MODELS_PATH | models/ScuNET | Path to directory with ScuNET model file(s). | |
--swinir-models-path | SWINIR_MODELS_PATH | models/SwinIR | Path to directory with SwinIR and SwinIR v2 model file(s). | |
--ldsr-models-path | LDSR_MODELS_PATH | models/LDSR | Path to directory with LDSR model file(s). | |
--lora-dir | LORA_DIR | models/Lora | Path to directory with Lora networks. | |
--clip-models-path | CLIP_MODELS_PATH | None | Path to directory with CLIP model file(s). | |
--embeddings-dir | EMBEDDINGS_DIR | embeddings/ | Embeddings directory for textual inversion (default: embeddings). | |
--textual-inversion-templates-dir | TEXTUAL_INVERSION_TEMPLATES_DIR | textual_inversion_templates | Directory with textual inversion templates. | |
--hypernetwork-dir | HYPERNETWORK_DIR | models/hypernetworks/ | hypernetwork directory. | |
--localizations-dir | LOCALIZATIONS_DIR | localizations/ | Localizations directory. | |
--styles-file | STYLES_FILE | styles.csv | Filename to use for styles. | |
--ui-config-file | UI_CONFIG_FILE | ui-config.json | Filename to use for UI configuration. | |
--no-progressbar-hiding | None | False | Do not hide progress bar in gradio UI (we hide it because it slows down ML if you have hardware acceleration in browser). | |
--max-batch-count | MAX_BATCH_COUNT | 16 | Maximum batch count value for the UI. | |
--ui-settings-file | UI_SETTINGS_FILE | config.json | Filename to use for UI settings. | |
--allow-code | None | False | Allow custom script execution from web UI. | |
--share | None | False | Useshare=Truefor gradio and make the UI accessible through their site. | |
--listen | None | False | Launch gradio with 0.0.0.0 as server name, allowing to respond to network requests. | |
--port | PORT | 7860 | Launch gradio with given server port, you need root/admin rights for ports < 1024; defaults to 7860 if available. | |
--hide-ui-dir-config | None | False | Hide directory configuration from web UI. | |
--freeze-settings | None | False | disable editing settings | |
--enable-insecure-extension-access | None | False | Enable extensions tab regardless of other options. | |
--gradio-debug | None | False | Launch gradio with--debugoption. | |
--gradio-auth | GRADIO_AUTH | None | Set gradio authentication likeusername:password; or comma-delimit multiple likeu1:p1,u2:p2,u3:p3. | |
--gradio-auth-path | GRADIO_AUTH_PATH | None | Set gradio authentication file path ex./path/to/auth/filesame auth format as--gradio-auth. | |
--disable-console-progressbars | None | False | Do not output progress bars to console. | |
--enable-console-prompts | None | False | Print prompts to console when generating with txt2img and img2img. | |
--api | None | False | Launch web UI with API. | |
--api-auth | API_AUTH | None | Set authentication for API likeusername:password; or comma-delimit multiple likeu1:p1,u2:p2,u3:p3. | |
--api-log | None | False | Enable logging of all API requests. | |
--nowebui | None | False | Only launch the API, without the UI. | |
--ui-debug-mode | None | False | Don't load model to quickly launch UI. | |
--device-id | DEVICE_ID | None | Select the default CUDA device to use (exportCUDA_VISIBLE_DEVICES=0,1etc might be needed before). | |
--administrator | None | False | Administrator privileges. | |
--cors-allow-origins | CORS_ALLOW_ORIGINS | None | Allowed CORS origin(s) in the form of a comma-separated list (no spaces). | |
--cors-allow-origins-regex | CORS_ALLOW_ORIGINS_REGEX | None | Allowed CORS origin(s) in the form of a single regular expression. | |
--tls-keyfile | TLS_KEYFILE | None | Partially enables TLS, requires--tls-certfileto fully function. | |
--tls-certfile | TLS_CERTFILE | None | Partially enables TLS, requires--tls-keyfileto fully function. | |
--disable-tls-verify | None | False | When passed, enables the use of self-signed certificates. | |
--server-name | SERVER_NAME | None | Sets hostname of server. | |
--no-gradio-queue | None | False | Disables gradio queue; causes the webpage to use http requests instead of websockets; was the default in earlier versions. | |
--gradio-allowed-path | None | None | Add path to Gradio'sallowed_paths; make it possible to serve files from it. | |
--no-hashing | None | False | Disable SHA-256 hashing of checkpoints to help loading performance. | |
--skip-version-check | None | False | Do not check versions of torch and xformers. | |
--skip-python-version-check | None | False | Do not check versions of Python. | |
--skip-torch-cuda-test | None | False | Do not check if CUDA is able to work properly. | |
--skip-install | None | False | Skip installation of packages. | |
PERFORMANCE | ||||
--xformers | None | False | Enable xformers for cross attention layers. | |
--force-enable-xformers | None | False | Enable xformers for cross attention layers regardless of whether the checking code thinks you can run it;do not make bug reports if this fails to work. | |
--xformers-flash-attention | None | False | Enable xformers with Flash Attention to improve reproducibility (supported for SD2.x or variant only). | |
--opt-sdp-attention | None | False | Enable scaled dot product cross-attention layer optimization; requires PyTorch 2.* | |
--opt-sdp-no-mem-attention | False | None | Enable scaled dot product cross-attention layer optimization without memory efficient attention, makes image generation deterministic; requires PyTorch 2.* | |
--opt-split-attention | None | False | Force-enables Doggettx's cross-attention layer optimization. By default, it's on for CUDA-enabled systems. | |
--opt-split-attention-invokeai | None | False | Force-enables InvokeAI's cross-attention layer optimization. By default, it's on when CUDA is unavailable. | |
--opt-split-attention-v1 | None | False | Enable older version of split attention optimization that does not consume all VRAM available. | |
--opt-sub-quad-attention | None | False | Enable memory efficient sub-quadratic cross-attention layer optimization. | |
--sub-quad-q-chunk-size | SUB_QUAD_Q_CHUNK_SIZE | 1024 | Query chunk size for the sub-quadratic cross-attention layer optimization to use. | |
--sub-quad-kv-chunk-size | SUB_QUAD_KV_CHUNK_SIZE | None | KV chunk size for the sub-quadratic cross-attention layer optimization to use. | |
--sub-quad-chunk-threshold | SUB_QUAD_CHUNK_THRESHOLD | None | The percentage of VRAM threshold for the sub-quadratic cross-attention layer optimization to use chunking. | |
--opt-channelslast | None | False | Enable alternative layout for 4d tensors, may result in faster inferenceonlyon Nvidia cards with Tensor cores (16xx and higher). | |
--disable-opt-split-attention | None | False | Force-disables cross-attention layer optimization. | |
--disable-nan-check | None | False | Do not check if produced images/latent spaces have nans; useful for running without a checkpoint in CI. | |
--use-cpu | {all, sd, interrogate, gfpgan, bsrgan, esrgan, scunet, codeformer} | None | Use CPU as torch device for specified modules. | |
--no-half | None | False | Do not switch the model to 16-bit floats. | |
--precision | {full,autocast} | autocast | Evaluate at this precision. | |
--no-half-vae | None | False | Do not switch the VAE model to 16-bit floats. | |
--upcast-sampling | None | False | Upcast sampling. No effect with--no-half. Usually produces similar results to--no-halfwith better performance while using less memory. | |
--medvram | None | False | Enable Stable Diffusion model optimizations for sacrificing a some performance for low VRAM usage. | |
--lowvram | None | False | Enable Stable Diffusion model optimizations for sacrificing a lot of speed for very low VRAM usage. | |
--lowram | None | False | Load Stable Diffusion checkpoint weights to VRAM instead of RAM. | |
--always-batch-cond-uncond | None | False | Disables cond/uncond batching that is enabled to save memory with--medvramor--lowvram. | |
FEATURES | ||||
--autolaunch | None | False | Open the web UI URL in the system's default browser upon launch. | |
--theme | None | Unset | Open the web UI with the specified theme (lightordark). If not specified, uses the default browser theme. | |
--use-textbox-seed | None | False | Use textbox for seeds in UI (no up/down, but possible to input long seeds). | |
--disable-safe-unpickle | None | False | Disable checking PyTorch models for malicious code. | |
--ngrok | NGROK | None | ngrok authtoken, alternative to gradio--share. | |
--ngrok-region | NGROK_REGION | us | The region in which ngrok should start. | |
--update-check | None | None | On startup, notifies whether or not your web UI version (commit) is up-to-date with the current master branch. | |
--update-all-extensions | None | None | On startup, it pulls the latest updates for all extensions you have installed. | |
--reinstall-xformers | None | False | Force-reinstall xformers. Useful for upgrading - but remove it after upgrading or you'll reinstall xformers perpetually. | |
--reinstall-torch | None | False | Force-reinstall torch. Useful for upgrading - but remove it after upgrading or you'll reinstall torch perpetually. | |
--tests | TESTS | False | Run test to validate web UI functionality, see wiki topic for more details. | |
--no-tests | None | False | Do not run tests even if--testsoption is specified. | |
DEFUNCT OPTIONS | ||||
--show-negative-prompt | None | False | No longer has an effect. | |
--deepdanbooru | None | False | No longer has an effect. | |
--unload-gfpgan | None | False | No longer has an effect. | |
--gradio-img2img-tool | GRADIO_IMG2IMG_TOOL | None | No longer has an effect. | |
--gradio-inpaint-tool | GRADIO_INPAINT_TOOL | None | No longer has an effect. | |
--gradio-queue | None | False | No longer has an effect. |
stable-diffusion-webui/wiki:https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki
git proxy 的设置方法:https://zhuanlan.zhihu.com/p/625628413
CUDA 下载:https://developer.nvidia.com/cuda-downloads
Python/3106:https://www.python.org/downloads/release/python-3106/
Steam++:https://github.com/BeyondDimension/SteamTools
Github 加速:https://ghproxy.com/
stability.ai/stablediffusion:https://stability.ai/stablediffusion
huggingface/sdmodels:https://huggingface.co/spaces/stabilityai/stable-diffusion
ChatGLM2:https://github.com/thudm/chatglm2-6b