Skip to content

Generalize Flux to allow use of other AD systems #139

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

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/GalacticOptim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ using Reexport
@reexport using DiffEqBase
@reexport using SciMLBase
using Requires
using DiffResults, ForwardDiff, Zygote, ReverseDiff, Tracker, FiniteDiff
using DiffResults, ForwardDiff, Zygote, ReverseDiff, FiniteDiff
import Tracker
@reexport using Optim, Flux
using Logging, ProgressLogging, Printf, ConsoleProgressMonitor, TerminalLoggers, LoggingExtras
using ArrayInterface, Base.Iterators
Expand Down
9 changes: 3 additions & 6 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function __solve(prob::OptimizationProblem, opt, data = DEFAULT_DATA;
# Flux is silly and doesn't have an abstract type on its optimizers, so assume
# this is a Flux optimizer
θ = copy(prob.u0)
ps = Flux.params(θ)
G = copy(θ)

t0 = time()

Expand All @@ -87,10 +87,7 @@ function __solve(prob::OptimizationProblem, opt, data = DEFAULT_DATA;

@withprogress progress name="Training" begin
for (i,d) in enumerate(data)
gs = Flux.Zygote.gradient(ps) do
x = prob.f(θ,prob.p, d...)
first(x)
end
f.grad(G, θ, d...)
x = f.f(θ, prob.p, d...)
cb_call = cb(θ, x...)
if !(typeof(cb_call) <: Bool)
Expand All @@ -100,7 +97,7 @@ function __solve(prob::OptimizationProblem, opt, data = DEFAULT_DATA;
end
msg = @sprintf("loss: %.3g", x[1])
progress && ProgressLogging.@logprogress msg i/maxiters
Flux.update!(opt, ps, gs)
Flux.update!(opt, θ, G)

if save_best
if first(x) < first(min_err) #found a better solution
Expand Down
5 changes: 0 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ if GROUP == "All" || GROUP == "Core"
@safetestset "DiffEqFlux" begin include("diffeqfluxtests.jl") end
end

if !is_APPVEYOR && GROUP == "Downstream"
activate_downstream_env()
Pkg.test("DiffEqFlux")
end

if !is_APPVEYOR && GROUP == "GPU"
activate_downstream_env()
@safetestset "DiffEqFlux GPU" begin include("downstream/gpu_neural_ode.jl") end
Expand Down