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

An Issue with solve_1d_linesearch_quad Function #442

Closed
Nuwaisir-1998 opened this issue Mar 8, 2023 · 3 comments
Closed

An Issue with solve_1d_linesearch_quad Function #442

Nuwaisir-1998 opened this issue Mar 8, 2023 · 3 comments

Comments

@Nuwaisir-1998
Copy link

I had this error: TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

After some observation, I found that inside solve_1d_linesearch_quad function in optim.py, np.divide is used. I think it should be nx.divide where nx = get_backend(a, b, c). And inside TorchBackend class, a new method for divide should be added that uses torch.div function.

@rflamary
Copy link
Collaborator

rflamary commented Mar 8, 2023

Hello @Nuwaisir-1998 very good point!

We are reworking all the optimization pipeline in PR #431 and I seem to recall that this has been corrected. @cedricvincentcuaz could you confirm that the PR correct this bug?

@cedricvincentcuaz
Copy link
Collaborator

cedricvincentcuaz commented Mar 8, 2023

Hello @Nuwaisir-1998 and @rflamary.

Indeed this np.divide operation has been removed in PR #431 to prevent this kind of error. The minimum is now computed using only python operators as minimum = min(1., max(0., -b / (2.0 * a))) which inherits the type of a and b, whether there are 1D tensors or floats. Note that the priority system of any backend implies that if a is a tensor and b a float, minimum will be a tensor of the same type than a (and vice-versa).

I do not think that a new method nx.divide is necessary in this function. Please correct me if I am wrong.

@Nuwaisir-1998
Copy link
Author

Hi @cedricvincentcuaz,
I think you are correct, thanks!

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

No branches or pull requests

3 participants