Zekun Wu commited on
Commit
007e487
·
1 Parent(s): ee31c61
Files changed (2) hide show
  1. app.py +3 -3
  2. model_util.py +16 -16
app.py CHANGED
@@ -40,7 +40,7 @@ def calculate_flops_hf(model_name, input_shape, access_token, bp_factor, output_
40
  model = get_mode_from_hf(model_name=model_name, library="auto", access_token=access_token)
41
  data, return_print = calculate_flops_in_hugging_space(model_name=model_name, empty_model=model,
42
  access_token=access_token, input_shape=input_shape,
43
- bp_factor=bp_factor, output_unit=output_unit)
44
  print(f"Data: {data}")
45
 
46
  total_flops = data[0]['Forward+Backward FLOPs'] * 10 ** 9 # Convert GFLOPs to FLOPs
@@ -99,10 +99,10 @@ elif calculation_method == "Hugging Face Model":
99
  input_shape = (batch_size, max_seq_length)
100
  access_token = st.text_input("Hugging Face Access Token:", "")
101
  bp_factor = st.number_input("Backward Pass Factor (BP Factor):", min_value=0.0, value=1.0, step=0.1)
102
- output_unit = st.selectbox("Output Unit:", ["auto", "MFLOPs", "GFLOPs", "TFLOPs", "PFLOPs"])
103
 
104
  if st.button("Calculate FLOPs (Hugging Face Model)"):
105
- result = calculate_flops_hf(model_name, input_shape, access_token, bp_factor, output_unit)
106
  st.write(f"Total FLOPs: {result['total_flops']:.2e} FLOPs")
107
  st.write(f"Meets high impact capabilities criteria: {result['meets_criteria']}")
108
  st.write("Detailed FLOPs Data:")
 
40
  model = get_mode_from_hf(model_name=model_name, library="auto", access_token=access_token)
41
  data, return_print = calculate_flops_in_hugging_space(model_name=model_name, empty_model=model,
42
  access_token=access_token, input_shape=input_shape,
43
+ bp_factor=bp_factor)#, output_unit=output_unit)
44
  print(f"Data: {data}")
45
 
46
  total_flops = data[0]['Forward+Backward FLOPs'] * 10 ** 9 # Convert GFLOPs to FLOPs
 
99
  input_shape = (batch_size, max_seq_length)
100
  access_token = st.text_input("Hugging Face Access Token:", "")
101
  bp_factor = st.number_input("Backward Pass Factor (BP Factor):", min_value=0.0, value=1.0, step=0.1)
102
+ #output_unit = st.selectbox("Output Unit:", ["auto", "MFLOPs", "GFLOPs", "TFLOPs", "PFLOPs"])
103
 
104
  if st.button("Calculate FLOPs (Hugging Face Model)"):
105
+ result = calculate_flops_hf(model_name, input_shape, access_token, bp_factor) #output_unit)
106
  st.write(f"Total FLOPs: {result['total_flops']:.2e} FLOPs")
107
  st.write(f"Meets high impact capabilities criteria: {result['meets_criteria']}")
108
  st.write("Detailed FLOPs Data:")
model_util.py CHANGED
@@ -15,8 +15,8 @@ def calculate_flops_in_hugging_space(model_name: str,
15
  empty_model: torch.nn.modules,
16
  access_token: str,
17
  input_shape: tuple,
18
- bp_factor: float,
19
- output_unit: str):
20
  "Calculates the FLOPs and Params usage for a model init on `meta` device"
21
 
22
  try:
@@ -35,20 +35,20 @@ def calculate_flops_in_hugging_space(model_name: str,
35
  fw_bp_flops = flops * (1.0 + bp_factor)
36
  fw_bp_macs = macs * (1.0 + bp_factor)
37
 
38
- if output_unit == "":
39
- pass
40
- elif output_unit == "auto":
41
- params = params_to_string(params, units=None, precision=3)
42
- flops = flops_to_string(flops, units=None, precision=3)
43
- macs = macs_to_string(macs, units=None, precision=3)
44
- fw_bp_flops = flops_to_string(fw_bp_flops, units=None, precision=3)
45
- fw_bp_macs = macs_to_string(fw_bp_macs, units=None, precision=3)
46
- elif output_unit == "T" or output_unit == "G" or output_unit == "M" or output_unit == "K" or output_unit == "m" or output_unit == "u":
47
- params = params_to_string(params, units=output_unit, precision=3)
48
- flops = flops_to_string(flops, units=output_unit, precision=3)
49
- macs = macs_to_string(macs, units=output_unit, precision=3)
50
- fw_bp_flops = flops_to_string(fw_bp_flops, units=output_unit, precision=3)
51
- fw_bp_macs = macs_to_string(fw_bp_macs, units=output_unit, precision=3)
52
 
53
  return_lines = return_print.split("\n")
54
  return_start = False
 
15
  empty_model: torch.nn.modules,
16
  access_token: str,
17
  input_shape: tuple,
18
+ bp_factor: float):
19
+ #output_unit: str):
20
  "Calculates the FLOPs and Params usage for a model init on `meta` device"
21
 
22
  try:
 
35
  fw_bp_flops = flops * (1.0 + bp_factor)
36
  fw_bp_macs = macs * (1.0 + bp_factor)
37
 
38
+ # if output_unit == "":
39
+ # pass
40
+ # elif output_unit == "auto":
41
+ # params = params_to_string(params, units=None, precision=3)
42
+ # flops = flops_to_string(flops, units=None, precision=3)
43
+ # macs = macs_to_string(macs, units=None, precision=3)
44
+ # fw_bp_flops = flops_to_string(fw_bp_flops, units=None, precision=3)
45
+ # fw_bp_macs = macs_to_string(fw_bp_macs, units=None, precision=3)
46
+ # elif output_unit == "T" or output_unit == "G" or output_unit == "M" or output_unit == "K" or output_unit == "m" or output_unit == "u":
47
+ # params = params_to_string(params, units=output_unit, precision=3)
48
+ # flops = flops_to_string(flops, units=output_unit, precision=3)
49
+ # macs = macs_to_string(macs, units=output_unit, precision=3)
50
+ # fw_bp_flops = flops_to_string(fw_bp_flops, units=output_unit, precision=3)
51
+ # fw_bp_macs = macs_to_string(fw_bp_macs, units=output_unit, precision=3)
52
 
53
  return_lines = return_print.split("\n")
54
  return_start = False