Generate a markdown report summarizing the session.
(df: pd.DataFrame, baselines: dict | None)
| 371 | # --------------------------------------------------------------------------- |
| 372 | |
| 373 | def generate_report(df: pd.DataFrame, baselines: dict | None) -> None: |
| 374 | """Generate a markdown report summarizing the session.""" |
| 375 | |
| 376 | lines = [] |
| 377 | timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| 378 | |
| 379 | lines.append("# AutoKernel Session Report") |
| 380 | lines.append("") |
| 381 | lines.append(f"Generated: {timestamp}") |
| 382 | lines.append("") |
| 383 | |
| 384 | # Group by kernel type |
| 385 | if "kernel_type" in df.columns: |
| 386 | kernel_types = sorted(df["kernel_type"].fillna("unknown").unique()) |
| 387 | else: |
| 388 | kernel_types = ["unknown"] |
| 389 | |
| 390 | for kt in kernel_types: |
| 391 | kt_df = df[df["kernel_type"].fillna("unknown") == kt] if "kernel_type" in df.columns else df |
| 392 | classifications = kt_df.apply(classify_row, axis=1) |
| 393 | |
| 394 | lines.append(f"## Kernel: {kt}") |
| 395 | lines.append("") |
| 396 | |
| 397 | # Summary stats |
| 398 | n_total = len(kt_df) |
| 399 | n_kept = int((classifications == "kept").sum()) |
| 400 | n_failed = int((classifications == "failed").sum()) |
| 401 | n_reverted = int((classifications == "reverted").sum()) |
| 402 | |
| 403 | baseline_tp = _get_baseline_throughput(kt_df, baselines) |
| 404 | valid_tps = kt_df["throughput_tflops"].dropna() |
| 405 | valid_tps = valid_tps[valid_tps > 0] |
| 406 | best_tp = float(valid_tps.max()) if len(valid_tps) > 0 else None |
| 407 | |
| 408 | lines.append("### Summary") |
| 409 | lines.append("") |
| 410 | lines.append(f"| Metric | Value |") |
| 411 | lines.append(f"|--------|-------|") |
| 412 | lines.append(f"| Total experiments | {n_total} |") |
| 413 | lines.append(f"| Kept | {n_kept} |") |
| 414 | lines.append(f"| Reverted | {n_reverted} |") |
| 415 | lines.append(f"| Failed | {n_failed} |") |
| 416 | if baseline_tp: |
| 417 | lines.append(f"| Baseline throughput | {baseline_tp:.2f} TFLOPS |") |
| 418 | if best_tp: |
| 419 | lines.append(f"| Best throughput | {best_tp:.2f} TFLOPS |") |
| 420 | if baseline_tp and best_tp and baseline_tp > 0: |
| 421 | lines.append(f"| Speedup vs PyTorch | {best_tp / baseline_tp:.2f}x |") |
| 422 | lines.append("") |
| 423 | |
| 424 | # Key discoveries (kept experiments) |
| 425 | kept_df = kt_df[classifications == "kept"] |
| 426 | if len(kept_df) > 0: |
| 427 | lines.append("### Key Discoveries (Kept)") |
| 428 | lines.append("") |
| 429 | for _, r in kept_df.iterrows(): |
| 430 | exp = r.get("experiment", "?") |
no test coverage detected