xxyux commited on
Commit
9b4534c
1 Parent(s): 9791f0c

Update record func, add count = gr.Number.

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -4,8 +4,8 @@ import pandas as pd
4
  col=['Layer number', 'Hidden size', 'FFN Hidden size', 'Sequence length', 'Head number', 'Group number',
5
  'dp', 'tp', 'pp', 'cp', 'GPU numbers', 'Batch size', 'FP8', 'Model parameters', 'Model_states', 'Activation', 'Total']
6
 
7
- # global data
8
- table_data = pd.DataFrame(columns=col)
9
 
10
  def Get_GigaByte(memory):
11
  return memory / 1024**3
@@ -267,7 +267,7 @@ def compute_activation_memory(vocab_size, seq_length, layer_num, b, b_global, he
267
 
268
  # compute_btn.click.function
269
  def Compute_ALL_Model_memory(vocab_size, layer_num, hidden_size, ffn_size, seq_length, head_num, is_group_query, group_query_num, is_bias, act_func,
270
- dp, tp, pp, cp, is_sp, is_ip, vp, is_dist_opt, b, b_global, is_fp8, is_fp8_init, g_ty, o_ty):
271
  # get model states
272
  numParameters, weight_memory, gradient_memory, optimizer_memory, master_weight_memory, model_states_memory = Compute_Model_states(vocab_size, layer_num, hidden_size,
273
  ffn_size, head_num, is_group_query, group_query_num, is_bias, act_func, dp, tp, pp, cp, is_dist_opt, is_fp8, is_fp8_init, g_ty, o_ty)
@@ -288,11 +288,14 @@ def Compute_ALL_Model_memory(vocab_size, layer_num, hidden_size, ffn_size, seq_l
288
  Total = round(model_states_memory + activation_memory, 3)
289
 
290
  # record
291
- global table_data
292
  new_row = pd.DataFrame([[layer_num, hidden_size, ffn_size, seq_length, head_num, group_query_num, dp, tp, pp, cp, gpu_num, b, is_fp8,
293
  numParametersTotal, model_states_memory, activation_memory, Total]],
294
  columns=col)
295
- table_data = table_data._append(new_row, ignore_index=True)
 
 
 
 
296
 
297
  # return str(gpu_num), str(model_states) + " GB", str(activation) + " GB", str(total) + " GB", table_data
298
  return f"""
@@ -302,25 +305,16 @@ def Compute_ALL_Model_memory(vocab_size, layer_num, hidden_size, ffn_size, seq_l
302
  Model_states = {str(model_states_memory)} GB, \n
303
  Activation = {str(activation_memory)} GB, \n
304
  Total memory consumption = {str(Total)} GB \n
305
- """, table_data
306
 
307
- def generate_csv():
308
- # 创建示例 DataFrame
309
- df = table_data
310
-
311
  # 将 DataFrame 保存为 CSV 文件
312
  csv_filename = "data.csv"
313
- df.to_csv(csv_filename, index=False)
314
 
315
  # 返回 CSV 文件路径
316
  return csv_filename
317
 
318
- # P = P_{input} + P_{middle} +
319
- # \begin{cases}
320
- # P_{output}, & \text{if }pp = 1 \\\\
321
- # 0, & \text{if }pp > 1
322
- # \end{cases} \\\\
323
-
324
  # formula string
325
  formula = r"""
326
  > **Note**🔑: In this formula, we assume LLM training with FP32 Gradient and Optimizer state, and bias = False, Zero1 = False, SP = True.
@@ -491,18 +485,19 @@ with gr.Blocks() as demo:
491
  label="Record Table",
492
  headers=col
493
  )
494
-
495
  compute_btn.click(
496
  fn=Compute_ALL_Model_memory,
497
  inputs=[vocab_size, layer_num, hidden_size, ffn_size, sequence_len, head_num, is_group_query, group_query_num, is_bias, act_func,
498
- dp, tp, pp, cp, is_sp, is_ip, vp, is_dist_opt, b, b_global, is_fp8, is_fp8_init, g_ty, o_ty],
499
- outputs=[output_text, record_df]
500
  )
501
 
502
  output_file=gr.File(label="When you click the download button, the downloaded form will be displayed here.")
503
  # download func
504
  download_btn.click(
505
  fn=generate_csv,
 
506
  outputs=output_file
507
  )
508
 
 
4
  col=['Layer number', 'Hidden size', 'FFN Hidden size', 'Sequence length', 'Head number', 'Group number',
5
  'dp', 'tp', 'pp', 'cp', 'GPU numbers', 'Batch size', 'FP8', 'Model parameters', 'Model_states', 'Activation', 'Total']
6
 
7
+ # # global data
8
+ # table_data = pd.DataFrame(columns=col)
9
 
10
  def Get_GigaByte(memory):
11
  return memory / 1024**3
 
267
 
268
  # compute_btn.click.function
269
  def Compute_ALL_Model_memory(vocab_size, layer_num, hidden_size, ffn_size, seq_length, head_num, is_group_query, group_query_num, is_bias, act_func,
270
+ dp, tp, pp, cp, is_sp, is_ip, vp, is_dist_opt, b, b_global, is_fp8, is_fp8_init, g_ty, o_ty, record_df, count):
271
  # get model states
272
  numParameters, weight_memory, gradient_memory, optimizer_memory, master_weight_memory, model_states_memory = Compute_Model_states(vocab_size, layer_num, hidden_size,
273
  ffn_size, head_num, is_group_query, group_query_num, is_bias, act_func, dp, tp, pp, cp, is_dist_opt, is_fp8, is_fp8_init, g_ty, o_ty)
 
288
  Total = round(model_states_memory + activation_memory, 3)
289
 
290
  # record
 
291
  new_row = pd.DataFrame([[layer_num, hidden_size, ffn_size, seq_length, head_num, group_query_num, dp, tp, pp, cp, gpu_num, b, is_fp8,
292
  numParametersTotal, model_states_memory, activation_memory, Total]],
293
  columns=col)
294
+ if count == 1:
295
+ record_df = new_row
296
+ else:
297
+ record_df = record_df._append(new_row, ignore_index=True)
298
+ count = count + 1
299
 
300
  # return str(gpu_num), str(model_states) + " GB", str(activation) + " GB", str(total) + " GB", table_data
301
  return f"""
 
305
  Model_states = {str(model_states_memory)} GB, \n
306
  Activation = {str(activation_memory)} GB, \n
307
  Total memory consumption = {str(Total)} GB \n
308
+ """, record_df, count
309
 
310
+ def generate_csv(record_df):
 
 
 
311
  # 将 DataFrame 保存为 CSV 文件
312
  csv_filename = "data.csv"
313
+ record_df.to_csv(csv_filename, index=False)
314
 
315
  # 返回 CSV 文件路径
316
  return csv_filename
317
 
 
 
 
 
 
 
318
  # formula string
319
  formula = r"""
320
  > **Note**🔑: In this formula, we assume LLM training with FP32 Gradient and Optimizer state, and bias = False, Zero1 = False, SP = True.
 
485
  label="Record Table",
486
  headers=col
487
  )
488
+ count = gr.Number(label="Row count", value=1, visible=False)
489
  compute_btn.click(
490
  fn=Compute_ALL_Model_memory,
491
  inputs=[vocab_size, layer_num, hidden_size, ffn_size, sequence_len, head_num, is_group_query, group_query_num, is_bias, act_func,
492
+ dp, tp, pp, cp, is_sp, is_ip, vp, is_dist_opt, b, b_global, is_fp8, is_fp8_init, g_ty, o_ty, record_df, count],
493
+ outputs=[output_text, record_df, count]
494
  )
495
 
496
  output_file=gr.File(label="When you click the download button, the downloaded form will be displayed here.")
497
  # download func
498
  download_btn.click(
499
  fn=generate_csv,
500
+ inputs=record_df,
501
  outputs=output_file
502
  )
503