Skip to content

Instantly share code, notes, and snippets.

View takuma104's full-sized avatar

Takuma Mori takuma104

  • Tokyo
View GitHub Profile
@takuma104
takuma104 / merge.sh
Created March 7, 2023 12:54
furusu's weight recover
#!/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)
@takuma104
takuma104 / controlnetdiffusersdevelopment.ipynb
Last active February 19, 2023 10:40
controlnetdiffusersdevelopment.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@takuma104
takuma104 / plot_controlnet_sample.py
Created February 17, 2023 18:06
Diffusers' ControlNet Implementation Subjective Evaluation
# 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
@takuma104
takuma104 / readme.md
Last active January 21, 2023 09:35
Reproducible generation with xFormers for SD2.x or variant models
@takuma104
takuma104 / diffusers_xformers_repro.py
Last active January 20, 2023 16:09
Generating (almost) reproducible pictures using Diffusers with xFormers
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'
@takuma104
takuma104 / diffusers_sd_xformers_flash_attention.py
Last active July 29, 2023 20:09
Generating (almost) reproducible pictures using Diffusers with xFormers
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):