bedead commited on
Commit
48483ef
·
verified ·
1 Parent(s): e4edbf8

added cuda/cpu useabiltiy

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -28,19 +28,20 @@ state_dict = load_state_dict(model_file)
28
  model, _, _, _, _ = ControlNetModel_Union._load_pretrained_model(
29
  controlnet_model, state_dict, model_file, "xinsir/controlnet-union-sdxl-1.0"
30
  )
31
- model.to(device="cpu", dtype=torch.float16)
32
 
 
33
  vae = AutoencoderKL.from_pretrained(
34
- "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
35
- ).to("cpu")
36
 
37
  pipe = StableDiffusionXLFillPipeline.from_pretrained(
38
  "SG161222/RealVisXL_V5.0_Lightning",
39
- torch_dtype=torch.float16,
40
  vae=vae,
41
  controlnet=model,
42
- variant="fp16",
43
- ).to("cpu")
44
 
45
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
46
 
@@ -50,7 +51,7 @@ prompt = "high quality"
50
  negative_prompt_embeds,
51
  pooled_prompt_embeds,
52
  negative_pooled_prompt_embeds,
53
- ) = pipe.encode_prompt(prompt, "cpu", True)
54
 
55
 
56
  def fill_image(image, model_selection):
 
28
  model, _, _, _, _ = ControlNetModel_Union._load_pretrained_model(
29
  controlnet_model, state_dict, model_file, "xinsir/controlnet-union-sdxl-1.0"
30
  )
31
+ device = torch.cuda.is_available()
32
 
33
+ model.to(device=device, dtype=torch.float16 if device == 'cuda' else torch.float32)
34
  vae = AutoencoderKL.from_pretrained(
35
+ "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16 if device == 'cuda' else torch.float32
36
+ ).to(device)
37
 
38
  pipe = StableDiffusionXLFillPipeline.from_pretrained(
39
  "SG161222/RealVisXL_V5.0_Lightning",
40
+ torch_dtype=torch.float16 if device == 'cuda' else torch.float32,
41
  vae=vae,
42
  controlnet=model,
43
+ variant="fp16" if device == 'cuda' else None,
44
+ ).to(device)
45
 
46
  pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
47
 
 
51
  negative_prompt_embeds,
52
  pooled_prompt_embeds,
53
  negative_pooled_prompt_embeds,
54
+ ) = pipe.encode_prompt(prompt, device, True)
55
 
56
 
57
  def fill_image(image, model_selection):