00 / WHICH CHANGE?
Which kind of model change do you need to see?
| What changed | Tool | What you get | Limits |
|---|---|---|---|
| Layers, connections, inputs in the Python model | tensorViz Review model changes | Before / Diff / After graph with the Python diff beside it | Compares source without executing either revision; does not compare checkpoint values. |
| Exported graph (.pt2/ExportedProgram) | Google Model Explorer split pane | Side-by-side graphs and deleted/new-node highlights by ID | Export each revision separately; matching IDs does not prove semantic equivalence. Git/PR integration: Not documented. |
| Weights in two checkpoint files | state_dict comparison script / Git-Theta | Script: missing/extra keys, shapes and changed tensor values. Git-Theta: which tracked parameter groups changed. | Load the checkpoint format correctly. Git-Theta needs tracking setup; its README says it is under active development and should be used with caution. |
| Hyperparameters and metrics | DVC params diff / metrics diff | Recorded parameter or metric differences between git revisions | Requires recorded params/metrics; does not compare weight tensors or architecture. |
| Which large files changed | dvc diff | Which DVC-tracked files changed between revisions | Does not show what changed inside a checkpoint. |
Compare two .pt state_dict checkpoints
Retrieve the checkpoint from each revision as before.pt and after.pt. If your repository uses large-file storage, retrieve the actual files rather than pointer files. This example expects plain state_dict mappings of names to dense, real-valued tensors, including saved buffers. For a training checkpoint wrapper, select the model mapping (for example, checkpoint["model_state_dict"]) after loading each file.
Checkpoint comparison example not run for this page. Save as compare_checkpoints.py and run python compare_checkpoints.py in an environment with PyTorch:
import torch
before = torch.load("before.pt", map_location="cpu", weights_only=True)
after = torch.load("after.pt", map_location="cpu", weights_only=True)
print("Missing in after:", sorted(before.keys() - after.keys()))
print("Extra in after:", sorted(after.keys() - before.keys()))
for key in sorted(before.keys() & after.keys()):
a, b = before[key], after[key]
if a.shape != b.shape:
print(key, "shape:", tuple(a.shape), "->", tuple(b.shape))
continue
if a.dtype != b.dtype:
print(key, "dtype:", a.dtype, "->", b.dtype)
if not torch.equal(a, b):
delta = (a.to(torch.float64) - b.to(torch.float64)).abs()
print(key, "changed; max abs diff:", delta.max().item() if delta.numel() else 0)
The comparison uses exact tensor equality, not a tolerance. The maximum absolute difference is a float64 diagnostic: very large integers can lose precision, and NaNs or infinities can make it non-finite. Adapt the script for sparse, quantized or complex tensors and non-tensor extra state. It does not compare forward behavior or reconstruct the architecture.
For .safetensors, replace each torch.load call with safetensors.torch.load_file("before.safetensors", device="cpu") (and the after filename), after importing safetensors.torch; see the Safetensors Torch API. A checkpoint saved with torch.save(model) is a whole pickled module: loading it needs weights_only=False and the model classes, then .state_dict(). Only do this with trusted files, since unpickling can execute code. Prefer saving state_dicts; see torch.load.
Track checkpoints or compare experiment records
Git-Theta is a Git extension built on Git LFS that tracks checkpoint parameter groups and shows which groups changed. Its documented setup includes pip install 'git-theta[pytorch]', git theta install and git theta track model.pt. This sets up tracking; it does not replace retrieving two existing checkpoint files for the script above. The README cautions that the tool is under active development.
For recorded experiment values, use dvc params diff A B and dvc metrics diff A B, replacing A and B with the git revisions. Use dvc diff A B to list changed DVC-tracked files. It does not inspect their tensor values. These commands were not run for this page.
01 / SIDE BY SIDE
Which tools can compare PyTorch model changes?
Source review, manual diagram comparison and exported-graph comparison answer different questions. “Not documented” means the cited documentation does not establish a capability.
| Tool | What it compares | Execution and setup | Git or PR workflow | Highlights and limits | Better choice for |
|---|---|---|---|---|---|
| tensorViz | Python source in Before / Diff / After views with the code diff beside the graph | Review does not execute either revision. No Open as Graph, example inputs or export required. | Working changes, branch changes, two local revisions; native Python diff and Source Control entry points; direct GitHub.com PR URL without checkout | Added, removed, modified source/parameters, changed inputs/connections. Unmapped or ambiguous changes remain unresolved. Existing capture shapes are context, not fresh measurements. | Reviewing source changes beside the architecture in an editor |
| torchview | Render two static Graphviz diagrams and compare by eye; diff/compare feature: Not documented | Run a forward pass in each revision with example inputs. Requires torchview and Graphviz; device='meta' is supported. |
Git/PR integration: Not documented; use separate checkouts or worktrees | Automatic change highlights: Not documented. Keep input shape, depth and nested-expansion settings consistent. | Static before/after diagrams in papers or review notes |
| TorchVista | Render two interactive notebook graphs or HTML exports and compare by eye; diff/compare feature: Not documented | Run the forward pass in each revision with example inputs | Git/PR integration: Not documented; use separate checkouts or worktrees | Automatic change highlights: Not documented. Interactive collapse, drag/zoom and node parameter inspection. | Exploring each revision in a web-based notebook |
| Google Model Explorer | Two loaded models in a split pane, with navigation synchronized by node ID or an uploaded JSON mapping | Export each PyTorch revision with torch.export to an ExportedProgram or .pt2 file. Both must export successfully. |
Git/PR integration: Not documented; check out and export each revision separately | Highlight deleted and new nodes under Match node id: red/green borders for IDs absent from the other pane. ID matching does not establish semantic equivalence. | Large exported graphs and comparing converted or quantized models |
For file viewing and a broader alternatives comparison, see Netron alternative for PyTorch and PyTorch model visualization tools compared.
02 / SOURCE REVIEW
How to diff a PyTorch model between two commits
Commands and usage examples not run for this page. Install the editor extension for VS Code 1.106+, Cursor or VSCodium. Model capture uses Python 3.10+ and the separate service needs Python 3.11+; this source review does not execute the model.
code --install-extension tensorviz.tensorviz-vscode
git log --oneline -5
- Open your Git repository in the editor. Identify the older and newer commits with
git log. Both revisions must be available locally. - Open the Command Palette and run tensorViz: Review model changes.
- Choose Two revisions, then select the before and after revisions. You can use two local commits, tags or branches.
- Choose the affected model when asked. Read Before / Diff / After with the Python diff beside the graph. Use the change navigator and click nodes to reveal the corresponding code line.
You do not need to open a live graph, configure inputs, export a model or check out either revision for this review. See Review model changes.
Compare a branch with its base
Fetch the refs you need first, for example:
git fetch origin
Then choose Branch changes and a base branch such as origin/main. This compares the merge base of that branch and HEAD against HEAD. The comparison reads local Git only; fetching is a separate step.
03 / OTHER ENTRY POINTS
Review working files, staged changes or a pull request
- Canvas toolbar → Review model changes → Working changes: compare HEAD with working files, including unsaved Python buffers. The Command Palette command also offers Working changes.
- Graph diff on an open native Python diff: review the revisions displayed in that diff. In Source Control, Changes compares the index with working files, including unsaved buffers; Staged Changes compares HEAD with the index. Graph diff against HEAD compares HEAD with working files.
- Open PR in Canvas, or tensorViz: Open PR in the Command Palette: paste a GitHub.com PR URL or choose from the repository’s 100 most recent open PRs. Closed and merged PR URLs work too. No checkout, Open as Graph or example inputs are required. GitHub Enterprise hosts are not yet supported.
The PR workflow documentation describes direct review and its coverage limits.
Review changes with a coding agent
The coding-agent plugin preview supports Codex, Claude Code, Cursor and T3 Code, with CPython 3.12 and CPU capture. For Codex or Claude Code, the documented installation commands are:
codex plugin marketplace add tensorviz-org/tensorviz-plugins
codex plugin add tensorviz@tensorviz-standalone
claude plugin marketplace add tensorviz-org/tensorviz-plugins
claude plugin install tensorviz@tensorviz-standalone --scope user
A connected coding agent can call the open_graph_diff MCP tool to open this same source review for HEAD versus current files. It does not execute either revision.
04 / INTERPRETING THE RESULT
What does a graph diff prove?
tensorViz review is a source comparison. Green marks added nodes; red marks removed nodes; amber marks modified source or parameters; blue marks changed inputs or incoming connections. Use the change navigator and the adjacent code diff to inspect each change.
It does not execute either revision or prove behavioral equivalence. Existing capture shapes provide context, not new before/after measurements. Capture each revision separately with the inputs you care about when you need runtime evidence. A source-only preview also has no measured shapes. Unmapped or ambiguous changes remain unresolved.
Discovery is AST-only. Documented per-project review limits are 256 files, 1 MiB per file and 8 MiB total. Working snapshots additionally cap the repository at 8,192 files / 64 MB. Read coverage notes rather than treating a partial comparison as a complete inventory. These are source-review budgets, not model-size limits.
05 / RENDER EACH REVISION
How to compare commits with the other tools
All snippets in this recipe were not run for this page. Start in a clean checkout of the intended after commit. Replace <commit> with the older commit. This creates a separate before worktree and an output folder beside both checkouts:
git worktree add ../model-before <commit>
mkdir -p ../model-comparison
The adapter below assumes each revision exposes MlpTiny in model.py with input shape [1, 16], as in the small model example. Replace the import, model construction and input with your own. Use the dependencies required by each revision, in separate Python environments if necessary. Keep input shape and rendering settings consistent.
Save this as ../model-comparison/render_model.py. Run it from each checkout’s root so the model import resolves to that revision:
import sys
from pathlib import Path
import torch
sys.path.insert(0, str(Path.cwd()))
from model import MlpTiny # Adapt to your repository in both revisions.
tool, label = sys.argv[1:]
output = Path.cwd().parent / 'model-comparison' / label
output.mkdir(parents=True, exist_ok=True)
model = MlpTiny().eval()
x = torch.randn(1, 16)
if tool == 'torchview':
from torchview import draw_graph
draw_graph(
model, input_size=tuple(x.shape), expand_nested=True,
depth=3, device='meta', save_graph=True,
filename=str(output / 'torchview'),
)
elif tool == 'torchvista':
from torchvista import trace_model
trace_model(
model, x, export_format='html',
export_path=str(output / 'torchvista.html'),
)
elif tool == 'export':
ep = torch.export.export(model, (x,))
torch.export.save(ep, output / 'model.pt2')
else:
raise ValueError('Choose torchview, torchvista or export')
torchview: compare static diagrams by eye
Install the Graphviz dot binary for your OS and the Python packages in the environment for each revision. See the installation instructions. Run from the after checkout:
pip install torchview graphviz
python ../model-comparison/render_model.py torchview after
(cd ../model-before && python ../model-comparison/render_model.py torchview before)
Open the saved diagrams under ../model-comparison/before/ and ../model-comparison/after/ and compare by eye. A built-in diff/compare feature is Not documented. This is useful for static diagrams in review notes or papers.
TorchVista: compare interactive HTML exports by eye
Its trace_model API supports HTML export. Run from the after checkout; install the package in both revision environments as needed:
pip install torchvista
python ../model-comparison/render_model.py torchvista after
(cd ../model-before && python ../model-comparison/render_model.py torchvista before)
Open each torchvista.html in a browser, or trace each revision in its own web-based notebook. Expand modules and inspect nodes to compare by eye. A built-in diff/compare feature is Not documented.
Google Model Explorer: compare two exported graphs
Use a PyTorch version compatible with Model Explorer in each revision environment. Both models must pass torch.export. On Windows, Model Explorer requires WSL.
pip install ai-edge-model-explorer
python ../model-comparison/render_model.py export after
(cd ../model-before && python ../model-comparison/render_model.py export before)
model-explorer
- In the local browser UI, select both
before/model.pt2andafter/model.pt2from../model-comparison/. - Use the model selector’s split-pane control. Put before on the left and after on the right.
- Enable synchronized navigation with Match node id, then check Highlight deleted and new nodes. Red borders mark IDs present only on the left; green borders mark IDs present only on the right.
- If IDs do not line up, the documented Upload mapping from computer mode accepts a JSON node mapping for synchronized navigation. Inspect the correspondence; matching IDs alone do not prove two operations mean the same thing.
See the split-pane user guide and deleted/new-node highlights. Model Explorer is a good choice for large exported graphs and comparing converted or quantized models. Git and PR integration is Not documented; these commands prepare two loaded models, and the highlights compare node IDs.
Frequently asked questions
How do I compare two PyTorch .pt checkpoint files?
Load each state_dict with torch.load(path, map_location="cpu", weights_only=True), then compare missing and extra keys, tensor shapes and torch.equal results; report the maximum absolute difference for changed tensors. The script above handles plain state_dicts. Select the model mapping inside wrapped training checkpoints. Whole pickled modules require trusted files and weights_only=False.
Does tensorViz compare model weights between commits?
No. Review model changes compares Python source and architecture without executing either revision. It does not compare weights or checkpoint values. Use a state_dict comparison or Git-Theta for weights.
Does tensorViz execute either commit during graph review?
No. Review model changes compares Python source without executing either revision. It needs no Open as Graph, example inputs or export. Existing capture shapes are context, not new before/after measurements; capture each revision separately for runtime evidence.
Can I compare two commits without checking them out?
Yes. In tensorViz: Review model changes, choose Two revisions and select two local commits, tags or branches. Branch changes compares the chosen base branch’s merge base with HEAD against HEAD and reads local Git only, so fetch refs first if needed.
Can I review a GitHub pull request without a model capture?
Yes. Choose Open PR or tensorViz: Open PR and paste a GitHub.com PR URL, including a closed or merged PR, or choose from the repository’s 100 most recent open PRs. No checkout, Open as Graph or example inputs are required. GitHub Enterprise hosts are not yet supported.
Do torchview and TorchVista have a built-in model diff?
A diff/compare feature is Not documented for either tool. Use separate checkouts or git worktrees, render each revision with consistent inputs and settings, and compare the diagrams or HTML exports by eye. Each rendering runs a forward pass.
Can Google Model Explorer highlight changes between two models?
Yes. It provides a split-pane view and synchronized navigation by node ID or an uploaded JSON mapping. Under Match node id, Highlight deleted and new nodes marks IDs absent from the other pane with red or green borders. For PyTorch, export each revision separately with torch.export. Git or PR integration is Not documented.
Does an unchanged graph prove the model behaves the same?
No. tensorViz source review does not prove behavioral equivalence, and unmapped or ambiguous changes remain unresolved. Model Explorer’s node-ID highlights also do not establish semantic equivalence. Capture each revision separately for runtime evidence with the inputs you care about.
Sources and what we did not verify
tensorViz: Review model changes, direct PR and code-diff review, including limits, open_graph_diff, installation and requirements, capture concepts and the public coding-agent plugin catalog. tensorViz is free to install; core graph tools need no AI key. The PyPI package named tensorviz is an unrelated project.
Competitors: torchview README and draw_graph API; TorchVista README and trace_model API; Google Model Explorer user guide (PyTorch files, split pane, sync navigation and deleted/new-node highlights), API guide and limitations.
Checkpoint and experiment tools: Git-Theta README; DVC params diff, metrics diff and diff.
What we did not verify: we did not run Git-Theta or DVC for this page; we did not run these snippets for this page, benchmark review or rendering, test CUDA support, or measure model-size limits. We did not validate runtime equivalence or every Git, PR, dependency or export configuration. “Not documented” records a documentation gap, not a tested absence. A complete source inventory or matching node IDs does not prove matching model behavior.