pingnie commited on
Commit
034968f
1 Parent(s): f3caf97

add gpu info

Browse files
backend-cli.py CHANGED
@@ -6,6 +6,7 @@ import argparse
6
 
7
  import socket
8
  import random
 
9
  from datetime import datetime
10
 
11
  from src.backend.run_eval_suite import run_evaluation
@@ -16,7 +17,7 @@ from src.backend.manage_requests import EvalRequest
16
  from src.leaderboard.read_evals import EvalResult
17
 
18
  from src.envs import QUEUE_REPO, RESULTS_REPO, API
19
- from src.utils import my_snapshot_download
20
 
21
  from src.leaderboard.read_evals import get_raw_eval_results
22
 
@@ -123,7 +124,16 @@ def request_to_result_name(request: EvalRequest) -> str:
123
 
124
 
125
  def process_evaluation(task: Task, eval_request: EvalRequest, limit: Optional[int] = None) -> dict:
126
- batch_size = 4
 
 
 
 
 
 
 
 
 
127
  try:
128
  results = run_evaluation(
129
  eval_request=eval_request,
@@ -150,6 +160,14 @@ def process_evaluation(task: Task, eval_request: EvalRequest, limit: Optional[in
150
  raise
151
 
152
  # print("RESULTS", results)
 
 
 
 
 
 
 
 
153
 
154
  dumped = json.dumps(results, indent=2, default=lambda o: "<not serializable>")
155
  # print(dumped)
@@ -409,23 +427,27 @@ if __name__ == "__main__":
409
  local_debug = args.debug
410
  # debug specific task by ping
411
  if local_debug:
412
- debug_model_names = [args.model] # Use model from arguments
413
- debug_task_name = args.task # Use task from arguments
 
 
 
414
  task_lst = TASKS_HARNESS.copy()
415
- for task in task_lst:
416
- for debug_model_name in debug_model_names:
417
- task_name = task.benchmark
418
- if task_name != debug_task_name:
419
- continue
420
- eval_request = EvalRequest(
421
- model=debug_model_name,
422
- private=False,
423
- status="",
424
- json_filepath="",
425
- precision=args.precision, # Use precision from arguments
426
- inference_framework=args.inference_framework # Use inference framework from arguments
427
- )
428
- results = process_evaluation(task, eval_request, limit=args.limit)
 
429
  else:
430
  while True:
431
  res = False
 
6
 
7
  import socket
8
  import random
9
+ import threading
10
  from datetime import datetime
11
 
12
  from src.backend.run_eval_suite import run_evaluation
 
17
  from src.leaderboard.read_evals import EvalResult
18
 
19
  from src.envs import QUEUE_REPO, RESULTS_REPO, API
20
+ from src.utils import my_snapshot_download, analyze_gpu_stats, parse_nvidia_smi, monitor_gpus
21
 
22
  from src.leaderboard.read_evals import get_raw_eval_results
23
 
 
124
 
125
 
126
  def process_evaluation(task: Task, eval_request: EvalRequest, limit: Optional[int] = None) -> dict:
127
+ batch_size = eval_request.batch_size
128
+
129
+ init_gpu_info = analyze_gpu_stats(parse_nvidia_smi())
130
+ # if init_gpu_info['Mem(M)'] > 500:
131
+ # assert False, f"This machine is not empty: {init_gpu_info}"
132
+ gpu_stats_list = []
133
+ stop_event = threading.Event()
134
+ monitor_thread = threading.Thread(target=monitor_gpus, args=(stop_event, 5, gpu_stats_list))
135
+ monitor_thread.start()
136
+
137
  try:
138
  results = run_evaluation(
139
  eval_request=eval_request,
 
160
  raise
161
 
162
  # print("RESULTS", results)
163
+ stop_event.set()
164
+ monitor_thread.join()
165
+ gpu_info = analyze_gpu_stats(gpu_stats_list)
166
+ for task_name in results['results'].keys():
167
+ for key, value in gpu_info.items():
168
+ results['results'][task_name][f"{key},none"] = int(value)
169
+
170
+ print("GPU Usage:", gpu_info)
171
 
172
  dumped = json.dumps(results, indent=2, default=lambda o: "<not serializable>")
173
  # print(dumped)
 
427
  local_debug = args.debug
428
  # debug specific task by ping
429
  if local_debug:
430
+ # debug_model_names = [args.model] # Use model from arguments
431
+ # debug_task_name = [args.task] # Use task from arguments
432
+ debug_model_names = ["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x7B-v0.1"] # Use model from arguments
433
+ debug_task_name = ['mmlu', 'selfcheckgpt'] # Use task from arguments
434
+ precisions = ['float16', 'float16', '8bit']
435
  task_lst = TASKS_HARNESS.copy()
436
+ for precision in precisions:
437
+ for task in task_lst:
438
+ for debug_model_name in debug_model_names:
439
+ task_name = task.benchmark
440
+ if task_name not in debug_task_name:
441
+ continue
442
+ eval_request = EvalRequest(
443
+ model=debug_model_name,
444
+ private=False,
445
+ status="",
446
+ json_filepath="",
447
+ precision=args.precision, # Use precision from arguments
448
+ inference_framework=args.inference_framework # Use inference framework from arguments
449
+ )
450
+ results = process_evaluation(task, eval_request, limit=args.limit)
451
  else:
452
  while True:
453
  res = False
src/backend/hflm_with_measurement.py CHANGED
@@ -57,12 +57,12 @@ class StopWatch(TextStreamer):
57
  self.start_decoding = time()
58
  self.decoding_iterations += 1
59
  return
60
-
61
  def end(self):
62
  if self.decoding_time is None and self.start_decoding is not None:
63
  self.decoding_time = time() - self.start_decoding
64
  return
65
-
66
 
67
  class HFLMWithMeasurement(HFLM):
68
  def __init__(self, **kwargs):
@@ -287,7 +287,7 @@ class HFLMWithMeasurement(HFLM):
287
  pbar.close()
288
 
289
  return re_ord.get_original(res)
290
-
291
  def _model_generate(self, context, max_length, stop, **generation_kwargs):
292
  # temperature = 0.0 if not set
293
  # if do_sample is false and temp==0.0:
@@ -318,7 +318,7 @@ class HFLMWithMeasurement(HFLM):
318
  **generation_kwargs,
319
  )
320
  end = time()
321
-
322
  batch_size = context.shape[0]
323
  output_length = stop_watch.decoding_iterations
324
 
@@ -403,7 +403,7 @@ class HFLMWithMeasurement(HFLM):
403
  f"Expected `kwargs` to be of type `dict` but got {type(gen_kwargs)}"
404
  )
405
  # add EOS token to stop sequences
406
- eos = self.tok_decode(self.eot_token_id, skip_special_tokens=False)
407
  if not until:
408
  until = [eos]
409
  else:
 
57
  self.start_decoding = time()
58
  self.decoding_iterations += 1
59
  return
60
+
61
  def end(self):
62
  if self.decoding_time is None and self.start_decoding is not None:
63
  self.decoding_time = time() - self.start_decoding
64
  return
65
+
66
 
67
  class HFLMWithMeasurement(HFLM):
68
  def __init__(self, **kwargs):
 
287
  pbar.close()
288
 
289
  return re_ord.get_original(res)
290
+
291
  def _model_generate(self, context, max_length, stop, **generation_kwargs):
292
  # temperature = 0.0 if not set
293
  # if do_sample is false and temp==0.0:
 
318
  **generation_kwargs,
319
  )
320
  end = time()
321
+
322
  batch_size = context.shape[0]
323
  output_length = stop_watch.decoding_iterations
324
 
 
403
  f"Expected `kwargs` to be of type `dict` but got {type(gen_kwargs)}"
404
  )
