from clip_text_custom_embedder import text_embeddings
from diffusers import StableDiffusionPipeline
import torch
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 | |
import torch.nn | |
def test_monkey_patch(): | |
x = torch.randn((2, 2)).cuda() | |
target = torch.nn.Linear(2, 2).cuda() | |
with torch.no_grad(): | |
y = target(x) | |
assert y.shape == (2, 2) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | |
import safetensors.torch | |
import sys | |
def dump_keys(parent, suffix=''): | |
for k in sorted(parent.keys()): | |
if isinstance(parent[k], torch.Tensor): | |
print(f'{suffix}{k} {list(parent[k].shape)}') | |
else: | |
dump_keys(parent[k], f'{suffix}{k}.') |
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
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler | |
from torch | |
from PIL import Image | |
def image_grid(imgs, rows, cols): | |
assert len(imgs) == rows*cols | |
w, h = imgs[0].size | |
grid = Image.new('RGB', size=(cols*w, rows*h)) | |
grid_w, grid_h = grid.size |
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] |
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
# 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 |