Practical overview
When it fits
Use Torchview when a PyTorch model’s structure or forward computation is easier to inspect as a diagram than from its code alone.
Who it is for
- Python developers inspecting the structure of PyTorch models.
- Machine-learning practitioners documenting or exploring model architecture and computation flow.
Documented uses
- Turn a PyTorch model’s forward computation into a visual graph.
- Inspect module hierarchy, tensor operations and input/output shapes.
- Adjust diagram detail with options for graph depth, nested modules and rolling recursively used modules.
Requirements & limits
Torchview is distributed as a Python library through uv, pip and conda, and its repository identifies an MIT license.
- The documented interface supports PyTorch 1.7 and later; meta-tensor support requires PyTorch 1.13 or later.
- Graphviz must be installed, and its dot layout command must be available to the Python interface.
- The function accepts either input data or input sizes, with dtypes needing to match the model input.
- Large SVG output may be cropped in VS Code; the README suggests PNG rendering as a workaround.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Create a PyTorch model graph
Generate a Graphviz visualization of a PyTorch model using Torchview’s documented Python interface.
Before you start
- Python 3.9 or later
- PyTorch 1.7 or later
- Torchview and the Graphviz Python package
- The Graphviz dot layout command available on the system
- A PyTorch model and its input size or input data
Steps
Install Graphviz and ensure the system dot command is available.
Install Torchview with uv, pip or conda.
Import draw_graph and pass it a model and input description, for example draw_graph(model, input_size=(2, 128), device='meta').
Access the returned graph’s visual_graph property.
Expected outcome
A Graphviz model diagram that can show module structure, tensor operations and input/output shapes.
Guide limitations
- Meta-device visualization requires PyTorch 1.13 or later.
- The model’s input description must match its expected input types and dimensions.
- The README reports that large SVG graphs can be cropped in VS Code and suggests PNG rendering in that environment.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 13 October 2026
- Original website title
- mert-kurttutan/torchview · Official homepage title · retained in its source language