405
  # add EOS token to stop sequences
406
+ eos = self.tok_decode(self.eot_token_id)
407
  if not until:
408
  until = [eos]
409
  else:
src/backend/manage_requests.py CHANGED
@@ -27,10 +27,11 @@ class EvalRequest:
27
  likes: Optional[int] = 0
28
  params: Optional[int] = None
29
  license: Optional[str] = ""
 
30
 
31
  def get_model_args(self) -> str:
32
  model_args = f"pretrained={self.model},revision={self.revision},parallelize=True" # ,max_length=4096"
33
-
34
  if self.precision in ["float16", "float32", "bfloat16"]:
35
  model_args += f",dtype={self.precision}"
36
  # Quantized models need some added config, the install of bits and bytes, etc
@@ -44,7 +45,6 @@ class EvalRequest:
44
  pass
45
  elif self.precision == "8bit":
46
  model_args += ",load_in_8bit=True"
47
- model_args += ",trust_remote_code=True"
48
  else:
49
  raise Exception(f"Unknown precision {self.precision}.")
50
  return model_args
 
27
  likes: Optional[int] = 0
28
  params: Optional[int] = None
29
  license: Optional[str] = ""
30
+ batch_size: Optional[int] = 1
31
 
32
  def get_model_args(self) -> str:
