cocktailpeanut commited on
Commit
15f0453
1 Parent(s): 8c19a23
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -62,10 +62,13 @@ with open("defaults_data.json", "r") as file:
62
  #device = "cuda"
63
  if torch.cuda.is_available():
64
  device = "cuda"
 
65
  elif torch.backends.mps.is_available():
66
  device = "mps"
 
67
  else:
68
  device = "cpu"
 
69
 
70
  state_dicts = {}
71
 
@@ -118,13 +121,13 @@ controlnet_path = f'data/checkpoints/ControlNetModel'
118
 
119
  # load IdentityNet
120
  st = time.time()
121
- identitynet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
122
- zoedepthnet = ControlNetModel.from_pretrained("diffusers/controlnet-zoe-depth-sdxl-1.0",torch_dtype=torch.float16)
123
  et = time.time()
124
  elapsed_time = et - st
125
  print('Loading ControlNet took: ', elapsed_time, 'seconds')
126
  st = time.time()
127
- vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
128
  et = time.time()
129
  elapsed_time = et - st
130
  print('Loading VAE took: ', elapsed_time, 'seconds')
@@ -132,7 +135,7 @@ st = time.time()
132
  pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_pretrained("rubbrband/albedobaseXL_v21",
133
  vae=vae,
134
  controlnet=[identitynet, zoedepthnet],
135
- torch_dtype=torch.float16)
136
  pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True)
137
  pipe.load_ip_adapter_instantid(face_adapter)
138
  pipe.set_ip_adapter_scale(0.8)
@@ -225,7 +228,7 @@ def merge_incompatible_lora(full_path_lora, lora_scale):
225
  for_inference=True,
226
  )
227
  lora_model.merge_to(
228
- pipe.text_encoder, pipe.unet, weights_sd, torch.float16, "cuda"
229
  )
230
  del weights_sd
231
  del lora_model
 
62
  #device = "cuda"
63
  if torch.cuda.is_available():
64
  device = "cuda"
65
+ dtype = torch.float16
66
  elif torch.backends.mps.is_available():
67
  device = "mps"
68
+ dtype = torch.float32
69
  else:
70
  device = "cpu"
71
+ dtype = torch.float32
72
 
73
  state_dicts = {}
74
 
 
121
 
122
  # load IdentityNet
123
  st = time.time()
124
+ identitynet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=dtype)
125
+ zoedepthnet = ControlNetModel.from_pretrained("diffusers/controlnet-zoe-depth-sdxl-1.0",torch_dtype=dtype)
126
  et = time.time()
127
  elapsed_time = et - st
128
  print('Loading ControlNet took: ', elapsed_time, 'seconds')
129
  st = time.time()
130
+ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=dtype)
131
  et = time.time()
132
  elapsed_time = et - st
133
  print('Loading VAE took: ', elapsed_time, 'seconds')
 
135
  pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_pretrained("rubbrband/albedobaseXL_v21",
136
  vae=vae,
137
  controlnet=[identitynet, zoedepthnet],
138
+ torch_dtype=dtype)
139
  pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True)
140
  pipe.load_ip_adapter_instantid(face_adapter)
141
  pipe.set_ip_adapter_scale(0.8)
 
228
  for_inference=True,
229
  )
230
  lora_model.merge_to(
231
+ pipe.text_encoder, pipe.unet, weights_sd, dtype, device
232
  )
233
  del weights_sd
234
  del lora_model