本地部署 Stable Diffusion3

6月13日,Stability AI 正式开源20亿参数版本的Stable Diffusion 3 Medium。本文将在本地部署 SD3,GPU配置如下 GPU 2080TI / 22G

安装依赖

修改 WORKSPACE 位置信息,安装ComfyUI

复制代码
# #@title Environment Setup

from pathlib import Path

OPTIONS = {}
UPDATE_COMFY_UI = True  #@param {type:"boolean"}
INSTALL_COMFYUI_MANAGER = True  #@param {type:"boolean"}
INSTALL_ANIMATEDIFF = True  #@param {type:"boolean"}
INSTALL_CUSTOM_NODES_DEPENDENCIES = True  #@param {type:"boolean"}
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI
OPTIONS['INSTALL_COMFYUI_MANAGER'] = INSTALL_COMFYUI_MANAGER
OPTIONS['INSTALL_ANIMATEDIFF'] = INSTALL_ANIMATEDIFF
OPTIONS['INSTALL_CUSTOM_NODES_DEPENDENCIES'] = INSTALL_CUSTOM_NODES_DEPENDENCIES

WORKSPACE = "/notebook/SD/ComfyUI"



%cd /notebook/SD/

![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI

%cd $WORKSPACE

!echo $WORKSPACE

if OPTIONS['UPDATE_COMFY_UI']:
  !echo "-= Updating ComfyUI =-"
  !git pull
 
!pip install -r requirements.txt

下载模型权重

复制代码
#@markdown ###Download standard resources

### SDXL
### I recommend these workflow examples: https://comfyanonymous.github.io/ComfyUI_examples/sdxl/

OPTIONS = {}

#@markdown **Models**

!wget -c "https://modelscope.cn/api/v1/models/AI-ModelScope/stable-diffusion-3-medium/repo?Revision=master&FilePath=sd3_medium.safetensors" -P ./models/checkpoints/

下载 Text Encoder

复制代码
#@markdown **clip**

!wget -c "https://modelscope.cn/api/v1/models/AI-ModelScope/stable-diffusion-3-medium/repo?Revision=master&FilePath=text_encoders%2Fclip_g.safetensors" -P ./models/clip/
!wget -c "https://modelscope.cn/api/v1/models/AI-ModelScope/stable-diffusion-3-medium/repo?Revision=master&FilePath=text_encoders%2Fclip_l.safetensors" -P ./models/clip/
!wget -c "https://modelscope.cn/api/v1/models/AI-ModelScope/stable-diffusion-3-medium/repo?Revision=master&FilePath=text_encoders%2Ft5xxl_fp16.safetensors" -P ./models/clip/
!wget -c "https://modelscope.cn/api/v1/models/AI-ModelScope/stable-diffusion-3-medium/repo?Revision=master&FilePath=text_encoders%2Ft5xxl_fp8_e4m3fn.safetensors" -P ./models/clip/
#通过cloudflared启动 ComfyUI ,
!wget "https://modelscope.oss-cn-beijing.aliyuncs.com/resource/cloudflared-linux-amd64.deb"
!dpkg -i cloudflared-linux-amd64.deb

启动 ComfyUI 服务器

复制代码
%cd /notebook/SD/ComfyUI
import subprocess
import threading
import time
import socket
import urllib.request

def iframe_thread(port):
  while True:
      time.sleep(0.5)
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      result = sock.connect_ex(('127.0.0.1', port))
      if result == 0:
        break
      sock.close()
  print("\nComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")

  p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  for line in p.stderr:
    l = line.decode()
    if "trycloudflare.com " in l:
      print("This is the URL to access ComfyUI:", l[l.find("http"):], end='')
    #print(l, end='')


threading.Thread(target=iframe_thread, daemon=True, args=(8891,)).start()
!python main.py --dont-print-server  --listen "0.0.0.0"  --port 8891 

运行

服务器启动之后,导入工作流配置

  1. 导入配置文件,配置文件位置在 https://www.modelscope.cn/models/AI-ModelScope/stable-diffusion-3-medium/files,comfy_example_workflows/sd3_medium_example_workflow_basic.json
  2. 输入提示词,点击 Queue Prompt 生成图片。

总结

根据以下提示词,比较ChatGPT、Google 和 SD 的差距。

复制代码
A transparent glass of very very small slim capsule is being held by fingers, inside the capsule there is a nuclear explosion, there is smoke and fire, the background of a cozy room

ChatGPT

Google Gemini


SD3

ChatGPT最好,比较细腻,其次是Gemini ,SD 稍微差一些,SD的好处是可以私有化部署,可以根据需要进行私有数据训练,SD 生成速度 2.1 it/s。

相关推荐
love530love1 天前
【避坑指南】提示词“闹鬼”?Stable Diffusion 自动注入神秘词汇 xiao yi xian 排查全记录
人工智能·windows·stable diffusion·model keyword
世界尽头与你1 天前
Stable Diffusion web UI 未授权访问漏洞
安全·网络安全·stable diffusion·渗透测试
love530love1 天前
【故障解析】Stable Diffusion WebUI 更换主题后启动报 JSONDecodeError?可能是“主题加载”惹的祸
人工智能·windows·stable diffusion·大模型·json·stablediffusion·gradio 主题
ai_xiaogui6 天前
Stable Diffusion Web UI 绘世版 v4.6.1 整合包:一键极速部署,深度解决 AI 绘画环境配置与 CUDA 依赖难题
人工智能·stable diffusion·环境零配置·高性能内核优化·全功能插件集成·极速部署体验
微学AI7 天前
金仓数据库的新格局:以多模融合开创文档数据库
人工智能·stable diffusion
我的golang之路果然有问题7 天前
开源绘画大模型简单了解
人工智能·ai作画·stable diffusion·人工智能作画
我的golang之路果然有问题7 天前
comfyUI中的动作提取分享
人工智能·stable diffusion·ai绘画·人工智能作画·comfy
stephen one11 天前
2026 AI深度伪造危机:实测 Midjourney v7 与 Flux 2 Max 识别,谁才是 AI 检测的天花板?
人工智能·ai作画·stable diffusion·aigc·midjourney
长不大的蜡笔小新14 天前
基于Stable Diffusion的多模态图像生成与识别系统
stable diffusion
米汤爱学习14 天前
stable-diffusion-webui【笔记】
笔记·stable diffusion