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

Can't differentiate foreigncall expression when trying to compute gradient #1338

Closed
LucasPa opened this issue Sep 18, 2020 · 2 comments
Closed

Comments

@LucasPa
Copy link

LucasPa commented Sep 18, 2020

Hi,

I am beginner in Julia and I would like to use Flux. I tried to do the following:

using Flux
NN = Chain(Dense(1, 5, σ), Dense(5, 1, σ))

model(x) = NN([x])[1];
df(x) = gradient(model, x)[1]

function lossEq(x)
(df(x) - 2.0 * x - 3)^2
end

gs = gradient(() -> lossEq(0.2), params(NN))

But the following error is raised:

ERROR: Can't differentiate foreigncall expression

Is it actually possible to compute such a gradient that involves a gradient ?

Best,

Lucas

@DhairyaLGandhi
Copy link
Member

You should be able to see this. You could also check out https://github.com/DhairyaLGandhi/Zygote.jl/tree/dg/iddict to see if that works out better

@DhairyaLGandhi
Copy link
Member

Also, when taking nested gradients, it might be better to call y, back = Zygote.pullback(...) and then back(...) explicitly.

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

3 participants