-
Notifications
You must be signed in to change notification settings - Fork 4
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"view size is not compatible with input tensor's size and stride" #1
Comments
Thanks, I will check if the fix is OK, and merge it. |
Fixed. thanks |
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for the great LBFGS optimizer. This issue is to bring to your attention an error that appeared for my use case.
I was using the LBFGS optimizer as a general purpose optimizer, with it being initialized as
optimizer = LBFGSNew([tensor_1, tensor_2], lr=lr, history_size=6, max_iter=4, line_search_fn=True)
for example.I got the following error during an optimization step:
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
This error did not appear when I did optimizations with respect to single tensors, for example:
optimizer = LBFGSNew([tensor_1], lr=lr, history_size=6, max_iter=4, line_search_fn=True)
Based on this Pytorch issue, I'm guessing that the way that the separate tensors are (combined?) and stored in memory is not contiguous.
I managed to avoid the error by changing all the lines that used
.view(...)
to.reshape(...)
or.contiguous().view(...)
, with these lines being lines 87, 89 and 108:pytorch/lbfgsnew.py
Line 87 in 6c229b9
pytorch/lbfgsnew.py
Line 89 in 6c229b9
pytorch/lbfgsnew.py
Line 108 in 6c229b9
My optimization seemed to work out well after this change (I opted for the
.contiguous().view(...)
change), but I just wanted to check if these changes won't create other problems as I'm not sure about the motivation for using.view(...)
over.reshape(...)
in the first place. Thank you!The text was updated successfully, but these errors were encountered: