FluxML/Flux.jl

Add docs note about saving/loading models with anonymous functions

Open

#2263 opened on Jun 9, 2023

View on GitHub
 (9 comments) (1 reaction) (0 assignees)Julia (4,725 stars) (619 forks)batch import
documentationhelp wanted

Description

The new save/load docs promote JLD2.jl which does not support saving/loading anonymous functions reliably. This most commonly occurs for activation functions. The solution is to use Flux.state + Flux.loadmodel! and set the desired anonymous function in the destination of loadmodel!. This avoids needing the serialization library to correctly handle the anonymous function.

This will be problematic when the anonymous function contains data (state) that actually should be restored. A possible solution here is to make the closure an explicit struct. Maybe there are better solutions.

Regardless, new users are unlikely to realize these edge cases. We should expand the saving/loading documentation to explain how to handle these cases with code examples.

Contributor guide