--- language: - en pipeline_tag: unconditional-image-generation tags: - Diffusion Models - Stable Diffusion - Perturbed-Attention Guidance - PAG --- # Perturbed-Attention Guidance ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/6601282b569b30694e67b886/27Lmuol8anwd6L6BLzyWf.jpeg) This repository is based on [Diffusers](https://huggingface.co/docs/diffusers/index). StableDiffusionPAGPipeline is a modification of StableDiffusionPipeline to support Perturbed-Attention Guidance (PAG). ## Quickstart Load StableDiffusionPAGPipeline as below: ``` 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) ``` Sampling: ``` 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 ``` ## Parameters pag_scale : gudiance scale of PAG (ex: 5.0) pag_applied_layers_index = index of the layer to apply perturbation (ex: ['m0'])