33
  model_args = f"pretrained={self.model},revision={self.revision},parallelize=True" # ,max_length=4096"
34
+ model_args += ",trust_remote_code=True"
35
  if self.precision in ["float16", "float32", "bfloat16"]:
36
  model_args += f",dtype={self.precision}"
37
  # Quantized models need some added config, the install of bits and bytes, etc
 
45
  pass
46
  elif self.precision == "8bit":
47
  model_args += ",load_in_8bit=True"
 
48
  else:
49
  raise Exception(f"Unknown precision {self.precision}.")
50
  return model_args
src/backend/run_eval_suite.py CHANGED
@@ -13,7 +13,7 @@ orig_higher_is_better = ConfigurableTask.higher_is_better
13
  def process_results_decorator(func):
14
  def wrapper(self, doc, results, *args, **kwargs):
15
  processed_results = [r[0] for r in results]
16
-
17
  end_to_end_time = sum([r[1] for r in results]) / len(results)
18
  prefilling_time = sum([r[2] for r in results]) / len(results)
19
  decoding_throughput = sum([r[3] for r in results]) / len(results)
 
13
  def process_results_decorator(func):
14
  def wrapper(self, doc, results, *args, **kwargs):
15
  processed_results = [r[0] for r in results]
16
+
17
  end_to_end_time = sum([r[1] for r in results]) / len(results)
18
  prefilling_time = sum([r[2] for r in results]) / len(results)
19
  decoding_throughput = sum([r[3] for r in results]) / len(results)
src/display/utils.py CHANGED
@@ -13,6 +13,11 @@ TS = "T/s" #Decoding throughput (tok/s)
13
  InFrame = "Method" #"Inference framework"
14
  MULTIPLE_CHOICEs = ["mmlu"]
15
 
 
 
 
 
 
16
  @dataclass
17
  class Task:
18
  benchmark: str
@@ -81,11 +86,16 @@ auto_eval_column_dict.append(["inference_framework", ColumnContent, ColumnConten
81
  for task in Tasks:
82
  auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
83
  # System performance metrics
84
- auto_eval_column_dict.append([f"{task.name}_end_to_end_time", ColumnContent, ColumnContent(f"{task.value.col_name}-{E2Es}", "number", True)])
85
  if task.value.benchmark in MULTIPLE_CHOICEs:
86
  continue
87
- auto_eval_column_dict.append([f"{task.name}_prefilling_time", ColumnContent, ColumnContent(f"{task.value.col_name}-{PREs}", "number", True)])
88
- auto_eval_column_dict.append([f"{task.name}_decoding_throughput", ColumnContent, ColumnContent(f"{task.value.col_name}-{TS}", "number", True)])
 
 
 
 
 
89
 
90
  # Model information
91
  auto_eval_column_dict.append(["model_type", ColumnContent, ColumnContent("Type", "str", False)])
 
13
  InFrame = "Method" #"Inference framework"
14
  MULTIPLE_CHOICEs = ["mmlu"]
15
 
16
+ GPU_TEMP = 'Temp(C)'
17
+ GPU_Power = 'Power(W)'
18
+ GPU_Mem = 'Mem(M)'
19
+ GPU_Util = 'Util(%)'
20
+
21
  @dataclass
22
  class Task:
23
  benchmark: str
 
86
  for task in Tasks:
87
  auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True)])
