|
| 1 | +import importlib |
| 2 | +import sys |
| 3 | +import inspect |
| 4 | +import datetime |
| 5 | + |
| 6 | +def check_function_exists(module_path, function_name): |
| 7 | + try: |
| 8 | + module = importlib.import_module(module_path) |
| 9 | + if hasattr(module, function_name): |
| 10 | + function = getattr(module, function_name) |
| 11 | + # Get function signature if possible |
| 12 | + try: |
| 13 | + signature = str(inspect.signature(function)) |
| 14 | + return True, signature |
| 15 | + except (ValueError, TypeError): |
| 16 | + # If we can't get signature, just return that it exists |
| 17 | + return True, "Unable to determine signature" |
| 18 | + else: |
| 19 | + return False, None |
| 20 | + except ImportError: |
| 21 | + return False, None |
| 22 | + except Exception as e: |
| 23 | + print(f"Error checking {module_path}.{function_name}: {e}") |
| 24 | + return False, None |
| 25 | + |
| 26 | +# List of functions to check |
| 27 | +functions_to_check = [ |
| 28 | + ("aiter.fused_moe_bf16_asm", "moe_sorting_ck"), |
| 29 | + ("aiter.fused_moe_bf16_asm", "asm_moe"), |
| 30 | + ("aiter.fused_moe_bf16_asm", "ck_moe_2stages") |
| 31 | +] |
| 32 | + |
| 33 | +# Check each function |
| 34 | +missing_functions = [] |
| 35 | +changed_functions = [] |
| 36 | +unchanged_functions = [] |
| 37 | + |
| 38 | +# Load previous signatures if available |
| 39 | +previous_signatures = {} |
| 40 | +try: |
| 41 | + with open("function_signatures.txt", "r") as f: |
| 42 | + for line in f: |
| 43 | + if line.strip(): |
| 44 | + parts = line.strip().split(" | ") |
| 45 | + if len(parts) == 3: |
| 46 | + func_path, func_name, signature = parts |
| 47 | + previous_signatures[f"{func_path}.{func_name}"] = signature |
| 48 | +except FileNotFoundError: |
| 49 | + # No previous signatures file |
| 50 | + pass |
| 51 | + |
| 52 | +# Check current functions and compare with previous state |
| 53 | +current_signatures = {} |
| 54 | +for module_path, function_name in functions_to_check: |
| 55 | + full_path = f"{module_path}.{function_name}" |
| 56 | + exists, signature = check_function_exists(module_path, function_name) |
| 57 | + |
| 58 | + if exists: |
| 59 | + current_signatures[full_path] = signature if signature else "Unknown" |
| 60 | + |
| 61 | + if full_path in previous_signatures: |
| 62 | + if previous_signatures[full_path] != signature: |
| 63 | + changed_functions.append((full_path, previous_signatures[full_path], signature)) |
| 64 | + else: |
| 65 | + unchanged_functions.append(full_path) |
| 66 | + else: |
| 67 | + # First time seeing this function |
| 68 | + unchanged_functions.append(full_path) |
| 69 | + else: |
| 70 | + missing_functions.append(full_path) |
| 71 | + |
| 72 | +# Save current signatures for future comparison |
| 73 | +with open("function_signatures.txt", "w") as f: |
| 74 | + for module_path, function_name in functions_to_check: |
| 75 | + full_path = f"{module_path}.{function_name}" |
| 76 | + if full_path in current_signatures: |
| 77 | + f.write(f"{module_path} | {function_name} | {current_signatures[full_path]}\n") |
| 78 | + |
| 79 | +# Report results |
| 80 | +print(f"API Check Report - {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") |
| 81 | +print("=" * 60) |
| 82 | + |
| 83 | +if not missing_functions and not changed_functions: |
| 84 | + print("✅ All functions exist and signatures are unchanged.") |
| 85 | + print("\nFunctions checked:") |
| 86 | + for func in unchanged_functions: |
| 87 | + print(f"- {func}: {current_signatures.get(func, 'Unknown')}") |
| 88 | + sys.exit(0) |
| 89 | +else: |
| 90 | + print("⚠️ API CHANGES DETECTED") |
| 91 | + print("\nDetails:") |
| 92 | + |
| 93 | + if missing_functions: |
| 94 | + print("\n🔴 Missing Functions:") |
| 95 | + for func in missing_functions: |
| 96 | + print(f"- {func}") |
| 97 | + |
| 98 | + if changed_functions: |
| 99 | + print("\n🟠 Changed Function Signatures:") |
| 100 | + for func, old_sig, new_sig in changed_functions: |
| 101 | + print(f"- {func}:") |
| 102 | + print(f" Old: {old_sig}") |
| 103 | + print(f" New: {new_sig}") |
| 104 | + |
| 105 | + if unchanged_functions: |
| 106 | + print("\n🟢 Unchanged Functions:") |
| 107 | + for func in unchanged_functions: |
| 108 | + print(f"- {func}: {current_signatures.get(func, 'Unknown')}") |
| 109 | + |
| 110 | + sys.exit(1) |
0 commit comments