1010import sys
1111from collections .abc import Iterator , Sequence
1212from glob import glob
13- from typing import Optional , Union
13+ from typing import Any , Optional , Union
1414
1515try :
1616 import git
140140parser .add_argument ("-c" , "--compare" , help = help_c )
141141help_t = (
142142 "The tool whose data is being compared. "
143- "Either 'llama-bench' (default) or 'test-backend-ops'. "
143+ "Either 'llama-bench' or 'test-backend-ops'. "
144144 "This determines the database schema and comparison logic used."
145145)
146- parser .add_argument ("-t" , "--tool" , help = help_t , default = "llama-bench" , choices = ["llama-bench" , "test-backend-ops" ])
146+ parser .add_argument ("-t" , "--tool" , help = help_t , default = None , choices = [None , "llama-bench" , "test-backend-ops" ])
147147help_i = (
148148 "JSON/JSONL/SQLite/CSV files for comparing commits. "
149149 "Specify multiple times to use multiple input files (JSON/CSV only). "
@@ -394,7 +394,7 @@ def _get_rows_test_backend_ops(self, properties: list[str], hexsha8_baseline: st
394394
395395
396396class LlamaBenchDataSQLite3File (LlamaBenchDataSQLite3 ):
397- def __init__ (self , data_file : str , tool : str = "llama-bench" ):
397+ def __init__ (self , data_file : str , tool : Any ):
398398 super ().__init__ (tool )
399399
400400 self .connection .close ()
@@ -405,18 +405,30 @@ def __init__(self, data_file: str, tool: str = "llama-bench"):
405405 tables = self .cursor .execute ("SELECT name FROM sqlite_master WHERE type='table';" ).fetchall ()
406406 table_names = [table [0 ] for table in tables ]
407407
408- if "test_backend_ops" in table_names and tool == "test-backend-ops" :
409- self .table_name = "test_backend_ops"
410- elif "test" in table_names and tool == "llama-bench" :
411- self .table_name = "test"
412- elif "test" in table_names :
413- # Fallback to test table for backward compatibility
414- self .table_name = "test"
415- if tool == "test-backend-ops" :
416- logger .warning ("test-backend-ops tool specified but only 'test' table found. Assuming llama-bench data." )
408+ # Tool selection logic
409+ if tool is None :
410+ if "test" in table_names :
411+ self .table_name = "test"
417412 self .tool = "llama-bench"
413+ elif "test_backend_ops" in table_names :
414+ self .table_name = "test_backend_ops"
415+ self .tool = "test-backend-ops"
416+ else :
417+ raise RuntimeError (f"No suitable table found in database. Available tables: { table_names } " )
418+ elif tool == "llama-bench" :
419+ if "test" in table_names :
420+ self .table_name = "test"
421+ self .tool = "llama-bench"
422+ else :
423+ raise RuntimeError (f"Table 'test' not found for tool 'llama-bench'. Available tables: { table_names } " )
424+ elif tool == "test-backend-ops" :
425+ if "test_backend_ops" in table_names :
426+ self .table_name = "test_backend_ops"
427+ self .tool = "test-backend-ops"
428+ else :
429+ raise RuntimeError (f"Table 'test_backend_ops' not found for tool 'test-backend-ops'. Available tables: { table_names } " )
418430 else :
419- raise RuntimeError (f"No suitable table found for tool ' { tool } ' in database. Available tables : { table_names } " )
431+ raise RuntimeError (f"Unknown tool: { tool } " )
420432
421433 self ._builds_init ()
422434
0 commit comments