e42.uk Circle Device

 

Quick Reference

PyTorch with Diffusers (quick start)

Diffusers Quick Start

Make sure that you have the correct version of python in use and that PyTorch is installed, the correct version for your GPU.

python -m venv venv
. venv/bin/activate
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/rocm6.4
pip3 install diffusers["torch"] accelerate transformers

To run a pipeline, create a python file containing the following, cuda here is fine for an AMD GPU using ROCm:

from diffusers import DiffusionPipeline
import torch
base_pipeline = DiffusionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
)
base_pipeline.to("cuda", torch.float16)

Then build and execute the pipeline:

seed = 43827935
steps = 25
width = 832
height = 1216
positive_prompt = "Colorful Roaring Lion sitting on a victorian couch, flat icon, vector"
negative_prompt = "realistic, realism, photograph"
torch.manual_seed(seed)
generator = torch.Generator(device="cuda").manual_seed(seed)

images = base_pipeline(width=width,
            height=height,
            guidance_scale=8,
            num_inference_steps=steps,
            prompt=positive_prompt,
            negative_prompt=negative_prompt,
            generator=generator).images

References

Quick Links: Techie Stuff | General | Personal | Quick Reference