-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
add method to make tensor constant for debug purposes #30458
Comments
https://pytorch.org/docs/stable/autograd.html#torch.autograd.detect_anomaly might solve the problem. IIRC it should tell you where in the forward pass you used an op that caused an error in backwards. |
I would agree that this would be a useful feature to have in general. |
One thing we could take design inspiration from is numpy's flags: https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html. One can set a numpy array's WRITEABLE flag to off, making the array read-only. |
Yes, i am trying to pinpoint the place with detect_anomaly and doing tensor.clone(), so making all the data readonly would be really helpful |
We've talked about this internally before too, it's a generally good idea we should support. |
Where should check for the flag be placed? I am not familiar with the source yet.. |
Not clear; the design for this may be fairly involved :) |
Maybe one could make this more general: we could introduce a hook if a tensor is modified inplace. This is a bit complicated as we would make it "if the storage underlying the tensor is modified inplace", but I think it would have more general applications, too (e.g. caching computations which only need to be re-computed when inputs change). |
馃殌 Feature
Add method to make constant tensors
tensor.make_const()
Motivation
This option will make it easy to find inplace operators in case of such exceptions:
Instead RuntimeError should be thrown when inplace operation is performed on constant tensor.
Alternatives
Perhaps it is even better to make all tensors constant by default, since inplace operators rarely needed.
cc @ezyang @ssnl @albanD @zou3519 @gqchen
The text was updated successfully, but these errors were encountered: