secondmind-labs / trieste

A Bayesian optimization toolbox built on TensorFlow
Apache License 2.0
221 stars 42 forks source link

Support saving models as tf.saved_model #750

Closed uri-granta closed 1 year ago

uri-granta commented 1 year ago

Support exporting trieste models using tf.saved_model. Note that we don't inherit from tf.Module for two reasons:

  1. it would limit type checking on models (since mypy treats tf.Module as Any)
  2. it wouldn't be enough by at itself anyway as some of our wrappers include other components that are themselves not tf.Modules

Instead we add a get_module_with_variables method for all models, which returns a tf.Module containing references to all the variables contained within the model (using recursive traversal). This can then be extended with any tf,function-decorated methods we wish to export.