-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add README message to point users to Serialization stdlib, JLD2, and LightBSON #122
Comments
Agreed. Perhaps Flux docs should start pointing users to these libraries too? The most stable way to save a Flux model right now is to save the named tuple representation instead of the struct anyways. I know Legolas has its own system for saving/loading. Do you have a recommendation on which alternate library has worked best for you? |
I've been using LegolasFlux which uses Arrow to serialize the weights (incl non-trainable parameters like BatchNorm means/variances). It is a pretty light package, just traversing through the model to collect the arrays, then flattening them (since Arrow doesn't do multi-dim arrays well), and storing the sizes separately, and then reversing the process to deserialize. It does not keep track of the code/layers, and suggests storing an That has been working reliably, but may not be the best solution for everyone, since it means you have to keep track of the code yourself somewhat carefully, rather than storing it in the serialized artifact. Before that, we used Serialization, which works well unless the layout of one of the constitutient structures changes (e.g. fields move around in a layer, e.g. since you changed Flux versions), which can totally break deserialization. (This can be an issue for LegolasFlux as well, but you can still pull the weights out of the arrow table without an issue, but then to load them into the new structure maybe you need to rearrange them or something - still not great). Also, Serialization has trouble with anonymous functions and you need to ensure your model doesn't have any before serializing. Haven't tried any other options. |
To my knowledge BSON has all the same limitations as Serialization here, so the quickest change we could make is substituting it in the Flux docs. More tricky is updating Metalhead weights, though we could bundle that into the v0.8 release. Landing FluxML/Functors.jl#56 would make using different serialization libraries (including Legolas) much easier, but I'm partially responsible for holding it up with some bikeshedding, apologies. |
One thing we can do on the Flux side is to make clear that there are two options for storing models:
|
BSON.jl has many serious bugs, and despite targeting a generic format (BSON), the way it uses Julia internals to serialize arbitrary objects is not very robust. I think we should add a big README warning pointing new users to the Serialization stdlib (for serializing arbitrary objects & code), JLD2 (for arbitrary objects), and LightBSON (for serializing some objects to BSON, e.g. via the StructTypes API).
The text was updated successfully, but these errors were encountered: