【AIGC】如何在Windows/Linux上部署stable diffusion

news2024/10/9 6:25:46

文章目录

  • 整体安装步骤
  • windows10安装stable diffusion
    • 环境要求
    • 安装步骤
    • 注意事项
    • 参考博客
    • 其他事项
      • 安装显卡驱动
      • 安装cuda
      • 卸载cuda
      • 安装对应版本pytorch
      • 安装git上的python包
      • Q&A
  • linux安装stable diffusion
    • 安装anaconda
    • 安装cuda
    • git 加速
    • 配置虚拟环境
    • 挂载oss(optional)
    • 端口开放
    • 启动服务
    • controlnet
    • 显卡使用监控
    • 插件安装
    • 参考文章
  • 脚本安装stable diffusion
  • stable diffusion教程
    • models
    • tutorial
    • prompt reference

整体安装步骤

  1. GPU环境安装:NVIDIA驱动和cuda(注意版本,建议安装cuda11.7,方便后续使用xformer)
  2. 配置git环境
  3. git拉取stable diffusion项目
  4. 配置python虚拟环境
  5. 安装GPU版torch
  6. 安装虚拟环境依赖包:项目本身的requirement及子项目依赖
  7. 下载模型文件
  8. 启动stable diffusion

windows10安装stable diffusion

环境要求

  1. 独立显卡:最低配置4GB显存,基本配置6GB显存,推荐配置8GB显存以上。(显存越大越好。显存越大,可以生成的图片分辨率就越大。)
  2. 内存:内存16G或者以上。
  3. 磁盘:至少10GB。

安装步骤

  1. 安装Python3.10.6
  2. 安装git
  3. 下载sd项目:AUTOMATIC1111
  4. 下载模型文件(例如:stable-diffusion-v1-5)
    • Stable Diffusion的官方模型V1.5版本一共提供了两个模型,一个3.97GB,另一个是7.17GB。
    • 绘画版|3.97GB模型:推荐正常绘图的人使用,无需训练自己的模型。
    • 训练版|7.17GB模型:如果您想以该模型为基础,训练自己的模型。那么下载该模型可以得到更好的效果。
  5. 运行webui-user.bat脚本

注意事项

  1. cuda版本与显卡驱动版本适配;
  2. pytorch的gpu版本与cuda版本对应;
    • 脚本中默认会装,就是比较慢,耐心等待就行;
    • 自己下载对应版本wheel文件安装(搜索:2.0.1+cu118):https://download.pytorch.org/whl/torch/
    • 可能会失败,见issue:https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/1742
  3. 提前下载GitHub项目:GFPGAN、CLIP、open_clip,之后需要安装到Python虚拟环境中;
    • python setup.py install 可能失败。可以提前cd到对应项目中,使用pip install -r requirements.txt安装依赖包。
  4. 提前下载GitHub项目:stable-diffusion-stability-ai、taming-transformers、k-diffusion、CodeFormer、BLIP,之后需要cp到项目的repositories路径中;

参考博客

  1. https://stable-diffusion-art.com/install-windows/
  2. https://aituts.com/stable-diffusion-on-windows-automatic1111/

其他事项

安装显卡驱动

https://www.volcengine.com/docs/6419/69858

安装cuda

cuda版本与显卡驱动对照表
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

要安装的显卡驱动是,所以对应的cuda版本应该是 CUDA 12.0.x 、12.1.x等

安装成功后可以在cmd使用nvcc -V查看cuda版本,使用nsmi

好像需要安装cuda11.8版本?
下载链接:https://developer.nvidia.com/cuda-12-1-0-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exe_local

检查环境

python -m torch.utils.collect_env

卸载cuda

cuda 和 cudnn 库的卸载与安装:https://zhuanlan.zhihu.com/p/102966512

安装对应版本pytorch

在以下网址搜索:2.0.1+cu118
https://download.pytorch.org/whl/torch/
其中cu118对应刚刚安装的cuda11.8版本

安装git上的python包

cd path to CLIP
# python setup.py install --user
python setup.py install

