-
Notifications
You must be signed in to change notification settings - Fork 64
serialization: apply new scheme for package (breaking change) #457
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
serialization: apply new scheme for package (breaking change) #457
Conversation
- introduces new policy for consistent naming for serilization (see bayesflow-org#451 for a discussion): standard is the path of a module a class resides in, trucated at depth to. So for all class in bayesflow.networks, we set package="bayesflow.networks", even if the live in the bayesflow.networks.mlp submodule. - The `serializable` decorator checks this and errors if this is not followed. The check can be disabled for certain cases (e.g., classes in the experimental module, that might eventually live somewhere else). - After this commit, previously saved models will not be loadable. As we introduced a bug regarding this anyway (bayesflow-org#451), we will accept this and should inform users about it. - usage of direct calls to `keras.saving.register_keras_serializable` were replaced with our custom decorator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should think about whether we want the current module check to be a flag in the serializable decorator. If users are supposed to use our pipeline rather than the one from keras, the check must be off by default.
I think one of the following options is better:
- We add a check in any
test_serialize_deserialize
for the module structure, but remove the flag from the decorator altogether. - We leave the flag in the current
serializable
decorator, but turn it off by default. Internal modules can use something likefrom bayesflow.internal import serializable
which is apartial(bayesflow.utils.serializable, disable_module_check=False)
I am in favor of 1, since it avoids the issue of 2 that new contributors may accidentally use the "wrong" kind of decorator.
…BayesFlow into serialize-explicit-check
Thanks for your comments. I like the idea of moving the test to the test suite, but as far as I can tell (correct me if I'm wrong) the Would you say that we actually want users to to use our decorator instead of the Keras-provided one? Currently the only thing it does is to supply this check, which is only relevant internally, so we could also think about making it private. Or do we expect to encounter future scenarios where we want to have additional functionality in this decorator? As we cannot rule out that users use the Keras decorator instead, I think this would not be so desirable anyways. What do you think? |
This should ensure that users that try to use our decorator with external classes do not encounter the error. Possible edge case: they also name their module "bayesflow".
Thanks for the update. I think users should use our decorator, as this gives us the most flexibility in terms of maneuvering around keras. |
Closes #451.
serializable
decorator produces wrong package for serialization #451for a discussion): standard is the path of a module a class resides
in, truncated at depth two. So for a class in
bayesflow.networks
, weset
package="bayesflow.networks"
, even if they live in thebayesflow.networks.mlp
submodule.serializable
decorator checks this and errors if this is notfollowed. The check can be disabled for certain cases (e.g., classes
in the experimental module, that might eventually live somewhere
else).
introduced a bug regarding this anyway ([BUG]
serializable
decorator produces wrong package for serialization #451), we will accept this andshould inform users about it.
keras.saving.register_keras_serializable
were replaced with our custom decorator.
Todo for next patch release