FluxML / Flux.jl

Relax! Flux is the ML library that doesn't make you tensor
https://fluxml.ai/
Other
4.54k stars 609 forks source link

Cryptic error in Flux#zygote "Can't differentiate foreigncall expression" #817

Closed mbeltagy closed 2 years ago

mbeltagy commented 5 years ago

We (@metanoid and I) were trying to see if can get the char-rnn example to work

We modified https://github.com/FluxML/model-zoo/blob/zygote/text/char-rnn/char-rnn.jl#L32:L36 to

function loss(xs, ys)
  l = sum(crossentropy.(m.(gpu.(xs)), gpu.(ys)))
  return l
end

assuming that call to truncate! will not longer been needed since we no longer doing tracking.

We got this very strange error


Can't differentiate foreigncall expression
in top-level scope at base/none
in  at base/none
in #train!#12 at Flux/MBJYi/src/optimise/train.jl:67
in macro expansion at Juno/TfNYn/src/progress.jl:124 
in macro expansion at Flux/MBJYi/src/optimise/train.jl:69 
in gradient at Zygote/fuj2C/src/compiler/interface.jl:47
in  at Zygote/fuj2C/src/compiler/interface.jl:101
in  at Zygote/fuj2C/src/compiler/interface2.jl
in #14 at Flux/MBJYi/src/optimise/train.jl:70 
in  at Zygote/fuj2C/src/lib/grad.jl:46
in #135 at Zygote/fuj2C/src/lib/lib.jl:129 
in  at char-rnn.jl:33
in  at Zygote/fuj2C/src/compiler/interface2.jl
in broadcasted at base/broadcast.jl:1161 
in #260#back at Zygote/fuj2C/src/lib/grad.jl:46 
in #135 at Zygote/fuj2C/src/lib/lib.jl:129 
in #3049#back at Zygote/fuj2C/src/lib/grad.jl:46 
in  at Zygote/fuj2C/src/lib/broadcast.jl:113
in map at base/abstractarray.jl:2091 
in collect at base/array.jl:606
in iterate at base/generator.jl:47 
in #3 at base/generator.jl:36 
in #1182 at Zygote/fuj2C/src/lib/broadcast.jl:113 
in  at Zygote/fuj2C/src/compiler/interface2.jl
in gpu at Flux/MBJYi/src/treelike.jl:68 
in  at Zygote/fuj2C/src/compiler/interface2.jl
in mapleaves at Flux/MBJYi/src/treelike.jl:28 
in  at Zygote/fuj2C/src/compiler/interface2.jl
in #mapleaves#39 at Flux/MBJYi/src/treelike.jl:28 
in  at Zygote/fuj2C/src/compiler/interface2.jl
in haskey at base/abstractdict.jl:17 
in  at Zygote/fuj2C/src/compiler/interface2.jl
in in at base/abstractdict.jl:665 
in  at Zygote/fuj2C/src/compiler/interface2.jl
in get at base/abstractdict.jl:594 
in error at base/error.jl:33
bhvieira commented 4 years ago

Zygote is probably trying to differentiate something inside Cuda. Why do you need to call gpu inside loss?

DhairyaLGandhi commented 4 years ago

I think this is a Julia 1.0 issue, and nothing we can do about it. There doesn't seem to be a problem otherwise, everything works as expected once the error is thrown

ToucheSir commented 2 years ago

Julia 1.6 is the new LTS, and AFAIK the char-nn should work on it.