Q&A

  1. stable diffusion报错RuntimeError: “LayerNormKernelImpl” not implem

解决方法:运行命令修改为./webui.sh --precision full --no-half

在webui-user.bat中添加命令行参数:
set COMMANDLINE_ARGS=–skip-torch-cuda-test --precision full --no-half

  1. AssertionError: extension access disabled because of command line flags

What’s happening is that, since you’re not running on localhost and everyone in the whole wide world can in theory access your Web UI, you need to explicitly enable extensions.

解决方法:adding the --enable-insecure-extension-access flag

linux安装stable diffusion

简单版可查看之前的博客:【AIGC】阿里云ecs部署stable diffusion

安装anaconda

安装Python、wget、git
sudo apt install python3 python3-pip python3-virtualenv wget git

安装前置依赖
sudo apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6

下载anaconda
wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh

创建Python 3.10.6的虚拟环境
conda create --name sdwebui python=3.10.6

安装cuda

os=ubuntu2004
arch=x86_64
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt update
sudo apt install cuda-11-8

git 加速

开启加速
export http_proxy=http://172.181.217.43:12798 && export https_proxy=http://172.181.217.43:12798
关闭加速
unset http_proxy && unset https_proxy

【todo:注意关闭配置】https://blog.csdn.net/zhiboqingyun/article/details/123912058

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

配置虚拟环境

启动虚拟环境
conda activate sdwebui

如果想要于bash script自动以conda启动虚拟环境,可以把这二行加入至webui-user.sh顶端:
eval “$(conda shell.bash hook)”
conda activate sdwebui

下载模型
wget -nc -P ~/stable-diffusion-webui/models/Stable-diffusion https://huggingface.co/andite/anything-v4.0/resolve/main/anything-v4.5-pruned.safetensors -O anything-v4.5-pruned.safetensors

首次启动
./webui.sh

./webui.sh --xformers --skip-install --enable-insecure-extension-access

挂载oss(optional)

https://help.aliyun.com/document_detail/153892.html?spm=a2c4g.153893.0.0.1d877f1fHkYVYt

端口开放

https://www.bilibili.com/read/cv23060248

启动服务时需要添加 --listen参数
./webui.sh --listen

sed -i ‘s/can_run_as_root=0/can_run_as_root=1/g’ webui.sh &&
./webui.sh --no-download-sd-model --xformers

启动后的一些权限问题

sudo chown -R root stable-diffusion-webui
sudo chgrp -R root stable-diffusion-webui

服务地址:http://xxx.xxx.xxx.xxx:7860/

启动服务

sudo ./webui.sh --listen --skip-install --enable-insecure-extension-access

controlnet

https://github.com/Mikubill/sd-webui-controlnet/issues/1399

Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘cairo’ found
ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects

sudo apt install libcairo2-dev

I fixed itby this way:

  1. run command below on linux
    sudo apt install libcairo2-dev

  2. install svglib package manually or relaunch webui
    pip install svglib

显卡使用监控

watch -n 1 nvidia-smi

插件安装

在这里插入图片描述

抠图插件安装:https://zhuanlan.zhihu.com/p/632888046

参考文章

查看Linux服务器配置|是否有GPU以及GPU信息:https://blog.csdn.net/qq_41725313/article/details/123784429

安装至Linux:https://ivonblog.com/posts/stable-diffusion-webui-manuals/zh-cn/installation/linux-installation/

安装驱动:https://ivonblog.com/posts/ubuntu-install-nvidia-drivers/

安装驱动(阿里云官方文档):https://help.aliyun.com/document_detail/163824.htm?spm=a2c4g.298150.0.0.1e0b5355t3jXPh#concept-ecy-qrz-wgb

脚本安装stable diffusion

# git配置
git config --global http.postBuffer 524288000
git config --global https.postBuffer 524288000
git config --global core.compression -1
git config --global http.sslVerify "false"

# 拉取stable diffusion
cd ~
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd ~/stable-diffusion-webui
git checkout 89f9faa63388756314e8a1d96cf86bf5e0663045

