Comments (5)
Have you solved it, I also met the error.
from torch-pruning.
I have got same problem on version 0.2.7. I just use torch_pruning==0.2.6.
from torch-pruning.
I am facing the same issue with another model. Tried both 0.2.6 and 0.2.7 versions. Does anyone know how to fix it?
from torch-pruning.
Hi @MPiotr, does this problem still exist with the latest commit?
This script works for me:
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
import torch
import torch.nn as nn
import torch_pruning as tp
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.conv1 = nn.Conv2d(1, 6, 5)
self.relu1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.relu2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(2)
self.fc1 = nn.Linear(256, 120)
self.relu3 = nn.ReLU()
self.fc2 = nn.Linear(120, 84)
self.relu4 = nn.ReLU()
self.fc3 = nn.Linear(84, 10)
self.relu5 = nn.ReLU()
def forward(self, x):
y = self.conv1(x)
y = self.relu1(y)
y = self.pool1(y)
y = self.conv2(y)
y = self.relu2(y)
y = self.pool2(y)
y = y.view(y.shape[0], -1)
y = self.fc1(y)
y = self.relu3(y)
y = self.fc2(y)
y = self.relu4(y)
y = self.fc3(y)
y = self.relu5(y)
return y
model = Model()
# pruning according to L1 Norm
strategy = tp.strategy.L1Strategy() # or tp.strategy.RandomStrategy()
# build layer dependency for resnet18
DG = tp.DependencyGraph()
DG.build_dependency(model, example_inputs=torch.randn(1,1,28,28))
# get a pruning plan according to the dependency graph. idxs is the indices of pruned filters.
pruning_idxs = [0, 2, 6] #strategy(model.conv1.weight, amount=0.4) # or manually selected [0, 2, 6]
pruning_plan = DG.get_pruning_plan( model.fc2, tp.prune_linear_out_channel, idxs=pruning_idxs )
print(pruning_plan)
# execute this plan (prune the model)
if DG.check_pruning_plan(pruning_plan):
pruning_plan.exec()
from torch-pruning.
Hi, @VainF, thank you for reply. Eventually, that was my mistake. Some gradients of the model were frozen, that broke the graph builder
from torch-pruning.
Related Issues (20)
- torch pruning + DETR HOT 1
- yolov8-pose cuda error HOT 4
- module2node bug HOT 1
- 关于全局剪枝
- YOLOv8剪枝 HOT 5
- Pruning other models, reporting errors
- Wouldn't it be better to use Real-world data for pruning?
- 关于分组剪枝
- Need a example for pruning my own Block
- Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!
- Training is slow after switching to your own data set HOT 1
- yolov7
- Fails Pruning on Mobilenet v2 and v3 HOT 1
- Importance Ambiguity HOT 1
- prune DeSTSeg
- pruning_ratio_dict HOT 1
- What exactly does this method prune? HOT 1
- Layer and Weights are Ambiguous
- How to iteratively prune in yolov5? HOT 1
- Channel Sorting HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torch-pruning.