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

Support for Reactant.jl #28

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Support for Reactant.jl #28

wants to merge 1 commit into from

Conversation

mcabbott
Copy link
Member

This doesn't work yet, but wants to work like this:

julia> using Flux, Fluxperimental, Reactant, Enzyme
julia> img = rand32(28, 28, 1, 128);
julia> loss(m, x) = sum(abs2, m(x));
julia> mlp = Chain(Flux.flatten, Dense(28^2 => 32, tanh), Dense(32 => 10));

julia> mlp(img)[1:3]  # plain Julia
3-element Vector{Float32}:
  0.22694848
 -0.72605485
  0.57976365

julia> re_mlp = Fluxactor(mlp);  # uses Reactant

julia> re_mlp(img)[1:3]
┌ Info: compiling...summary(xr) = "28×28×1×128 ConcreteRArray{Float32, 4}"
3-element ConcreteRArray{Float32, 1}:
  0.22694828
 -0.72605544
  0.57976323

julia> re_mlp  # after forward but not yet gradient
Fluxactor(
  Chain(
    Flux.flatten,
    Dense(784 => 32, tanh),             # 25_120 parameters
    Dense(32 => 10),                    # 330 parameters
  ),
  # compiled for 28×28×1×128 ConcreteRArray{Float32, 4}
  # norm(∇) ≈ 0.0f0
  # ∇compiled for nothing
)         # Total: 4 trainable arrays, 25_450 parameters,
          # plus 4 non-trainable, 25_450 parameters, summarysize 689 bytes.

julia> Flux.gradient(loss, mlp, img)[1].layers[2].bias[1:3]  # uses Zygote
3-element Vector{Float32}:
   90.490005
 -208.77806
   28.711397

julia> Flux.gradient(loss, re_mlp, Const(img))[1].layers[2].bias[1:3]  # uses Reactant
[ Info: compiling gradient(loss, ::Fluxactor)...

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

Successfully merging this pull request may close these issues.

1 participant