-
Notifications
You must be signed in to change notification settings - Fork 231
BFGS GPU Support #931
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
BFGS GPU Support #931
Conversation
ChrisRackauckas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could fuse a bit more operations, but this probably isn't the place for high performance nasty code, so this will give the right mix of generality and conciseness.
Project.toml
Outdated
| Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" | ||
| PositiveFactorizations = "85a6dd25-e78a-55b7-8502-1745935b8125" | ||
| Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
| RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to add a compat
|
Thanks. I had to approve CI runs since this is your first contribution. Looks good to me. |
Codecov Report
@@ Coverage Diff @@
## master #931 +/- ##
==========================================
+ Coverage 83.60% 83.67% +0.06%
==========================================
Files 43 42 -1
Lines 3020 3019 -1
==========================================
+ Hits 2525 2526 +1
+ Misses 495 493 -2
Continue to review full report at Codecov.
|
|
Hello, I see in the release notes of v1.4 that this pull request has been merged. Does this mean that BFGS now has GPU support? I'm able to use LBFGS, but not BFGS on GPU. using GalacticOptim, CUDA, Optim, Zygote
CUDA.allowscalar(false)
lossFn(θ, p) = sum(abs, θ)
θ0 = cu(zeros(2));
f = OptimizationFunction(lossFn, GalacticOptim.AutoZygote())
prob = GalacticOptim.OptimizationProblem(f, initθ);
# sol1 = GalacticOptim.solve(prob, Optim.BFGS()); # doesn't work
# sol2 = GalacticOptim.solve(prob, Optim.LBFGS()); # worksDetails:
ERROR: LoadError: Scalar indexing is disallowed.
Invocation of getindex resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore are only permitted from the REPL for prototyping purposes.
If you did intend to index this array, annotate the caller with @allowscalar.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] assertscalar(op::String)
@ GPUArrays /scratch/user/vish0908/.julia/packages/GPUArrays/0vqbc/src/host/indexing.jl:53
[3] getindex(::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, ::Int64, ::Int64)
@ GPUArrays /scratch/user/vish0908/.julia/packages/GPUArrays/0vqbc/src/host/indexing.jl:86
[4] macro expansion
@ /scratch/user/vish0908/.julia/packages/Optim/3K7JI/src/multivariate/solvers/first_order/bfgs.jl:166 [inlined]
[5] macro expansion
@ ./simdloop.jl:77 [inlined]
[6] update_h!(d::TwiceDifferentiable{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}, state::Optim.BFGSState{CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat})
@ Optim /scratch/user/vish0908/.julia/packages/Optim/3K7JI/src/multivariate/solvers/first_order/bfgs.jl:165
[7] optimize(d::TwiceDifferentiable{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}, initial_x::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, options::Optim.Options{Float64, GalacticOptim.var"#_cb#103"{GalacticOptim.var"#101#109", BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, Base.Iterators.Cycle{Tuple{GalacticOptim.NullData}}}}, state::Optim.BFGSState{CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}})
@ Optim /scratch/user/vish0908/.julia/packages/Optim/3K7JI/src/multivariate/optimize/optimize.jl:71
[8] optimize(d::TwiceDifferentiable{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}, initial_x::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, options::Optim.Options{Float64, GalacticOptim.var"#_cb#103"{GalacticOptim.var"#101#109", BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, Base.Iterators.Cycle{Tuple{GalacticOptim.NullData}}}})
@ Optim /scratch/user/vish0908/.julia/packages/Optim/3K7JI/src/multivariate/optimize/optimize.jl:35
[9] __solve(prob::OptimizationProblem{true, OptimizationFunction{true, GalacticOptim.AutoZygote, typeof(lossFn3), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, SciMLBase.NullParameters, Nothing, Nothing, Nothing, Nothing, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, opt::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, data::Base.Iterators.Cycle{Tuple{GalacticOptim.NullData}}; maxiters::Nothing, cb::Function, progress::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ GalacticOptim /scratch/user/vish0908/.julia/packages/GalacticOptim/bEh06/src/solve/optim.jl:55
[10] __solve (repeats 2 times)
@ /scratch/user/vish0908/.julia/packages/GalacticOptim/bEh06/src/solve/optim.jl:10 [inlined]
[11] #solve#476
@ /scratch/user/vish0908/.julia/packages/SciMLBase/n3U0M/src/solve.jl:3 [inlined]
[12] solve(::OptimizationProblem{true, OptimizationFunction{true, GalacticOptim.AutoZygote, typeof(lossFn3), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, SciMLBase.NullParameters, Nothing, Nothing, Nothing, Nothing, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat})
@ SciMLBase /scratch/user/vish0908/.julia/packages/SciMLBase/n3U0M/src/solve.jl:3 |
|
The main culprit seems to be this function
|
TODO:
MWE:
Prev:
Curr: