Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

fix dot product for newer version of torch#25

Merged
ozansener merged 1 commit intoisl-org:masterfrom
shaanrockz:master
Apr 12, 2021
Merged

fix dot product for newer version of torch#25
ozansener merged 1 commit intoisl-org:masterfrom
shaanrockz:master

Conversation

@shaanrockz
Copy link
Copy Markdown
Contributor

fix(min_norm_solvers.py): change torch.dot -> torch.mul followed by sum() for Matrix dot product
fix(min_norm_solvers.py): change data[0] to data.cpu()

fix(min_norm_solvers.py): change torch.dot -> torch.mul followed by sum() for Matrix dot product
fix(min_norm_solvers.py): change data[0] to data.cpu()
@allenjack
Copy link
Copy Markdown

Hi, when running the code under my setting, I also got the issue "RuntimeError: 1D tensors expected, got 2D". How I solve this issue is that I flatten the original tensor gradients and make it fit into the torch.dot function.

If what I am doing is correct, we are simply doing an element-wise matrix followed by sum() instead of torch.mul.

Hope someone can clarify it.

@shaanrockz
Copy link
Copy Markdown
Contributor Author

Hi, when running the code under my setting, I also got the issue "RuntimeError: 1D tensors expected, got 2D". How I solve this issue is that I flatten the original tensor gradients and make it fit into the torch.dot function.

If what I am doing is correct, we are simply doing an element-wise matrix followed by sum() instead of torch.mul.

Hope someone can clarify it.

Hi,
Sorry for late reply. Yes, that will also work. I however found another issue with the '.data[0]' for newer version of torch, we need to convert it to cpu if the tensors are in gpu.
torch.dot() requires 1D tensor inputs, that is why I used torch.mul() followed by sum().
Cheers

Copy link
Copy Markdown
Collaborator

@ozansener ozansener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants