Practical overview
When it fits
Use it when a PyTorch workflow calls for structural model changes and you can provide an example input for dependency-graph construction.
Who it is for
- PyTorch developers adding structural pruning to a model workflow.
- Researchers comparing model-compression approaches across neural-network architectures.
Documented uses
- Identify dependencies between parameters or dimensions across model layers.
- Remove coupled model components together rather than only applying zero-valued masks.
- Build compression experiments using examples for language, vision and other neural-network models.
Requirements & limits
The repository is public and specifies the MIT license. The README provides pip and editable-install instructions.
- The dependency graph is built using PyTorch AutoGrad, which the README says must remain enabled for graph construction.
- Graph construction requires a dummy example input representative of the model’s input shape.
- The README contrasts structural removal with
torch.nn.utils.prune, which uses masking. - Version guidance differs: the technical summary specifies PyTorch 2.0 or later, while the README says compatible with PyTorch 1.x and 2.x.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Build a dependency graph and prune selected ResNet channels
Use the README’s ResNet-18 example to build a dependency graph and prune a checked group of output channels.
Before you start
- PyTorch, Torchvision and Torch-Pruning installed
- A ResNet-18 model
- An example input shaped for the model, as in the README
- AutoGrad enabled during graph construction
Steps
Create the ResNet-18 model in evaluation mode and construct a dummy input.
Build a DependencyGraph with the model and example input.
Request a pruning group for the selected convolution output channels and indices.
Check the group with
check_pruning_group; if accepted, callgroup.prune().Clear gradients and save the structurally changed model; reload it using the README’s guidance.
Expected outcome
The selected channels and dependency-linked parameters are pruned, and the example saves the modified model.
Guide limitations
- The README example uses specific ResNet-18 layer names, channel indices and input shape; adapt them to the model being pruned.
- The README warns that pruning must not remove all channels and notes a
weights_only=Falseoption may be needed when loading with PyTorch 2.6.0 or later. - The recipe does not establish model accuracy or runtime performance after pruning.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 13 October 2026
- Original website title
- VainF/Torch-Pruning · Official homepage title · retained in its source language

