edit csv_to_html to combine en & zh
This commit is contained in:
		
							parent
							
								
									591bae092c
								
							
						
					
					
						commit
						b151a9b672
					
				
					 2 changed files with 92 additions and 48 deletions
				
			
		| 
						 | 
					@ -1,8 +1,8 @@
 | 
				
			||||||
Index,Model,Precision,en,zh
 | 
					Index,Model,Precision,ppl_result
 | 
				
			||||||
0,Llama-2-7b-chat-hf,fp16,4.7019,
 | 
					0,Llama-2-7b-chat-hf,fp16,4.7019
 | 
				
			||||||
1,chatglm2-6b,fp16,,22.321
 | 
					1,chatglm2-6b,fp16,22.321
 | 
				
			||||||
2,chatglm3-6b,fp16,,30.1281
 | 
					2,chatglm3-6b,fp16,30.1281
 | 
				
			||||||
3,Baichuan2-7B-Chat,fp16,,10.7676
 | 
					3,Baichuan2-7B-Chat,fp16,10.7676
 | 
				
			||||||
4,mpt-7b-chat,fp16,5.7882,
 | 
					4,mpt-7b-chat,fp16,5.7882
 | 
				
			||||||
5,falcon-7b-instruct-with-patch,fp16,5.2532,
 | 
					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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		
		
			
  | 
| 
						 | 
					@ -37,8 +37,8 @@ def nonzero_min(lst):
 | 
				
			||||||
    non_zero_lst = [num for num in lst if num > 0.0]
 | 
					    non_zero_lst = [num for num in lst if num > 0.0]
 | 
				
			||||||
    return min(non_zero_lst) if non_zero_lst else None
 | 
					    return min(non_zero_lst) if non_zero_lst else None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def is_diffs_within_normal_range(diff_en, diff_zh, threshold=5.0):
 | 
					def is_diffs_within_normal_range(diff_ppl_result, threshold=5.0):
 | 
				
			||||||
    return not any(diff < (-threshold) for diff in diff_en + diff_zh if isinstance(diff, float))
 | 
					    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):
 | 
					def add_to_dict(dict, key, value):
 | 
				
			||||||
    if key not in dict:
 | 
					    if key not in dict:
 | 
				
			||||||
