C4G-HKUST commited on
Commit
694fec8
·
1 Parent(s): 5cb609b

Add GPU availability check in worker process for @spaces.GPU decorator

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -577,6 +577,17 @@ def run_graio_demo(args):
577
  # 参考: https://huggingface.co/spaces/KlingTeam/LivePortrait/blob/main/app.py
578
  @spaces.GPU(duration=360)
579
  def gpu_wrapped_generate_video(*args, **kwargs):
 
 
 
 
 
 
 
 
 
 
 
580
  return generate_video(*args, **kwargs)
581
 
582
  def toggle_audio_inputs(person_num):
 
577
  # 参考: https://huggingface.co/spaces/KlingTeam/LivePortrait/blob/main/app.py
578
  @spaces.GPU(duration=360)
579
  def gpu_wrapped_generate_video(*args, **kwargs):
580
+ # 在 worker 进程中检查 GPU 可用性
581
+ try:
582
+ if torch.cuda.is_available():
583
+ # 尝试访问 GPU 以确保它已准备好
584
+ _ = torch.cuda.current_device()
585
+ logging.info(f"GPU ready in worker process: {torch.cuda.get_device_name(0)}")
586
+ else:
587
+ logging.warning("GPU not available in worker process, but continuing...")
588
+ except RuntimeError as e:
589
+ logging.warning(f"GPU initialization error in worker process: {e}. Continuing anyway...")
590
+
591
  return generate_video(*args, **kwargs)
592
 
593
  def toggle_audio_inputs(person_num):