harry900000 commited on
Commit
4953ce6
·
1 Parent(s): 745eaaf

fix that gpu watcher is not completely clear after generation

Browse files
Files changed (2) hide show
  1. app.py +2 -3
  2. gpu_info.py +10 -0
app.py CHANGED
@@ -9,11 +9,10 @@ from typing import List, Tuple
9
  import gradio as gr
10
  import spaces
11
 
12
- from gpu_info import watch_gpu_memory
13
 
14
  PWD = os.path.dirname(__file__)
15
  CHECKPOINTS_PATH = "/data/checkpoints"
16
- # CHECKPOINTS_PATH = os.path.join(PWD, "checkpoints")
17
  LOG_DIR = os.path.join(PWD, "logs")
18
  os.makedirs(LOG_DIR, exist_ok=True)
19
 
@@ -346,7 +345,7 @@ def generate_video(
346
  log.info(f"Time taken: {end_time - start_time} s")
347
 
348
  # stop the watcher
349
- watcher.cancel()
350
 
351
  video = videos[0]
352
 
 
9
  import gradio as gr
10
  import spaces
11
 
12
+ from gpu_info import stop_watcher, watch_gpu_memory
13
 
14
  PWD = os.path.dirname(__file__)
15
  CHECKPOINTS_PATH = "/data/checkpoints"
 
16
  LOG_DIR = os.path.join(PWD, "logs")
17
  os.makedirs(LOG_DIR, exist_ok=True)
18
 
 
345
  log.info(f"Time taken: {end_time - start_time} s")
346
 
347
  # stop the watcher
348
+ stop_watcher()
349
 
350
  video = videos[0]
351
 
gpu_info.py CHANGED
@@ -47,6 +47,16 @@ def watch_gpu_memory(interval: int = 1, callback: Callable[[List[int]], None] =
47
  return gpu_memory_watcher
48
 
49
 
 
 
 
 
 
 
 
 
 
 
50
  if __name__ == "__main__":
51
  from time import sleep
52
 
 
47
  return gpu_memory_watcher
48
 
49
 
50
+ def stop_watcher():
51
+ global gpu_memory_watcher
52
+ if gpu_memory_watcher is None:
53
+ return
54
+
55
+ gpu_memory_watcher.cancel()
56
+ del gpu_memory_watcher
57
+ gpu_memory_watcher = None
58
+
59
+
60
  if __name__ == "__main__":
61
  from time import sleep
62