Comments (4)
Hi Qiyao,
Beware of BatchNorm
; most of the quantities returned by BackPACK are not defined when there's a batchnorm layer in the middle (see e.g. #239).
Easy checks of things that can cause something like this to happen would be calling backward
twice (where the first backward clears the graph, and the second backward
then crashes), and maybe missing a call to backpack.extend(model)
. But this doesn't seem to be the case here.
Only a rough guess looking at the stack, but the error might be specific to BatchNorm.
The error occurs after the computation of the backward pass, during cleanup.
delete_old_quantities = not self.__should_retain_backproped_quantities(module)
. The error 'BatchNorm2d' object has no attribute 'output'
indicates that the extension needed to store additional quantities during the forward pass (the output of the layer) but did not. This is weird; I would expect it to crash much earlier. What extension are you running with batchnorm?
from backpack.
- hmmm, is there currently an alternative to BatchNorm? I guess it would be safest to just stick to linear and conv layers + activations, although the accuracy will for sure decrease in that case
- Yeah I don't think I am calling backward twice, and I made sure to add model = extend(model). BTW, the documentation page also recommended trying use_converter=True, but I guess that one has its own bugs so I did not dig deeper.
- Even though I don't have the full MWE ready, the error code is easy to share
model = get_cls_net()
model = extend(model)
with backpack(BatchGrad()):
model(torch.rand(1,3,32,32)).sum().backward()
The weird thing is, BatchNorm worked with this code when I was trying it on a smaller model, so what I am doing right now is trying to sort out the structural differences between these two models and see if I can find anything useful
from backpack.
is there currently an alternative to BatchNorm?
There are, for example GroupNorm or LayerNorm (see https://pytorch.org/docs/stable/nn.html#normalization-layers).
The problem with BatchNorm is that there are no "individual gradient"; it is not possible to isolate the contribution of one sample to the loss because BatchNorm mixes them.
What's the model (get_cls_net
)?
from backpack.
Oh I thought backpack doesn't support GroupNorm
BTW I might have figured out the issue, it goes away when I do add an eval like: extend(model).eval(). Not sure why but I guess that is a fix!
from backpack.
Related Issues (20)
- Support for Custom models? HOT 1
- AttributeError: 'Parameter' object has no attribute 'grad_batch' HOT 7
- pytorch 1.13 support HOT 2
- Extending `BCEWithLogitsLoss` to non-binary labels
- [Feature Request] Levenberg Marquardt HOT 1
- cannot import backpack nor extend HOT 9
- Are customized loss functions supported? HOT 10
- Optimizing the locations of the Jacobians HOT 5
- add support for torch 2.0? HOT 7
- Encountered node that may break second-order extensions HOT 2
- Second order extension HOT 2
- Container modules with advanced control flow & modules with multiple inputs HOT 23
- torch version < 2.x in `setup.cfg` HOT 2
- AdaptiveAvgPool not supported for 2nd order derivatives? HOT 4
- Missing implementation of supported layers for DiagHessian and BatchDiagHessian
- Facing error while Using DiagHessian for torchvision.models.resnet18 HOT 1
- Feature for backpack on VAEs HOT 2
- Extend backpack to deal with weighted sums HOT 14
- Missing Support for BatchNorm and AdaptiveAvgPool in HBP methods (KFAC, KFRA, KFLR) and GGNMP HOT 8
- Second Order Extensions for Custom Loss Modules HOT 8
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 backpack.