SD3.5环境配置及问题解决
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.环境配置
-
创建虚环境
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())
关于AI绘画技术储备
学好 AI绘画 不论是就业还是做副业赚钱都不错,但要学会 AI绘画 还是要有一个学习规划。最后大家分享一份全套的 AI绘画 学习资料,给那些想学习 AI绘画 的小伙伴们一点帮助!
感兴趣的小伙伴,赠送全套AIGC学习资料和安装工具,包含AI绘画、AI人工智能等前沿科技教程,模型插件,具体看下方。
需要的可以微信扫描下方优快云官方认证二维码免费领取【保证100%免费】
一、AIGC所有方向的学习路线
AIGC所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。
二、AIGC必备工具
工具都帮大家整理好了,安装就可直接上手!
三、最新AIGC学习笔记
当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。
四、AIGC视频教程合集
观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。
五、实战案例
纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
这份完整版的学习资料已经上传优快云,朋友们如果需要可以微信扫描下方优快云官方认证二维码免费领取【保证100%免费】