Shuang59 commited on
Commit
8712735
β€’
1 Parent(s): b97fb24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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 = th.cuda.is_available()
37
- device = th.device('cpu' if not has_cuda else 'cuda')
38
- print(device)
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(device)
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(th.device('cpu'))
56
- model.load_state_dict(load_checkpoint('base', th.device('cpu'))
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(th.device('cpu'))
68
- model_up.load_state_dict(load_checkpoint('upsample', th.device('cpu')))
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 has_cuda else 'cuda'):
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