Stable diffusion 3.5本地运行环境配置记录

1.环境配置

  • 创建虚环境

    bash 复制代码
    conda create -n sd3.5 python=3.10
  • Pytorch(>2.0)

    bash 复制代码
    conda install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 pytorch-cuda=12.1 -c pytorch -c nvidia
  • Jupyter能使用Anaconda虚环境

    bash 复制代码
    conda install ipykernel
    python -m ipykernel install --user --name sd3.5 --display-name "SD3.5"
  • 安装transformer和tokenizer

    bash 复制代码
    pip install transformers==4.38.2 
    pip install tokenizers==0.15.2
  • 安装最新版本的diffuser

    复制代码
    pip install -U diffusers
  • 安装量化库节约VRAM GPUs

    bash 复制代码
    pip install bitsandbytes
  • 安装sentencepiece

    bash 复制代码
    pip install sentencepiece
  • 根据项目需要安装其他库

    bash 复制代码
    pip install matplotlib
    pip install numpy==1.26.4    # 降级,否则有些时候会报错
    pip install accelerate
    pip install protobuf==3.19.0

    2.报错解决

如果报错:Exception: data did not match any variant of untagged enum PyPreTokenizerTypeWrapper at line 960 column 3

降级解决

复制代码
pip install transformers==4.38.2
pip install tokenizers==0.15.2

如果报错ValueError: Cannot instantiate this tokenizer from a slow version. If it's based on sentencepiece, make sure you have sentencepiece installed.

安装sentencepiece:

bash 复制代码
pip install sentencepiece

如果报错:ValueError: The current PyTorch version does not support the scaled_dot_product_attention function.

解决:安装高于Pytorch>2.0

如果报错:T5Converter requires the protobuf library but it was not found in your environment. Checkout the instructions on the

解决:

bash 复制代码
pip install protobuf==3.19.0

3.实测

  • 官网例子:
python 复制代码
local_path = "/home/aic/diffusion_models/stable-diffusion-3.5-large/"
pipe = StableDiffusion3Pipeline.from_pretrained(local_path, torch_dtype=torch.bfloat16)
pipe = pipe.to("cuda")

image = pipe(
    "A capybara holding a sign that reads Hello World",
    num_inference_steps=28,
    guidance_scale=3.5,
).images[0]
image.save("capybara.png")
  • 自定义例子

    "一名古代风格的中国女学生坐在现代的计算机教室里面学习编程"

    prompts:"An ancient-style Chinese female student sitting in a modern computer classroom learning programming, focused eyes, traditional Hanfu attire, modern technology, code editor, keyboard, mouse, fusion of digital age and traditional aesthetics, rich in detail, high-definition quality."

python 复制代码
prompts="An ancient-style Chinese female student sitting in a modern computer classroom learning programming, focused eyes, traditional Hanfu attire, modern technology, code editor, keyboard, mouse, fusion of digital age and traditional aesthetics, rich in detail, high-definition quality."
image = pipe(
    prompt=prompt,
    num_inference_steps=28,
    guidance_scale=4.5,
    max_sequence_length=512,
).images[0]

image.save("girls.png")
plt.imshow(plt.imread("girls.png"))
plt.axis('off')  # 不显示坐标轴
display(plt.gcf())
相关推荐
北上ing1 天前
从FP32到BF16,再到混合精度的全景解析
人工智能·pytorch·深度学习·计算机视觉·stable diffusion
源客z2 天前
搭建Stable Diffusion图像生成系统实现通过网址访问(Ngrok+Flask实现项目系统公网测试,轻量易部署)
stable diffusion
源客z3 天前
搭建 Stable Diffusion 图像生成系统并通过 Ngrok 暴露到公网(实现本地系统网络访问)——项目记录
stable diffusion
朴拙数科5 天前
Stable Diffusion秋叶整合包V4独立版Python本地API连接指南
开发语言·python·stable diffusion
璇转的鱼6 天前
爆肝整理!Stable Diffusion的完全使用手册(二)
人工智能·ai作画·stable diffusion·aigc
曲幽7 天前
Stable Diffusion LoRA模型加载实现风格自由
python·ai·stable diffusion·lora·文生图·diffusers
nan_black9 天前
在Pycharm配置stable diffusion环境(使用conda虚拟环境)
stable diffusion·pycharm·conda
AI绘画咪酱9 天前
Stable Diffusion【进阶篇】:如何实现人脸一致
人工智能·深度学习·学习·机器学习·ai作画·stable diffusion
AIGC-Lison10 天前
AI绘画SD中,如何保持生成人物角色脸部一致?Stable Diffusion精准控制AI人像一致性两种实用方法教程!
人工智能·ai作画·stable diffusion·midjourney·sd
AI绘画咪酱11 天前
SD教程|巧用Stable Diffusion,实现不同风格的LOGO设计|实战篇幅,建议收藏!
人工智能·学习·ai作画·stable diffusion·sd