char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
96ffdc41c
char/aliceai-t5-moe
1#!/usr/bin/env python3 2 3import sys 4from collections import defaultdict 5import re 6 7 8def parse_log_file (filepath ): 9functions = defaultdict (lambda : {'vgprs' :0 ,'spill' :0 ,'location' :'' }) 10func_stack = [] 11 12try : 13with open (filepath ,'r' )as f : 14for line in f : 15# Match function name lines 16func_match = re .search (r'remark: ([^:]+):(\d+):\d+: Function Name: (\S+)' ,line ) 17if func_match : 18location = func_match .group (1 )+ ':' + func_match .group (2 ) 19func_name = func_match .group (3 ) 20# Extract just the filename and line number 21parts = location .split ('/' ) 22short_location = parts [- 1 ]if len (parts )> 0 else location 23functions [func_name ]['location' ]= short_location 24# Push function onto stack with its location 25func_stack .append ({'name' :func_name ,'location' :location }) 26continue 27 28# Match VGPR usage lines (only if we have functions in stack) 29vgpr_match = re .search (r'remark: ([^:]+):(\d+):\d+:\s+VGPRs: (\d+)' ,line ) 30if vgpr_match : 31location = vgpr_match .group (1 )+ ':' + vgpr_match .group (2 ) 32# Find the most recent function with matching location 33for i in range (len (func_stack )- 1 ,- 1 ,- 1 ): 34if func_stack [i ]['location' ]== location : 35functions [func_stack [i ]['name' ]]['vgprs' ]= int (vgpr_match .group (3 )) 36break 37continue 38 39spill_match = re .search (r'remark: ([^:]+):(\d+):\d+:\s+VGPRs Spill: (\d+)' ,line ) 40if spill_match : 41location = spill_match .group (1 )+ ':' + spill_match .group (2 ) 42# Find the most recent function with matching location 43for i in range (len (func_stack )- 1 ,- 1 ,- 1 ): 44if func_stack [i ]['location' ]== location : 45functions [func_stack [i ]['name' ]]['spill' ]= int (spill_match .group (3 )) 46break 47continue 48except FileNotFoundError : 49f"Error: File { filepath } not found" ,file = sys .stderr )# noqa: NP100 50sys .exit (1 ) 51 52return functions 53 54 55def main (): 56if len (sys .argv )< 2 : 57"Usage: ./vgpr_check.py <log_file>" ,file = sys .stderr )# noqa: NP100 58sys .exit (1 ) 59 60log_file = sys .argv [1 ] 61ignored = { 62'_ZL21gated_linear_attn_f32ILi128EEviiiifPKfS1_S1_S1_S1_Pf' , 63'_ZL13rwkv_wkv7_f32ILi128EEviiiiPKfS1_S1_S1_S1_S1_S1_Pf' , 64'_ZL12rwkv_wkv_f32ILi128EEviiiiPKfS1_S1_S1_S1_S1_Pf' , 65'_ZL9mul_mat_qIL9ggml_type10ELi64ELb1EEvPKcPKiS4_S4_PfS5_PKf15HIP_vector_typeIjLj3EEiiiiiS9_S9_iiiS9_S9_iiiS9_' , 66'_ZL9mul_mat_qIL9ggml_type42ELi128ELb1EEvPKcPKiS4_S4_PfS5_PKf15HIP_vector_typeIjLj3EEiiiiiS9_S9_iiiS9_S9_iiiS9_' , 67'_ZL18flash_attn_ext_f16ILi576ELi512ELi2ELi32ELb0ELb1ELb0EEvPKcS1_S1_S1_S1_PKiPfP15HIP_vector_typeIfLj2EEffffjfiS5_IjLj3EEiiiiiiiiiiiliiliiiiil' 68 } 69 70functions = parse_log_file (log_file ) 71found_issues = False 72 73# First print all ignored functions (deduplicated) 74printed_ignored = set () 75for func_name ,data in sorted (functions .items ()): 76total_vgprs = int (data ['vgprs' ])+ int (data ['spill' ]) 77if total_vgprs > 256 and func_name in ignored and func_name not in printed_ignored : 78location = data .get ('location' ,log_file ) 79f" { location } : { func_name } - Total VGPRs: { total_vgprs } ( { data [ 'vgprs' ] } + { data [ 'spill' ] } ) [IGNORED]" )# noqa: NP100 80printed_ignored .add (func_name ) 81 82# Then print new functions with issues in red 83for func_name ,data in sorted (functions .items ()): 84total_vgprs = int (data ['vgprs' ])+ int (data ['spill' ]) 85if total_vgprs > 256 and func_name not in ignored : 86status = "[IGNORED]" if func_name in ignored else "" 87location = data .get ('location' ,log_file ) 88# Print in red if not ignored 89color_code = "\033[91m" if func_name not in ignored else "" 90reset_code = "\033[0m" if func_name not in ignored else "" 91f" { color_code } { location } : { func_name } - Total VGPRs: { total_vgprs } ( { data [ 'vgprs' ] } + { data [ 'spill' ] } ) { status } { reset_code } " )# noqa: NP100 92if func_name not in ignored : 93found_issues = True 94 95sys .exit (1 if found_issues else 0 ) 96 97 98if __name__ == "__main__" : 99main ()