Skip to content
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

Torch warning about copying tensors #139

Open
talonchandler opened this issue Jul 25, 2023 · 1 comment
Open

Torch warning about copying tensors #139

talonchandler opened this issue Jul 25, 2023 · 1 comment

Comments

@talonchandler
Copy link
Collaborator

recOrder tests surfaced the following warnings at optics.py:321, optics.py:370, and stokes.py:291

recOrder/tests/cli_tests/test_reconstruct.py::test_reconstruct
  /Users/talon.chandler/waveorder/waveorder/optics.py:321: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
    * torch.tensor(z_position_list)[:, None, None]

You can generate these warnings with a call like

import torch
torch.tensor(torch.tensor([0,1,2]))[:,None,None]

The core issue seems to be that some optics and stokes functions can take either a list or a tensor.

@ziw-liu do you think we should make sure that only lists are passed? Or can you think of a simpler solution?

This does not seem critical.

@ziw-liu
Copy link
Contributor

ziw-liu commented Jul 25, 2023

We can use a simple util function to convert lists to tensor. This raises a warning because it is an implicit copy and can be quite expensive depending on the size of the tensors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants