Learning Julia metaprogramming to automatically construct ANN by expression. While everything works well for inference, a backward stage raises an error:
LoadError: Can't differentiate foreigncall expression
The next code shows where the problem appears. While eval(net(x)) works well, for some reason it throws an error at the gradient computation stage.
# define ANN by expression
net(x) = :($w2 * relu.($w1 * $x .+ $b1) .+ $b2)
# define loss and network evaluation
loss(x, y) = Flux.logitcrossentropy(eval(net(x)), y)
θ = Flux.Params([w1, b1, w2, b2])
# eval network and calculate gradients
gs = gradient(() -> loss(features, labels), θ) # where the problem appears