FluxML/Flux.jl

Add docs note about saving/loading models with anonymous functions

Open

#2.263 aberto em 9 de jun. de 2023

Ver no GitHub
 (9 comments) (1 reaction) (0 assignees)Julia (619 forks)batch import
documentationhelp wanted

Métricas do repositório

Stars
 (4.725 stars)
Métricas de merge de PR
 (Mesclagem média 4h 27m) (2 fundiu PRs em 30d)

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.

Guia do colaborador