hyoungwoncho's picture
Update README.md
82d2167 verified
metadata
language:
  - en
pipeline_tag: unconditional-image-generation
tags:
  - Diffusion Models
  - Stable Diffusion
  - Perturbed-Attention Guidance
  - PAG

Perturbed-Attention Guidance

image/jpeg

Project / arXiv / GitHub

This repository is based on Diffusers. The pipeline is a modification of StableDiffusionPipeline to support Perturbed-Attention Guidance (PAG).

Quickstart

Loading Custom Piepline:

from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    custom_pipeline="hyoungwoncho/sd_perturbed_attention_guidance",
    torch_dtype=torch.float16,
    safety_checker=None
)

device="cuda"
pipe = pipe.to(device)

prompts = ["a corgi"]

Sampling with PAG:

output = pipe(
    prompts,
    width=512,
    height=512,
    num_inference_steps=50,
    guidance_scale=0.0,
    pag_scale=5.0,
    pag_applied_layers_index=['m0']
).images

Sampling with PAG and CFG:

output = pipe(
    prompts,
    width=512,
    height=512,
    num_inference_steps=50,
    guidance_scale=4.0,
    pag_scale=3.0,
    pag_applied_layers_index=['m0']
).images

Parameters

guidance_scale : gudiance scale of CFG (ex: 7.5)

pag_scale : gudiance scale of PAG (ex: 5.0)

pag_applied_layers_index : index of the layer to apply perturbation (ex: ['m0'])

Stable Diffusion Demo

To join a demo of PAG on Stable Diffusion, run sd_pag_demo.ipynb.