Stable Diffusion 3.5 本地部署指南:从安装到标题解决,一站式搞定!

[复制链接]
发表于 2025-3-31 05:13:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
SD3.5环境设置及标题解决

Stable Diffusion 3.5 作为AI绘画领域的重磅升级,以其强大的图像天生能力和灵活的本地部署特性,吸引了无数创作者。本指南将手把手带你完成从环境设置到模型运行的完备流程,并针对常见标题提供解决方案,助你轻松开启AI艺术创作之旅!
Stable Diffusion 3.5(简称SD3.5)是由Stability AI推出的最新一代图像天生模型,是Stable Diffusion系列的重要升级版本。
SD3.5包含三个主要版本:


  • Stable Diffusion 3.5 Large:参数目为80亿,支持天生100万像素(1MP)的高分辨率图像,适合专业用户和对图像质量有较高要求的场景。
  • Stable Diffusion 3.5 Large Turbo:基于Large版本优化,采用对抗性扩散蒸馏(ADD)技能,显著提高了天生速率,同时保持高质量输出。
  • Stable Diffusion 3.5 Medium:参数目为25亿,实用于中平分辨率需求的用户,如天生40万像素(0.4MP)的图像。
SD3.5在多个方面进行了显著改:


  • 图像质量和细节:通过增长模型参数目,提升了图像分辨率上限至2048x2048,并改善了细节体现和真实感。
  • 提示词匹配度:优化了对复杂提示词的理解能力,能够更准确地天生符实用户需求的图像。
  • 速率提升:Large Turbo版本通过技能优化,大幅缩短了天生时间,适合需要快速天生大量图像的用户。
  • 多模态支持:支持多种视觉元素的整合,解决了早期版本中复杂细节和多元素集成的限制标题。

1.环境设置



  • 创建虚环境
    1. conda create -n sd3.5 python=3.10   
    复制代码
  • Pytorch(>2.0)
    1. conda install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 pytorch-cuda=12.1 -c pytorch -c nvidia   
    复制代码
  • Jupyter能利用Anaconda虚环境
    1. conda install ipykernel   python -m ipykernel install --user --name sd3.5 --display-name "SD3.5"   
    复制代码
  • 安装transformer和tokenizer
    1. pip install transformers==4.38.2    pip install tokenizers==0.15.2   
    复制代码
  • 安装最新版本的diffuser
    1. pip install -U diffusers   
    复制代码
  • 安装量化库节约VRAM GPUs
    1. pip install bitsandbytes   
    复制代码
  • 安装sentencepiece
    1. pip install sentencepiece   
    复制代码
  • 根据项目需要安装其他库
    1. 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降级解决
  1. 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:
  1. 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
解决:
  1. pip install protobuf==3.19.0   
复制代码
3.实测



  • 官网例子:
  1. 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.”
  1. 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())   
复制代码


回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表