from clip_text_custom_embedder import text_embeddings
from diffusers import StableDiffusionPipeline
import torch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import safetensors | |
import torch | |
from diffusers import DiffusionPipeline | |
""" | |
Kohya's LoRA format Loader for Diffusers | |
Usage: | |
```py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |