Comments (4)
GLU
is currently not supported, so it's treated as an element-wise operation. However, since split
is supported, you can create your own GLU
operation like this:
class CustomGLU(nn.Module):
def __init__(self, dim=1):
super(CustomGLU, self).__init__()
self.dim = dim
def forward(self, x):
first_half, second_half = torch.split(x, x.size(self.dim)//2, dim=self.dim)
return first_half * torch.sigmoid(second_half)
If you don't use it extensively, the performance degradation shouldn't be significant.
from torch-pruning.
Hi @janthmueller, thanks for the workaround, I tried that but the network comes back with only the last conv layer pruned. No dep group with first conv layer is being returned for pruning.
from torch-pruning.
Hi @janthmueller, thanks for the workaround, I tried that but the network comes back with only the last conv layer pruned. No dep group with first conv layer is being returned for pruning.
After running the get_pruning_group
method within the prune_local
function of the MetaPruner
class, you might notice that the group containing the first layer appears to have double the number of indices. This likely occurs to prevent shape mismatch errors. However, with a pruning ratio of 0.5, attempting to prune the entire output of the first layer becomes impossible. This is because a group is ignored for pruning if all its filters or channels are pruned, resulting in nothing being pruned in your case.
To accommodate this scenario, it's crucial to apply a targeted adjustment before gathering the pruning_idxs
. Specifically, for groups involving the custom glu operation, a workaround involves halving the number of pruned indices (n_pruned
) for the affected group. This ensures that the pruning process correctly reflects the intended proportion.
To implement this adjustment, insert the following code snippet before collecting pruning_idxs
within both the prune_local
and prune_global
methods:
for dep, _ in group:
if isinstance(dep.target.module, ops._SplitOp):
n_pruned = n_pruned // 2
break
By incorporating this adjustment, the pruning mechanism can appropriately handle scenarios involving the custom glu operation, ensuring accurate pruning outcomes.
I think it might be best to fix this for all possible scenarios including a split, maybe similar to _is_attn_group
with a _is_split_group
check @VainF.
from torch-pruning.
Great, thanks for the workaround and the explanation!
It would be great to have this merged such that the lib works directly on GLU!
from torch-pruning.
Related Issues (20)
- AttributeError: Can't get attribute '__main__' on <module 'builtins' (built-in)>
- Improve Iterative Pruning: Verify Pruning Status Before Training HOT 1
- The QRcode of WeChat group has expired, could anyone please share a new one? HOT 1
- Yolov8 upgrade ultralytics version HOT 2
- Cannot calculate importance score for a single group HOT 1
- What is 'N' in "Iˆ = N · I / P{TopN(I )}" HOT 1
- Yolov8 pruning with Taylor criteria
- Add hooks to a module (make sure the hooks are removed), cannot deepcopy OBB model HOT 1
- How to make tracer account for arbitrary restrictions such as making a particular dim divisible by 4? HOT 1
- Hi i have already sparsity the gamma of layerNorm in Segformer. Can I use the methode to prune the model ?
- Clarification around MetaPruner
- How can I get the mask of the pruned model when I apply the soft pruning?
- loss stop reducing after pruning.
- Can the process of structural pruning be rolled back?
- The parameters and computation decreased, but FPS was worse than the baseline model HOT 2
- AttributeError: partially initialized module 'torch_pruning' has no attribute 'DependencyGraph' HOT 1
- Yolov10 Pruning HOT 3
- Fine-Tuning a U-Net trained using MONAI lib
- 微信群 HOT 6
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.