88
  # System performance metrics
89
+ auto_eval_column_dict.append([f"{task.name}_end_to_end_time", ColumnContent, ColumnContent(f"{task.value.col_name} {E2Es}", "number", True)])
90
  if task.value.benchmark in MULTIPLE_CHOICEs:
91
  continue
92
+ auto_eval_column_dict.append([f"{task.name}_prefilling_time", ColumnContent, ColumnContent(f"{task.value.col_name} {PREs}", "number", True)])
93
+ auto_eval_column_dict.append([f"{task.name}_decoding_throughput", ColumnContent, ColumnContent(f"{task.value.col_name} {TS}", "number", True)])
94
+
95
+ auto_eval_column_dict.append([f"{task.name}_gpu_mem", ColumnContent, ColumnContent(f"{task.value.col_name} {GPU_Mem}", "number", True)])
96
+ auto_eval_column_dict.append([f"{task.name}_gpu_power", ColumnContent, ColumnContent(f"{task.value.col_name} {GPU_Power}", "number", True)])
97
+ auto_eval_column_dict.append([f"{task.name}_gpu_temp", ColumnContent, ColumnContent(f"{task.value.col_name} {GPU_TEMP}", "number", True)])
98
+ auto_eval_column_dict.append([f"{task.name}_gpu_util", ColumnContent, ColumnContent(f"{task.value.col_name} {GPU_Util}", "number", True)])
99
 
100
  # Model information
101
  auto_eval_column_dict.append(["model_type", ColumnContent, ColumnContent("Type", "str", False)])
src/populate.py CHANGED
@@ -12,7 +12,7 @@ from src.leaderboard.read_evals import get_raw_eval_results, EvalResult, update_
12
 
13
  from src.backend.envs import Tasks as BackendTasks
14
  from src.display.utils import Tasks
15
- from src.display.utils import E2Es, PREs, TS
16
 
