Download scripts/report.py from trl-internal-testing/ci-profile: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/datasets/trl-internal-testing/ci-profile/resolve/main/scripts/report.py
- Command line
-
hf download hf://datasets/trl-internal-testing/ci-profile/scripts/report.py
-
curl -L -o report.py https://huggingface.co/datasets/trl-internal-testing/ci-profile/resolve/main/scripts/report.py
2.29 kB
| """Summarize a profile run as markdown, comparing to the previous run in data_dir. | |
| Usage: python report.py <results.jsonl> <data_dir> > summary.md | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| def load(path): | |
| return [json.loads(line) for line in Path(path).read_text().splitlines()] | |
| def table(rows, key, unit, n=20): | |
| lines = [f"| test | {key} ({unit}) | outcome |", "|---|---:|---|"] | |
| for r in sorted(rows, key=lambda r: r[key], reverse=True)[:n]: | |
| lines.append(f"| `{r['nodeid']}` | {r[key]:.1f} | {r['outcome']} |") | |
| return "\n".join(lines) | |
| current_path, data_dir = Path(sys.argv[1]), Path(sys.argv[2]) | |
| rows = load(current_path) | |
| meta = rows[0] | |
| previous = sorted(p for p in data_dir.glob("*.jsonl") if p.name != current_path.name) | |
| out = [f"# CI profile {meta['date']} @ {meta['sha'][:8]}", ""] | |
| out.append( | |
| f"{len(rows)} tests, {sum(r['total_s'] for r in rows) / 60:.1f} min total, " | |
| f"{sum(r['outcome'] == 'failed' for r in rows)} failed, {sum(r['outcome'] == 'error' for r in rows)} errors, " | |
| f"{sum(r['outcome'] == 'skipped' for r in rows)} skipped. " | |
| f"torch {meta['torch']}, transformers {meta['transformers']}, {meta['gpu']}." | |
| ) | |
| out += ["", "## Slowest tests", "", table(rows, "total_s", "s")] | |
| out += ["", "## Highest peak memory", "", table(rows, "peak_alloc_mib", "MiB")] | |
| if previous: | |
| prev = {r["nodeid"]: r for r in load(previous[-1])} | |
| slower, heavier = [], [] | |
| for r in rows: | |
| p = prev.get(r["nodeid"]) | |
| if p is None or r["outcome"] != "passed" or p["outcome"] != "passed": | |
| continue | |
| if r["total_s"] > 1.5 * p["total_s"] and r["total_s"] - p["total_s"] > 5: | |
| slower.append(f"| `{r['nodeid']}` | {p['total_s']:.1f} | {r['total_s']:.1f} |") | |
| if r["peak_alloc_mib"] > 1.2 * p["peak_alloc_mib"] and r["peak_alloc_mib"] - p["peak_alloc_mib"] > 256: | |
| heavier.append(f"| `{r['nodeid']}` | {p['peak_alloc_mib']:.0f} | {r['peak_alloc_mib']:.0f} |") | |
| out += ["", f"## Regressions vs {previous[-1].stem}", ""] | |
| out += ["Time (>1.5x and >5 s):", "", "| test | before (s) | now (s) |", "|---|---:|---:|", *slower, ""] | |
| out += ["Peak memory (>1.2x and >256 MiB):", "", "| test | before (MiB) | now (MiB) |", "|---|---:|---:|", *heavier] | |
| print("\n".join(out)) | |