Exploring Stable diffusion Pipeline

Exploring the stable diffusion pipeline

Load necessary modules

Setup the notebook’s configuration parameters

params=Parameters().from_json('../config.json')
params.gpu = device_by_name("Tesla")
params.height = 512  # default height of Stable Diffusion
params.width = 512  # default width of Stable Diffusion
params.num_inference_steps = 25  # Number of denoising steps
params.guidance_scale = 7.5  # Scale for classifier-free guidance
params.seed = 0

we will use the gpu

device=params.gpu

load pretrained model

params.model_name='stabilityai/stable-diffusion-2-1-base'
pipe = StableDiffusionPipeline.from_pretrained(params.model_name, torch_dtype=torch.float16 , requires_safety_checker = False).to(device)
# pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
# # Workaround for not accepting attention shape using VAE for Flash Attention
# pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None)

Setup prompt

prompt = ["a photograph of a cute puppy"]
generator = torch.Generator(device = device)
generator.manual_seed(params.seed)  # Seed generator to create the inital latent noise
<torch._C.Generator>

Run the standard model

image = pipe(prompt, generator = generator).images[0]

image

lets try another prompt

prompt = ["a graffity of the monalisa on a brick wall, a red gorilla painter"]

image = pipe(prompt, generator = generator).images[0]

image

negative_prompt

prompt = ["a red gorilla painter painting a graffity of the monalisa on a brick wall"]
negative_prompt = ["a photo"]

image = pipe(prompt, negative_prompt = negative_prompt, generator = generator).images[0]

image