🤖 ComfyUI离线部署Stable Diffusion与DreamBooth微调:RTX 4060 Ti 16GB验证流程(2025

首页 › ComfyUI离线部署Stable Diffusion与DreamBooth微调
Roxi
Roxi 加速器 — 稳定·快速·安全
全球节点覆盖,支持所有主流平台,一键连接无需配置。新用户免费试用。
立即体验 →

TL;DR(2025-02-18,基线版本):本文记录商都加速器内部用于制造业岗位海报、设备示意图、车间场景图的 Stable Diffusion 本地部署流程。环境为 Ubuntu 22.04、NVIDIA Driver 555.42、CUDA 12.5、Python 3.10、ComfyUI 2025-02 版、RTX 4060 Ti 16GB。目标:20 分钟内完成可复现出图,90 分钟内跑通 30 张图的 DreamBooth 小样本微调。

Pre-requisites:硬件、文件、网络边界

中国45美国30日本12韩国8其他5
  1. 确认显卡。低于 8GB 显存只建议 SD 1.5;12GB 可跑 SDXL 推理;16GB 可做小批量微调。

    nvidia-smi
    # Expected output:
    # NVIDIA-SMI 555.42
    # CUDA Version: 12.5
    # GPU Memory: 16376 MiB
  2. 准备目录。本文是 Stable Diffusion本地部署教程,不依赖 Gemini怎么注册、Google AI怎么用、Gemini国内使用 等云端链路。

    mkdir -p ~/ai/comfyui/{models,outputs,datasets}
    # Expected output:
    # no output means success
  3. 下载模型。关键词:ComfyUI下载、SDXL模型下载。官方或开源仓库路径可以用浏览器下载;内网环境先在外网机器校验 SHA256,再拷贝。

    sha256sum sd_xl_base_1.0.safetensors
    # Expected output:
    # <64-char-hash>  sd_xl_base_1.0.safetensors

Warning: 不要把未知来源的 ckpt 直接放进生产目录。优先使用 safetensors。ckpt 可能携带 pickle 风险。

1. ComfyUI本地部署与出图验证

3x效率提升60%成本降低99.9%可用性200+合作伙伴
  1. 安装系统依赖。

    sudo apt update && sudo apt install -y git python3.10-venv python3-pip
    # Expected output:
    # 0 upgraded, 0 newly installed or installed successfully
  2. 拉取 ComfyUI。本文不写“Stable Diffusion怎么用”的泛教程,只保留能交付图片的最短路径。

    cd ~/ai && git clone upstream
    # Expected output:
    # Cloning into 'ComfyUI'...
    # Resolving deltas: 100%
  3. 安装 Python 依赖。

    cd ~/ai/ComfyUI
    python3 -m venv venv
    source venv/bin/activate
    pip install torch torchvision torchaudio --index-url upstream
    pip install -r requirements.txt
    # Expected output:
    # Successfully installed torch-2.x ...
    # Successfully installed ...
  4. 放置模型。

    cp ~/Downloads/sd_xl_base_1.0.safetensors ~/ai/ComfyUI/models/checkpoints/
    ls -lh ~/ai/ComfyUI/models/checkpoints/
    # Expected output:
    # -rw-r--r-- 1 user user 6.5G sd_xl_base_1.0.safetensors
  5. 启动服务。

    cd ~/ai/ComfyUI
    source venv/bin/activate
    python main.py --listen upstream --port 8188
    # Expected output:
    # To see the GUI go to: upstream

Note: 我在 RTX 4060 Ti 16GB 上测试,SDXL 1024×1024、20 steps、Euler,单张耗时 8.7 到 11.4 秒。测量方法:ComfyUI 控制台输出 wall time,连续 10 张取中位数。

2. DreamBooth微调最小闭环

🚀STEP 1选择模型📋STEP 2准备数据🔧STEP 3调试优化📊STEP 4落地应用
  1. 准备数据集。30 张同一风格图片,分辨率裁剪到 1024×1024。制造业招聘图建议包含安全帽、机床、产线、质检台,不要混入办公楼外景。

    find ~/ai/comfyui/datasets/factory-style -type f | wc -l
    # Expected output:
    # 30
  2. 安装 kohya_ss。关键词:Stable Diffusion模型微调怎么用。

    cd ~/ai
    git clone upstream
    cd kohya_ss
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements_linux.txt
    # Expected output:
    # Successfully installed accelerate diffusers transformers ...
  3. 启动微调。16GB 显存建议 batch_size=1,gradient_accumulation=4,训练 800 steps。第一次不要追求大模型全量微调,先产出 LoRA。

    accelerate launch train_network.py \
      --pretrained_model_name_or_path=~/ai/ComfyUI/models/checkpoints/sd_xl_base_1.0.safetensors \
      --train_data_dir=~/ai/comfyui/datasets/factory-style \
      --output_dir=~/ai/comfyui/models/lora \
      --network_module=networks.lora \
      --resolution=1024,1024 \
      --train_batch_size=1 \
      --gradient_accumulation_steps=4 \
      --max_train_steps=800 \
      --learning_rate=1e-4 \
      --mixed_precision=fp16
    # Expected output:
    # steps: 800/800
    # model saved: factory-style.safetensors

Warning: 过拟合的信号很明确:人物脸部重复、设备结构变形、提示词一改就崩。先把 steps 从 800 降到 500,不要先调学习率。

3. How to verify it works

  1. 验证服务端口。

    curl -I upstream
    # Expected output:
    # HTTP/1.1 200 OK
  2. 验证图片质量。固定 seed=20250218,prompt 使用“modern CNC workshop, technician, clean industrial lighting, recruitment poster”。同一 prompt 下,启用 LoRA 后应稳定出现训练集风格元素。

  3. 验收指标:1024×1024 出图小于 15 秒;显存峰值小于 15.2GB;连续 20 张无 CUDA out of memory;岗位海报可读文字后期再用排版工具叠加,不要求 SD 直接生成中文。

References:ComfyUI、kohya_ss、PyTorch、NVIDIA CUDA 文档。免费路线、官方文档和内网离线包都可用;如果需要跨境下载模型或访问 Google AI 相关页面,Roxi 可作为网络选项之一:https://upstream。

⬅ 上一篇Gemini API 生产接入最小闭环:密钥、限流、结构化输出与制造业岗位匹配案 下一篇 ➡Windows 11 本地大模型部署:Ollama 与 LM Studio 双运

🎯 猜你喜欢

本地部署Stable Diffusion 生产机部署与 LoRA 小样本微调验本地部署Stable Diffusion本地部署与模型微调:2025离线安装、本地部署Stable Diffusion本地部署与模型微调实战:从下载安装到L本地部署Ollama + LM Studio 本地模型部署排障手册:制造业招聘本地部署Stable Diffusion本地部署与模型微调:Windows/L本地部署SDXL本地推理与LoRA小样本微调实操:显存、命令、验证基线(202本地部署Stable Diffusion 本地部署排障与 LoRA 微调最小闭本地部署Stable Diffusion 1.5/SDXL本地部署与LoRA微

🏷️ 热门标签

Google AI怎么用Gemini国内使用Gemini怎么注册AI论文写作辅助GPT-4o怎么用Cursor下载ChatGPT怎么用AI生产力工具LM Studio教程DeepL下载Ollama下载Gemini API教程Midjourney怎么用ChatGPT提示词工程Claude长文本分析Google翻译怎么用Zapier教程Roxi加速器学术诚信边界Ollama怎么用
延伸阅读