Skip to content

Instantly share code, notes, and snippets.

View takuma104's full-sized avatar

Takuma Mori takuma104

  • Tokyo
View GitHub Profile
@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
@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.
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)
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
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:
@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
# Script for converting a HF Diffusers saved pipeline to a ControlNet checkpoint.
# *Only* converts the ControlNet.
# Does not convert optimizer state or any other thing.
import argparse
import os.path as osp
import re
import torch
from safetensors.torch import load_file, save_file
@takuma104
takuma104 / README.md
Last active August 28, 2024 05:03
clip_text_custom_embedder

Usage

from clip_text_custom_embedder import text_embeddings
from diffusers import StableDiffusionPipeline
import torch
import math
import safetensors
import torch
from diffusers import DiffusionPipeline
"""
Kohya's LoRA format Loader for Diffusers
Usage:
```py
import torch
import sys
from safetensors.torch import load_file
from diffusers import StableDiffusionPipeline
state_dict = load_file('some_lora.safetensors')
new_state_dict = {}
for key, value in state_dict.items():
if "lora_down" in key:
lora_name = key.split(".")[0]