nodelee733 commited on
Commit
4799078
Β·
verified Β·
1 Parent(s): 2ba15af

Update run_generator.py

Browse files
Files changed (1) hide show
  1. 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=30)
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=30)
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()