Registry / ai-ml / torchinfo

torchinfo

JSON →
library1.8.0pypypi✓ verified 23d ago

Torchinfo provides comprehensive model summaries for PyTorch, similar to TensorFlow's `model.summary()` API. It's a completely rewritten version of the original `torchsummary` and `torchsummaryX` projects, addressing previous issues and introducing a new API. It helps in debugging networks by visualizing layer details, input/output shapes, parameter counts, and operations. The current version is 1.8.0, and it follows an active release cadence with frequent updates.

pip install torchinfo
INSTALL
IMPORT
SIG · TORCHINFO
T
torchinfo
ai-mlpythonv1.8.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

summary
from torchinfo import summary
from torchinfo import summary

Initialize a PyTorch model and use `torchinfo.summary` to print its structure, parameter counts, input/output shapes, and other statistics. You can provide either `input_size` (a tuple representing the tensor shape, including batch size) or actual `input_data` (a tensor or sequence of tensors) for the model's forward pass.

import torch import torch.nn as nn from torchinfo import summary class ConvNet(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.relu1 = nn.ReLU() self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.dropout = nn.Dropout2d() self.relu2 = nn.ReLU() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10) def forward(self, x): x = self.relu1(self.conv1(x)) x = nn.functional.max_pool2d(x, 2) x = self.relu2(self.dropout(self.conv2(x))) x = nn.functional.max_pool2d(x, 2) x = x.view(-1, 320) x = nn.functional.relu(self.fc1(x)) x = self.fc2(x) return x model = ConvNet() # Example with input_size (batch_size, channels, height, width) summary(model, input_size=(16, 1, 28, 28)) # Example with input_data (for more complex forward passes) # dummy_input = torch.randn(16, 1, 28, 28) # summary(model, input_data=dummy_input)
torchinfo --version
Debug
Known issues
breakingThe `torch-summary` PyPI package has been renamed to `torchinfo`. While the old package might still exist, `torchinfo` is the actively maintained successor. Using `torch-summary` may lead to outdated features or lack of support.
fix
Migrate to `pip install torchinfo` and update import statements to `from torchinfo import summary`.
affects: <1.6.0 (for torch-summary), all versions (for users attempting old package)
deprecatedPython 3.6 support was deprecated in `torchinfo` v1.6.0. Users on Python 3.6 should install an older version of `torchinfo`.
fix
Upgrade to Python 3.7+ or install a compatible older version like `pip install 'torchinfo<1.6.0'`.
affects: >=1.6.0
gotchaEnsure your model's `train()` and `eval()` modes are consistent across layers when using `summary`. If layers are not all in the same mode, running `summary` may have unintended side effects on batch normalization or dropout statistics, as `torchinfo` performs a forward pass to gather information.
fix
Set your model to a consistent mode before calling `summary`, e.g., `model.eval()` or `model.train()`.
affects: all
gotcha`torchinfo` officially supports PyTorch versions 1.4.0 and higher. Using very old or very new (untested) PyTorch versions might lead to compatibility issues. Subsequent `torchinfo` releases (e.g., v1.7.1, v1.8.0) include updates for newer PyTorch versions like 1.12 and 2.0.
fix
Ensure your PyTorch version is 1.4.0 or newer. Check `torchinfo`'s release notes for compatibility with the latest PyTorch versions.
affects: <1.4.0 (PyTorch), any version (potential for new PyTorch versions)
Upgrade
Version history
1.8.0latest on PyPI · released May 14, 2023
Audit
Dependencies
torchrequiredCore PyTorch library for model definition and tensor operations.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
torchinfo — pip install torchinfo · libregistry