Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,34 @@
|
|
| 1 |
import torch
|
| 2 |
from diffusers.utils import load_image
|
| 3 |
from diffusers import FluxControlNetPipeline, FluxControlNetModel
|
|
|
|
| 4 |
|
| 5 |
# Clear unnecessary memory
|
| 6 |
torch.cuda.empty_cache()
|
| 7 |
|
| 8 |
# Set the environment variable to handle memory fragmentation
|
| 9 |
-
import os
|
| 10 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
| 11 |
|
| 12 |
base_model = 'black-forest-labs/FLUX.1-dev'
|
| 13 |
controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Union'
|
| 14 |
|
| 15 |
-
# Use
|
| 16 |
controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.float16)
|
| 17 |
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.float16)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
pipe.to("cuda")
|
| 19 |
|
| 20 |
control_image_canny = load_image("https://huggingface.co/InstantX/FLUX.1-dev-Controlnet-Union-alpha/resolve/main/images/canny.jpg")
|
| 21 |
controlnet_conditioning_scale = 0.5
|
| 22 |
control_mode = 0
|
| 23 |
|
| 24 |
-
#
|
| 25 |
width, height = control_image_canny.size
|
|
|
|
|
|
|
| 26 |
|
| 27 |
prompt = 'A bohemian-style female travel blogger with sun-kissed skin and messy beach waves.'
|
| 28 |
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers.utils import load_image
|
| 3 |
from diffusers import FluxControlNetPipeline, FluxControlNetModel
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
# Clear unnecessary memory
|
| 7 |
torch.cuda.empty_cache()
|
| 8 |
|
| 9 |
# Set the environment variable to handle memory fragmentation
|
|
|
|
| 10 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
| 11 |
|
| 12 |
base_model = 'black-forest-labs/FLUX.1-dev'
|
| 13 |
controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Union'
|
| 14 |
|
| 15 |
+
# Use mixed precision with float16
|
| 16 |
controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.float16)
|
| 17 |
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.float16)
|
| 18 |
+
|
| 19 |
+
# Offload some parts to CPU
|
| 20 |
+
pipe.enable_model_cpu_offload()
|
| 21 |
+
|
| 22 |
pipe.to("cuda")
|
| 23 |
|
| 24 |
control_image_canny = load_image("https://huggingface.co/InstantX/FLUX.1-dev-Controlnet-Union-alpha/resolve/main/images/canny.jpg")
|
| 25 |
controlnet_conditioning_scale = 0.5
|
| 26 |
control_mode = 0
|
| 27 |
|
| 28 |
+
# Reduce the image resolution if needed to fit into memory
|
| 29 |
width, height = control_image_canny.size
|
| 30 |
+
width = width // 2
|
| 31 |
+
height = height // 2
|
| 32 |
|
| 33 |
prompt = 'A bohemian-style female travel blogger with sun-kissed skin and messy beach waves.'
|
| 34 |
|