Skip to content

Commit 187ab55

Browse files
quic-boyucclaude
andcommitted
fx_viewer: switch layout to fast-sugiyama with natural edge flow
Replace the vendored grandalf fork with the Rust-backed fast-sugiyama package and rewrite the post-layout compaction in exporter.py to produce a natural top-down edge flow. Layout changes in _compute_layout_with_ext_lines / _compact_components: - Drive layout via fast-sugiyama's from_edges + rect_pack_layouts. - Run per-layer spine cohesion (chain detection across real and dummy nodes, iterative mean-pull, pure-A overlap repair) so linear op chains render as straight spines. - Flip Phase 6's y so graph inputs / placeholders land at the top of the canvas and outputs / sinks at the bottom. - Anchor edge endpoints to the bottom-midpoint of the source and top-midpoint of the target, giving each node a predictable dock. Also refresh the README's dependency / layout section to point at fast-sugiyama[all] and drop the grandalf install instructions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 144154a commit 187ab55

14 files changed

Lines changed: 342 additions & 3868 deletions

File tree

devtools/fx_viewer/README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Python side:
88
1. Extract FX graph (`torch.export` / `torch.fx`).
9-
2. Compute layout (Grandalf/Sugiyama).
9+
2. Compute layout (fast-sugiyama — Rust-backed Sugiyama).
1010
3. Build payload (`base` + `extensions`).
1111
4. Export JSON / JS snippet / standalone HTML.
1212

@@ -15,6 +15,25 @@ JS side:
1515
2. Layer toggles and color-by controls.
1616
3. State-driven API for embedding, compare mode, fullscreen, and runtime layer mutation.
1717

18+
## Dependencies
19+
20+
Layout computation is delegated to the external
21+
[`fast-sugiyama`](https://github.com/austinorr/fast-sugiyama) package
22+
(Rust-backed, drop-in replacement for the previously vendored `grandalf`
23+
fork). Install with the `[all]` extra so that `rectangle-packer` is pulled
24+
in — it is required to pack disconnected graph components into a single
25+
non-overlapping layout:
26+
27+
```bash
28+
pip install 'fast-sugiyama[all]'
29+
```
30+
31+
- Python ≥ 3.11 is required by `fast-sugiyama`. Users still on Python 3.10
32+
cannot use `FXGraphExporter`'s HTML/JSON output until they upgrade.
33+
- The package is **not** declared in executorch's `pyproject.toml`: it is
34+
imported lazily on the first layout call. If it is missing, the exporter
35+
raises an `ImportError` with install instructions.
36+
1837
## Quick Start
1938

2039
From repo root:
@@ -37,18 +56,21 @@ from executorch.backends.qualcomm.utils.fx_viewer import (
3756
CategoricalColorRule,
3857
)
3958

40-
exporter = FXGraphExporter(graph_module)
59+
# Step 1 instantiate exporter
60+
f = FXGraphExporter(graph_module)
4161

62+
# Optional (define graph extension Layer)
4263
ext = GraphExtension(id="backend", name="Backend Assignment")
4364
ext.add_node_data("node_0", {"backend": "cpu"})
4465
ext.set_color_rule(CategoricalColorRule(attribute="backend"))
66+
f.add_extension(ext)
4567

46-
exporter.add_extension(ext)
47-
exporter.export_html("graph.html")
68+
# Step 2 save standalone html
69+
f.export_html("graph.html")
4870
```
4971

5072
Main exporter methods:
51-
1. `generate_json_payload()`
73+
1. [ ] `generate_json_payload()`
5274
2. `export_json(path)`
5375
3. `export_js(container_id)`
5476
4. `export_html(path)`

0 commit comments

Comments
 (0)