-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Optimiser state a not moving to GPU #179
Comments
can be fixed with julia> Adapt.@adapt_structure Optimisers.Leaf
julia> cu(opt_st).state[1]
2-element CuArray{Float32, 1, CUDA.DeviceMemory}:
0.0
0.0 |
Since Leaf is a functor, it will move to GPU when using Flux.gpu or MLDataDevices.jl. Also, if the input to setup is on GPU (which tipically is what you want), the state will be on GPU as well. So maybe there is no need for Adapt? |
I routinely save the optimizer state to checkpoint files during training. So I need to move em back to the GPU when I restart training. |
Yes, but that's already doable with |
Thanks for the speedy reply @ToucheSir, my use case is below. I am using (from #180 (comment))
using Optimisers, CUDA, LuxCUDA, MLDataDevices, Adapt
struct TrainState{Tp, To}
p::Tp
opt_st::To
end
Adapt.@adapt_structure TrainState
p = rand(2)
opt_st = Optimisers.setup(Optimisers.Adam(), p)
ts = TrainState(p, opt_st)
device = gpu_device()
device(ts).opt_st.state[1]
2-element Vector{Float64}:
0.0
0.0 |
Per the docs, you need to define |
Thanks all, I appreciate your patience in explaining this to me. I directly defined function (dev::MLDataDevices.CPUDevice)(state::TrainState)
TrainState(dev(state.p), dev(state.opt_st))
end |
The text was updated successfully, but these errors were encountered: