question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GPflow wrapper update may be incompatible with tf.function()

See original GitHub issue

As mentioned on https://github.com/secondmind-labs/trieste/pull/54, there might be an issue with the current way of how Trieste updates data in GPflow models when you want to use tf.function to speed up the prediction step (currently, Trieste only uses tf.function for model optimization, and relies on eager mode for predictions).

VariationalGaussianProcess.update() sets the model’s data attribute to the new (X, Y) tuple. However, if model.predict_f() is wrapped in tf.function(), it will store the values of (X, Y) when first called in the cached graph. To enable data update with tf.function(), model.data must be set to a tuple of tf.Variables, which are then .assign()ed rather than overwritten in VariationalGaussianProcess.update().

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
johnamcleodcommented, Jul 2, 2021

model.num_data in a variable causes the elbo method to fail

Unfortunately the tf.eye function only supports Tensors, Python Integral and np.integer types for the first input. If none of those work with tf.function you could consider creating a subclass of the VGP model in Trieste to turn the num_data attribute into a @property. Then it could be dynamically calculated from the size of the Xdata variable. If that works we could incorporate it into GPflow.

0reactions
uri-grantacommented, Jul 2, 2021

I’m currently looking at this (see #271) and am hitting an issue with updating the VGP wrapper. Putting model.data in two variables works fine, but putting model.num_data in a variable causes the elbo method to fail when it tries to execute tf.eye(self.num_data, dtype=default_float()), claiming the self.num_data isn’t an integer. Any idea if there’s a way round this? @johnamcleod

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is GPflow's Scipy optimizer incompatible with decorating ...
Scipy() is a wrapper around Scipy's minimize(), and as it calls into non-TensorFlow operations, you cannot wrap it in tf.function .
Read more >
GPflow with TensorFlow 2
In TensorFlow 2, we can optimize (trainable) model parameters with TensorFlow optimizers using tf.GradientTape . In this simple example, we perform one gradient ......
Read more >
tf.function | TensorFlow v2.11.0
Compiles a function into a callable TensorFlow graph. ... f() <tf.Tensor: ... numpy=array([7, 7], ...)> func may also use ops with side ...
Read more >
Bayesian Optimisation for Sequential Experimental Design ...
Finding the optimal design of an experiment can be challenging. ... then the acquisition function will be updated with the results of that...
Read more >
GPflow - Bountysource
Currently, the GPflow Scipy optimizer wrapper ( gpflow.optimizers. ... as well as deserialization functions for each submodule (e.g. we would deserialize a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found