bofenghuang commited on
Commit
dbe8f3a
·
1 Parent(s): b05c0b3
Files changed (1) hide show
  1. run_demo_multi_models.py +17 -2
run_demo_multi_models.py CHANGED
@@ -29,10 +29,24 @@ logger = logging.getLogger(__name__)
29
  logger.setLevel(logging.DEBUG)
30
 
31
  device = 0 if torch.cuda.is_available() else "cpu"
32
- logger.info(f"Model will be loaded on device {device}")
33
 
34
  cached_models = {}
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  def maybe_load_cached_pipeline(model_name):
37
  pipe = cached_models.get(model_name)
38
  if pipe is None:
@@ -50,6 +64,7 @@ def maybe_load_cached_pipeline(model_name):
50
  pipe.model.config.max_length = MAX_NEW_TOKENS + 1
51
 
52
  logger.info(f"`{model_name}` pipeline has been initialized")
 
53
 
54
  cached_models[model_name] = pipe
55
  return pipe
@@ -71,7 +86,7 @@ def transcribe(microphone, file_upload, model_name):
71
  pipe = maybe_load_cached_pipeline(model_name)
72
  text = pipe(file)["text"]
73
 
74
- logger.info(f"Transcription: {text}")
75
 
76
  return warn_output + text
77
 
 
29
  logger.setLevel(logging.DEBUG)
30
 
31
  device = 0 if torch.cuda.is_available() else "cpu"
32
+ logger.info(f"Model will be loaded on device `{device}`")
33
 
34
  cached_models = {}
35
 
36
+
37
+ def print_cuda_memory_info():
38
+ used_mem, tot_mem = torch.cuda.mem_get_info()
39
+ logger.info(f"CUDA memory info - Free: {used_mem / 1024 ** 3:.2f} Gb, used: {(tot_mem - used_mem) / 1024 ** 3:.2f} Gb, total: {tot_mem / 1024 ** 3:.2f} Gb")
40
+
41
+
42
+ def print_memory_info():
43
+ # todo
44
+ if device == "cpu":
45
+ pass
46
+ else:
47
+ print_cuda_memory_info()
48
+
49
+
50
  def maybe_load_cached_pipeline(model_name):
51
  pipe = cached_models.get(model_name)
52
  if pipe is None:
 
64
  pipe.model.config.max_length = MAX_NEW_TOKENS + 1
65
 
66
  logger.info(f"`{model_name}` pipeline has been initialized")
67
+ print_memory_info()
68
 
69
  cached_models[model_name] = pipe
70
  return pipe
 
86
  pipe = maybe_load_cached_pipeline(model_name)
87
  text = pipe(file)["text"]
88
 
89
+ logger.info(f"Transcription by `{model_name}`: {text}")
90
 
91
  return warn_output + text
92