Skip to content

Instantly share code, notes, and snippets.

View takuma104's full-sized avatar

Takuma Mori takuma104

  • Tokyo
View GitHub Profile
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
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}.')
@takuma104
takuma104 / scratchpad.ipynb
Last active May 16, 2023 15:46
scratchpad_mod
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@takuma104
takuma104 / scratchpad.ipynb
Last active May 16, 2023 16:47
scratchpad-lora
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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)
@takuma104
takuma104 / scratchpad.ipynb
Last active May 18, 2023 16:02
scratchpad
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@takuma104
takuma104 / untitled11.ipynb
Last active May 19, 2023 18:26
monkey_patch_minimum_test.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
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)} mean={torch.mean(parent[k]):.3g} std={torch.std(parent[k]):.3g}')
else:
dump_keys(parent[k], f'{suffix}{k}.')
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
def create_pipeline():
pipe = StableDiffusionPipeline.from_pretrained(
"gsdf/Counterfeit-V2.5", torch_dtype=torch.float16, safety_checker=None
).to("cuda")
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True)
pipe.enable_xformers_memory_efficient_attention()
return pipe
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
def create_pipeline():
pipe = StableDiffusionPipeline.from_pretrained(
"gsdf/Counterfeit-V2.5", torch_dtype=torch.float16, safety_checker=None
).to("cuda")
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True)
pipe.enable_xformers_memory_efficient_attention()
return pipe