# Flux.jl: Save model and optimizer from gpu

**URL:** <https://discourse.julialang.org/t/flux-jl-save-model-and-optimizer-from-gpu/89982>\
**Category:** Machine Learning\
**Tags:** question\
**Created:** [November 9, 2022, 12:51pm UTC](https://discourse.julialang.org/t/flux-jl-save-model-and-optimizer-from-gpu/89982 "2022-11-09T12:51:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [November 9, 2022, 12:51pm UTC](https://discourse.julialang.org/t/flux-jl-save-model-and-optimizer-from-gpu/89982/1 "2022-11-09T12:51:08Z")

</div>

I am trying to save my Flux.jl model and the optimizer to disk. This seems to work just fine when everything is on the CPU but I cannot get the optimizer out of the GPU. `cpu(opt)` doesn’t seem to do anything. Is this supported? There a dedicated paragraph on saving the state of the optimizer in the documentation [1].

[1] [Flux.jl/saving.md at master · FluxML/Flux.jl · GitHub](https://github.com/FluxML/Flux.jl/blob/master/docs/src/saving.md)

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [November 9, 2022, 9:06pm UTC](https://discourse.julialang.org/t/flux-jl-save-model-and-optimizer-from-gpu/89982/2 "2022-11-09T21:06:05Z")

</div>

This is one big weak point of the current Flux optimizer design, and there’s no easy way to fix it. That’s why Flux is moving to use [GitHub - FluxML/Optimisers.jl: Optimisers.jl defines many standard optimisers and utilities for learning loops.](https://github.com/FluxML/Optimisers.jl), which _does_ let you do `cpu(opt_state)` and save things that way. If you can, I’d recommend switching to it today so that you’re also future-proofed when Flux switches over.
