enzokro commited on
Commit
020e16c
1 Parent(s): 60e8b07

notebook fixes

Browse files
Files changed (2) hide show
  1. app.ipynb +7 -7
  2. app.py +9 -9
app.ipynb CHANGED
@@ -17,8 +17,8 @@
17
  "source": [
18
  "#| export\n",
19
  "import gradio as gr\n",
20
- "import cf_guidance\n",
21
- "import min_diffusion\n",
22
  "import torch\n",
23
  "import nbdev"
24
  ]
@@ -52,7 +52,7 @@
52
  "}\n",
53
  "\n",
54
  "def load_model():\n",
55
- " pipeline = min_diffusion.core.MinimalDiffusion(\n",
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 = cf_guidance.schedules.get_cos_sched(**cos_params)\n",
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
- "schedules = {\n",
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 schedules.items():\n",
192
  " # make the guidance norm\n",
193
- " gtfm = cf_guidance.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",
 
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', 'schedules', 'iface',
8
- 'load_model', 'cos_harness', 'compare_dynamic_guidance']
9
 
10
  # %% app.ipynb 1
11
  import gradio as gr
12
- import cf_guidance
13
- import min_diffusion
14
  import torch
15
  import nbdev
16
 
@@ -36,7 +36,7 @@ model_kwargs = {
36
  }
37
 
38
  def load_model():
39
- pipeline = min_diffusion.core.MinimalDiffusion(
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 = cf_guidance.schedules.get_cos_sched(**cos_params)
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
- schedules = {
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 schedules.items():
152
  # make the guidance norm
153
- gtfm = cf_guidance.transforms.GuidanceTfm(sched)
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)