Skip to content

Commit d02233b

Browse files
chore: add large graph render scripts to scripts/
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2857db7 commit d02233b

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

scripts/CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
| File | Purpose |
66
|------|---------|
77
| `check_flops_coverage.py` | Reports FLOPs module coverage against all decorated torch functions |
8+
| `run_250k.py` | Render a 250k-node graph with ELK layout |
9+
| `run_1M.py` | Render a 1M-node graph with ELK (phased: construct → log → render) |
810

911
## check_flops_coverage.py
1012

scripts/run_1M.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Standalone script: render a 1M-node graph with ELK stress + topo seeding."""
2+
3+
import os
4+
import sys
5+
import time
6+
7+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "tests"))
8+
9+
import torch
10+
from example_models import RandomGraphModel
11+
from torchlens import log_forward_pass
12+
13+
outdir = os.path.join("tests", "test_outputs", "visualizations", "large")
14+
os.makedirs(outdir, exist_ok=True)
15+
16+
# Phase 1: Model construction
17+
t0 = time.time()
18+
model = RandomGraphModel(target_nodes=1000000, seed=42)
19+
x = torch.randn(2, 64)
20+
t1 = time.time()
21+
print(f"Phase 1 — Model construction: {t1 - t0:.1f}s", flush=True)
22+
23+
# Phase 2: log_forward_pass (logging + postprocessing)
24+
ml = log_forward_pass(model, x, layers_to_save=None, detect_loops=False)
25+
t2 = time.time()
26+
print(f"Phase 2 — log_forward_pass: {t2 - t1:.1f}s ({len(ml)} layers)", flush=True)
27+
28+
# Phase 3: Render
29+
ml.render_graph(
30+
vis_opt="unrolled",
31+
vis_nesting_depth=1000,
32+
vis_outpath=os.path.join(outdir, "elk_1M"),
33+
save_only=True,
34+
vis_fileformat="svg",
35+
vis_node_placement="elk",
36+
)
37+
t3 = time.time()
38+
print(f"Phase 3 — ELK render: {t3 - t2:.1f}s", flush=True)
39+
40+
total = t3 - t0
41+
print(f"Total: {total:.1f}s ({total / 60:.1f} min)", flush=True)
42+
43+
svg_path = os.path.join(outdir, "elk_1M.svg")
44+
if os.path.exists(svg_path):
45+
size_mb = os.path.getsize(svg_path) / 1024 / 1024
46+
print(f"Output: {svg_path} ({size_mb:.0f} MB)")
47+
48+
ml.cleanup()

scripts/run_250k.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Standalone script: render a 250k-node graph with ELK."""
2+
3+
import os
4+
import sys
5+
import time
6+
7+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "tests"))
8+
9+
import torch
10+
from example_models import RandomGraphModel
11+
from torchlens import show_model_graph
12+
13+
outdir = os.path.join("tests", "test_outputs", "visualizations", "large")
14+
os.makedirs(outdir, exist_ok=True)
15+
16+
model = RandomGraphModel(target_nodes=250000, seed=42)
17+
x = torch.randn(2, 64)
18+
19+
print("Starting 250k ELK render...", flush=True)
20+
t0 = time.time()
21+
show_model_graph(
22+
model,
23+
x,
24+
vis_node_placement="elk",
25+
vis_fileformat="svg",
26+
save_only=True,
27+
vis_outpath=os.path.join(outdir, "elk_250k"),
28+
)
29+
elapsed = time.time() - t0
30+
print(f"Done in {elapsed:.1f}s ({elapsed / 60:.1f} min)")

0 commit comments

Comments
 (0)