Spaces:
Running
on
Zero
Running
on
Zero
Update raw.py
Browse files
raw.py
CHANGED
|
@@ -2,6 +2,7 @@ import torch
|
|
| 2 |
import spaces
|
| 3 |
import os
|
| 4 |
from diffusers.utils import load_image
|
|
|
|
| 5 |
from diffusers import FluxControlNetModel, FluxControlNetPipeline, AutoencoderKL
|
| 6 |
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig
|
| 7 |
from transformers import T5EncoderModel
|
|
@@ -43,13 +44,62 @@ pipe = FluxControlNetPipeline.from_pretrained(
|
|
| 43 |
# adapter_id3 = "enhanceaiteam/Flux-uncensored-v2"
|
| 44 |
|
| 45 |
pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# pipe.load_lora_weights(adapter_id, adapter_name="turbo")
|
| 47 |
# pipe.load_lora_weights(adapter_id2, adapter_name="real")
|
| 48 |
# pipe.load_lora_weights(adapter_id3, weight_name="lora.safetensors", adapter_name="enhance")
|
| 49 |
# pipe.set_adapters(["turbo", "real", "enhance"], adapter_weights=[0.9, 0.66, 0.6])
|
| 50 |
# pipe.fuse_lora(adapter_names=["turbo", "real", "enhance"], lora_scale=1.0)
|
| 51 |
# pipe.unload_lora_weights()
|
| 52 |
-
# pipe.enable_xformers_memory_efficient_attention()
|
| 53 |
# save to the Hub
|
| 54 |
# pipe.push_to_hub("FLUX.1M-8step_upscaler-cnet")
|
| 55 |
|
|
@@ -74,7 +124,9 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
|
|
| 74 |
guidance_scale=guidance_scale,
|
| 75 |
height=control_image.size[1],
|
| 76 |
width=control_image.size[0],
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
).images[0]
|
| 79 |
|
| 80 |
return image
|
|
@@ -94,7 +146,7 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as iface:
|
|
| 94 |
seed = gr.Slider(0, MAX_SEED, value=42, label="Seed", step=1)
|
| 95 |
steps = gr.Slider(2, 16, value=8, label="Steps")
|
| 96 |
controlnet_conditioning_scale = gr.Slider(0, 1, value=0.6, label="ControlNet Scale")
|
| 97 |
-
guidance_scale = gr.Slider(1,
|
| 98 |
guidance_end = gr.Slider(0, 1, value=1.0, label="Guidance End")
|
| 99 |
|
| 100 |
|
|
|
|
| 2 |
import spaces
|
| 3 |
import os
|
| 4 |
from diffusers.utils import load_image
|
| 5 |
+
from diffusers.hooks import apply_group_offloading
|
| 6 |
from diffusers import FluxControlNetModel, FluxControlNetPipeline, AutoencoderKL
|
| 7 |
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig
|
| 8 |
from transformers import T5EncoderModel
|
|
|
|
| 44 |
# adapter_id3 = "enhanceaiteam/Flux-uncensored-v2"
|
| 45 |
|
| 46 |
pipe.to("cuda")
|
| 47 |
+
try:
|
| 48 |
+
apply_group_offloading(
|
| 49 |
+
pipe.transformer,
|
| 50 |
+
offload_type="leaf_level",
|
| 51 |
+
offload_device=torch.device("cpu"),
|
| 52 |
+
onload_device=torch.device("cuda"),
|
| 53 |
+
use_stream=True,
|
| 54 |
+
)
|
| 55 |
+
apply_group_offloading(
|
| 56 |
+
pipe.text_encoder,
|
| 57 |
+
offload_device=torch.device("cpu"),
|
| 58 |
+
onload_device=torch.device("cuda"),
|
| 59 |
+
offload_type="leaf_level",
|
| 60 |
+
use_stream=True,
|
| 61 |
+
)
|
| 62 |
+
apply_group_offloading(
|
| 63 |
+
pipe.text_encoder_2,
|
| 64 |
+
offload_device=torch.device("cpu"),
|
| 65 |
+
onload_device=torch.device("cuda"),
|
| 66 |
+
offload_type="leaf_level",
|
| 67 |
+
use_stream=True,
|
| 68 |
+
)
|
| 69 |
+
apply_group_offloading(
|
| 70 |
+
pipe.vae,
|
| 71 |
+
offload_device=torch.device("cpu"),
|
| 72 |
+
onload_device=torch.device("cuda"),
|
| 73 |
+
offload_type="leaf_level",
|
| 74 |
+
use_stream=True,
|
| 75 |
+
)
|
| 76 |
+
except:
|
| 77 |
+
console.log("debug-group")
|
| 78 |
+
|
| 79 |
+
try:
|
| 80 |
+
pipe.enable_sequential_cpu_offload()
|
| 81 |
+
except:
|
| 82 |
+
console.log("debug-1")
|
| 83 |
+
try:
|
| 84 |
+
pipe.vae.enable_slicing()
|
| 85 |
+
except:
|
| 86 |
+
console.log("debug-2")
|
| 87 |
+
try:
|
| 88 |
+
pipe.vae.enable_tiling()
|
| 89 |
+
except:
|
| 90 |
+
console.log("debug-3")
|
| 91 |
+
try:
|
| 92 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 93 |
+
except:
|
| 94 |
+
console.log("debug-4")
|
| 95 |
+
|
| 96 |
+
|
| 97 |
# pipe.load_lora_weights(adapter_id, adapter_name="turbo")
|
| 98 |
# pipe.load_lora_weights(adapter_id2, adapter_name="real")
|
| 99 |
# pipe.load_lora_weights(adapter_id3, weight_name="lora.safetensors", adapter_name="enhance")
|
| 100 |
# pipe.set_adapters(["turbo", "real", "enhance"], adapter_weights=[0.9, 0.66, 0.6])
|
| 101 |
# pipe.fuse_lora(adapter_names=["turbo", "real", "enhance"], lora_scale=1.0)
|
| 102 |
# pipe.unload_lora_weights()
|
|
|
|
| 103 |
# save to the Hub
|
| 104 |
# pipe.push_to_hub("FLUX.1M-8step_upscaler-cnet")
|
| 105 |
|
|
|
|
| 124 |
guidance_scale=guidance_scale,
|
| 125 |
height=control_image.size[1],
|
| 126 |
width=control_image.size[0],
|
| 127 |
+
control_guidance_start=0.0,
|
| 128 |
+
control_guidance_end=guidance_end,
|
| 129 |
+
guidance_scale=30.0,
|
| 130 |
).images[0]
|
| 131 |
|
| 132 |
return image
|
|
|
|
| 146 |
seed = gr.Slider(0, MAX_SEED, value=42, label="Seed", step=1)
|
| 147 |
steps = gr.Slider(2, 16, value=8, label="Steps")
|
| 148 |
controlnet_conditioning_scale = gr.Slider(0, 1, value=0.6, label="ControlNet Scale")
|
| 149 |
+
guidance_scale = gr.Slider(1, 30, value=3.5, label="Guidance Scale")
|
| 150 |
guidance_end = gr.Slider(0, 1, value=1.0, label="Guidance End")
|
| 151 |
|
| 152 |
|