common.title

Docs
Quantum Circuit
TYTAN CLOUD

QUANTUM GAMING


Desktop RAG

Overview
Terms of service

Privacy policy

Contact
Research

Sign in
Sign up
common.title

在AMD GPU上运行Stable Diffusion XL

Yuichiro Minato

2024/08/11 03:47

在AMD GPU上运行Stable Diffusion XL

你好。我想可能有人希望在AMD上运行Stable Diffusion,所以我决定尝试一下。

我使用的CPU是Ryzen 9 5950X,GPU是Radeon 7900XTX(配备24GB的VRAM)。由于VRAM容量充足,我想检查一下它的性能和可用性。

在这次测试中,我使用了Stable Diffusion的SDXL版本。

首先,你需要安装与ROCm(AMD的标准)兼容的PyTorch。然后,像往常一样使用pip安装所需的库:

pip install diffusers invisible_watermark transformers accelerate safetensors

使用方法与NVIDIA GPU相同。由于我使用的是标准的SDXL设置,没有使用任何特殊的库,所以没有遇到任何问题。

from diffusers import DiffusionPipeline
import torch

# 指定GPU
device = "cuda"

# 设置固定种子
generator = torch.Generator(device).manual_seed(100)

# 编写提示词
prompt = "An astronaut riding a green horse"

# 构建管道并设置为fp16
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
pipe.to(device)

# 生成并获取图像
images = pipe(prompt=prompt, generator=generator).images[0]
images

与CUDA版本相比,没有明显差异。

对于1024x1024尺寸的图像,在标准的50步生成中,生成速度为16秒。

image

虽然生成速度稍慢,但仍然非常可用。

© 2025, blueqat Inc. All rights reserved