Pick a method
Forward-pass and export columns describe the recipes below. Netron itself does not execute Python. “Not documented” means the cited documentation does not establish the capability.
| Method | What you get | Needs a forward pass? | Needs export (ONNX/torch.export)? | Interactive? | Where it runs |
|---|---|---|---|---|---|
| print(model) | Registered submodule tree; no output shapes or functional operations | No | No | No | Python terminal or notebook |
| torchinfo | Layer table with output shapes and parameter counts | Yes, with input_size for shapes | No | No; text | Python script or notebook |
| torchview | Static Graphviz forward-pass diagram | Yes; meta tensors supported | No | No; static diagram | Python script or notebook; Graphviz dot required |
| TorchVista | Forward-pass graph with collapsible modules | Yes | No | Yes | Web-based notebooks: Jupyter, Colab, Kaggle, VS Code notebooks |
| TensorBoard add_graph | Traced computation graph | Yes; TorchScript tracing | No ONNX/torch.export; writes event logs | Yes | Python capture; TensorBoard browser UI |
| Netron (via ONNX or torch.export file) | Saved-file graph | During export; viewer does not run Python | Yes for these recipes | Yes | Browser, desktop app or local Python server |
| Google Model Explorer (torch.export) | ExportedProgram graph | During torch.export | Yes; ExportedProgram. Compare two loaded models in a split pane; Highlight deleted and new nodes by node ID. | Yes | Local browser UI; Windows via WSL |
| tensorViz | Source graph with measured shapes from one call; source-only preview available. Source review does not execute either revision. | Yes for Open as Graph; no for Inspect source only | No | Yes | VS Code, Cursor, VSCodium; coding-agent plugin preview; saved graphs in browser. Notebook integration: Not documented |
Start with one small model
Examples not run for this page. Save this as model.py in a Python environment with PyTorch. Each Python recipe below runs from that folder and uses this class. Install additional packages in the same environment; notebook kernels must use it too.
import torch
from torch import nn
# tensorviz: input=1,3,32,32
class TinyCNN(nn.Module):
def __init__(self):
super().__init__()
self.conv = nn.Conv2d(3, 8, kernel_size=3, padding=1)
self.relu = nn.ReLU()
self.pool = nn.AdaptiveAvgPool2d((1, 1))
self.head = nn.Linear(8, 4)
def forward(self, x):
x = self.pool(self.relu(self.conv(x)))
return self.head(torch.flatten(x, 1))
The input is one RGB image with height and width 32. The functional torch.flatten call is in the forward method rather than a registered submodule, illustrating why a printed module tree is different from a computation graph.
1. Print the registered layers
No extra package is needed. Instantiate the class, then print it in a terminal or notebook:
from model import TinyCNN
model = TinyCNN().eval()
print(model)
This lists submodules without running the model. It does not show output shapes or functional operations such as our flatten call. See the nn.Module documentation.
2. Get a shape table with torchinfo
Install torchinfo, then supply the batch dimension and image dimensions. This recipe runs a forward pass to collect shapes and parameter counts.
pip install torchinfo
from model import TinyCNN
from torchinfo import summary
summary(TinyCNN().eval(), input_size=(1, 3, 32, 32))
The result is text. Without input_size or input_data, torchinfo does not run a forward pass and cannot provide these measured output shapes.
3. Render a static diagram with torchview
Install torchview and the Graphviz dot binary for your OS. Check dot -V, then render the model:
pip install torchview graphviz
from model import TinyCNN
from torchview import draw_graph
draw_graph(
TinyCNN().eval(), input_size=(1, 3, 32, 32),
expand_nested=True, depth=3, device="meta",
save_graph=True, filename="tiny-cnn",
)
This executes a forward pass using meta tensors and saves a static Graphviz diagram. Use it for a figure in a paper or a script-generated image.
4. Explore a notebook graph with TorchVista
Install TorchVista, then run the Python in a web-based notebook. It traces the chosen forward call and can export interactive HTML.
pip install torchvista
import torch
from model import TinyCNN
from torchvista import trace_model
model = TinyCNN().eval()
inputs = torch.randn(1, 3, 32, 32)
trace_model(model, inputs, export_format="html", export_path="tiny-cnn.html")
Drag and zoom, collapse modules and click nodes for parameter information. PNG/SVG exports and partial graphs on errors are documented.
5. Log a graph to TensorBoard
Install TensorBoard, write the graph with PyTorch’s SummaryWriter.add_graph, then start the browser UI.
pip install tensorboard
import torch
from model import TinyCNN
from torch.utils.tensorboard import SummaryWriter
model = TinyCNN().eval()
example_input = torch.randn(1, 3, 32, 32)
w = SummaryWriter()
w.add_graph(model, example_input)
w.close()
tensorboard --logdir runs
Open the displayed local URL and select the Graphs tab. add_graph uses TorchScript tracing (torch.jit.trace); data-dependent control flow is captured for that input only. No ONNX or torch.export file is required.
6. Export a file and open it in Netron
Netron views saved files and does not run an nn.Module class. For this example, create a torch.export file:
import torch
from model import TinyCNN
model = TinyCNN().eval()
x = torch.randn(1, 3, 32, 32)
ep = torch.export.export(model, (x,))
torch.export.save(ep, "model.pt2")
Open model.pt2 at netron.app. Alternatively, install the ONNX exporter dependencies and export an ONNX file:
pip install onnx onnxscript
import torch
from model import TinyCNN
model = TinyCNN().eval()
x = torch.randn(1, 3, 32, 32)
torch.onnx.export(model, (x,), "model.onnx")
pip install netron
netron model.onnx
Export must succeed first; inspect the resulting file in the browser or desktop viewer. Netron is the better choice for many saved formats, including TFLite and Core ML. See Netron alternatives for PyTorch source.
7. Open an ExportedProgram in Google Model Explorer
Install Google Model Explorer with its compatible PyTorch dependencies. Windows requires WSL. Export the model, then pass the ExportedProgram to the API:
pip install ai-edge-model-explorer
import torch
import model_explorer
from model import TinyCNN
model = TinyCNN().eval()
x = torch.randn(1, 3, 32, 32)
ep = torch.export.export(model, (x,))
model_explorer.visualize_pytorch("TinyCNN", exported_program=ep)
Explore the graph in the local browser UI. For a saved file, use torch.export.save(ep, "model.pt2") and launch model-explorer. This PyTorch path requires successful torch.export; nested layers, search and GPU rendering help with large graphs.
8. Open an interactive graph from Python with tensorViz
tensorViz is our product. Install the extension in VS Code 1.106+, Cursor or VSCodium. The model needs Python 3.10+ and its dependencies; the separate service needs Python 3.11+. Follow the quickstart.
code --install-extension tensorviz.tensorviz-vscode
- Open
model.pyfrom the example above. Keep# tensorviz: input=1,3,32,32aboveTinyCNN. - Click Open as Graph above the class. Choose your Python environment and review the example input. Setup is saved in
tensorviz.toml. - Capture one ordinary eager forward call in that environment, locally or on a Remote SSH host. No ONNX, torch.export or saved model file is needed. Shapes are measurements for this call only.
- Pan, zoom, expand or enter modules, and search names,
type=Conv2dorshape=256. Select a layer and use Code focus to find its Python line. Export SVG/PNG; saved graphs can open in a browser.
Choose Inspect source only to preview without running the model; it has no measured shapes. See input setup and canvas controls.
The coding-agent plugin preview supports Codex, Claude Code, Cursor and T3 Code, with CPython 3.12 and CPU capture. For Codex, install it with:
codex plugin marketplace add tensorviz-org/tensorviz-plugins
codex plugin add tensorviz@tensorviz-standalone
Ask the agent to open your model as a graph. tensorViz is free to install and core graph tools need no AI key. It does not open ONNX, TFLite or Core ML files as a general file viewer.
Which one should I use?
- Quick layer check: print(model). Use torchinfo when you also need output shapes and parameter counts in text.
- Static diagrams for papers: torchview, with Graphviz installed.
- Interactive notebooks: TorchVista. Notebook integration for tensorViz is Not documented.
- Existing TensorBoard workflow: add_graph keeps the traced graph with your run logs.
- Saved files and many formats: Netron. For large exported graphs or comparing converted and quantized models, use Google Model Explorer.
- Python source beside the graph: tensorViz in your editor, with source navigation and a source-only preview option.
For architecture changes, tensorViz Review model changes compares source and does not execute either revision. It does not prove behavioral equivalence. Model Explorer compares two loaded models in a split pane and can highlight deleted and new nodes by node ID; Git/PR integration is Not documented. See diff a PyTorch model between git commits for source review and separate-export recipes.
See the broader visualization tools comparison for tradeoffs. If a shape fails at the classifier, follow the flatten-to-Linear shape mismatch guide.
Compare diagrams from two revisions
Recipe not run for this page. For torchview or TorchVista, create a separate checkout of the earlier revision, then run the same rendering recipe with the same example input in each checkout. Give each output a distinct name and compare the diagrams by eye; a diff/compare feature is Not documented for these tools.
git worktree add ../model-before <commit>For Model Explorer, run the export recipe in each checkout and save distinct files with torch.export.save(ep, "before.pt2") and torch.export.save(ep, "after.pt2"). Launch model-explorer, load both exports in a split pane and enable Highlight deleted and new nodes under Match node id. These highlights use node IDs; synchronized navigation uses matching IDs or an uploaded JSON mapping. Both revisions must export successfully, and the comparison does not establish behavioral equivalence.
Frequently asked questions
How do I visualize a PyTorch model without ONNX?
Use print(model) or torchinfo for text, torchview or TorchVista for a forward-pass diagram, or tensorViz for an interactive graph in VS Code, Cursor or VSCodium. tensorViz Open as Graph runs one eager forward call without ONNX or torch.export; Inspect source only runs nothing and has no measured shapes.
How do I see layer output shapes?
Pass an input size to torchinfo for a text table, or capture a forward pass with tensorViz to inspect measured tensor shapes on the canvas. These shapes describe the chosen input and execution, not every possible input or branch.
Can I visualize a model from a .pth file?
A .pth state dict holds weights, not the forward graph. Load it into the original model class, then visualize that model with example inputs. The file extension alone does not identify what was saved.
Is tensorViz the pip package tensorviz?
No. The PyPI package named tensorviz is an unrelated project. Install tensorViz as an editor extension from the VS Code Marketplace or Open VSX, or use the coding-agent plugin preview.
Sources and what we did not verify
PyTorch and summaries: nn.Module, torchinfo README and API, TensorBoard add_graph, tracing limitations, ONNX export and torch.export.
Diagram and file tools: torchview README and API, TorchVista README and API, Netron README, Model Explorer API guide, user guide and limitations.
tensorViz: installation, quickstart, input setup, capture concepts, canvas and plugin preview. Install the extension from the VS Code Marketplace or Open VSX.
What we did not verify: all snippets were not run for this page. We did not benchmark these tools, test CUDA support, measure model-size limits or test every model, export, notebook or environment. “Not documented” records a documentation gap, not a tested absence. Captures describe chosen inputs; they do not establish every possible execution path.