# 配置python环境
conda create -y --name sdwebui python=3.10.6
source activate sdwebui
python -m venv venv
source venv/bin/activate            # conda activate sdwebui 可能会失败
# source venv/Scripts/activate      # for win10 git bash

# 安装GPU版torch
pip install torch==2.0.0+cu117 torchvision==0.15.0+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
pip install xformers==0.0.17

# python github环境包
mkdir tmp_envs
cd tmp_envs
git config --global http.sslVerify "false"      # 加上,以防断连
git clone https://github.com/TencentARC/GFPGAN.git
cd GFPGAN && git checkout 8d2447a2d918f8eba5a4a01463fd48e45126a379 
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install
cd ..

git config --global http.sslVerify "false"
git clone https://github.com/openai/CLIP.git
cd CLIP && git checkout d50d76daa670286dd6cacf3bcd80b5e4823fc8e1
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install
cd ..

git config --global http.sslVerify "false"
git clone https://github.com/mlfoundations/open_clip.git
cd open_clip && git checkout bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install
cd ..


# 下载模型
wget -nc -P ~/stable-diffusion-webui/models/Stable-diffusion https://huggingface.co/andite/anything-v4.0/resolve/main/anything-v4.5-pruned.safetensors -O anything-v4.5-pruned.safetensors

./webui.sh --xformers --skip-install


# 面部修复功能报错
# 下载模型文件:
cd ~/stable-diffusion-webui
wget https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth
mv codeformer.pth ~/stable-diffusion-webui/models/Codeformer/codeformer-v0.1.0.pt
# 下载权重文件
wget https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth
mv detection_Resnet50_Final.pth ~/stable-diffusion-webui/repositories/CodeFormer/weights/facelib/detection_Resnet50_Final.pth
wget https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth
mv parsing_parsenet.pth ~/stable-diffusion-webui/repositories/CodeFormer/weights/facelib/parsing_parsenet.pth

stable diffusion教程

models

stable-diffusion-v1-5: https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main

The 10 Best Stable Diffusion Models by Popularity (SD Models Explained):https://aituts.com/models/

AI 绘画与作画 stable diffusion webui 常见模型汇总及简介:https://www.tjsky.net/tutorial/583

C站下载模型:https://civitai.com/

hugging face下载:https://huggingface.co/models

ControlNet下载: https://huggingface.co/lllyasviel/ControlNet-v1-1/tree/main

lora模型下载:https://openai.wiki/lora-model-part-1.html

tutorial

AIGC入门教程:Stable Diffusion,万字保姆篇:https://www.woshipm.com/ai/5813208.html

超详细!外婆都能看懂的Stable Diffusion入门教程:https://www.uisdc.com/stable-diffusion-3

How to use Stable Diffusion v2.1 (AUTOMATIC1111 Guide):https://aituts.com/install-stable-diffusion-v2-1/

stable-diffusion-webui使用手册:https://ivonblog.com/posts/stable-diffusion-webui-manuals/zh-cn/installation/windows-installation/

Stable Diffusion 速览: https://www.zhihu.com/question/550101073/answer/2931261853

AI绘画指南 stable diffusion webui (SD webui)如何设置与使用:https://www.tjsky.net/tutorial/488

How to use models(LoRA):https://github.com/civitai/civitai/wiki/How-to-use-models#lora

How to generate realistic people in Stable Diffusion:https://stable-diffusion-art.com/realistic-people/

How to make a video with Stable Diffusion (Deforum):https://stable-diffusion-art.com/deforum/

AI绘画教程:从入门到放弃(xiaobai):https://zhuanlan.zhihu.com/p/607892849

LoRA模型的训练脚本:https://github.com/kohya-ss/sd-scripts

prompt reference

风格提示词:https://lexica.art/

image on playgroundai: https://playgroundai.com/c/landscapes

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1554718.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Transformers —— 以通俗易懂的方式解释-Part 1

