Spaces:
Build error
Build error
Compile opt and Native batch support
Browse files- app.py +15 -16
- guided_diffusion/gaussian_diffusion.py +1 -1
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import argparse
|
|
| 4 |
import os
|
| 5 |
import random
|
| 6 |
import torch as th
|
|
|
|
| 7 |
import torchvision as tv
|
| 8 |
|
| 9 |
from guided_diffusion import logger
|
|
@@ -65,6 +66,7 @@ def load_model():
|
|
| 65 |
model, diffusion = load_model()
|
| 66 |
model.convert_to_fp16()
|
| 67 |
model.eval()
|
|
|
|
| 68 |
# Label to color mapping
|
| 69 |
label_color_mapping = {
|
| 70 |
0: (0, 0, 0), # No information
|
|
@@ -188,29 +190,26 @@ def generate_image(input_image, semantic_drawing, num_imgs):
|
|
| 188 |
input_image = th.tensor(np.where(semantic_label == 0, img, 0))
|
| 189 |
input_label[0, -3:, :, :] = input_image
|
| 190 |
input_semantics = input_label.scatter_(1, th.tensor(semantic_label).long(), 1.0)
|
| 191 |
-
model_kwargs = {'y': input_semantics,}
|
| 192 |
model_kwargs['s'] = args.s
|
| 193 |
print(args.s)
|
| 194 |
-
|
| 195 |
-
diffusion = recreate_diffusion_with_steps(args, diffusion_steps)
|
| 196 |
-
print(f"Recreated diffusion with {diffusion_steps} steps")
|
| 197 |
|
| 198 |
sample_fn = (
|
| 199 |
diffusion.p_sample_loop if not args.use_ddim else diffusion.ddim_sample_loop
|
| 200 |
)
|
| 201 |
|
| 202 |
-
output_imgs = []
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
output_img = sample.cpu().numpy()[
|
| 214 |
output_imgs.append(output_img)
|
| 215 |
|
| 216 |
return output_imgs # return twice: for output and new input
|
|
|
|
| 4 |
import os
|
| 5 |
import random
|
| 6 |
import torch as th
|
| 7 |
+
th.set_float32_matmul_precision('high')
|
| 8 |
import torchvision as tv
|
| 9 |
|
| 10 |
from guided_diffusion import logger
|
|
|
|
| 66 |
model, diffusion = load_model()
|
| 67 |
model.convert_to_fp16()
|
| 68 |
model.eval()
|
| 69 |
+
model = th.compile(model, mode="reduce-overhead", fullgraph=True)
|
| 70 |
# Label to color mapping
|
| 71 |
label_color_mapping = {
|
| 72 |
0: (0, 0, 0), # No information
|
|
|
|
| 190 |
input_image = th.tensor(np.where(semantic_label == 0, img, 0))
|
| 191 |
input_label[0, -3:, :, :] = input_image
|
| 192 |
input_semantics = input_label.scatter_(1, th.tensor(semantic_label).long(), 1.0)
|
| 193 |
+
model_kwargs = {'y': input_semantics.tile(num_imgs, 1, 1, 1),}
|
| 194 |
model_kwargs['s'] = args.s
|
| 195 |
print(args.s)
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
sample_fn = (
|
| 198 |
diffusion.p_sample_loop if not args.use_ddim else diffusion.ddim_sample_loop
|
| 199 |
)
|
| 200 |
|
| 201 |
+
output_imgs = []
|
| 202 |
+
sample = sample_fn(
|
| 203 |
+
model,
|
| 204 |
+
(num_imgs, 3, 256, 256),
|
| 205 |
+
clip_denoised=args.clip_denoised,
|
| 206 |
+
model_kwargs=model_kwargs,
|
| 207 |
+
progress=True,
|
| 208 |
+
)
|
| 209 |
+
sample = (sample + 1) / 2.0
|
| 210 |
+
sample = sample.cpu().permute(0, 2, 3, 1)
|
| 211 |
+
for num in range(num_imgs):
|
| 212 |
+
output_img = sample.cpu().numpy()[num]
|
| 213 |
output_imgs.append(output_img)
|
| 214 |
|
| 215 |
return output_imgs # return twice: for output and new input
|
guided_diffusion/gaussian_diffusion.py
CHANGED
|
@@ -254,7 +254,7 @@ class GaussianDiffusion:
|
|
| 254 |
"""
|
| 255 |
if model_kwargs is None:
|
| 256 |
model_kwargs = {}
|
| 257 |
-
|
| 258 |
B, C = x.shape[:2]
|
| 259 |
assert t.shape == (B,)
|
| 260 |
if 'y' in model_kwargs:
|
|
|
|
| 254 |
"""
|
| 255 |
if model_kwargs is None:
|
| 256 |
model_kwargs = {}
|
| 257 |
+
th.compiler.cudagraph_mark_step_begin()
|
| 258 |
B, C = x.shape[:2]
|
| 259 |
assert t.shape == (B,)
|
| 260 |
if 'y' in model_kwargs:
|