Spaces:
Running
Running
added cuda/cpu useabiltiy
Browse files
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 |
-
|
32 |
|
|
|
33 |
vae = AutoencoderKL.from_pretrained(
|
34 |
-
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
|
35 |
-
).to(
|
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(
|
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,
|
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):
|