char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

uvosCI: hip-quality-check: ignore spill added in bfdc32183d57f1e35bacf35c47d6311e2028bbbc (#28909)96ffdc41c

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