Update run_generator.py
Browse files- run_generator.py +52 -3
run_generator.py
CHANGED
|
@@ -32,10 +32,10 @@ def parse_args():
|
|
| 32 |
|
| 33 |
parser.add_argument("--upscale_model_name", type=str, default="None")
|
| 34 |
parser.add_argument("--upscale_model_scale", type=float, default=2.0)
|
| 35 |
-
parser.add_argument("--upscale_chunk_size", type=int, default=
|
| 36 |
parser.add_argument("--frame_rate", type=int, default=16); parser.add_argument("--interpolation", type=str, default="on")
|
| 37 |
parser.add_argument("--rife_fast_mode", type=str, default="on"); parser.add_argument("--rife_ensemble", type=str, default="on")
|
| 38 |
-
parser.add_argument("--rife_chunk_size", type=int, default=
|
| 39 |
parser.add_argument("--connect_lora_clip", type=str, default="off")
|
| 40 |
parser.add_argument("--video_encoder", type=str, default="GPU: HEVC (NVENC)"); parser.add_argument("--nvenc_cq", type=int, default=25); parser.add_argument("--nvenc_preset", type=str, default="p5"); parser.add_argument("--cpu_crf", type=int, default=19) # FFmpeg
|
| 41 |
parser.add_argument("--lora_high_1_name", type=str, default="None"); parser.add_argument("--lora_high_1_strength_model", type=float, default=1.0); parser.add_argument("--lora_high_1_strength_clip", type=float, default=1.0)
|
|
@@ -56,6 +56,14 @@ def to_bool(s: str) -> bool: return s.lower() in ['true', '1', 't', 'y', 'yes',
|
|
| 56 |
def clear_memory():
|
| 57 |
if torch.cuda.is_available(): torch.cuda.empty_cache(); torch.cuda.ipc_collect()
|
| 58 |
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
COMFYUI_BASE_PATH = '/content/ComfyUI'
|
| 60 |
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
| 61 |
try: return obj[index]
|
|
@@ -107,6 +115,10 @@ def import_custom_nodes() -> None:
|
|
| 107 |
|
| 108 |
def main():
|
| 109 |
args = parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
print("π λμμ μμ±μ μμν©λλ€ (Full Control Mode, VRAM Optimized)...\n")
|
| 111 |
|
| 112 |
# βββ μμ λ λΆλΆ: μμ μ κΈ°μ‘΄ output ν΄λ μ 리 (μ΅μ’
νμΌ μ μ§) βββ
|
|
@@ -148,6 +160,7 @@ def main():
|
|
| 148 |
pathchsageattentionkj=NODE_CLASS_MAPPINGS["PathchSageAttentionKJ"]()
|
| 149 |
|
| 150 |
# --- 1λ¨κ³: CLIP Vision λ‘μ§ μΆκ° λ° μ΄κΈ° Latent μμ± ---
|
|
|
|
| 151 |
print("\n1λ¨κ³: λ°μ΄ν° λ‘λ© λ° μ΄κΈ° Latent μμ± μ€...");
|
| 152 |
print(f" - CLIP λ‘λ©: {args.clip_name}");
|
| 153 |
cliploader_460 = cliploader.load_clip(clip_name=args.clip_name, type="wan", device="default");
|
|
@@ -196,9 +209,11 @@ def main():
|
|
| 196 |
else: print(" β οΈ (μ€μ ) LoRA CLIP μ°κ²° μ΅μ
μ΄ νμ±νλμ΄ 3λ¨κ³κΉμ§ CLIP λͺ¨λΈμ μ μ§ν©λλ€.")
|
| 197 |
print(" β¨ (μ΅μ ν) 1λ¨κ³ μλ£, μμ VAE λ° CLIP Vision λͺ¨λΈμ ν΄μ ν©λλ€.");
|
| 198 |
del vaeloader_temp, clipvisionloader_cv, clipvisionencode_cv, clip_vision_output;
|
|
|
|
| 199 |
clear_memory(); print("1λ¨κ³ μλ£.");
|
| 200 |
|
| 201 |
# --- 2λ¨κ³: High Noise (KSampler) ---
|
|
|
|
| 202 |
print(f"\n2λ¨κ³: High Noise μνλ§ μμ..."); print(f" - UNet High λ‘λ©: {args.unet_high_name}"); unetloadergguf_495 = unetloadergguf.load_unet(unet_name=args.unet_high_name); model = get_value_at_index(unetloadergguf_495, 0); clip = get_value_at_index(cliploader_460, 0) if should_keep_clip_loaded else None; model_for_patching = model;
|
| 203 |
if to_bool(args.sageattention): print(" β¨ SageAttention ν¨μΉ μ μ© μ€ (High)..."); pathchsageattentionkj_124 = pathchsageattentionkj.patch(sage_attention="auto", model=model_for_patching); model_for_patching = get_value_at_index(pathchsageattentionkj_124, 0)
|
| 204 |
if args.lora_high_common_name != "None": print(f" - H Common LoRA: {args.lora_high_common_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_high_common_name, strength_model=args.lora_high_common_strength_model, strength_clip=args.lora_high_common_strength_clip, model=model_for_patching, clip=clip)
|
|
@@ -209,9 +224,11 @@ def main():
|
|
| 209 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 210 |
ksampleradvanced_466 = ksampleradvanced.sample(add_noise="enable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_high, sampler_name=args.sampler_name_high, scheduler=args.scheduler_high, start_at_step=0, end_at_step=split_step, return_with_leftover_noise="enable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(wanimagetovideo_464, 2));
|
| 211 |
if to_bool(args.sageattention): del pathchsageattentionkj_124
|
|
|
|
| 212 |
del unetloadergguf_495, model, clip, model_for_patching, shifted_model, final_model; clear_memory(); print("2λ¨κ³ μλ£.")
|
| 213 |
|
| 214 |
# --- 3λ¨κ³: Low Noise (KSampler) ---
|
|
|
|
| 215 |
print(f"\n3λ¨κ³: Low Noise μνλ§ μμ..."); print(f" - UNet Low λ‘λ©: {args.unet_low_name}"); unetloadergguf_496 = unetloadergguf.load_unet(unet_name=args.unet_low_name); model = get_value_at_index(unetloadergguf_496, 0); clip = get_value_at_index(cliploader_460, 0) if should_keep_clip_loaded else None; model_for_patching = model;
|
| 216 |
if to_bool(args.sageattention): print(" β¨ SageAttention ν¨μΉ μ μ© μ€ (Low)..."); pathchsageattentionkj_129 = pathchsageattentionkj.patch(sage_attention="auto", model=model_for_patching); model_for_patching = get_value_at_index(pathchsageattentionkj_129, 0)
|
| 217 |
if args.lora_low_common_name != "None": print(f" - L Common LoRA: {args.lora_low_common_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_low_common_name, strength_model=args.lora_low_common_strength_model, strength_clip=args.lora_low_common_strength_clip, model=model_for_patching, clip=clip)
|
|
@@ -222,10 +239,12 @@ def main():
|
|
| 222 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 223 |
ksampleradvanced_465 = ksampleradvanced.sample(add_noise="disable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_low, sampler_name=args.sampler_name_low, scheduler=args.scheduler_low, start_at_step=split_step, end_at_step=10000, return_with_leftover_noise="disable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(ksampleradvanced_466, 0));
|
| 224 |
if to_bool(args.sageattention): del pathchsageattentionkj_129
|
|
|
|
| 225 |
if should_keep_clip_loaded: print(" β¨ (λ©λͺ¨λ¦¬) LoRA CLIP μ°κ²° μ΅μ
μ¬μ© μλ£, CLIP λͺ¨λΈμ ν΄μ ν©λλ€."); del cliploader_460
|
| 226 |
del unetloadergguf_496, model, clip, model_for_patching, shifted_model, final_model, ksampleradvanced_466, wanimagetovideo_464; clear_memory(); print("3λ¨κ³ μλ£.")
|
| 227 |
|
| 228 |
# --- 4λ¨κ³: VAE λμ½λ© ---
|
|
|
|
| 229 |
print(f"\n4λ¨κ³: VAE λμ½λ© λ° μμ μ μ₯ μ€...");
|
| 230 |
|
| 231 |
print(f" - VAE λͺ¨λΈ λ‘λ© (λμ½λ©μ©, {args.vae_weight_dtype}): {args.vae_name}");
|
|
@@ -237,9 +256,11 @@ def main():
|
|
| 237 |
|
| 238 |
vaedecode_469 = vaedecode.decode(samples=get_value_at_index(ksampleradvanced_465, 0), vae=get_value_at_index(vaeloader_461, 0));
|
| 239 |
saveimage.save_images(filename_prefix="temp/example", images=get_value_at_index(vaedecode_469, 0));
|
|
|
|
| 240 |
del ksampleradvanced_465, vaeloader_461, vaedecode_469, loadimage_88, imageresizekjv2_401; clear_memory(); print("4λ¨κ³ μλ£.")
|
| 241 |
|
| 242 |
# --- 5λ¨κ³: μ
μ€μΌμΌλ§ ---
|
|
|
|
| 243 |
combine_input_dir_for_ffmpeg = f"{COMFYUI_BASE_PATH}/output/temp"
|
| 244 |
if args.upscale_ratio > 1 or to_bool(args.upscale_keep_size):
|
| 245 |
if args.upscale_model_name == "None": print("\n5λ¨κ³: μ
μ€μΌμΌλ§ 건λλ (λͺ¨λΈμ΄ μ νλμ§ μμ).")
|
|
@@ -258,6 +279,7 @@ def main():
|
|
| 258 |
raise
|
| 259 |
print(f" - μ΄ {total_frames}κ°μ νλ μμ {chunk_size}κ° λ¨μλ‘ λΆν νμ¬ μ€νν©λλ€...")
|
| 260 |
for i in range(0, total_frames, chunk_size):
|
|
|
|
| 261 |
print(f" - λ°°μΉ μ²λ¦¬ μ€ (νλ μ {i} ~ {min(i + chunk_size, total_frames) - 1})...")
|
| 262 |
vhs_load_chunk = vhs_loadimagespath.load_images(directory=base_dir, skip_first_images=i, image_load_cap=chunk_size); loaded_images = get_value_at_index(vhs_load_chunk, 0);
|
| 263 |
if loaded_images is None: print(" - (κ²½κ³ ) 건λλΈ μ μλ μ΄λ―Έμ§κ° λ‘λλμμ΅λλ€, μ΄ λ°°μΉλ₯Ό 건λλλλ€."); continue
|
|
@@ -268,11 +290,18 @@ def main():
|
|
| 268 |
image=get_value_at_index(imageupscale_chunk, 0)
|
| 269 |
);
|
| 270 |
saveimage.save_images(filename_prefix="up/example", images=get_value_at_index(imagescale_chunk, 0));
|
|
|
|
|
|
|
|
|
|
| 271 |
del vhs_load_chunk, loaded_images, imageupscale_chunk, imagescale_chunk; clear_memory()
|
| 272 |
del upscalemodelloader_384; clear_memory(); combine_input_dir_for_ffmpeg = f"{COMFYUI_BASE_PATH}/output/up"; print("5λ¨κ³ μλ£.")
|
| 273 |
else: print("\n5λ¨κ³: μ
μ€μΌμΌλ§ 건λκΉ (λΉμ¨ 1.0).")
|
| 274 |
|
|
|
|
|
|
|
|
|
|
| 275 |
# --- 6λ¨κ³: RIFE λ° λΉλμ€ κ²°ν© ---
|
|
|
|
| 276 |
print("\n6λ¨κ³: λΉλμ€ κ²°ν© μ€λΉ μ€..."); final_frame_rate = float(args.frame_rate); ffmpeg_input_dir = combine_input_dir_for_ffmpeg
|
| 277 |
if to_bool(args.interpolation):
|
| 278 |
print(" - νλ μ λ³΄κ° (RIFE)μ νμ±νν©λλ€."); interpolated_dir = f"{COMFYUI_BASE_PATH}/output/interpolated"; source_dir = combine_input_dir_for_ffmpeg
|
|
@@ -285,6 +314,7 @@ def main():
|
|
| 285 |
print(f" - μ΄ {total_frames_rife}κ°μ νλ μμ RIFE μ²ν¬ {chunk_size}κ° λ¨μλ‘ λΆν νμ¬ μ€νν©λλ€ (Overlap μ μ©)...")
|
| 286 |
current_frame_idx = 0; is_first_chunk = True
|
| 287 |
while current_frame_idx < total_frames_rife:
|
|
|
|
| 288 |
load_from = current_frame_idx; load_cap = chunk_size
|
| 289 |
if not is_first_chunk:
|
| 290 |
load_from -= 1; load_cap += 1
|
|
@@ -309,6 +339,9 @@ def main():
|
|
| 309 |
print(f" - (Overlap) μ€λ³΅ νλ μ 1κ° μ κ±° ν μ μ₯")
|
| 310 |
images_to_save = rife_chunk_result_tensor[1:]
|
| 311 |
saveimage.save_images(filename_prefix="interpolated/example", images=images_to_save);
|
|
|
|
|
|
|
|
|
|
| 312 |
del vhs_load_chunk, loaded_images, rife_chunk_result_tensor, images_to_save; clear_memory()
|
| 313 |
current_frame_idx += chunk_size; is_first_chunk = False
|
| 314 |
ffmpeg_input_dir = interpolated_dir; final_frame_rate *= 2
|
|
@@ -325,7 +358,9 @@ def main():
|
|
| 325 |
ffmpeg_cmd.extend(["-pix_fmt", "yuv420p", "-y", output_path])
|
| 326 |
print(f" - μ€ν λͺ
λ Ήμ΄: {' '.join(ffmpeg_cmd)}")
|
| 327 |
try:
|
|
|
|
| 328 |
result = subprocess.run(ffmpeg_cmd, capture_output=True, text=True, check=True, encoding='utf-8')
|
|
|
|
| 329 |
print(" - FFmpeg μ€ν μλ£.")
|
| 330 |
except FileNotFoundError: print(" β μ€λ₯: 'ffmpeg' λͺ
λ Ήμ΄λ₯Ό μ°Ύμ μ μμ΅λλ€. μμ€ν
μ μ€μΉλμ΄ μλμ§ νμΈνμΈμ."); raise
|
| 331 |
except subprocess.CalledProcessError as e:
|
|
@@ -362,7 +397,11 @@ def main():
|
|
| 362 |
except Exception as e:
|
| 363 |
print(f"β μλ³Έ 볡μ¬λ³Έ μμ± μ€ν¨: {e}")
|
| 364 |
|
|
|
|
|
|
|
|
|
|
| 365 |
# --- 7λ¨κ³: λ‘κ·Έ νμΌ (.txt) μ μ₯ ---
|
|
|
|
| 366 |
log_file_path = f"{base}.txt"
|
| 367 |
print(f"\n7λ¨κ³: μ€μ λ‘κ·Έ νμΌ μμ± μ€ ({os.path.basename(log_file_path)})...")
|
| 368 |
try:
|
|
@@ -413,7 +452,11 @@ Video Encoder: {args.video_encoder}
|
|
| 413 |
except Exception as e:
|
| 414 |
print(f"β μ€μ λ‘κ·Έ νμΌ μμ± μ€ μ€λ₯ λ°μ: {e}")
|
| 415 |
|
|
|
|
|
|
|
|
|
|
| 416 |
# --- 8λ¨κ³: μμ
ν μ 리 (μμ²λλ‘ μμ ν΄λ 3κ°λ§ μμ ) ---
|
|
|
|
| 417 |
print("\n8λ¨κ³: μμ
ν μ 리 μμ (temp, up, interpolated ν΄λλ§ μμ )");
|
| 418 |
try:
|
| 419 |
temp_dirs = ["temp", "up", "interpolated"]
|
|
@@ -431,7 +474,13 @@ Video Encoder: {args.video_encoder}
|
|
| 431 |
print("β
μμ
ν μ 리 μλ£.")
|
| 432 |
except Exception as e:
|
| 433 |
print(f"β μμ
ν μ 리 μ€ μ€λ₯ λ°μ: {e}")
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
if __name__ == "__main__":
|
| 437 |
main()
|
|
|
|
| 32 |
|
| 33 |
parser.add_argument("--upscale_model_name", type=str, default="None")
|
| 34 |
parser.add_argument("--upscale_model_scale", type=float, default=2.0)
|
| 35 |
+
parser.add_argument("--upscale_chunk_size", type=int, default=10)
|
| 36 |
parser.add_argument("--frame_rate", type=int, default=16); parser.add_argument("--interpolation", type=str, default="on")
|
| 37 |
parser.add_argument("--rife_fast_mode", type=str, default="on"); parser.add_argument("--rife_ensemble", type=str, default="on")
|
| 38 |
+
parser.add_argument("--rife_chunk_size", type=int, default=10)
|
| 39 |
parser.add_argument("--connect_lora_clip", type=str, default="off")
|
| 40 |
parser.add_argument("--video_encoder", type=str, default="GPU: HEVC (NVENC)"); parser.add_argument("--nvenc_cq", type=int, default=25); parser.add_argument("--nvenc_preset", type=str, default="p5"); parser.add_argument("--cpu_crf", type=int, default=19) # FFmpeg
|
| 41 |
parser.add_argument("--lora_high_1_name", type=str, default="None"); parser.add_argument("--lora_high_1_strength_model", type=float, default=1.0); parser.add_argument("--lora_high_1_strength_clip", type=float, default=1.0)
|
|
|
|
| 56 |
def clear_memory():
|
| 57 |
if torch.cuda.is_available(): torch.cuda.empty_cache(); torch.cuda.ipc_collect()
|
| 58 |
gc.collect()
|
| 59 |
+
def format_duration(seconds: float) -> str:
|
| 60 |
+
if seconds < 60:
|
| 61 |
+
return f"{seconds:.1f}μ΄"
|
| 62 |
+
minutes, rem = divmod(seconds, 60)
|
| 63 |
+
if minutes < 60:
|
| 64 |
+
return f"{int(minutes)}λΆ {rem:.1f}μ΄"
|
| 65 |
+
hours, minutes = divmod(minutes, 60)
|
| 66 |
+
return f"{int(hours)}μκ° {int(minutes)}λΆ {rem:.1f}μ΄"
|
| 67 |
COMFYUI_BASE_PATH = '/content/ComfyUI'
|
| 68 |
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
| 69 |
try: return obj[index]
|
|
|
|
| 115 |
|
| 116 |
def main():
|
| 117 |
args = parse_args()
|
| 118 |
+
pipeline_start = time.perf_counter()
|
| 119 |
+
stage_timings = {}
|
| 120 |
+
upscale_batch_timings = []
|
| 121 |
+
rife_batch_timings = []
|
| 122 |
print("π λμμ μμ±μ μμν©λλ€ (Full Control Mode, VRAM Optimized)...\n")
|
| 123 |
|
| 124 |
# βββ μμ λ λΆλΆ: μμ μ κΈ°μ‘΄ output ν΄λ μ 리 (μ΅μ’
νμΌ μ μ§) βββ
|
|
|
|
| 160 |
pathchsageattentionkj=NODE_CLASS_MAPPINGS["PathchSageAttentionKJ"]()
|
| 161 |
|
| 162 |
# --- 1λ¨κ³: CLIP Vision λ‘μ§ μΆκ° λ° μ΄κΈ° Latent μμ± ---
|
| 163 |
+
stage_start = time.perf_counter()
|
| 164 |
print("\n1λ¨κ³: λ°μ΄ν° λ‘λ© λ° μ΄κΈ° Latent μμ± μ€...");
|
| 165 |
print(f" - CLIP λ‘λ©: {args.clip_name}");
|
| 166 |
cliploader_460 = cliploader.load_clip(clip_name=args.clip_name, type="wan", device="default");
|
|
|
|
| 209 |
else: print(" β οΈ (μ€μ ) LoRA CLIP μ°κ²° μ΅μ
μ΄ νμ±νλμ΄ 3λ¨κ³κΉμ§ CLIP λͺ¨λΈμ μ μ§ν©λλ€.")
|
| 210 |
print(" β¨ (μ΅μ ν) 1λ¨κ³ μλ£, μμ VAE λ° CLIP Vision λͺ¨λΈμ ν΄μ ν©λλ€.");
|
| 211 |
del vaeloader_temp, clipvisionloader_cv, clipvisionencode_cv, clip_vision_output;
|
| 212 |
+
stage_timings["step_1"] = time.perf_counter() - stage_start; print(f" [TIME] Step 1: {format_duration(stage_timings['step_1'])}")
|
| 213 |
clear_memory(); print("1λ¨κ³ μλ£.");
|
| 214 |
|
| 215 |
# --- 2λ¨κ³: High Noise (KSampler) ---
|
| 216 |
+
stage_start = time.perf_counter()
|
| 217 |
print(f"\n2λ¨κ³: High Noise μνλ§ μμ..."); print(f" - UNet High λ‘λ©: {args.unet_high_name}"); unetloadergguf_495 = unetloadergguf.load_unet(unet_name=args.unet_high_name); model = get_value_at_index(unetloadergguf_495, 0); clip = get_value_at_index(cliploader_460, 0) if should_keep_clip_loaded else None; model_for_patching = model;
|
| 218 |
if to_bool(args.sageattention): print(" β¨ SageAttention ν¨μΉ μ μ© μ€ (High)..."); pathchsageattentionkj_124 = pathchsageattentionkj.patch(sage_attention="auto", model=model_for_patching); model_for_patching = get_value_at_index(pathchsageattentionkj_124, 0)
|
| 219 |
if args.lora_high_common_name != "None": print(f" - H Common LoRA: {args.lora_high_common_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_high_common_name, strength_model=args.lora_high_common_strength_model, strength_clip=args.lora_high_common_strength_clip, model=model_for_patching, clip=clip)
|
|
|
|
| 224 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 225 |
ksampleradvanced_466 = ksampleradvanced.sample(add_noise="enable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_high, sampler_name=args.sampler_name_high, scheduler=args.scheduler_high, start_at_step=0, end_at_step=split_step, return_with_leftover_noise="enable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(wanimagetovideo_464, 2));
|
| 226 |
if to_bool(args.sageattention): del pathchsageattentionkj_124
|
| 227 |
+
stage_timings["step_2"] = time.perf_counter() - stage_start; print(f" [TIME] Step 2: {format_duration(stage_timings['step_2'])}")
|
| 228 |
del unetloadergguf_495, model, clip, model_for_patching, shifted_model, final_model; clear_memory(); print("2λ¨κ³ μλ£.")
|
| 229 |
|
| 230 |
# --- 3λ¨κ³: Low Noise (KSampler) ---
|
| 231 |
+
stage_start = time.perf_counter()
|
| 232 |
print(f"\n3λ¨κ³: Low Noise μνλ§ μμ..."); print(f" - UNet Low λ‘λ©: {args.unet_low_name}"); unetloadergguf_496 = unetloadergguf.load_unet(unet_name=args.unet_low_name); model = get_value_at_index(unetloadergguf_496, 0); clip = get_value_at_index(cliploader_460, 0) if should_keep_clip_loaded else None; model_for_patching = model;
|
| 233 |
if to_bool(args.sageattention): print(" β¨ SageAttention ν¨μΉ μ μ© μ€ (Low)..."); pathchsageattentionkj_129 = pathchsageattentionkj.patch(sage_attention="auto", model=model_for_patching); model_for_patching = get_value_at_index(pathchsageattentionkj_129, 0)
|
| 234 |
if args.lora_low_common_name != "None": print(f" - L Common LoRA: {args.lora_low_common_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_low_common_name, strength_model=args.lora_low_common_strength_model, strength_clip=args.lora_low_common_strength_clip, model=model_for_patching, clip=clip)
|
|
|
|
| 239 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 240 |
ksampleradvanced_465 = ksampleradvanced.sample(add_noise="disable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_low, sampler_name=args.sampler_name_low, scheduler=args.scheduler_low, start_at_step=split_step, end_at_step=10000, return_with_leftover_noise="disable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(ksampleradvanced_466, 0));
|
| 241 |
if to_bool(args.sageattention): del pathchsageattentionkj_129
|
| 242 |
+
stage_timings["step_3"] = time.perf_counter() - stage_start; print(f" [TIME] Step 3: {format_duration(stage_timings['step_3'])}")
|
| 243 |
if should_keep_clip_loaded: print(" β¨ (λ©λͺ¨λ¦¬) LoRA CLIP μ°κ²° μ΅μ
μ¬μ© μλ£, CLIP λͺ¨λΈμ ν΄μ ν©λλ€."); del cliploader_460
|
| 244 |
del unetloadergguf_496, model, clip, model_for_patching, shifted_model, final_model, ksampleradvanced_466, wanimagetovideo_464; clear_memory(); print("3λ¨κ³ μλ£.")
|
| 245 |
|
| 246 |
# --- 4λ¨κ³: VAE λμ½λ© ---
|
| 247 |
+
stage_start = time.perf_counter()
|
| 248 |
print(f"\n4λ¨κ³: VAE λμ½λ© λ° μμ μ μ₯ μ€...");
|
| 249 |
|
| 250 |
print(f" - VAE λͺ¨λΈ λ‘λ© (λμ½λ©μ©, {args.vae_weight_dtype}): {args.vae_name}");
|
|
|
|
| 256 |
|
| 257 |
vaedecode_469 = vaedecode.decode(samples=get_value_at_index(ksampleradvanced_465, 0), vae=get_value_at_index(vaeloader_461, 0));
|
| 258 |
saveimage.save_images(filename_prefix="temp/example", images=get_value_at_index(vaedecode_469, 0));
|
| 259 |
+
stage_timings["step_4"] = time.perf_counter() - stage_start; print(f" [TIME] Step 4: {format_duration(stage_timings['step_4'])}")
|
| 260 |
del ksampleradvanced_465, vaeloader_461, vaedecode_469, loadimage_88, imageresizekjv2_401; clear_memory(); print("4λ¨κ³ μλ£.")
|
| 261 |
|
| 262 |
# --- 5λ¨κ³: μ
μ€μΌμΌλ§ ---
|
| 263 |
+
stage_start = time.perf_counter()
|
| 264 |
combine_input_dir_for_ffmpeg = f"{COMFYUI_BASE_PATH}/output/temp"
|
| 265 |
if args.upscale_ratio > 1 or to_bool(args.upscale_keep_size):
|
| 266 |
if args.upscale_model_name == "None": print("\n5λ¨κ³: μ
μ€μΌμΌλ§ 건λλ (λͺ¨λΈμ΄ μ νλμ§ μμ).")
|
|
|
|
| 279 |
raise
|
| 280 |
print(f" - μ΄ {total_frames}κ°μ νλ μμ {chunk_size}κ° λ¨μλ‘ λΆν νμ¬ μ€νν©λλ€...")
|
| 281 |
for i in range(0, total_frames, chunk_size):
|
| 282 |
+
batch_start = time.perf_counter()
|
| 283 |
print(f" - λ°°μΉ μ²λ¦¬ μ€ (νλ μ {i} ~ {min(i + chunk_size, total_frames) - 1})...")
|
| 284 |
vhs_load_chunk = vhs_loadimagespath.load_images(directory=base_dir, skip_first_images=i, image_load_cap=chunk_size); loaded_images = get_value_at_index(vhs_load_chunk, 0);
|
| 285 |
if loaded_images is None: print(" - (κ²½κ³ ) 건λλΈ μ μλ μ΄λ―Έμ§κ° λ‘λλμμ΅λλ€, μ΄ λ°°μΉλ₯Ό 건λλλλ€."); continue
|
|
|
|
| 290 |
image=get_value_at_index(imageupscale_chunk, 0)
|
| 291 |
);
|
| 292 |
saveimage.save_images(filename_prefix="up/example", images=get_value_at_index(imagescale_chunk, 0));
|
| 293 |
+
batch_elapsed = time.perf_counter() - batch_start
|
| 294 |
+
upscale_batch_timings.append((i, min(i + chunk_size, total_frames) - 1, batch_elapsed))
|
| 295 |
+
print(f" [TIME] Upscale batch {i} ~ {min(i + chunk_size, total_frames) - 1}: {format_duration(batch_elapsed)}")
|
| 296 |
del vhs_load_chunk, loaded_images, imageupscale_chunk, imagescale_chunk; clear_memory()
|
| 297 |
del upscalemodelloader_384; clear_memory(); combine_input_dir_for_ffmpeg = f"{COMFYUI_BASE_PATH}/output/up"; print("5λ¨κ³ μλ£.")
|
| 298 |
else: print("\n5λ¨κ³: μ
μ€μΌμΌλ§ 건λκΉ (λΉμ¨ 1.0).")
|
| 299 |
|
| 300 |
+
|
| 301 |
+
stage_timings["step_5"] = time.perf_counter() - stage_start; print(f" [TIME] Step 5: {format_duration(stage_timings['step_5'])}")
|
| 302 |
+
|
| 303 |
# --- 6λ¨κ³: RIFE λ° λΉλμ€ κ²°ν© ---
|
| 304 |
+
stage_start = time.perf_counter()
|
| 305 |
print("\n6λ¨κ³: λΉλμ€ κ²°ν© μ€λΉ μ€..."); final_frame_rate = float(args.frame_rate); ffmpeg_input_dir = combine_input_dir_for_ffmpeg
|
| 306 |
if to_bool(args.interpolation):
|
| 307 |
print(" - νλ μ λ³΄κ° (RIFE)μ νμ±νν©λλ€."); interpolated_dir = f"{COMFYUI_BASE_PATH}/output/interpolated"; source_dir = combine_input_dir_for_ffmpeg
|
|
|
|
| 314 |
print(f" - μ΄ {total_frames_rife}κ°μ νλ μμ RIFE μ²ν¬ {chunk_size}κ° λ¨μλ‘ λΆν νμ¬ μ€νν©λλ€ (Overlap μ μ©)...")
|
| 315 |
current_frame_idx = 0; is_first_chunk = True
|
| 316 |
while current_frame_idx < total_frames_rife:
|
| 317 |
+
batch_start = time.perf_counter()
|
| 318 |
load_from = current_frame_idx; load_cap = chunk_size
|
| 319 |
if not is_first_chunk:
|
| 320 |
load_from -= 1; load_cap += 1
|
|
|
|
| 339 |
print(f" - (Overlap) μ€λ³΅ νλ μ 1κ° μ κ±° ν μ μ₯")
|
| 340 |
images_to_save = rife_chunk_result_tensor[1:]
|
| 341 |
saveimage.save_images(filename_prefix="interpolated/example", images=images_to_save);
|
| 342 |
+
batch_elapsed = time.perf_counter() - batch_start
|
| 343 |
+
rife_batch_timings.append((load_from, load_from + load_cap - 1, batch_elapsed))
|
| 344 |
+
print(f" [TIME] RIFE batch {load_from} ~ {load_from + load_cap - 1}: {format_duration(batch_elapsed)}")
|
| 345 |
del vhs_load_chunk, loaded_images, rife_chunk_result_tensor, images_to_save; clear_memory()
|
| 346 |
current_frame_idx += chunk_size; is_first_chunk = False
|
| 347 |
ffmpeg_input_dir = interpolated_dir; final_frame_rate *= 2
|
|
|
|
| 358 |
ffmpeg_cmd.extend(["-pix_fmt", "yuv420p", "-y", output_path])
|
| 359 |
print(f" - μ€ν λͺ
λ Ήμ΄: {' '.join(ffmpeg_cmd)}")
|
| 360 |
try:
|
| 361 |
+
ffmpeg_start = time.perf_counter()
|
| 362 |
result = subprocess.run(ffmpeg_cmd, capture_output=True, text=True, check=True, encoding='utf-8')
|
| 363 |
+
stage_timings["ffmpeg"] = time.perf_counter() - ffmpeg_start; print(f" [TIME] FFmpeg: {format_duration(stage_timings['ffmpeg'])}")
|
| 364 |
print(" - FFmpeg μ€ν μλ£.")
|
| 365 |
except FileNotFoundError: print(" β μ€λ₯: 'ffmpeg' λͺ
λ Ήμ΄λ₯Ό μ°Ύμ μ μμ΅λλ€. μμ€ν
μ μ€μΉλμ΄ μλμ§ νμΈνμΈμ."); raise
|
| 366 |
except subprocess.CalledProcessError as e:
|
|
|
|
| 397 |
except Exception as e:
|
| 398 |
print(f"β μλ³Έ 볡μ¬λ³Έ μμ± μ€ν¨: {e}")
|
| 399 |
|
| 400 |
+
|
| 401 |
+
stage_timings["step_6"] = time.perf_counter() - stage_start; print(f" [TIME] Step 6: {format_duration(stage_timings['step_6'])}")
|
| 402 |
+
|
| 403 |
# --- 7λ¨κ³: λ‘κ·Έ νμΌ (.txt) μ μ₯ ---
|
| 404 |
+
stage_start = time.perf_counter()
|
| 405 |
log_file_path = f"{base}.txt"
|
| 406 |
print(f"\n7λ¨κ³: μ€μ λ‘κ·Έ νμΌ μμ± μ€ ({os.path.basename(log_file_path)})...")
|
| 407 |
try:
|
|
|
|
| 452 |
except Exception as e:
|
| 453 |
print(f"β μ€μ λ‘κ·Έ νμΌ μμ± μ€ μ€λ₯ λ°μ: {e}")
|
| 454 |
|
| 455 |
+
|
| 456 |
+
stage_timings["step_7"] = time.perf_counter() - stage_start; print(f" [TIME] Step 7: {format_duration(stage_timings['step_7'])}")
|
| 457 |
+
|
| 458 |
# --- 8λ¨κ³: μμ
ν μ 리 (μμ²λλ‘ μμ ν΄λ 3κ°λ§ μμ ) ---
|
| 459 |
+
stage_start = time.perf_counter()
|
| 460 |
print("\n8λ¨κ³: μμ
ν μ 리 μμ (temp, up, interpolated ν΄λλ§ μμ )");
|
| 461 |
try:
|
| 462 |
temp_dirs = ["temp", "up", "interpolated"]
|
|
|
|
| 474 |
print("β
μμ
ν μ 리 μλ£.")
|
| 475 |
except Exception as e:
|
| 476 |
print(f"β μμ
ν μ 리 μ€ μ€λ₯ λ°μ: {e}")
|
| 477 |
+
stage_timings["step_8"] = time.perf_counter() - stage_start; print(f" [TIME] Step 8: {format_duration(stage_timings['step_8'])}")
|
| 478 |
+
stage_timings["total"] = time.perf_counter() - pipeline_start
|
| 479 |
+
print("\n[TIME SUMMARY]")
|
| 480 |
+
for timing_key in ["step_1", "step_2", "step_3", "step_4", "step_5", "step_6", "step_7", "step_8", "ffmpeg", "total"]:
|
| 481 |
+
if timing_key in stage_timings:
|
| 482 |
+
print(f" - {timing_key}: {format_duration(stage_timings[timing_key])}")
|
| 483 |
+
# --------------------------------------------------------
|
| 484 |
|
| 485 |
if __name__ == "__main__":
|
| 486 |
main()
|