More details and background: Generating (almost) reproducible pictures using Diffusers with xFormers
Unfortunately, Flash Attention won't accept SD1.x attention shapes, but will accept SD2.x or variants.
| #!/bin/bash | |
| models=("canny" "depth" "pose" ) | |
| for model in "${models[@]}" | |
| do | |
| echo $model | |
| python merge_controlnet_diff.py --sd15 ../wd-1-5-beta2/checkpoints/wd-1-5-beta2-fp32.safetensors --control diff_control_wd15beta2_$model.safetensors --dst control_wd15beta2_$model.safetensors --fp16 | |
| done |
| import torch | |
| import torch.nn.functional as F | |
| import safetensors.torch | |
| import sys | |
| def load_checkpoint(fn): | |
| if fn.endswith(".safetensors"): | |
| checkpoint = safetensors.torch.load_file(fn) | |
| else: |
| import torch | |
| import pytest | |
| import PIL.Image | |
| import numpy as np | |
| from diffusers.utils import ( | |
| PIL_INTERPOLATION, | |
| ) | |
| # `batch` = batch_size * num_images_per_prompt | |
| # When the input is a single image or a tensor with b==1, repeat it the `batch` times. |
| import torch | |
| from diffusers import UNet2DConditionModel | |
| mem_bytes = torch.cuda.max_memory_allocated() | |
| torch.cuda.reset_peak_memory_stats() | |
| controlnet = UNet2DConditionModel.from_pretrained("takuma104/control_sd15_canny", subfolder="controlnet").cuda() | |
| mem_bytes = torch.cuda.max_memory_allocated() | |
| print(mem_bytes) | |
| # Diffusers' ControlNet Implementation Subjective Evaluation | |
| # https://github.com/takuma104/diffusers/tree/controlnet | |
| import einops | |
| import numpy as np | |
| import pytest | |
| import torch | |
| from diffusers import StableDiffusionControlNetPipeline |
| # from https://github.com/lllyasviel/ControlNet/blob/main/gradio_canny2image.py | |
| from share import * | |
| import config | |
| import cv2 | |
| import einops | |
| import gradio as gr | |
| import numpy as np | |
| import torch |
More details and background: Generating (almost) reproducible pictures using Diffusers with xFormers
Unfortunately, Flash Attention won't accept SD1.x attention shapes, but will accept SD2.x or variants.
| import torch | |
| from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler | |
| import matplotlib.pyplot as plt | |
| from PIL import Image | |
| import numpy as np | |
| import xformers | |
| import xformers.ops | |
| plt.rcParams["figure.figsize"] = (10,5) | |
| plt.rcParams['figure.facecolor'] = 'white' |
| import torch | |
| from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler | |
| import matplotlib.pyplot as plt | |
| from PIL import Image | |
| import numpy as np | |
| plt.rcParams["figure.figsize"] = (10,5) | |
| plt.rcParams['figure.facecolor'] = 'white' | |
| def generate_tuxedo_cat_picture(fn_prefix, seed=0): |