17
  def get_leaderboard_df(
18
  results_path: str,
@@ -52,6 +52,13 @@ def get_leaderboard_df(
52
  "decoding_throughput": f"{TS}",
53
  }
54
 
 
 
 
 
 
 
 
55
  all_data_json = []
56
  for entry in all_data_json_:
57
  new_entry = copy.deepcopy(entry)
@@ -63,6 +70,10 @@ def get_leaderboard_df(
63
  if sys_metric in entry[k]:
64
  new_entry[f"{k} {metric_namne}"] = entry[k][sys_metric]
65
 
 
 
 
 
66
  all_data_json += [new_entry]
67
 
68
  # all_data_json.append(baseline_row)
 
12
 
13
  from src.backend.envs import Tasks as BackendTasks
14
  from src.display.utils import Tasks
15
+ from src.display.utils import E2Es, PREs, TS, GPU_Mem, GPU_Power, GPU_TEMP, GPU_Util
16
 
17
  def get_leaderboard_df(
18
  results_path: str,
 
52
  "decoding_throughput": f"{TS}",
53
  }
54
 
55
+ gpu_metrics_to_name_map = {
56
+ GPU_Util: GPU_Util,
57
+ GPU_TEMP: GPU_TEMP,
58
+ GPU_Power: GPU_Power,
59
+ GPU_Mem: GPU_Mem
60
+ }
61
+
62
  all_data_json = []
63
  for entry in all_data_json_:
64
  new_entry = copy.deepcopy(entry)
 
70
  if sys_metric in entry[k]:
71
  new_entry[f"{k} {metric_namne}"] = entry[k][sys_metric]
72
 
73
+ for gpu_metric, metric_namne in gpu_metrics_to_name_map.items():
74
+ if gpu_metric in entry[k]:
75
+ new_entry[f"{k} {metric_namne}"] = entry[k][gpu_metric]
76
+
77
  all_data_json += [new_entry]
78
 
79
  # all_data_json.append(baseline_row)
src/utils.py CHANGED
@@ -1,6 +1,12 @@
1
  import pandas as pd
2
  from huggingface_hub import snapshot_download
3
-
 
 
 
 
 
 
4
 
5
  def my_snapshot_download(repo_id, revision, local_dir, repo_type, max_workers):
6
  for i in range(10):
@@ -32,3 +38,61 @@ def get_dataset_summary_table(file_path):
32
  df = df[["Category", "Benchmark", "Data Split", "Data Size", "Language"]]
33
 
34
  return df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  from huggingface_hub import snapshot_download
3
+ import subprocess
4
+ import re
5
+ try:
6
+ from src.display.utils import GPU_TEMP, GPU_Mem, GPU_Power, GPU_Util
7
+ except:
8
+ print("local debug: from display.utils")
9
+ from display.utils import GPU_TEMP, GPU_Mem, GPU_Power, GPU_Util
10
 
11
  def my_snapshot_download(repo_id, revision, local_dir, repo_type, max_workers):
12
  for i in range(10):
 
38
  df = df[["Category", "Benchmark", "Data Split", "Data Size", "Language"]]
39
 
40
  return df
41
+
42
+ def parse_nvidia_smi():
43
+ # Execute the nvidia-smi command
44
+ result = subprocess.run(['nvidia-smi'], capture_output=True, text=True)
45
+ output = result.stdout.strip()
46
+
47
+ # Initialize data storage
48
+ gpu_stats = []
49
+
50
+ # Regex to extract the relevant data for each GPU
51
+ gpu_info_pattern = re.compile(r'(\d+)C\s+P\d+\s+(\d+)W / \d+W\s+\|\s+(\d+)MiB / \d+MiB\s+\|\s+(\d+)%')
52
+ lines = output.split('\n')
53
+
54
+ for line in lines:
55
+ match = gpu_info_pattern.search(line)
56
+ if match:
57
+ temp, power_usage, mem_usage, gpu_util = map(int, match.groups())
58
+ gpu_stats.append({
59
+ GPU_TEMP: temp,
60
+ GPU_Power: power_usage,
61
+ GPU_Mem: mem_usage,
62
+ GPU_Util: gpu_util
63
+ })
64
+
65
+ gpu_stats_total = {
66
+ GPU_TEMP: 0,
67
+ GPU_Power: 0,
68
+ GPU_Mem: 0,
69
+ GPU_Util: 0
70
+ }
71
+ for gpu_stat in gpu_stats:
72
+ gpu_stats_total[GPU_TEMP] += gpu_stat[GPU_TEMP]
73
+ gpu_stats_total[GPU_Power] += gpu_stat[GPU_Power]
74
+ gpu_stats_total[GPU_Mem] += gpu_stat[GPU_Mem]
75
+ gpu_stats_total[GPU_Util] += gpu_stat[GPU_Util]
76
+
77
+ gpu_stats_total[GPU_TEMP] /= len(gpu_stats)
78
+ gpu_stats_total[GPU_Power] /= len(gpu_stats)
79
+ gpu_stats_total[GPU_Util] /= len(gpu_stats)
80
+
81
+ return [gpu_stats_total]
82
+
83
+ def monitor_gpus(stop_event, interval, stats_list):
84
+ while not stop_event.is_set():
85
+ gpu_stats = parse_nvidia_smi()
86
+ if gpu_stats:
87
+ stats_list.extend(gpu_stats)
88
+ stop_event.wait(interval)
89
+
90
+ def analyze_gpu_stats(stats_list):
91
+ if not stats_list:
92
+ return None
93
+ avg_stats = {key: sum(d[key] for d in stats_list) / len(stats_list) for key in stats_list[0]}
94
+ return avg_stats
95
+
96
+
97
+ if __name__ == "__main__":
98
+ print(analyze_gpu_stats(parse_nvidia_smi()))