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

ERROR: UndefVarError: to_same_device not defined #115

Closed
alastair-marshall opened this issue Jul 6, 2022 · 3 comments
Closed

ERROR: UndefVarError: to_same_device not defined #115

alastair-marshall opened this issue Jul 6, 2022 · 3 comments

Comments

@alastair-marshall
Copy link

Ran into a strange bug in Yota when I tried to broadcast a multiplication of a ComplexF64 to a Matrix of ComplexF64:

ERROR: UndefVarError: to_same_device not defined
Stacktrace:
  [1] unbroadcast_prod_x(x::ComplexF64, y::Matrix{ComplexF64}, Δ::Matrix{ComplexF64})
    @ Yota ~/.julia/packages/Yota/VCIzN/src/helpers.jl:78

I had a look in the source code and I can't see the function to_same_device anywhere inside the package.

P.S. I hit the error in the first place because I was lazy and didn't want to write a rrule for ChainRulesCore.rrule(::typeof(*), ::ComplexF64, ::Float64, ::Matrix{ComplexF64}) = ... and so I tried broadcasting the multiplication instead. I'm not sure if its a code path that anyone else would usually reach.

@dfdx
Copy link
Owner

dfdx commented Jul 6, 2022

Oh, I thought I got rid of them! to_same_device() used to move one array argument to the same device (e.g. CPU or GPU) as the other one. As a quick and dirty fix, you can try to redefine these methods without the conversion:

import Yota

Yota.unbroadcast_prod_x(x::Number, y::ArrayOrBroadcasted, Δ) = Yota.unbroadcast_prod_x([x], y, Δ)[1]
Yota.unbroadcast_prod_x(x::ArrayOrBroadcasted, y::Number, Δ) = Yota.unbroadcast_prod_x(x, [y], Δ)
Yota.unbroadcast_prod_y(x::ArrayOrBroadcasted, y::Number, Δ) = Yota.unbroadcast_prod_y(x, [y], Δ)[1]
Yota.unbroadcast_prod_y(x::Number, y::ArrayOrBroadcasted, Δ) = Yota.unbroadcast_prod_y([x], y, Δ)

I will try to come up with a better fix and tests in the next couple of days.

@dfdx
Copy link
Owner

dfdx commented Jul 8, 2022

Do you have a reproducible example that I can test the fix on?

@dfdx
Copy link
Owner

dfdx commented Jul 9, 2022

This should be fixed by #119 , please, let me know if it didn't help.

@dfdx dfdx closed this as completed Jul 9, 2022
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