Spaces:
Runtime error
Runtime error
notebook fixes
Browse files
app.ipynb
CHANGED
@@ -17,8 +17,8 @@
|
|
17 |
"source": [
|
18 |
"#| export\n",
|
19 |
"import gradio as gr\n",
|
20 |
-
"import
|
21 |
-
"import
|
22 |
"import torch\n",
|
23 |
"import nbdev"
|
24 |
]
|
@@ -52,7 +52,7 @@
|
|
52 |
"}\n",
|
53 |
"\n",
|
54 |
"def load_model():\n",
|
55 |
-
" pipeline =
|
56 |
" model_name,\n",
|
57 |
" device,\n",
|
58 |
" dtype,\n",
|
@@ -137,7 +137,7 @@
|
|
137 |
" cos_params.update(new_params)\n",
|
138 |
" \n",
|
139 |
" # return the new cosine schedule\n",
|
140 |
-
" sched =
|
141 |
" return sched\n",
|
142 |
"\n",
|
143 |
"\n",
|
@@ -149,7 +149,7 @@
|
|
149 |
"inv_k_sched = [max_val - g + min_val for g in k_sched]\n",
|
150 |
"\n",
|
151 |
"# group the schedules \n",
|
152 |
-
"
|
153 |
" 'cosine': {'g': inv_k_sched},\n",
|
154 |
" 'static': {'g': static_sched},\n",
|
155 |
"}\n",
|
@@ -188,9 +188,9 @@
|
|
188 |
" res = []\n",
|
189 |
"\n",
|
190 |
" # generate images with static and dynamic schedules\n",
|
191 |
-
" for (name,sched) in
|
192 |
" # make the guidance norm\n",
|
193 |
-
" gtfm =
|
194 |
" # generate the image\n",
|
195 |
" with torch.autocast(device), torch.no_grad():\n",
|
196 |
" img = pipeline.generate(prompt, gtfm, **generation_kwargs)\n",
|
|
|
17 |
"source": [
|
18 |
"#| export\n",
|
19 |
"import gradio as gr\n",
|
20 |
+
"from cf_guidance import schedules, transforms\n",
|
21 |
+
"from min_diffusion.core import MinimalDiffusion\n",
|
22 |
"import torch\n",
|
23 |
"import nbdev"
|
24 |
]
|
|
|
52 |
"}\n",
|
53 |
"\n",
|
54 |
"def load_model():\n",
|
55 |
+
" pipeline = MinimalDiffusion(\n",
|
56 |
" model_name,\n",
|
57 |
" device,\n",
|
58 |
" dtype,\n",
|
|
|
137 |
" cos_params.update(new_params)\n",
|
138 |
" \n",
|
139 |
" # return the new cosine schedule\n",
|
140 |
+
" sched = schedules.get_cos_sched(**cos_params)\n",
|
141 |
" return sched\n",
|
142 |
"\n",
|
143 |
"\n",
|
|
|
149 |
"inv_k_sched = [max_val - g + min_val for g in k_sched]\n",
|
150 |
"\n",
|
151 |
"# group the schedules \n",
|
152 |
+
"scheds = {\n",
|
153 |
" 'cosine': {'g': inv_k_sched},\n",
|
154 |
" 'static': {'g': static_sched},\n",
|
155 |
"}\n",
|
|
|
188 |
" res = []\n",
|
189 |
"\n",
|
190 |
" # generate images with static and dynamic schedules\n",
|
191 |
+
" for (name,sched) in scheds.items():\n",
|
192 |
" # make the guidance norm\n",
|
193 |
+
" gtfm = transforms.GuidanceTfm(sched)\n",
|
194 |
" # generate the image\n",
|
195 |
" with torch.autocast(device), torch.no_grad():\n",
|
196 |
" img = pipeline.generate(prompt, gtfm, **generation_kwargs)\n",
|
app.py
CHANGED
@@ -4,13 +4,13 @@
|
|
4 |
__all__ = ['model_name', 'revision', 'dtype', 'device', 'better_vae', 'unet_attn_slice', 'sampler_kls', 'hf_sampler',
|
5 |
'model_kwargs', 'num_steps', 'height', 'width', 'k_sampler', 'use_karras_sigmas', 'NEG_PROMPT',
|
6 |
'generation_kwargs', 'baseline_g', 'max_val', 'min_val', 'num_warmup_steps', 'warmup_init_val', 'num_cycles',
|
7 |
-
'k_decay', 'DEFAULT_COS_PARAMS', 'static_sched', 'k_sched', 'inv_k_sched', '
|
8 |
-
'
|
9 |
|
10 |
# %% app.ipynb 1
|
11 |
import gradio as gr
|
12 |
-
import
|
13 |
-
import
|
14 |
import torch
|
15 |
import nbdev
|
16 |
|
@@ -36,7 +36,7 @@ model_kwargs = {
|
|
36 |
}
|
37 |
|
38 |
def load_model():
|
39 |
-
pipeline =
|
40 |
model_name,
|
41 |
device,
|
42 |
dtype,
|
@@ -105,7 +105,7 @@ def cos_harness(new_params: dict) -> dict:
|
|
105 |
cos_params.update(new_params)
|
106 |
|
107 |
# return the new cosine schedule
|
108 |
-
sched =
|
109 |
return sched
|
110 |
|
111 |
|
@@ -117,7 +117,7 @@ k_sched = cos_harness({'k_decay': 0.2})
|
|
117 |
inv_k_sched = [max_val - g + min_val for g in k_sched]
|
118 |
|
119 |
# group the schedules
|
120 |
-
|
121 |
'cosine': {'g': inv_k_sched},
|
122 |
'static': {'g': static_sched},
|
123 |
}
|
@@ -148,9 +148,9 @@ def compare_dynamic_guidance(prompt):
|
|
148 |
res = []
|
149 |
|
150 |
# generate images with static and dynamic schedules
|
151 |
-
for (name,sched) in
|
152 |
# make the guidance norm
|
153 |
-
gtfm =
|
154 |
# generate the image
|
155 |
with torch.autocast(device), torch.no_grad():
|
156 |
img = pipeline.generate(prompt, gtfm, **generation_kwargs)
|
|
|
4 |
__all__ = ['model_name', 'revision', 'dtype', 'device', 'better_vae', 'unet_attn_slice', 'sampler_kls', 'hf_sampler',
|
5 |
'model_kwargs', 'num_steps', 'height', 'width', 'k_sampler', 'use_karras_sigmas', 'NEG_PROMPT',
|
6 |
'generation_kwargs', 'baseline_g', 'max_val', 'min_val', 'num_warmup_steps', 'warmup_init_val', 'num_cycles',
|
7 |
+
'k_decay', 'DEFAULT_COS_PARAMS', 'static_sched', 'k_sched', 'inv_k_sched', 'scheds', 'iface', 'load_model',
|
8 |
+
'cos_harness', 'compare_dynamic_guidance']
|
9 |
|
10 |
# %% app.ipynb 1
|
11 |
import gradio as gr
|
12 |
+
from cf_guidance import schedules, transforms
|
13 |
+
from min_diffusion.core import MinimalDiffusion
|
14 |
import torch
|
15 |
import nbdev
|
16 |
|
|
|
36 |
}
|
37 |
|
38 |
def load_model():
|
39 |
+
pipeline = MinimalDiffusion(
|
40 |
model_name,
|
41 |
device,
|
42 |
dtype,
|
|
|
105 |
cos_params.update(new_params)
|
106 |
|
107 |
# return the new cosine schedule
|
108 |
+
sched = schedules.get_cos_sched(**cos_params)
|
109 |
return sched
|
110 |
|
111 |
|
|
|
117 |
inv_k_sched = [max_val - g + min_val for g in k_sched]
|
118 |
|
119 |
# group the schedules
|
120 |
+
scheds = {
|
121 |
'cosine': {'g': inv_k_sched},
|
122 |
'static': {'g': static_sched},
|
123 |
}
|
|
|
148 |
res = []
|
149 |
|
150 |
# generate images with static and dynamic schedules
|
151 |
+
for (name,sched) in scheds.items():
|
152 |
# make the guidance norm
|
153 |
+
gtfm = transforms.GuidanceTfm(sched)
|
154 |
# generate the image
|
155 |
with torch.autocast(device), torch.no_grad():
|
156 |
img = pipeline.generate(prompt, gtfm, **generation_kwargs)
|