Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions sd/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"import torch\n",
"\n",
"DEVICE = \"cpu\"\n",
"IDLE_DEVICE = \"cpu\"\n",
"\n",
"ALLOW_CUDA = False\n",
"ALLOW_MPS = False\n",
Expand All @@ -29,7 +30,9 @@
"\n",
"tokenizer = CLIPTokenizer(\"../data/vocab.json\", merges_file=\"../data/merges.txt\")\n",
"model_file = \"../data/v1-5-pruned-emaonly.ckpt\"\n",
"models = model_loader.preload_models_from_standard_weights(model_file, DEVICE)\n",
"models = model_loader.preload_models_from_standard_weights(\n",
" model_file, DEVICE, IDLE_DEVICE\n",
")\n",
"\n",
"## TEXT TO IMAGE\n",
"\n",
Expand Down Expand Up @@ -67,13 +70,20 @@
" seed=seed,\n",
" models=models,\n",
" device=DEVICE,\n",
" idle_device=\"cpu\",\n",
" idle_device=IDLE_DEVICE,\n",
" tokenizer=tokenizer,\n",
")\n",
"\n",
"# Combine the input image and the output image into a single image.\n",
"Image.fromarray(output_image)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
4 changes: 2 additions & 2 deletions sd/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import model_converter

def preload_models_from_standard_weights(ckpt_path, device):
state_dict = model_converter.load_from_standard_weights(ckpt_path, device)
def preload_models_from_standard_weights(ckpt_path, device, idle_device):
state_dict = model_converter.load_from_standard_weights(ckpt_path, idle_device)

encoder = VAE_Encoder().to(device)
encoder.load_state_dict(state_dict['encoder'], strict=True)
Expand Down
2 changes: 2 additions & 0 deletions sd/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def generate(
# (Batch_Size, Channel, Height, Width) -> (Batch_Size, Height, Width, Channel)
images = images.permute(0, 2, 3, 1)
images = images.to("cpu", torch.uint8).numpy()

torch.cuda.empty_cache()
return images[0]

def rescale(x, old_range, new_range, clamp=False):
Expand Down