From 591bae092c61abf166179cbc3c62758ded2de56e Mon Sep 17 00:00:00 2001 From: jenniew Date: Mon, 8 Apr 2024 19:37:51 +0800 Subject: [PATCH 01/10] combine english and chinese, remove nan --- python/llm/dev/benchmark/perplexity/make_csv.py | 8 ++++---- python/llm/dev/benchmark/perplexity/make_table.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/llm/dev/benchmark/perplexity/make_csv.py b/python/llm/dev/benchmark/perplexity/make_csv.py index 0876bec7828..426e8d539a0 100644 --- a/python/llm/dev/benchmark/perplexity/make_csv.py +++ b/python/llm/dev/benchmark/perplexity/make_csv.py @@ -35,9 +35,8 @@ def make_csv(result_dict, output_path=None): current_date = datetime.datetime.now().strftime("%Y-%m-%d") file_name = f'results_{current_date}.csv' full_path = os.path.join(output_path, file_name) if output_path else file_name - print('Writing to', full_path) file_name = full_path - headers = ["Index", "Model", "Precision", "en", "zh"] + headers = ["Index", "Model", "Precision", "ppl_result"] with open(file_name, mode='w', newline='') as csv_file: writer = csv.writer(csv_file) @@ -46,10 +45,10 @@ def make_csv(result_dict, output_path=None): for model, model_results in result_dict.items(): for precision, prec_results in model_results.items(): row = [index, model, precision] - for language in headers[3:]: + for language in ["en","zh"]: task_results = prec_results.get(language.lower(), None) if task_results is None: - row.append("") + continue else: result = task_results["results"] row.append("%.4f" % result) @@ -89,6 +88,7 @@ def main(*args): output_path = args[2] merged_results = merge_results(input_path) + make_csv(merged_results, output_path) diff --git a/python/llm/dev/benchmark/perplexity/make_table.py b/python/llm/dev/benchmark/perplexity/make_table.py index 18906b5a072..e502b5cea94 100644 --- a/python/llm/dev/benchmark/perplexity/make_table.py +++ b/python/llm/dev/benchmark/perplexity/make_table.py @@ -35,8 +35,8 @@ def make_table(result_dict): """Generate table of results.""" md_writer = MarkdownTableWriter() latex_writer = LatexTableWriter() - md_writer.headers = ["Model", "Precision", "en", "zh"] - latex_writer.headers = ["Model", "Precision", "en", "zh"] + md_writer.headers = ["Model", "Precision", "ppl_result"]#["Model", "Precision", "en", "zh"] + latex_writer.headers = ["Model", "Precision", "ppl_result"]#"en", "zh"] languages = ["en", "zh"] values = [] @@ -46,7 +46,7 @@ def make_table(result_dict): for language in languages: task_results = prec_results.get(language, None) if task_results is None: - value.append("") + continue#value.append("") else: result = task_results["results"] value.append("%.4f" % result) From b151a9b672fcdb3da4982e6a7802262d39524903 Mon Sep 17 00:00:00 2001 From: jenniew Date: Thu, 11 Apr 2024 17:35:36 +0800 Subject: [PATCH 02/10] edit csv_to_html to combine en & zh --- python/llm/test/benchmark/perplexity/fp16.csv | 16 +-- .../benchmark/perplexity/ppl_csv_to_html.py | 124 ++++++++++++------ 2 files changed, 92 insertions(+), 48 deletions(-) diff --git a/python/llm/test/benchmark/perplexity/fp16.csv b/python/llm/test/benchmark/perplexity/fp16.csv index 2b812f841fa..00915746c2d 100644 --- a/python/llm/test/benchmark/perplexity/fp16.csv +++ b/python/llm/test/benchmark/perplexity/fp16.csv @@ -1,8 +1,8 @@ -Index,Model,Precision,en,zh -0,Llama-2-7b-chat-hf,fp16,4.7019, -1,chatglm2-6b,fp16,,22.321 -2,chatglm3-6b,fp16,,30.1281 -3,Baichuan2-7B-Chat,fp16,,10.7676 -4,mpt-7b-chat,fp16,5.7882, -5,falcon-7b-instruct-with-patch,fp16,5.2532, -6,mistral-7b-v0.1,fp16,3.6597, \ No newline at end of file +Index,Model,Precision,ppl_result +0,Llama-2-7b-chat-hf,fp16,4.7019 +1,chatglm2-6b,fp16,22.321 +2,chatglm3-6b,fp16,30.1281 +3,Baichuan2-7B-Chat,fp16,10.7676 +4,mpt-7b-chat,fp16,5.7882 +5,falcon-7b-instruct-with-patch,fp16,5.2532 +6,Mistral-7B-v0.1,fp16,3.6597 diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index d1175d1966f..24efaead9bd 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -37,8 +37,8 @@ def nonzero_min(lst): non_zero_lst = [num for num in lst if num > 0.0] return min(non_zero_lst) if non_zero_lst else None -def is_diffs_within_normal_range(diff_en, diff_zh, threshold=5.0): - return not any(diff < (-threshold) for diff in diff_en + diff_zh if isinstance(diff, float)) +def is_diffs_within_normal_range(diff_ppl_result, threshold=5.0): + return not any(diff < (-threshold) for diff in diff_ppl_result + diff_ppl_result if isinstance(diff, float))#diff_en + diff_zh def add_to_dict(dict, key, value): if key not in dict: @@ -58,11 +58,17 @@ def create_fp16_dict(fp16_path): fp16_dict = {} for _, row in fp16_df.iterrows(): model = row['Model'] + # print("I want to test the ppl_result row", row['ppl_result']) # Formalize the data to have 2 decimal places + # fp16_dict[model] = { + # 'en': "{:.2f}".format(row['en']), + # 'zh': "{:.2f}".format(row['zh']) + # } fp16_dict[model] = { - 'en': "{:.2f}".format(row['en']), - 'zh': "{:.2f}".format(row['zh']) + 'ppl_result': "{:.2f}".format(row['ppl_result']) + # 'zh': "{:.2f}".format(row['zh']) } + # print(fp16_dict[model]) return fp16_dict def calculate_percentage_difference(current, fp16): @@ -104,24 +110,30 @@ def main(): diffs_within_normal_range = True - # Add display of FP16 values for each model and add percentage difference column - for task in ['en', 'zh']: + # Add display of FP16 values for each model and add percentage difference column + + for task in ['ppl_result']:#['en', 'zh']: latest_csv[f'{task}_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get(task, 'N/A')) + # print("This is the stuff I want to check",latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get(task, 'N/A') == 'N/A')) latest_csv[f'{task}_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row[task], row[f'{task}_FP16']), axis=1) + print(csv_files) if len(csv_files)>1: + if args.baseline_path: previous_csv = pd.read_csv(args.baseline_path, index_col=0) else: previous_csv = pd.read_csv(csv_files[1], index_col=0) - last_en=['']*len(latest_csv.index) - diff_en=['']*len(latest_csv.index) - last_zh=['']*len(latest_csv.index) - diff_zh=['']*len(latest_csv.index) + last_ppl_result=['']*len(latest_csv.index) + diff_ppl_result=['']*len(latest_csv.index) + # last_en=['']*len(latest_csv.index) + # diff_en=['']*len(latest_csv.index) + # last_zh=['']*len(latest_csv.index) + # diff_zh=['']*len(latest_csv.index) - en='en' - zh='zh' + ppl_result = 'ppl_result'#en='en' + #zh='zh' csv_dict = {} for csv_file in csv_files: @@ -129,17 +141,22 @@ def main(): for current_csv_ind,current_csv_row in current_csv.iterrows(): current_csv_model=current_csv_row['Model'].strip() current_csv_precision=current_csv_row['Precision'].strip() - current_csv_model_en=current_csv_model+'-'+current_csv_precision+'-'+'en' - current_csv_model_zh=current_csv_model+'-'+current_csv_precision+'-'+'zh' - add_to_dict(csv_dict, current_csv_model_en, current_csv_row[en]) - add_to_dict(csv_dict, current_csv_model_zh, current_csv_row[zh]) + + current_csv_model_ppl_result=current_csv_model+'-'+current_csv_precision+'-'+'ppl_result' + # current_csv_model_en=current_csv_model+'-'+current_csv_precision+'-'+'en' + # current_csv_model_zh=current_csv_model+'-'+current_csv_precision+'-'+'zh' + + add_to_dict(csv_dict, current_csv_model_ppl_result, current_csv_row[ppl_result]) + # add_to_dict(csv_dict, current_csv_model_en, current_csv_row[en]) + # add_to_dict(csv_dict, current_csv_model_zh, current_csv_row[zh]) for latest_csv_ind,latest_csv_row in latest_csv.iterrows(): latest_csv_model=latest_csv_row['Model'].strip() latest_csv_precision=latest_csv_row['Precision'].strip() - latest_en=latest_csv_row[en] - latest_zh=latest_csv_row[zh] + latest_ppl_result=latest_csv_row[ppl_result]#latest_en=latest_csv_row[en] + print("This is the latest_ppl_result",latest_ppl_result) + # latest_zh=latest_csv_row[zh] in_previous_flag=False @@ -150,40 +167,48 @@ def main(): if latest_csv_model==previous_csv_model and latest_csv_precision==previous_csv_precision: - previous_en=previous_csv_row[en] - previous_zh=previous_csv_row[zh] - if previous_en > 0.0 or previous_zh > 0.0: - last_en[latest_csv_ind]=previous_en - diff_en[latest_csv_ind]=round((latest_en-previous_en)*100/previous_en,2) - last_zh[latest_csv_ind]=previous_zh - diff_zh[latest_csv_ind]=round((latest_zh-previous_zh)*100/previous_zh,2) + previous_ppl_result=previous_csv_row[ppl_result] #previous_en=previous_csv_row[en] + print("This is the previous_ppl_result", previous_ppl_result) + # previous_zh=previous_csv_row[zh] + if previous_ppl_result > 0.0:# or previous_zh > 0.0: + last_ppl_result[latest_csv_ind]=previous_ppl_result + diff_ppl_result[latest_csv_ind]=round((latest_ppl_result-previous_ppl_result)*100/previous_ppl_result,2) + # last_zh[latest_csv_ind]=previous_zh + # diff_zh[latest_csv_ind]=round((latest_zh-previous_zh)*100/previous_zh,2) in_previous_flag=True + # last_en[latest_csv_ind]=previous_en + # diff_en[latest_csv_ind]=round((latest_en-previous_en)*100/previous_en,2) + # last_zh[latest_csv_ind]=previous_zh + # diff_zh[latest_csv_ind]=round((latest_zh-previous_zh)*100/previous_zh,2) + # in_previous_flag=True + if not in_previous_flag: - last_en[latest_csv_ind]=pd.NA - diff_en[latest_csv_ind]=pd.NA - last_zh[latest_csv_ind]=pd.NA - diff_zh[latest_csv_ind]=pd.NA + last_ppl_result[latest_csv_ind]=pd.NA + diff_ppl_result[latest_csv_ind]=pd.NA + # last_zh[latest_csv_ind]=pd.NA + # diff_zh[latest_csv_ind]=pd.NA - latest_csv.insert(loc=9,column='last_en',value=last_en) - latest_csv.insert(loc=10,column='diff_en(%)',value=diff_en) - latest_csv.insert(loc=11,column='last_zh',value=last_zh) - latest_csv.insert(loc=12,column='diff_zh(%)',value=diff_zh) + latest_csv.insert(loc=6,column='last_ppl_result',value=last_ppl_result) + latest_csv.insert(loc=7,column='last_diff_ppl_result(%)',value=diff_ppl_result) + # latest_csv.insert(loc=11,column='last_zh',value=last_zh) + # latest_csv.insert(loc=12,column='diff_zh(%)',value=diff_zh) - diffs_within_normal_range = is_diffs_within_normal_range(diff_en, diff_zh, threshold=highlight_threshold) + diffs_within_normal_range = is_diffs_within_normal_range(diff_ppl_result, threshold=highlight_threshold)#en, diff_zh, threshold=highlight_threshold) - subset1=['diff_en(%)','diff_zh(%)'] + subset1=['last_diff_ppl_result(%)']#['diff_en(%)','diff_zh(%)'] - columns={'en': '{:.2f}', 'zh': '{:.2f}', 'last_en': '{:.2f}', 'diff_en(%)': '{:.2f}', - 'last_zh': '{:.2f}', 'diff_zh(%)': '{:.2f}'} - + columns={'ppl_result': '{:.2f}', 'last_ppl_result': '{:.2f}', 'last_diff_ppl_result(%)': '{:.2f}'} + #{'en': '{:.2f}', 'zh': '{:.2f}', 'last_en': '{:.2f}', 'diff_en(%)': '{:.2f}', + #'last_zh': '{:.2f}', 'diff_zh(%)': '{:.2f}'} latest_csv.drop('Index', axis=1, inplace=True) styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True), subset=subset1) - for task in ['en', 'zh']: + for task in ['ppl_result']:#['en', 'zh']: styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) + # add css style to restrict width and wrap text styled_df.set_table_styles([{ 'selector': 'th, td', @@ -195,7 +220,26 @@ def main(): with open(daily_html, 'w') as f: f.write(html_output) else: - latest_csv.to_html(daily_html) + latest_csv.drop('Index', axis=1, inplace=True) + columns_sec={'ppl_result': '{:.2f}'} + #{'en': '{:.2f}', 'zh': '{:.2f}', 'last_en': '{:.2f}', 'diff_en(%)': '{:.2f}', + #'last_zh': '{:.2f}', 'diff_zh(%)': '{:.2f}'} + styled_df = latest_csv.style.format(columns_sec).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True))#, subset=subset1) + for task in ['ppl_result']:#['en', 'zh']: + styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) + + + # add css style to restrict width and wrap text + styled_df.set_table_styles([{ + 'selector': 'th, td', + 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] + }], overwrite=False) + + html_output = styled_df.set_table_attributes("border=1").to_html() + + with open(daily_html, 'w') as f: + f.write(html_output) + # latest_csv.to_html(daily_html) if args.baseline_path and not diffs_within_normal_range: print("The diffs are outside the normal range: %" + str(highlight_threshold)) From bb34c6e32520ad98c9b3415782e9ccfca505ef78 Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 13:26:36 +0800 Subject: [PATCH 03/10] Mark Color Modification --- .../benchmark/perplexity/ppl_csv_to_html.py | 178 ++++++++++-------- 1 file changed, 95 insertions(+), 83 deletions(-) diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index 24efaead9bd..ff4eafeb92b 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -28,7 +28,7 @@ def highlight_vals(val, max=3.0, color1='red', color2='green', color3='yellow', return 'background-color: %s' % color1 elif val <= -max: return 'background-color: %s' % color2 - elif val != 0.0 and not pd.isna(val) and is_last: + elif val != 0.0 and is_last: return 'background-color: %s' % color3 else: return '' @@ -38,7 +38,7 @@ def nonzero_min(lst): return min(non_zero_lst) if non_zero_lst else None def is_diffs_within_normal_range(diff_ppl_result, threshold=5.0): - return not any(diff < (-threshold) for diff in diff_ppl_result + diff_ppl_result if isinstance(diff, float))#diff_en + diff_zh + return not any(diff < (-threshold) for diff in diff_ppl_result if isinstance(diff, float)) def add_to_dict(dict, key, value): if key not in dict: @@ -58,17 +58,11 @@ def create_fp16_dict(fp16_path): fp16_dict = {} for _, row in fp16_df.iterrows(): model = row['Model'] - # print("I want to test the ppl_result row", row['ppl_result']) - # Formalize the data to have 2 decimal places - # fp16_dict[model] = { - # 'en': "{:.2f}".format(row['en']), - # 'zh': "{:.2f}".format(row['zh']) - # } + fp16_dict[model] = { 'ppl_result': "{:.2f}".format(row['ppl_result']) - # 'zh': "{:.2f}".format(row['zh']) } - # print(fp16_dict[model]) + return fp16_dict def calculate_percentage_difference(current, fp16): @@ -112,10 +106,9 @@ def main(): # Add display of FP16 values for each model and add percentage difference column - for task in ['ppl_result']:#['en', 'zh']: - latest_csv[f'{task}_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get(task, 'N/A')) - # print("This is the stuff I want to check",latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get(task, 'N/A') == 'N/A')) - latest_csv[f'{task}_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row[task], row[f'{task}_FP16']), axis=1) + task = 'ppl_result' + latest_csv[f'{task}_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get(task, 'N/A')) + latest_csv[f'{task}_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row[task], row[f'{task}_FP16']), axis=1) print(csv_files) if len(csv_files)>1: @@ -127,13 +120,8 @@ def main(): last_ppl_result=['']*len(latest_csv.index) diff_ppl_result=['']*len(latest_csv.index) - # last_en=['']*len(latest_csv.index) - # diff_en=['']*len(latest_csv.index) - # last_zh=['']*len(latest_csv.index) - # diff_zh=['']*len(latest_csv.index) - ppl_result = 'ppl_result'#en='en' - #zh='zh' + ppl_result = 'ppl_result' csv_dict = {} for csv_file in csv_files: @@ -143,20 +131,15 @@ def main(): current_csv_precision=current_csv_row['Precision'].strip() current_csv_model_ppl_result=current_csv_model+'-'+current_csv_precision+'-'+'ppl_result' - # current_csv_model_en=current_csv_model+'-'+current_csv_precision+'-'+'en' - # current_csv_model_zh=current_csv_model+'-'+current_csv_precision+'-'+'zh' add_to_dict(csv_dict, current_csv_model_ppl_result, current_csv_row[ppl_result]) - # add_to_dict(csv_dict, current_csv_model_en, current_csv_row[en]) - # add_to_dict(csv_dict, current_csv_model_zh, current_csv_row[zh]) - + for latest_csv_ind,latest_csv_row in latest_csv.iterrows(): latest_csv_model=latest_csv_row['Model'].strip() latest_csv_precision=latest_csv_row['Precision'].strip() - latest_ppl_result=latest_csv_row[ppl_result]#latest_en=latest_csv_row[en] + latest_ppl_result=latest_csv_row[ppl_result] print("This is the latest_ppl_result",latest_ppl_result) - # latest_zh=latest_csv_row[zh] in_previous_flag=False @@ -167,84 +150,113 @@ def main(): if latest_csv_model==previous_csv_model and latest_csv_precision==previous_csv_precision: - previous_ppl_result=previous_csv_row[ppl_result] #previous_en=previous_csv_row[en] + previous_ppl_result=previous_csv_row[ppl_result] print("This is the previous_ppl_result", previous_ppl_result) - # previous_zh=previous_csv_row[zh] - if previous_ppl_result > 0.0:# or previous_zh > 0.0: + + if previous_ppl_result > 0.0: last_ppl_result[latest_csv_ind]=previous_ppl_result diff_ppl_result[latest_csv_ind]=round((latest_ppl_result-previous_ppl_result)*100/previous_ppl_result,2) - # last_zh[latest_csv_ind]=previous_zh - # diff_zh[latest_csv_ind]=round((latest_zh-previous_zh)*100/previous_zh,2) in_previous_flag=True - # last_en[latest_csv_ind]=previous_en - # diff_en[latest_csv_ind]=round((latest_en-previous_en)*100/previous_en,2) - # last_zh[latest_csv_ind]=previous_zh - # diff_zh[latest_csv_ind]=round((latest_zh-previous_zh)*100/previous_zh,2) - # in_previous_flag=True - if not in_previous_flag: last_ppl_result[latest_csv_ind]=pd.NA diff_ppl_result[latest_csv_ind]=pd.NA - # last_zh[latest_csv_ind]=pd.NA - # diff_zh[latest_csv_ind]=pd.NA + latest_csv.insert(loc=6,column='last_ppl_result',value=last_ppl_result) - latest_csv.insert(loc=7,column='last_diff_ppl_result(%)',value=diff_ppl_result) - # latest_csv.insert(loc=11,column='last_zh',value=last_zh) - # latest_csv.insert(loc=12,column='diff_zh(%)',value=diff_zh) + latest_csv.insert(loc=7,column='ppl_result_diff_last(%)',value=diff_ppl_result) - diffs_within_normal_range = is_diffs_within_normal_range(diff_ppl_result, threshold=highlight_threshold)#en, diff_zh, threshold=highlight_threshold) + diffs_within_normal_range = is_diffs_within_normal_range(diff_ppl_result, threshold=highlight_threshold) - subset1=['last_diff_ppl_result(%)']#['diff_en(%)','diff_zh(%)'] + subset1='ppl_result_diff_last(%)' - columns={'ppl_result': '{:.2f}', 'last_ppl_result': '{:.2f}', 'last_diff_ppl_result(%)': '{:.2f}'} - #{'en': '{:.2f}', 'zh': '{:.2f}', 'last_en': '{:.2f}', 'diff_en(%)': '{:.2f}', - #'last_zh': '{:.2f}', 'diff_zh(%)': '{:.2f}'} + # columns will be different: columns_sec={'ppl_result': '{:.2f}'} + columns={'ppl_result': '{:.2f}', 'last_ppl_result': '{:.2f}', 'ppl_result_diff_last(%)': '{:.2f}'} + # This is the same latest_csv.drop('Index', axis=1, inplace=True) + # subset is different - styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True), subset=subset1) - for task in ['ppl_result']:#['en', 'zh']: - styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) + styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=True), subset=['ppl_result_diff_last(%)']) + styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=['ppl_result_diff_FP16(%)']) + + else: + columns={'ppl_result': '{:.2f}'} + latest_csv.drop('Index', axis=1, inplace=True) + styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=['ppl_result_diff_FP16(%)']) + + # add css style to restrict width and wrap text + styled_df.set_table_styles([{ + 'selector': 'th, td', + 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] + }], overwrite=False) + + html_output = styled_df.set_table_attributes("border=1").to_html() + + with open(daily_html, 'w') as f: + f.write(html_output) + + if args.baseline_path and not diffs_within_normal_range: + print("The diffs are outside the normal range: %" + str(highlight_threshold)) + return 1 + return 0 + +if __name__ == "__main__": + sys.exit(main()) + + - # add css style to restrict width and wrap text - styled_df.set_table_styles([{ - 'selector': 'th, td', - 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] - }], overwrite=False) - html_output = styled_df.set_table_attributes("border=1").to_html() - - with open(daily_html, 'w') as f: - f.write(html_output) - else: - latest_csv.drop('Index', axis=1, inplace=True) - columns_sec={'ppl_result': '{:.2f}'} - #{'en': '{:.2f}', 'zh': '{:.2f}', 'last_en': '{:.2f}', 'diff_en(%)': '{:.2f}', - #'last_zh': '{:.2f}', 'diff_zh(%)': '{:.2f}'} - styled_df = latest_csv.style.format(columns_sec).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True))#, subset=subset1) - for task in ['ppl_result']:#['en', 'zh']: - styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) - # add css style to restrict width and wrap text - styled_df.set_table_styles([{ - 'selector': 'th, td', - 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] - }], overwrite=False) - html_output = styled_df.set_table_attributes("border=1").to_html() + + + + + + + +# styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True), subset=subset1) + +# # These are the same: +# task = 'ppl_result' +# styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) +# # add css style to restrict width and wrap text +# styled_df.set_table_styles([{ +# 'selector': 'th, td', +# 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] +# }], overwrite=False) + +# html_output = styled_df.set_table_attributes("border=1").to_html() + +# with open(daily_html, 'w') as f: +# f.write(html_output) +# else: +# latest_csv.drop('Index', axis=1, inplace=True) +# columns_sec={'ppl_result': '{:.2f}'} +# styled_df = latest_csv.style.format(columns_sec).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True))#, subset=subset1) +# task = 'ppl_result' +# styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) + - with open(daily_html, 'w') as f: - f.write(html_output) - # latest_csv.to_html(daily_html) + +# # add css style to restrict width and wrap text +# styled_df.set_table_styles([{ +# 'selector': 'th, td', +# 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] +# }], overwrite=False) + +# html_output = styled_df.set_table_attributes("border=1").to_html() - if args.baseline_path and not diffs_within_normal_range: - print("The diffs are outside the normal range: %" + str(highlight_threshold)) - return 1 - return 0 +# with open(daily_html, 'w') as f: +# f.write(html_output) -if __name__ == "__main__": - sys.exit(main()) +# if args.baseline_path and not diffs_within_normal_range: +# print("The diffs are outside the normal range: %" + str(highlight_threshold)) +# return 1 +# return 0 + +# if __name__ == "__main__": +# sys.exit(main()) From 9bbfcaf736a0f2fcda73031842d1035df09cbae2 Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 13:30:16 +0800 Subject: [PATCH 04/10] Mark Color Modification --- .../benchmark/perplexity/ppl_csv_to_html.py | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index ff4eafeb92b..c2c18558e07 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -214,49 +214,3 @@ def main(): - - - - -# styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True), subset=subset1) - -# # These are the same: -# task = 'ppl_result' -# styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) -# # add css style to restrict width and wrap text -# styled_df.set_table_styles([{ -# 'selector': 'th, td', -# 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] -# }], overwrite=False) - -# html_output = styled_df.set_table_attributes("border=1").to_html() - -# with open(daily_html, 'w') as f: -# f.write(html_output) -# else: -# latest_csv.drop('Index', axis=1, inplace=True) -# columns_sec={'ppl_result': '{:.2f}'} -# styled_df = latest_csv.style.format(columns_sec).applymap(lambda val: highlight_vals(val, max=3.0, is_last=True))#, subset=subset1) -# task = 'ppl_result' -# styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=[f'{task}_diff_FP16(%)']) - - - -# # add css style to restrict width and wrap text -# styled_df.set_table_styles([{ -# 'selector': 'th, td', -# 'props': [('max-width', '88px'), ('word-wrap', 'break-word')] -# }], overwrite=False) - -# html_output = styled_df.set_table_attributes("border=1").to_html() - -# with open(daily_html, 'w') as f: -# f.write(html_output) - -# if args.baseline_path and not diffs_within_normal_range: -# print("The diffs are outside the normal range: %" + str(highlight_threshold)) -# return 1 -# return 0 - -# if __name__ == "__main__": -# sys.exit(main()) From cdbb1de9721e19a8a58b97a067ebf4401b147c3f Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 14:00:50 +0800 Subject: [PATCH 05/10] Mark Color Modification --- .../dev/benchmark/perplexity/make_table.py | 6 +++--- .../benchmark/perplexity/ppl_csv_to_html.py | 21 ++----------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/python/llm/dev/benchmark/perplexity/make_table.py b/python/llm/dev/benchmark/perplexity/make_table.py index e502b5cea94..7a6c84fad98 100644 --- a/python/llm/dev/benchmark/perplexity/make_table.py +++ b/python/llm/dev/benchmark/perplexity/make_table.py @@ -35,8 +35,8 @@ def make_table(result_dict): """Generate table of results.""" md_writer = MarkdownTableWriter() latex_writer = LatexTableWriter() - md_writer.headers = ["Model", "Precision", "ppl_result"]#["Model", "Precision", "en", "zh"] - latex_writer.headers = ["Model", "Precision", "ppl_result"]#"en", "zh"] + md_writer.headers = ["Model", "Precision", "ppl_result"] + latex_writer.headers = ["Model", "Precision", "ppl_result"] languages = ["en", "zh"] values = [] @@ -46,7 +46,7 @@ def make_table(result_dict): for language in languages: task_results = prec_results.get(language, None) if task_results is None: - continue#value.append("") + continue else: result = task_results["results"] value.append("%.4f" % result) diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index c2c18558e07..f00cc5d1f1e 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -106,9 +106,8 @@ def main(): # Add display of FP16 values for each model and add percentage difference column - task = 'ppl_result' - latest_csv[f'{task}_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get(task, 'N/A')) - latest_csv[f'{task}_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row[task], row[f'{task}_FP16']), axis=1) + latest_csv['ppl_result_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get('ppl_result', 'N/A')) + latest_csv['ppl_result_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row['ppl_result'], row['ppl_result_FP16']), axis=1) print(csv_files) if len(csv_files)>1: @@ -168,14 +167,9 @@ def main(): diffs_within_normal_range = is_diffs_within_normal_range(diff_ppl_result, threshold=highlight_threshold) - - subset1='ppl_result_diff_last(%)' - # columns will be different: columns_sec={'ppl_result': '{:.2f}'} columns={'ppl_result': '{:.2f}', 'last_ppl_result': '{:.2f}', 'ppl_result_diff_last(%)': '{:.2f}'} - # This is the same latest_csv.drop('Index', axis=1, inplace=True) - # subset is different styled_df = latest_csv.style.format(columns).applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=True), subset=['ppl_result_diff_last(%)']) styled_df = styled_df.applymap(lambda val: highlight_vals(val, max=highlight_threshold, is_last=False), subset=['ppl_result_diff_FP16(%)']) @@ -203,14 +197,3 @@ def main(): if __name__ == "__main__": sys.exit(main()) - - - - - - - - - - - From 1a360823cea64911b2cd538a3f83c6dd5d3db696 Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 14:13:21 +0800 Subject: [PATCH 06/10] Mofidy Typos --- python/llm/test/benchmark/perplexity/ppl_csv_to_html.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index f00cc5d1f1e..53777682c81 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -58,7 +58,7 @@ def create_fp16_dict(fp16_path): fp16_dict = {} for _, row in fp16_df.iterrows(): model = row['Model'] - + # Formalize the data to have 2 decimal places fp16_dict[model] = { 'ppl_result': "{:.2f}".format(row['ppl_result']) } @@ -111,7 +111,6 @@ def main(): print(csv_files) if len(csv_files)>1: - if args.baseline_path: previous_csv = pd.read_csv(args.baseline_path, index_col=0) else: @@ -128,9 +127,7 @@ def main(): for current_csv_ind,current_csv_row in current_csv.iterrows(): current_csv_model=current_csv_row['Model'].strip() current_csv_precision=current_csv_row['Precision'].strip() - current_csv_model_ppl_result=current_csv_model+'-'+current_csv_precision+'-'+'ppl_result' - add_to_dict(csv_dict, current_csv_model_ppl_result, current_csv_row[ppl_result]) for latest_csv_ind,latest_csv_row in latest_csv.iterrows(): @@ -138,7 +135,6 @@ def main(): latest_csv_model=latest_csv_row['Model'].strip() latest_csv_precision=latest_csv_row['Precision'].strip() latest_ppl_result=latest_csv_row[ppl_result] - print("This is the latest_ppl_result",latest_ppl_result) in_previous_flag=False @@ -150,7 +146,6 @@ def main(): if latest_csv_model==previous_csv_model and latest_csv_precision==previous_csv_precision: previous_ppl_result=previous_csv_row[ppl_result] - print("This is the previous_ppl_result", previous_ppl_result) if previous_ppl_result > 0.0: last_ppl_result[latest_csv_ind]=previous_ppl_result From 382c18e6007b3faa30a1e7a930004f86001c525f Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 14:15:48 +0800 Subject: [PATCH 07/10] Mofidy Typos --- python/llm/test/benchmark/perplexity/ppl_csv_to_html.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index 53777682c81..8543b8f417f 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -108,7 +108,6 @@ def main(): latest_csv['ppl_result_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get('ppl_result', 'N/A')) latest_csv['ppl_result_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row['ppl_result'], row['ppl_result_FP16']), axis=1) - print(csv_files) if len(csv_files)>1: if args.baseline_path: From cb594e1fc5d9573b1d5c021b6e3beeb33bf231c8 Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 14:22:09 +0800 Subject: [PATCH 08/10] Mofidy Typos --- python/llm/test/benchmark/perplexity/ppl_csv_to_html.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py index 8543b8f417f..cef18a8526d 100644 --- a/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py +++ b/python/llm/test/benchmark/perplexity/ppl_csv_to_html.py @@ -104,8 +104,7 @@ def main(): diffs_within_normal_range = True - # Add display of FP16 values for each model and add percentage difference column - + # Add display of FP16 values for each model and add percentage difference column latest_csv['ppl_result_FP16'] = latest_csv['Model'].apply(lambda model: fp16_dict.get(model, {}).get('ppl_result', 'N/A')) latest_csv['ppl_result_diff_FP16(%)'] = latest_csv.apply(lambda row: calculate_percentage_difference(row['ppl_result'], row['ppl_result_FP16']), axis=1) From 7309f1ddf98613462ab313c5b711a7308adfe6f4 Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 14:23:13 +0800 Subject: [PATCH 09/10] Mofidy Typos --- python/llm/test/benchmark/perplexity/fp16.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/llm/test/benchmark/perplexity/fp16.csv b/python/llm/test/benchmark/perplexity/fp16.csv index 00915746c2d..41c4957099c 100644 --- a/python/llm/test/benchmark/perplexity/fp16.csv +++ b/python/llm/test/benchmark/perplexity/fp16.csv @@ -5,4 +5,4 @@ Index,Model,Precision,ppl_result 3,Baichuan2-7B-Chat,fp16,10.7676 4,mpt-7b-chat,fp16,5.7882 5,falcon-7b-instruct-with-patch,fp16,5.2532 -6,Mistral-7B-v0.1,fp16,3.6597 +6,mistral-7b-v0.1,fp16,3.6597 From dd0d2df5af7c90d575b1cfc5cf78b7be9adf4054 Mon Sep 17 00:00:00 2001 From: jenniew Date: Fri, 12 Apr 2024 14:28:46 +0800 Subject: [PATCH 10/10] Change fp16.csv mistral-7b-v0.1 into Mistral-7B-v0.1 --- python/llm/test/benchmark/perplexity/fp16.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/llm/test/benchmark/perplexity/fp16.csv b/python/llm/test/benchmark/perplexity/fp16.csv index 41c4957099c..00915746c2d 100644 --- a/python/llm/test/benchmark/perplexity/fp16.csv +++ b/python/llm/test/benchmark/perplexity/fp16.csv @@ -5,4 +5,4 @@ Index,Model,Precision,ppl_result 3,Baichuan2-7B-Chat,fp16,10.7676 4,mpt-7b-chat,fp16,5.7882 5,falcon-7b-instruct-with-patch,fp16,5.2532 -6,mistral-7b-v0.1,fp16,3.6597 +6,Mistral-7B-v0.1,fp16,3.6597