| 
						 | 
					@ -58,11 +58,17 @@ def create_fp16_dict(fp16_path):
 | 
				
			||||||
    fp16_dict = {}
 | 
					    fp16_dict = {}
 | 
				
			||||||
    for _, row in fp16_df.iterrows():
 | 
					    for _, row in fp16_df.iterrows():
 | 
				
			||||||
        model = row['Model']
 | 
					        model = row['Model']
 | 
				
			||||||
 | 
					        # print("I want to test the ppl_result row", row['ppl_result'])
 | 
				
			||||||
        # Formalize the data to have 2 decimal places
 | 
					        # Formalize the data to have 2 decimal places
 | 
				
			||||||
 | 
					        # fp16_dict[model] = {
 | 
				
			||||||
 | 
					        #     'en': "{:.2f}".format(row['en']),
 | 
				
			||||||
 | 
					        #     'zh': "{:.2f}".format(row['zh'])
 | 
				
			||||||
 | 
					        # }
 | 
				
			||||||
        fp16_dict[model] = {
 | 
					        fp16_dict[model] = {
 | 
				
			||||||
            'en': "{:.2f}".format(row['en']),
 | 
					            'ppl_result': "{:.2f}".format(row['ppl_result'])
 | 
				
			||||||
            'zh': "{:.2f}".format(row['zh'])
 | 
					            # 'zh': "{:.2f}".format(row['zh'])
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        # print(fp16_dict[model])
 | 
				
			||||||
    return fp16_dict
 | 
					    return fp16_dict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def calculate_percentage_difference(current, fp16):
 | 
					def calculate_percentage_difference(current, fp16):
 | 
				
			||||||
| 
						 | 
					@ -104,24 +110,30 @@ def main():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    diffs_within_normal_range = True
 | 
					    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
 | 
				
			||||||
    for task in ['en', 'zh']:
 | 
					
 | 
				
			||||||
 | 
					    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'))
 | 
					        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)
 | 
					        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 len(csv_files)>1:
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        if args.baseline_path:
 | 
					        if args.baseline_path:
 | 
				
			||||||
            previous_csv = pd.read_csv(args.baseline_path, index_col=0)
 | 
					            previous_csv = pd.read_csv(args.baseline_path, index_col=0)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            previous_csv = pd.read_csv(csv_files[1], index_col=0)
 | 
					            previous_csv = pd.read_csv(csv_files[1], index_col=0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        last_en=['']*len(latest_csv.index)
 | 
					        last_ppl_result=['']*len(latest_csv.index)
 | 
				
			||||||
        diff_en=['']*len(latest_csv.index)
 | 
					        diff_ppl_result=['']*len(latest_csv.index)
 | 
				
			||||||
        last_zh=['']*len(latest_csv.index)
 | 
					        # last_en=['']*len(latest_csv.index)
 | 
				
			||||||
        diff_zh=['']*len(latest_csv.index)
 | 
					        # diff_en=['']*len(latest_csv.index)
 | 
				
			||||||
 | 
					        # last_zh=['']*len(latest_csv.index)
 | 
				
			||||||
 | 
					        # diff_zh=['']*len(latest_csv.index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        en='en'
 | 
					        ppl_result = 'ppl_result'#en='en'
 | 
				
			||||||
        zh='zh'
 | 
					        #zh='zh'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        csv_dict = {}
 | 
					        csv_dict = {}
 | 
				
			||||||
        for csv_file in csv_files:
 | 
					        for csv_file in csv_files:
 | 
				
			||||||
| 
						 | 
					@ -129,17 +141,22 @@ def main():
 | 
				
			||||||
            for current_csv_ind,current_csv_row in current_csv.iterrows():
 | 
					            for current_csv_ind,current_csv_row in current_csv.iterrows():
 | 
				
			||||||
                current_csv_model=current_csv_row['Model'].strip()
 | 
					                current_csv_model=current_csv_row['Model'].strip()
 | 
				
			||||||
                current_csv_precision=current_csv_row['Precision'].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'
 | 
					                current_csv_model_ppl_result=current_csv_model+'-'+current_csv_precision+'-'+'ppl_result'
 | 
				
			||||||
                add_to_dict(csv_dict, current_csv_model_en, current_csv_row[en])
 | 
					                # current_csv_model_en=current_csv_model+'-'+current_csv_precision+'-'+'en'
 | 
				
			||||||
                add_to_dict(csv_dict, current_csv_model_zh, current_csv_row[zh]) 
 | 
					                # 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():
 | 
					        for latest_csv_ind,latest_csv_row in latest_csv.iterrows():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            latest_csv_model=latest_csv_row['Model'].strip()
 | 
					            latest_csv_model=latest_csv_row['Model'].strip()
 | 
				
			||||||
            latest_csv_precision=latest_csv_row['Precision'].strip()
 | 
					            latest_csv_precision=latest_csv_row['Precision'].strip()
 | 
				
			||||||
            latest_en=latest_csv_row[en]
 | 
					            latest_ppl_result=latest_csv_row[ppl_result]#latest_en=latest_csv_row[en]
 | 
				
			||||||
            latest_zh=latest_csv_row[zh]
 | 
					            print("This is the latest_ppl_result",latest_ppl_result)
 | 
				
			||||||
 | 
					            # latest_zh=latest_csv_row[zh]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            in_previous_flag=False
 | 
					            in_previous_flag=False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,40 +167,48 @@ def main():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if latest_csv_model==previous_csv_model and latest_csv_precision==previous_csv_precision:
 | 
					                if latest_csv_model==previous_csv_model and latest_csv_precision==previous_csv_precision:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    previous_en=previous_csv_row[en]
 | 
					                    previous_ppl_result=previous_csv_row[ppl_result] #previous_en=previous_csv_row[en]
 | 
				
			||||||
                    previous_zh=previous_csv_row[zh]
 | 
					                    print("This is the previous_ppl_result", previous_ppl_result)
 | 
				
			||||||
                    if previous_en > 0.0 or previous_zh > 0.0:
 | 
					                    # previous_zh=previous_csv_row[zh]
 | 
				
			||||||
                        last_en[latest_csv_ind]=previous_en
 | 
					                    if previous_ppl_result > 0.0:# or previous_zh > 0.0:
 | 
				
			||||||
                        diff_en[latest_csv_ind]=round((latest_en-previous_en)*100/previous_en,2)
 | 
					                        last_ppl_result[latest_csv_ind]=previous_ppl_result
 | 
				
			||||||
                        last_zh[latest_csv_ind]=previous_zh
 | 
					                        diff_ppl_result[latest_csv_ind]=round((latest_ppl_result-previous_ppl_result)*100/previous_ppl_result,2)
 | 
				
			||||||
                        diff_zh[latest_csv_ind]=round((latest_zh-previous_zh)*100/previous_zh,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
 | 
					                        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:
 | 
					            if not in_previous_flag:
 | 
				
			||||||
                last_en[latest_csv_ind]=pd.NA
 | 
					                last_ppl_result[latest_csv_ind]=pd.NA
 | 
				
			||||||
                diff_en[latest_csv_ind]=pd.NA
 | 
					                diff_ppl_result[latest_csv_ind]=pd.NA
 | 
				
			||||||
                last_zh[latest_csv_ind]=pd.NA
 | 
					                # last_zh[latest_csv_ind]=pd.NA
 | 
				
			||||||
                diff_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=6,column='last_ppl_result',value=last_ppl_result)
 | 
				
			||||||
        latest_csv.insert(loc=10,column='diff_en(%)',value=diff_en)
 | 
					        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=11,column='last_zh',value=last_zh)
 | 
				
			||||||
        latest_csv.insert(loc=12,column='diff_zh(%)',value=diff_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}',
 | 
					        columns={'ppl_result': '{:.2f}', 'last_ppl_result': '{:.2f}', 'last_diff_ppl_result(%)': '{:.2f}'}
 | 
				
			||||||
                'last_zh': '{:.2f}', 'diff_zh(%)': '{:.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)
 | 
					        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)
 | 
					        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(%)'])
 | 
					            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
 | 
					        # add css style to restrict width and wrap text
 | 
				
			||||||
        styled_df.set_table_styles([{
 | 
					        styled_df.set_table_styles([{
 | 
				
			||||||
            'selector': 'th, td',
 | 
					            'selector': 'th, td',
 | 
				
			||||||
| 
						 | 
					@ -195,7 +220,26 @@ def main():
 | 
				
			||||||
        with open(daily_html, 'w') as f:
 | 
					        with open(daily_html, 'w') as f:
 | 
				
			||||||
            f.write(html_output)
 | 
					            f.write(html_output)
 | 
				
			||||||
    else:
 | 
					    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:
 | 
					    if args.baseline_path and not diffs_within_normal_range:
 | 
				
			||||||
        print("The diffs are outside the normal range: %" + str(highlight_threshold))
 | 
					        print("The diffs are outside the normal range: %" + str(highlight_threshold))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue