Spaces:
Running on Zero
Running on Zero
add extra GPU reservation buffer slider 0-10s and unique guest IP identification
Browse files- pipeline_manager.py +39 -13
- ui.py +2 -1
- ui_modules/column_inputs.py +9 -0
pipeline_manager.py
CHANGED
|
@@ -60,7 +60,7 @@ def get_inference_duration(
|
|
| 60 |
guidance_scale, guidance_scale_2, current_seed, scheduler_name, flow_shift,
|
| 61 |
frame_multiplier, quality, duration_seconds, safe_mode=False, lora_groups=None,
|
| 62 |
custom_lora_url="", custom_lora_scale=1.0, enable_prompt_relay=False,
|
| 63 |
-
relay_prompt_schedule="", noise_temperature=1.0, *args, **kwargs
|
| 64 |
):
|
| 65 |
width, height = resized_image.size
|
| 66 |
# Non-linear 3D attention memory & sequence scaling for Wan 2.2 frame count
|
|
@@ -78,7 +78,13 @@ def get_inference_duration(
|
|
| 78 |
gen_time = gen_time * 2.0
|
| 79 |
|
| 80 |
overhead = 2.0 if num_frames <= 33 else (3.0 if num_frames <= 65 else 5.0)
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
if safe_mode:
|
| 83 |
total_time = total_time * 1.25
|
| 84 |
|
|
@@ -90,7 +96,7 @@ def run_inference(
|
|
| 90 |
guidance_scale, guidance_scale_2, current_seed, scheduler_name, flow_shift,
|
| 91 |
frame_multiplier, quality, duration_seconds, safe_mode=False, lora_groups=None,
|
| 92 |
custom_lora_url="", custom_lora_scale=1.0, enable_prompt_relay=False,
|
| 93 |
-
relay_prompt_schedule="", noise_temperature=1.0, progress=gr.Progress(track_tqdm=True)
|
| 94 |
):
|
| 95 |
scheduler_class = config.SCHEDULER_MAP.get(scheduler_name)
|
| 96 |
if scheduler_class.__name__ != pipe.scheduler.config._class_name or flow_shift != pipe.scheduler.config.get("flow_shift", "shift"):
|
|
@@ -207,26 +213,46 @@ def generate_video(
|
|
| 207 |
vip_rife_enhance_face=False,
|
| 208 |
vip_password="",
|
| 209 |
cached_lora="",
|
|
|
|
| 210 |
request: gr.Request = None,
|
| 211 |
progress=gr.Progress(track_tqdm=True)
|
| 212 |
):
|
| 213 |
if input_image is None:
|
| 214 |
raise gr.Error("Please upload an input image.")
|
| 215 |
|
| 216 |
-
hf_user = "
|
|
|
|
| 217 |
if request is not None:
|
| 218 |
try:
|
| 219 |
-
if hasattr(request, "
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
request.headers.get("x-hf-user-name") or
|
| 224 |
request.headers.get("x-hf-user") or
|
| 225 |
request.headers.get("x-username") or
|
| 226 |
-
|
| 227 |
)
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
active_custom_lora = str(custom_lora_url or "").strip()
|
| 232 |
if not active_custom_lora and cached_lora and str(cached_lora).strip() != "(None / Disable)":
|
|
@@ -259,7 +285,7 @@ def generate_video(
|
|
| 259 |
guidance_scale, guidance_scale_2, current_seed, scheduler, flow_shift,
|
| 260 |
frame_multiplier, quality, duration_seconds, safe_mode, None,
|
| 261 |
active_custom_lora, custom_lora_scale, enable_prompt_relay,
|
| 262 |
-
relay_prompt_schedule, noise_temperature, progress
|
| 263 |
)
|
| 264 |
|
| 265 |
raw_frames_np, task_n, gpu_time = run_inference(
|
|
@@ -267,7 +293,7 @@ def generate_video(
|
|
| 267 |
guidance_scale, guidance_scale_2, current_seed, scheduler, flow_shift,
|
| 268 |
frame_multiplier, quality, duration_seconds, safe_mode, None,
|
| 269 |
active_custom_lora, custom_lora_scale, enable_prompt_relay,
|
| 270 |
-
relay_prompt_schedule, noise_temperature, progress
|
| 271 |
)
|
| 272 |
|
| 273 |
print(f"GPU complete: {task_n}. Release GPU lock and now processing post-processing on CPU...")
|
|
|
|
| 60 |
guidance_scale, guidance_scale_2, current_seed, scheduler_name, flow_shift,
|
| 61 |
frame_multiplier, quality, duration_seconds, safe_mode=False, lora_groups=None,
|
| 62 |
custom_lora_url="", custom_lora_scale=1.0, enable_prompt_relay=False,
|
| 63 |
+
relay_prompt_schedule="", noise_temperature=1.0, extra_gpu_buffer=0, *args, **kwargs
|
| 64 |
):
|
| 65 |
width, height = resized_image.size
|
| 66 |
# Non-linear 3D attention memory & sequence scaling for Wan 2.2 frame count
|
|
|
|
| 78 |
gen_time = gen_time * 2.0
|
| 79 |
|
| 80 |
overhead = 2.0 if num_frames <= 33 else (3.0 if num_frames <= 65 else 5.0)
|
| 81 |
+
|
| 82 |
+
# Automatically add +3 seconds overhead if custom LoRA is requested
|
| 83 |
+
cached_l = str(kwargs.get("cached_lora") or "").strip()
|
| 84 |
+
if (custom_lora_url and str(custom_lora_url).strip()) or (cached_l and cached_l != "(None / Disable)"):
|
| 85 |
+
overhead += 3.0
|
| 86 |
+
|
| 87 |
+
total_time = overhead + gen_time + float(extra_gpu_buffer or 0)
|
| 88 |
if safe_mode:
|
| 89 |
total_time = total_time * 1.25
|
| 90 |
|
|
|
|
| 96 |
guidance_scale, guidance_scale_2, current_seed, scheduler_name, flow_shift,
|
| 97 |
frame_multiplier, quality, duration_seconds, safe_mode=False, lora_groups=None,
|
| 98 |
custom_lora_url="", custom_lora_scale=1.0, enable_prompt_relay=False,
|
| 99 |
+
relay_prompt_schedule="", noise_temperature=1.0, extra_gpu_buffer=0, progress=gr.Progress(track_tqdm=True)
|
| 100 |
):
|
| 101 |
scheduler_class = config.SCHEDULER_MAP.get(scheduler_name)
|
| 102 |
if scheduler_class.__name__ != pipe.scheduler.config._class_name or flow_shift != pipe.scheduler.config.get("flow_shift", "shift"):
|
|
|
|
| 213 |
vip_rife_enhance_face=False,
|
| 214 |
vip_password="",
|
| 215 |
cached_lora="",
|
| 216 |
+
extra_gpu_buffer=0,
|
| 217 |
request: gr.Request = None,
|
| 218 |
progress=gr.Progress(track_tqdm=True)
|
| 219 |
):
|
| 220 |
if input_image is None:
|
| 221 |
raise gr.Error("Please upload an input image.")
|
| 222 |
|
| 223 |
+
hf_user = "Guest"
|
| 224 |
+
user_ip = "Unknown"
|
| 225 |
if request is not None:
|
| 226 |
try:
|
| 227 |
+
if hasattr(request, "headers") and request.headers:
|
| 228 |
+
user_ip = (
|
| 229 |
+
request.headers.get("x-forwarded-for") or
|
| 230 |
+
request.headers.get("x-real-ip") or
|
| 231 |
+
request.headers.get("cf-connecting-ip") or
|
| 232 |
+
getattr(getattr(request, "client", None), "host", "Unknown")
|
| 233 |
+
)
|
| 234 |
+
if "," in user_ip:
|
| 235 |
+
user_ip = user_ip.split(",")[0].strip()
|
| 236 |
+
|
| 237 |
+
hf_name = (
|
| 238 |
request.headers.get("x-hf-user-name") or
|
| 239 |
request.headers.get("x-hf-user") or
|
| 240 |
request.headers.get("x-username") or
|
| 241 |
+
getattr(request, "username", None)
|
| 242 |
)
|
| 243 |
+
if hf_name and str(hf_name).strip():
|
| 244 |
+
hf_user = str(hf_name).strip()
|
| 245 |
+
elif user_ip and user_ip != "Unknown":
|
| 246 |
+
hf_user = f"Guest ({user_ip})"
|
| 247 |
+
else:
|
| 248 |
+
hf_user = "Guest (Anonymous)"
|
| 249 |
+
elif hasattr(request, "username") and request.username:
|
| 250 |
+
hf_user = request.username
|
| 251 |
+
except Exception as err:
|
| 252 |
+
print(f"User identification notice: {err}")
|
| 253 |
+
|
| 254 |
+
if hf_user == "Guest" and user_ip != "Unknown":
|
| 255 |
+
hf_user = f"Guest ({user_ip})"
|
| 256 |
|
| 257 |
active_custom_lora = str(custom_lora_url or "").strip()
|
| 258 |
if not active_custom_lora and cached_lora and str(cached_lora).strip() != "(None / Disable)":
|
|
|
|
| 285 |
guidance_scale, guidance_scale_2, current_seed, scheduler, flow_shift,
|
| 286 |
frame_multiplier, quality, duration_seconds, safe_mode, None,
|
| 287 |
active_custom_lora, custom_lora_scale, enable_prompt_relay,
|
| 288 |
+
relay_prompt_schedule, noise_temperature, extra_gpu_buffer, progress, cached_lora=active_custom_lora
|
| 289 |
)
|
| 290 |
|
| 291 |
raw_frames_np, task_n, gpu_time = run_inference(
|
|
|
|
| 293 |
guidance_scale, guidance_scale_2, current_seed, scheduler, flow_shift,
|
| 294 |
frame_multiplier, quality, duration_seconds, safe_mode, None,
|
| 295 |
active_custom_lora, custom_lora_scale, enable_prompt_relay,
|
| 296 |
+
relay_prompt_schedule, noise_temperature, extra_gpu_buffer, progress
|
| 297 |
)
|
| 298 |
|
| 299 |
print(f"GPU complete: {task_n}. Release GPU lock and now processing post-processing on CPU...")
|
ui.py
CHANGED
|
@@ -83,7 +83,8 @@ def create_ui():
|
|
| 83 |
vip['vip_rife_upscale_checkbox'],
|
| 84 |
vip['vip_rife_enhance_face_checkbox'],
|
| 85 |
vip['vip_master_password_input'],
|
| 86 |
-
c1['cached_lora_dropdown']
|
|
|
|
| 87 |
]
|
| 88 |
|
| 89 |
c1['generate_button'].click(
|
|
|
|
| 83 |
vip['vip_rife_upscale_checkbox'],
|
| 84 |
vip['vip_rife_enhance_face_checkbox'],
|
| 85 |
vip['vip_master_password_input'],
|
| 86 |
+
c1['cached_lora_dropdown'],
|
| 87 |
+
c1['extra_gpu_buffer_slider']
|
| 88 |
]
|
| 89 |
|
| 90 |
c1['generate_button'].click(
|
ui_modules/column_inputs.py
CHANGED
|
@@ -120,6 +120,14 @@ def render_column_inputs():
|
|
| 120 |
value=1.0,
|
| 121 |
info="Strength of the custom LoRA effect"
|
| 122 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
with gr.Row():
|
| 124 |
download_lora_btn = gr.Button("📥 Pre-Download LoRA to Cache (CPU)", variant="secondary")
|
| 125 |
download_status_box = gr.HTML()
|
|
@@ -159,6 +167,7 @@ def render_column_inputs():
|
|
| 159 |
"cached_lora_dropdown": cached_lora_dropdown,
|
| 160 |
"custom_lora_url_input": custom_lora_url_input,
|
| 161 |
"custom_lora_scale_input": custom_lora_scale_input,
|
|
|
|
| 162 |
"safe_mode_checkbox": safe_mode_checkbox,
|
| 163 |
"generate_button": generate_button
|
| 164 |
}
|
|
|
|
| 120 |
value=1.0,
|
| 121 |
info="Strength of the custom LoRA effect"
|
| 122 |
)
|
| 123 |
+
extra_gpu_buffer_slider = gr.Slider(
|
| 124 |
+
label="⚡ Extra GPU Reservation Buffer (Seconds)",
|
| 125 |
+
minimum=0,
|
| 126 |
+
maximum=10,
|
| 127 |
+
step=1,
|
| 128 |
+
value=3,
|
| 129 |
+
info="Manually add 0-10 extra seconds to ZeroGPU time reservation for LoRA fusion & heavy processing"
|
| 130 |
+
)
|
| 131 |
with gr.Row():
|
| 132 |
download_lora_btn = gr.Button("📥 Pre-Download LoRA to Cache (CPU)", variant="secondary")
|
| 133 |
download_status_box = gr.HTML()
|
|
|
|
| 167 |
"cached_lora_dropdown": cached_lora_dropdown,
|
| 168 |
"custom_lora_url_input": custom_lora_url_input,
|
| 169 |
"custom_lora_scale_input": custom_lora_scale_input,
|
| 170 |
+
"extra_gpu_buffer_slider": extra_gpu_buffer_slider,
|
| 171 |
"safe_mode_checkbox": safe_mode_checkbox,
|
| 172 |
"generate_button": generate_button
|
| 173 |
}
|