Stable Diffusion 3.5
在 Clore.ai 的 GPU 上使用 Stable Diffusion 3.5 生成高保真图像,并实现准确的文本渲染。
最后更新于
这有帮助吗?
这有帮助吗?
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
pip install diffusers transformers accelerate sentencepiece protobuf
python -c "import torch; print(torch.cuda.get_device_name(0))"import torch
from diffusers import StableDiffusion3Pipeline
pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3.5-large",
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
image = pipe(
prompt=(
"一块风化的木牌,上面写着 'OPEN 24 HOURS',挂在"
"霓虹灯照亮的餐馆外的一条生锈链条上,雨夜,"
"湿润柏油路上的反射,电影摄影风格"
),
negative_prompt="模糊、变形的文字、低质量",
guidance_scale=3.5,
num_inference_steps=28,
width=1024,
height=1024,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("diner_sign.png")
print("Saved diner_sign.png")import torch
from diffusers import StableDiffusion3Pipeline
pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3.5-large-turbo",
torch_dtype=torch.bfloat16,
).to("cuda")
# Turbo 变体:只需 4 步,guidance_scale=0(已蒸馏)
image = pipe(
prompt="机械表机芯的微距照片,复杂齿轮,金色光线",
guidance_scale=0.0,
num_inference_steps=4,
width=1024,
height=1024,
).images[0]
image.save("watch_turbo.png")import torch
from diffusers import StableDiffusion3Pipeline
pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3.5-medium",
torch_dtype=torch.float16,
).to("cuda")
image = pipe(
prompt="一间舒适咖啡馆内部的等角视图,像素艺术风格,温暖灯光",
guidance_scale=4.0,
num_inference_steps=28,
width=1024,
height=1024,
).images[0]
image.save("coffee_shop_medium.png")import torch
from diffusers import StableDiffusion3Pipeline
pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3.5-large",
torch_dtype=torch.bfloat16,
).to("cuda")
jobs = [
{"prompt": "一位宇航员在向日葵田的肖像", "w": 768, "h": 1344},
{"prompt": "冰岛高地的全景风光,阴郁的天空", "w": 1344, "h": 768},
{"prompt": "一瓶香水放在大理石表面上的产品照片", "w": 1024, "h": 1024},
]
for i, job in enumerate(jobs):
img = pipe(
prompt=job["prompt"],
guidance_scale=3.5,
num_inference_steps=28,
width=job["w"],
height=job["h"],
).images[0]
img.save(f"batch_{i:03d}.png")
print(f"[{i+1}/{len(jobs)}] {job['w']}x{job['h']} 完成")