Format the verification result into a human-readable report.
(result: VerificationResult, diagnose_results: Optional[List] = None)
| 833 | # --------------------------------------------------------------------------- |
| 834 | |
| 835 | def format_report(result: VerificationResult, diagnose_results: Optional[List] = None) -> str: |
| 836 | """Format the verification result into a human-readable report.""" |
| 837 | lines = [] |
| 838 | lines.append("") |
| 839 | lines.append("=== AutoKernel End-to-End Verification ===") |
| 840 | lines.append("") |
| 841 | lines.append(f"Model: {result.model_name}") |
| 842 | lines.append(f"Input: [{result.input_shape}], dtype={result.dtype_str}") |
| 843 | lines.append(f"GPU: {result.gpu_name}") |
| 844 | |
| 845 | # Reference run |
| 846 | lines.append("") |
| 847 | lines.append("--- Reference Run ---") |
| 848 | lines.append(f"Output shape: {result.ref_output_shape}") |
| 849 | lines.append(f"Latency: {result.ref_latency_ms:.1f} ms ({TIMED_RUNS} runs, median)") |
| 850 | |
| 851 | # Optimized run |
| 852 | lines.append("") |
| 853 | lines.append("--- Optimized Run ---") |
| 854 | if result.kernels_replaced: |
| 855 | lines.append("Kernels replaced:") |
| 856 | for k in result.kernels_replaced: |
| 857 | lines.append(f" {k['type']} (rank {k['rank']}): " |
| 858 | f"{k['speedup']:.1f}x -> {k['path']}") |
| 859 | else: |
| 860 | lines.append("Kernels replaced: none") |
| 861 | lines.append(f"Output shape: {result.opt_output_shape}") |
| 862 | lines.append(f"Latency: {result.opt_latency_ms:.1f} ms ({TIMED_RUNS} runs, median)") |
| 863 | |
| 864 | # Verification |
| 865 | lines.append("") |
| 866 | lines.append("--- Verification ---") |
| 867 | lines.append(f"correctness: {result.correctness}") |
| 868 | lines.append(f"max_abs_error: {result.max_abs_error:.2e}") |
| 869 | lines.append(f"mean_abs_error: {result.mean_abs_error:.2e}") |
| 870 | if result.has_nan: |
| 871 | lines.append("WARNING: NaN detected in optimized output") |
| 872 | if result.has_inf: |
| 873 | lines.append("WARNING: Inf detected in optimized output") |
| 874 | |
| 875 | # Summary |
| 876 | lines.append("") |
| 877 | lines.append("--- Summary ---") |
| 878 | lines.append(f"original_latency_ms: {result.ref_latency_ms:.1f}") |
| 879 | lines.append(f"optimized_latency_ms: {result.opt_latency_ms:.1f}") |
| 880 | lines.append(f"end_to_end_speedup: {result.end_to_end_speedup:.2f}x") |
| 881 | lines.append(f"kernels_replaced: {len(result.kernels_replaced)}") |
| 882 | |
| 883 | # Diagnosis |
| 884 | if diagnose_results: |
| 885 | lines.append("") |
| 886 | lines.append("--- Diagnosis (per-kernel) ---") |
| 887 | for dr in diagnose_results: |
| 888 | status = dr["correctness"] |
| 889 | line = f" {dr['kernel_type']} (rank {dr['rank']}): {status}" |
| 890 | if status == "PASS": |
| 891 | line += f" | max_err={dr['max_abs_error']:.2e}" |
| 892 | if dr.get("reason"): |