Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,15 +33,15 @@ from diffusers import StableDiffusionPipeline
|
|
33 |
# On CPU, generating one sample may take on the order of 20 minutes.
|
34 |
# On a GPU, it should be under a minute.
|
35 |
|
36 |
-
has_cuda =
|
37 |
-
|
38 |
-
|
39 |
|
40 |
# iniatilize stable diffusion model
|
41 |
pipe = StableDiffusionPipeline.from_pretrained(
|
42 |
"CompVis/stable-diffusion-v1-4",
|
43 |
use_auth_token='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'
|
44 |
-
).to(
|
45 |
|
46 |
# Create base model.
|
47 |
timestep_respacing = 100 # @param{type: 'number'}
|
@@ -52,8 +52,8 @@ model, diffusion = create_model_and_diffusion(**options)
|
|
52 |
model.eval()
|
53 |
if has_cuda:
|
54 |
model.convert_to_fp16()
|
55 |
-
model.to(
|
56 |
-
model.load_state_dict(load_checkpoint('base',
|
57 |
print('total base parameters', sum(x.numel() for x in model.parameters()))
|
58 |
|
59 |
# Create upsampler model.
|
@@ -64,8 +64,8 @@ model_up, diffusion_up = create_model_and_diffusion(**options_up)
|
|
64 |
model_up.eval()
|
65 |
if has_cuda:
|
66 |
model_up.convert_to_fp16()
|
67 |
-
model_up.to(
|
68 |
-
model_up.load_state_dict(load_checkpoint('upsample',
|
69 |
print('total upsampler parameters', sum(x.numel() for x in model_up.parameters()))
|
70 |
|
71 |
|
@@ -294,7 +294,7 @@ def compose_clevr_objects(prompt, guidance_scale, steps):
|
|
294 |
|
295 |
|
296 |
def stable_diffusion_compose(prompt, scale, steps):
|
297 |
-
with autocast('cpu' if not
|
298 |
image = pipe(prompt, guidance_scale=scale, num_inference_steps=steps)["sample"][0]
|
299 |
return image
|
300 |
|
|
|
33 |
# On CPU, generating one sample may take on the order of 20 minutes.
|
34 |
# On a GPU, it should be under a minute.
|
35 |
|
36 |
+
has_cuda = False
|
37 |
+
gpu = th.device('cpu' if not th.cuda.is_available() else 'cuda')
|
38 |
+
cpu = th.device('cpu')
|
39 |
|
40 |
# iniatilize stable diffusion model
|
41 |
pipe = StableDiffusionPipeline.from_pretrained(
|
42 |
"CompVis/stable-diffusion-v1-4",
|
43 |
use_auth_token='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'
|
44 |
+
).to(gpu)
|
45 |
|
46 |
# Create base model.
|
47 |
timestep_respacing = 100 # @param{type: 'number'}
|
|
|
52 |
model.eval()
|
53 |
if has_cuda:
|
54 |
model.convert_to_fp16()
|
55 |
+
model.to(cpu)
|
56 |
+
model.load_state_dict(load_checkpoint('base', cpu))
|
57 |
print('total base parameters', sum(x.numel() for x in model.parameters()))
|
58 |
|
59 |
# Create upsampler model.
|
|
|
64 |
model_up.eval()
|
65 |
if has_cuda:
|
66 |
model_up.convert_to_fp16()
|
67 |
+
model_up.to(cpu)
|
68 |
+
model_up.load_state_dict(load_checkpoint('upsample', cpu))
|
69 |
print('total upsampler parameters', sum(x.numel() for x in model_up.parameters()))
|
70 |
|
71 |
|
|
|
294 |
|
295 |
|
296 |
def stable_diffusion_compose(prompt, scale, steps):
|
297 |
+
with autocast('cpu' if not th.cuda.is_available() else 'cuda'):
|
298 |
image = pipe(prompt, guidance_scale=scale, num_inference_steps=steps)["sample"][0]
|
299 |
return image
|
300 |
|