公众号:Halo咯咯,欢迎关注~ 本系列主要介绍了为ChatGPT以及许多其他大型语言模型(LLM)提供支持的Transformer神经网络。我们将从基础的Transformer概念开始介绍,尽量避免使用数学和技术细节,使得更多人能够理解这一强大的技术。 Transformers —— 以通俗易懂的方式解释…

5、axios请求、动画、组件、路由重定向、UI组件

一、axios请求 Axios是一个基于Promise的HTTP状态库&#xff0c;封装ajax。ajax包含axios安装 npm install axios 引入 import axios form “axios” 1、get请求 <script> // 1.本页面引入 import axios from "axios";data() {return {imgSrc: ""…

Polar靶场web(三)

期待得到某一件事物的时候&#xff0c;才是最美好的。 签到 发现不能提交&#xff0c;看一下f12 发现提交按钮被禁用了&#xff0c;且最大输入9个字符&#xff0c;我们可以改一下。 现随便提交一个发现要提交ilovejijcxy session文件包含 发现有文件包含&#xff0c;那先包含…

Yolo 自制数据集dect训练改进

上一文请看 Yolo自制detect训练-CSDN博客 简介 如下图&#xff1a; 首先看一下每个图的含义 loss loss分为cls_loss, box_loss, obj_loss三部分。 cls_loss用于监督类别分类&#xff0c;计算锚框与对应的标定分类是否正确。 box_loss用于监督检测框的回归&#xff0c;预测框…

深入理解Java接口:定义、使用与重要性(day13)

导语&#xff1a;Java接口是Java编程语言中的一个核心概念&#xff0c;它提供了一种定义方法但不包含方法实现的方式。接口在Java编程中扮演着重要角色&#xff0c;能够帮助我们实现代码的高内聚、低耦合&#xff0c;提高代码的复用性和可维护性。本文将详细介绍Java接口的定义…

蓝桥杯刷题第四天

思路&#xff1a; 这道题很容易即可发现就是简单的暴力即可完成题目&#xff0c;我们只需满足所有数的和为偶数即可保证有满足条件的分法&#xff0c;同时也不需要存下每个输入的数据&#xff0c;只需要知道他是偶数还是奇数即可&#xff0c;因为我们只需要偶数个奇数搭配在一块…

PLC通讯时如何判断选用MODBUS方式还是现场总线方式?

在工业自动化领域&#xff0c;PLC扮演着至关重要的角色。然而&#xff0c;许多人在初次接触PLC通讯时&#xff0c;常因其复杂性而感到困扰。事实上&#xff0c;PLC的通讯并不如人们想象中的那么神秘&#xff0c;它主要只有两种类型&#xff1a;一种是需要编写代码的通讯方式&am…

深度学习(四)笔记1

0.前提 往后我会以我的笔记形式来发布我的文章&#xff08;每3次笔记为一篇文章&#xff09;&#xff0c;有爱的人可以自取学习&#xff0c;当然如果可以的话我会把我的文章翻出来变成文章。 1.数据操作 本期4.1数据操作的链接在这。 链接&#xff1a;https://pan.baidu.com/s…

Spring Cloud+Spring Alibaba笔记

Spring CloudSpring Alibaba 文章目录 Spring CloudSpring AlibabaNacos服务发现配置中心 OpenFeign超时机制开启httpclient5重试机制开启日志 SeataSentinel流量控制熔断降级热点控制规则持久化集成 OpenFeign集成 Gateway MicrometerZipKinGateway路由断言过滤器 Nacos 服务…

01_安装VMwareWorkstation虚拟机

环境&#xff1a;Win10 19045 软件版本&#xff1a;VMware-workstation-17.5.1 一、下载链接 Download VMware Workstation Pro 二、安装&#xff08;无脑下一步&#xff09; 安装位置自选&#xff0c;最好非系统盘。 增强型键盘驱动自选。 更新自选。 快捷方式自选。 三、…

CListCtrl中高亮插入行,条目上移下移

