Stable Diffusion
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("mps")
# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()
prompt = "便利店开业"
# First-time "warmup" pass if PyTorch version is 1.13 (see explanation above)
_ = pipe(prompt, num_inference_steps=1)
images = pipe(prompt=prompt).images[0]
images.save("output1.png")
diffusers
The Hugging Face platform provides basic model weights and general model training framework diffusers
reference
How to use Stable Diffusion in Apple Silicon (M1/M2)
stable-diffusion-xl
from diffusers import StableDiffusionXLPipeline
import torch
# pipe = StableDiffusionXLPipeline.from_pretrained(
# "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
# )
pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
# pipe.to("cuda")
pipe = pipe.to("mps")
# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
# First-time "warmup" pass if PyTorch version is 1.13 (see explanation above)
_ = pipe(prompt, num_inference_steps=1)
image = pipe(prompt=prompt).images[0]
image.save("sdxl.png")
https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl