Comments (7)
The commit doesn't actually change the behavior, it just makes the code easier to read. rbot0
and rbot1
will be modified in place, so even though in the previous version we put the save_for_backward
before populating rbot0
and rbot1
, the saved tensors weren't just zeros. You can verify this using gradcheck for example. That is, change all float
to double
in the correlation.py
and run the following code. Then change the location of save_for_backward
and try again. The gradcheck will pass both times. As for why I don't use comments, I have the philosophic that if your code requires comments then the code itself isn't written well enough (just my opinion though, I am well aware that the readability could still be improved with comments).
import torch
import sys; sys.path.insert(0, './correlation'); import correlation
class Network(torch.nn.Module):
def __init__(self):
super().__init__()
# end
def forward(self, tenOne, tenTwo):
return correlation.FunctionCorrelation(tenOne=tenOne, tenTwo=tenTwo)
# end
# end
netTest = Network().cuda()
tenOne = torch.randn(2, 4, 10, 10).double().cuda().requires_grad_()
tenTwo = torch.randn(2, 4, 10, 10).double().cuda().requires_grad_()
torch.autograd.gradcheck(func=netTest, inputs=tuple([tenOne, tenTwo]))
from pytorch-pwc.
I'm not quite buying that theory that save_for_backward
lets you modify the values afterwards. The reason I say this is that my epochs were taking 29 hours but after this change they are now taking 30 hours. Something is taking longer to calculate and this was the only change I made.
from pytorch-pwc.
I'm not quite buying that theory that save_for_backward lets you modify the values afterwards.
If you don't believe me then I encourage you to give it a try yourself. Print the average rbot0
in the backwards function and play around with the implementation. rbot0
(and rbot1
) will be nonzero regardless of where save_for_backward
is called but if you instead remove the two calls to kernel_Correlation_rearrange
then rbot0
(and rbot1
) will be zero.
from pytorch-pwc.
It isn't so much that I don't believe you. I know you have more experience with this than I do. I just don't understand why that change would be more computational if the value was allowed to be modified after the save_for_backward
plus the default for new_zeros
is requires_grad = False
which is what is declared right before the original save_for_backward
so a grad check on that tensor wouldn't show anything. Besides I always thought in place variable changes were the ones being passed in not on ones being passed out. It seems like save_for_backward
would retain the value at the time it was called but I can't find a lot of documentation on it.
from pytorch-pwc.
the one thing I do see is that mark_dirty
must be used to mark any input that is modified inplace by the forward function. It makes more sense if that is supposed to be used on rbot0
and rbot1
. I didn't really understand the use of mark_dirty
and I could not find a single example.
from pytorch-pwc.
I am afraid that I don't know what happens in PyTorch internally. Both versions of save_for_backward
produce the same result though, so if one is faster then the other for you there is nothing that should hold you back form using the faster one. 🙂
from pytorch-pwc.
Well as long as you are sure. I still wonder why the computations are taking longer though. It certainly seemed like it made a big difference in my loss total as well. I'm a PL/SQL developer in my professional life and I'm still very new at Python and Pytorch. I appreciate all of the information @sniklaus
from pytorch-pwc.
Related Issues (20)
- Can it test in CPU device? HOT 1
- Cannot inspect the model using TensorBoard HOT 4
- Generalization to unseen data HOT 1
- how to compute optical flow for small size imgs? HOT 1
- what is the range of optical flow value in an image? HOT 1
- About the direction of estimated flow HOT 2
- About pwc-net pretrained model in pytorch version HOT 1
- In run.py, self.netSix has out_channels = 196. Paper says 192. HOT 1
- Receiving a random error, CUDA_ERROR_ILLEGAL_ADDRESS HOT 9
- CuPy correlation layer error HOT 4
- Cupy cuda error. HOT 1
- What is the purpose of `tenMask` in `run.backwarp`? HOT 2
- the two same images HOT 4
- I already did what @fabiopk said but I am still getting this error HOT 2
- How to change the cuda version of correlation.py to the python version HOT 1
- how to import frames of river videos into PWC-Net codes HOT 7
- cupy issue HOT 1
- Normalization in `backward` function. HOT 1
- Deprecation of cupy.cuda.compile_with_cache() in cupy 13.0 HOT 3
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 pytorch-pwc.