OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Torch Pruning

Torch-Pruning is a Python framework for structurally pruning deep neural networks with DepGraph, which identifies coupled parameters so they can be removed together. Unlike mask-based pruning, its operations change model structure. The repository provides examples across language and vision model families.

Independent OpenViST project profile, based on linked sources.

Torch Pruning — OpenViST project profile in AI Developer Tools & SDKs.
OpenViST project illustration. See the linked sources for product details.
Understand the project

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.
Before you choose

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.

Source-based practical guide

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

  1. Create the ResNet-18 model in evaluation mode and construct a dummy input.

  2. Build a DependencyGraph with the model and example input.

  3. Request a pruning group for the selected convolution output channels and indices.

  4. Check the group with check_pruning_group; if accepted, call group.prune().

  5. 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=False option may be needed when loading with PyTorch 2.6.0 or later.
  • The recipe does not establish model accuracy or runtime performance after pruning.
Evidence and transparency

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