1. 样式修改 2. 关键代码 BOOL CMFCApplication3Dlg::OnInitDialog() {CDialogEx::OnInitDialog();// // 代码省略......//// 设置此对话框的图标。 当应用程序主窗口不是对话框时&#xff0c;框架将自动// 执行此操作SetIcon(m_hIcon, TRUE); // 设置大图标SetIcon(m_hIc…

linux 系统安装php 8.0.2

1. 安装包准备 https://www.php.net/distributions/php-8.0.22.tar.gz 我下载到 /usr/local/src 这个目录了 cd /usr/local/srcwget https://www.php.net/distributions/php-8.0.22.tar.gz 2. tar 解压 然后进到解压的文件夹 tar -zxvf php-8.0.22.tar.gz cd php-8.0.2…

【前端面试3+1】05v-if和v-show的区别、v-if和v-for能同时使用吗、Vuex是什么?【合并两个有序链表】

一、v-if和v-show的区别 v-if 和 v-show 是 Vue.js 中用来控制元素显示与隐藏的指令。 1.v-if&#xff1a; v-if 是根据表达式的真假值来决定是否渲染元素。当表达式为真时&#xff0c;元素会被渲染到 DOM 中&#xff1b;当表达式为假时&#xff0c;元素不会被渲染到 DOM 中。每…

【论文通读】UFO:A UI-Focused Agent for Windows OS Interaction

UFO&#xff1a;A UI-Focused Agent for Windows OS Interaction 前言AbstractMotivationMethodsExperimentConclusion 前言 Windows客户端第一个JARVIS&#xff0c;利用GPT4 Vision识别截图信息辅助智能体自动化执行操作&#xff0c;作为微软大肆宣传的一篇工作&#xff0c;其…

Ubuntu20.04下PCL安装,查看,卸载等操作

Ubuntu20.04下PCL安装&#xff0c;查看&#xff0c;卸载等操作 项目来源 https://github.com/PointCloudLibrary/pclhttps://pointclouds.org/documentation/modules.htmlhttps://pcl.readthedocs.io/projects/tutorials/en/master/ 点云学习&#xff1a; https://github.c…

QT----基于QT的人脸考勤系统ubuntu系统运行,编译到rk3588开发板运行

目录 1 Ubantu编译opencv和seetaface库1.1 Ubantu编译opencv1.2 Ubuntu编译seetaface1.3 安装qt 2 更改代码2.1 直接运行报错/usr/bin/ld: cannot find -lGL: No such file or directory2.2 遇到报错摄像头打不开2.3 修改部分代码2.4 解决中文语音输出问题 3 尝试交叉编译rk358…

141.环形链表 142.环形链表II

给你一个链表的头节点 head &#xff0c;判断链表中是否有环。 如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0c;评测系统内部使用整数 pos 来表示链表尾连接到链表中的位置&#xff08;索…

何时需要指定泛型:Scala编程指南

这里写目录标题 何时需要指定泛型&#xff1a;Scala编程指南为什么使用泛型类型安全 何时需要指定泛型结论 何时需要指定泛型&#xff1a;Scala编程指南 在Scala编程中&#xff0c;泛型是一种强大的特性&#xff0c;它允许开发者编写灵活且类型安全的代码。然而&#xff0c;正…

VMware虚拟机更换引导顺序

前言 我用wmware装了黑群晖测试&#xff0c;将img转成vmdisk的格式之后发现系统引导盘之后1G&#xff0c;有点太小了 我准备把wmware的黑群晖系统迁移到新添加的虚拟磁盘里 1.登录黑群晖的SSH 请先在黑群晖的控制面板中的终端机和SNMP里面启用SSH功能&#xff0c;才能使用ss…

天梯算法Day3整理

浮点数解析 炸鱼题掠过 冲突值 题面 解析 方法一 —— 并查集 按照边值排序&#xff0c;然后按边值从大到小遍历&#xff0c;通过并查集判断能否将所有点无冲突地归于两个集合。在判断时&#xff0c;若有两个点不得不产生冲突&#xff0c;则输出这两个点之间的边值并结束。…