This CVPR tool actually deletes neurons instead of masking them
A graph algorithm automatically tracks which layers must be trimmed together when you shrink a PyTorch model.

What it does
Torch-Pruning is a structural pruning framework for PyTorch that physically removes parameters rather than zeroing them out with masks. It supports a wide range of architectures, from classic CNNs to modern vision transformers, diffusion models, and large language models including DeepSeek-R1-Distill, Llama, and Qwen. The library offers both low-level pruning functions and high-level pruners for global, group-level, and interactive workflows.
The interesting bit
The core algorithm, DepGraph, treats the model as a computational graph and automatically discovers coupled layers—so if you prune an output channel from one convolution, it knows exactly which batch norms, activations, and subsequent layers must also be trimmed to keep the network valid. This automates the tedious bookkeeping that usually makes structural pruning error-prone.
Key highlights
- Backed by a CVPR 2023 paper and an ECCV 2024 follow-up (Isomorphic Pruning) for vision transformers and modern CNNs.
- Works off-the-shelf with Hugging Face, Timm, and Torchvision models, including YOLO, SAM, BERT, and Swin Transformers.
- Requires only PyTorch and NumPy; compatible with PyTorch 1.x and 2.x.
- Includes high-level pruners for global pruning, sparse training, and interactive pruning scenarios.
Caveats
- Building the dependency graph requires AutoGrad to be enabled, so model analysis cannot run inside
torch.no_grad(). - Pruned models must be saved and loaded as whole model objects rather than
state_dictsnapshots, and PyTorch 2.6.0+ users needweights_only=Falsefor loading. - You must explicitly validate pruning groups before trimming; the library guards against over-pruning channels to zero, but only if you invoke the check.
Verdict
Worth exploring if you need to shrink production PyTorch models for latency or memory, especially when dealing with complex modern architectures where manual layer coupling would be painful. Skip it if you are only experimenting with unstructured sparsity or prefer simple magnitude-based masking.
Frequently asked
- What is VainF/Torch-Pruning?
- A graph algorithm automatically tracks which layers must be trimmed together when you shrink a PyTorch model.
- Is Torch-Pruning open source?
- Yes — VainF/Torch-Pruning is open source, released under the MIT license.
- What language is Torch-Pruning written in?
- VainF/Torch-Pruning is primarily written in Python.
- How popular is Torch-Pruning?
- VainF/Torch-Pruning has 3.3k stars on GitHub.
- Where can I find Torch-Pruning?
- VainF/Torch-Pruning is on GitHub at https://github.com/VainF/Torch-Pruning.