Ubuntu18.04本地部署Stable-Diffusion-webui绘画

news/2024/7/10 19:47:49 标签: stable diffusion, AI作画

记录Ubuntu下安装Stable-Diffusion-webui,比较简单,以供参考。

系统:Ubuntu 18.04.4 LTS
内存:40G
显卡:32G
硬盘:500G

一、安装cuda

支持安装的cuda版本可以用nvidia-smi命令查看:
 

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.182.03   Driver Version: 470.182.03   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100-SXM2...  Off  | 00000000:00:08.0 Off |                    0 |
| N/A   39C    P0    55W / 300W |      0MiB / 32510MiB |      3%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+


显卡驱动支持的cuda版本最高是11.4,可以在这里下载对应的cuda版本:CUDA Toolkit Archive | NVIDIA Developer(https://developer.nvidia.com/cuda-toolkit-archive)。由于之前安装别的环境,已经装了cuda11.4版本,可以用nvcc -V查看安装的cuda版本。


二、搭建python虚拟环境(为了不影响原系统环境)

使用miniconda,我之前已经安装了。然后使用conda创建虚拟环境sdwebui,使用的python版本为3.10.9(stable-diffusion-webui用的python版本为3.10.6)。

conda create -n sdwebui python==3.10.9

激活环境

conda activate sdwebui

升级pip并更改默认库包下载地址为清华镜像(如果已经有镜像的可以忽略)

    python -m pip install --upgrade pip
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

安装torch

在pytorch官网Previous PyTorch Versions | PyTorch(https://pytorch.org/get-started/previous-versions/) 官网不能访问的可以打开:Pytorch和CUDA版本对应关系_TURING.DT的博客-CSDN博客

查看对应的cuda支持的torch版本,并且直接拷贝安装命令。

这里是我的cuda版本对应的安装命令。

conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch


三、下载并安装stable-diffusion-webui

切换到当前用户目录下,使用git命令下载stable-diffusion-webui源码

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

由于国内github不能稳定连接,所以可以从国内的gitee(码云)下载

git clone https://gitee.com/yiouyou/automatic1111-stable-diffusion-webui.git

打开v2-1_768-ema-pruned.ckpt · stabilityai/stable-diffusion-2-1 at main(https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.ckpt),下载训练模型(大小4.9G)。下载完成后,把v2-1_768-ema-pruned.ckpt这个训练模型放入stable-diffusion-webui的models/Stable-diffusion目录下,这个目录专门存放用于生成AI绘图的绘图元素的基础模型库。后续如果在其他网站比如civitai之类的地方下载的ckpt或者safetensors文件也是放在这个文件夹里面。


然后切换到webui目录下,安装依赖

    cd stable-diffusion-webui/
    pip install -r requirements_versions.txt
    pip install -r requirements.txt

安装完成后,启动stable-diffusion-webui

python launch.py

这里要安装很多依赖,并且要git clone相关包和模型文件,需要科学上网,否则会失败。

最终启动成功后如下图所示,会出来一个url:

(sdwebui) ubuntu@VM-16-ubuntu:~/sdwebui/stable-diffusion-webui$ python launch.py

Python 3.10.9 (main, Mar  8 2023, 10:47:38) [GCC 11.2.0]
Version: v1.4.0
Commit hash: 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8
Installing clip
Installing open_clip
Cloning Stable Diffusion into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...
Cloning K-diffusion into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/k-diffusion...
Cloning CodeFormer into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/CodeFormer...
Cloning BLIP into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/BLIP...
Installing requirements for CodeFormer
Installing requirements
Launching Web UI with arguments:
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-9vmy3hxk because the default path (/home/ubuntu/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.12.1.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================
Calculating sha256 for /home/ubuntu/sdwebui/stable-diffusion-webui/models/Stable-diffusion/v2-1_768-ema-pruned.ckpt: preload_extensions_git_metadata for 7 extensions took 0.00s
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 7.8s (import torch: 1.6s, import gradio: 1.5s, import ldm: 0.4s, other imports: 3.2s, load scripts: 0.5s, create ui: 0.5s).
ad2a33c361c1f593c4a1fb32ea81afce2b5bb7d1983c6b94793a26a3b54b08a0
Loading weights [ad2a33c361] from /home/ubuntu/sdwebui/stable-diffusion-webui/models/Stable-diffusion/v2-1_768-ema-pruned.ckpt
Creating model from config: /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/configs/stable-diffusion/v2-inference-v.yaml
LatentDiffusion: Running in v-prediction mode
DiffusionWrapper has 865.91 M params.
Applying attention optimization: Doggettx... done.


在浏览器打开这个url,表示环境部署成功。


四、使用stable-diffusion-webui

注意:如果在prompt输入后点击generate无法生成图片,看见黑色小框显示“float 32“之类的关键字,则在webui 页面的 Settings->StableDiffusion 最下面,勾选 float32 的选项框。接着点击上方的Apply settings 应用,然后按F5刷新页面后,即可正常使用。

在左上角的文本框prompt输入提示词,点击Generate,等待数秒钟(我的电脑大概等待15s左右),就会生成一张图。

默认端口是7860,如果想换端口 启动时加参数:python launch.py --port 7770


http://www.niftyadmin.cn/n/1005558.html

相关文章

http 协议和 https 协议的区别么?

HTTP(Hypertext Transfer Protocol)是一种用于在网络上传输超文本的协议,它是计算机之间传输数据的标准通信协议。 而HTTPS(Hypertext Transfer Protocol Secure)是基于HTTP协议的加密扩展协议。 以下是HTTP协议和HTT…

DL学习10-vggnet-mnist

对于vgg而言,他最重要的是VGGblock,总的来说就是通过循环生成一个多conv加一个relu的block层,然后将其使用flatten进行拉伸,最后送入线形层。 话不多说,看代码。 class reshape_data(nn.Module):def forward(self,X):…

js模拟锚点的功能

<a href"#aa">点击</a> <a id"aa">跳转位置</a>概述&#xff1a; 最近&#xff0c;项目上遇到一个小问题&#xff0c;加载完页面后直接跳转到url里面有个标识的位置&#xff0c;一开始我想用滚动条&#xff0c;后来发现滚动条不好…

王道考研计算机网络第四·章知识点汇总

4.1.1网络层功能概述 4.1.2 SDN基本概念 4.2.1 路由算法和路由协议概述 4.3.1 IP数据报格式 4.3.2 IP数据报分片 4.3.3 IPv4地址 4.3.4 网络地址转换NAT 4.3.5 子网划分和子网掩码 不同子网掩码得到的网络地址可能相同 网络号为B类地址&#xff0c;16位网络号&#xff1b;6位子…

47. Compose自定义绘制日历-1

有个日历的需求, 自己实现一下简单的 生成数据 private fun initData() {val listOfCalendar mutableListOf<CalendarData>()val calendar Calendar.getInstance()val todayYear calendar.get(Calendar.YEAR)val todayMonth calendar.get(Calendar.MONTH)val today…

conda 根目录内存满,更换新的目录

默认conda环境是在根目录&#xff0c;只需修改默认的目录即可 1 修改.condarc文件 vim ~/.condarc# 添加一行即可 envs_dirs:- /disk3/miniconda_envs/envs2 验证 创建一个conda环境 查看创建的路径 conda env list 这样以后都换把相关创建的包安装在disk3下&#xff0c;缓…

【线程池】线程池的ctl属性详解

目录 一、ctl介绍 二、线程池ctl源码 三、线程池ctl分析 1、private static int ctlOf(int rs, int wc) { return rs | wc; } 2、private final AtomicInteger ctl new AtomicInteger(ctlOf(RUNNING, 0)); 3、private static int runStateOf(int c) { return c &am…

打造自己的分布式MinIO对象存储

MinIO是一个对象存储解决方案&#xff0c;它提供了一个与Amazon Web Services S3兼容的API&#xff0c;并支持所有核心S3特性。MinIO旨在部署在任何地方——公共云或私有云、裸机基础架构、协调环境和边缘基础架构。 分布式MinIO如何工作 Server Pool由多个Minio服务节点与其附…