AI大模型教程
一起来学习

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

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在多个方面进行了显著改:

  • 图像质量和细节:通过增加模型参数量,提升了图像分辨率上限至2048×2048,并改善了细节表现和真实感。

  • 提示词匹配度:优化了对复杂提示词的理解能力,能够更准确地生成符合用户需求的图像。

  • 速度提升:Large Turbo版本通过技术优化,大幅缩短了生成时间,适合需要快速生成大量图像的用户。

  • 多模态支持:支持多种视觉元素的整合,解决了早期版本中复杂细节和多元素集成的限制问题。
    这份完整版的SD整合包已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

1.环境配置

  • 创建虚环境

    conda create -n sd3.5 python=3.10   
    
  • Pytorch(>2.0)

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

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

    pip install transformers==4.38.2    pip install tokenizers==0.15.2   
    
  • 安装最新版本的diffuser

    pip install -U diffusers   
    
  • 安装量化库节约VRAM GPUs

    pip install bitsandbytes   
    
  • 安装sentencepiece

    pip install sentencepiece   
    
  • 根据项目需要安装其他库

    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:

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

解决:

pip install protobuf==3.19.0   

3.实测

  • 官网例子:
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.”

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())   

这份完整版的SD整合包已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

文章来源于互联网:Stable Diffusion 3.5 本地部署指南:从安装到问题解决,一站式搞定!

相关推荐: 多模态与 AIGC:用 TensorFlow 构建图文 / 语音 / 视频生成模型

多模态与 AIGC:用 TensorFlow 构建图文 / 语音 / 视频生成模型 🎯 本章目标 了解主流 AIGC 多模态模型架构(图像、语音、视频) 构建文本生成模型(GPT-like) 构建图文生成模型(图像 Caption / Text-to-Imag…

赞(0)
未经允许不得转载:5bei.cn大模型教程网 » Stable Diffusion 3.5 本地部署指南:从安装到问题解决,一站式搞定!
分享到: 更多 (0)

AI大模型,我们的未来

小欢软考联系我们