|
1 | | -"""Compare two CUDA memory snapshots side-by-side in a single interactive HTML page.""" |
| 1 | +"""Backward-compatible alias for the `merge-memory` CLI.""" |
2 | 2 |
|
3 | | -from __future__ import annotations |
4 | | - |
5 | | -import pickle |
6 | | -from pathlib import Path |
7 | | -from typing import Annotated |
8 | | - |
9 | | -import typer |
10 | | - |
11 | | -app = typer.Typer(help="Compare two memory snapshots side-by-side.") |
12 | | - |
13 | | - |
14 | | -@app.command() |
15 | | -def main( |
16 | | - left: Annotated[Path, typer.Argument(help="Left snapshot pickle file.")], |
17 | | - right: Annotated[Path, typer.Argument(help="Right snapshot pickle file.")], |
18 | | - output: Annotated[Path, typer.Option("-o", "--output", help="Output HTML path.")] = Path( |
19 | | - "memory_comparison.html" |
20 | | - ), |
21 | | - device: Annotated[int, typer.Option("--device", help="CUDA device index.")] = 0, |
22 | | - device_left: Annotated[int | None, typer.Option("--device-left")] = None, |
23 | | - device_right: Annotated[int | None, typer.Option("--device-right")] = None, |
24 | | - title_left: Annotated[str | None, typer.Option("--title-left")] = None, |
25 | | - title_right: Annotated[str | None, typer.Option("--title-right")] = None, |
26 | | -): |
27 | | - """Generate a side-by-side memory comparison HTML from two snapshot pickles.""" |
28 | | - for p in (left, right): |
29 | | - if not p.exists(): |
30 | | - typer.echo(f"Error: {p} not found", err=True) |
31 | | - raise typer.Exit(1) |
32 | | - |
33 | | - from transformer_nuggets.utils.memory_viz import generate_memory_comparison_html |
34 | | - |
35 | | - with open(left, "rb") as f: |
36 | | - snapshot_left = pickle.load(f) |
37 | | - with open(right, "rb") as f: |
38 | | - snapshot_right = pickle.load(f) |
39 | | - |
40 | | - html = generate_memory_comparison_html( |
41 | | - snapshot_left, |
42 | | - snapshot_right, |
43 | | - device=device, |
44 | | - device_left=device_left, |
45 | | - device_right=device_right, |
46 | | - title_left=title_left or left.stem, |
47 | | - title_right=title_right or right.stem, |
48 | | - ) |
49 | | - |
50 | | - output.parent.mkdir(parents=True, exist_ok=True) |
51 | | - output.write_text(html) |
52 | | - typer.echo(f"Wrote comparison to {output}") |
| 3 | +from transformer_nuggets.utils.merge_memory import app, main |
53 | 4 |
|
54 | 5 |
|
55 | 6 | if __name__ == "__main__": |
|
0 commit comments