conda创建虚拟环境,安装Stable Diffusion webui

海哥  论坛元老 | 2025-4-16 04:04:26 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1720|帖子 1720|积分 5160

tips: python由conda来控制版本,这样可以给sd-webui一个相对空白的环境。
一 、下载前置资源 

下载CUDA 
1.查看CUDA版本

通过以下下令查看CUDA版本:
  1. nvidia-smi
复制代码

2. 下载CUDA 



  • 访问NVIDIA官网获取当前版本CUDA:CUDA Toolkit Downloads 
  • 获取旧版本CUDA:CUDA Toolkit Archive 
去https://download.pytorch.org/whl下载torch和xformers,安装的版本如下:


安装后查看是否乐成


如果直接使用pip install torch安装,版本是cpu版本。
3.安装anacoda,配置国内镜像源

二、安装stable-diffusion-webui

1.下载stable-diffusion-webui

  1. git clone https://gitcode.com/gh_mirrors/st/stable-diffusion-webui.git
复制代码
2.下载其他堆栈


放入stable-diffusion-webui\repositories目录中
3.下载模型

下载v2-1_768-ema-pruned.ckpt,放入stable-diffusion-webui\models\Stable-diffusion目录中
三、创建并激活环境

  1. conda create -n sd-webui python=3.10.6
  2. conda activate sd-webui
  3. pip install -r requirements.txt
复制代码
本地安装之前下载torch、torchvision、torchaudio
四、运行

  1. python launch.py --xformers --api
复制代码
运行乐成后浏览器直接打开http://127.0.0.1:7860/
        拉倒最下面,显示如下:

浏览器中打开http://127.0.0.1:7860/docs

可以调用。
测试生成图片,控台报错:
NansException: A tensor with NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check.
Time taken: 2.9 sec.
办理方法:
在settings标签中搜索Upcast,选中

然后再点击“Apply settings”生效,自动重启,可以生成图片。
五、大模型安装

        下载了Anything-V3.0.safetensors,把它放到stable-diffusion-webui\models\Stable-diffusion目录中,再次运行,在页面中载入大模型,控台报错:
        OSError: Can‘t load tokenizer for ‘openai/clip-vit-large-patch14‘
        办理方法:
        先在stable-diffusion-webui文件夹下创建openai文件夹,再去一些镜像repo,如:clip-vit-large-patch14: Mirror of https://huggingface.co/openai/clip-vit-large-patch14,repo clone到openai文件夹。
        重启后可以正常载入。
        拉倒最下面,显示如下:

六、插件安装

1.汉化插件安装

stable-diffusion-webui-chinese
七、运行时遇到的问题


1、clip反向推导时报错

OSError: Can't load tokenizer for 'bert-base-uncased'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'bert-base-uncased' is the correct path to a dir
问题说明

在使用到huggingface时,下载连接不稳定导致,ConnectError。
办理方式

  1. #Windows Powershell
  2. $env:HF_ENDPOINT = "https://hf-mirror.com"
  3. #Linux
  4. export HF_ENDPOINT="https://hf-mirror.com"
复制代码
重新运行py文件就可以下载并正常使用。




免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

海哥

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表