Handling unconnected gradients in Scipy optimizer
See original GitHub issueFeature request
Our Scipy optimizer wrapper should explicitly handle unconnected gradients.
Motivation
Currently, the GPflow Scipy optimizer wrapper (gpflow.optimizers.Scipy
) simply errors (with one of the typically unhelpful TensorFlow error messages) when one of the passed-in variables
is not connected to the loss to be minimized. This can easily happen in a valid case, for example when using an SVGP model with a Constant
kernel (which might be used as a very simple baseline) but having inducing locations not explicitly set to non-trainable. This could also happen erroneously in a bug case, e.g. when calling Scipy().minimize(model1.training_loss, model2.trainable_variables)
.
Proposal
Describe the solution you would like
An explicit error message when the variables are not connected to the loss (and hence the grads
list contains None
entries).
What alternatives have you considered?
We could also simply change the call for the gradient computation to use unconnected_gradients=tf.UnconnectedGradients.ZERO
. This might silently hide bug cases (see above), so perhaps this option could be an extra flag to the minimize() call?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Would you like to open a PR so we can discuss more concretely on the code? 😃
As you pointed out, sometimes its desired behavior eg. in bug cases. Am I right? 😃
Moving the check was a great idea ofc 😄 I would add the new flag as a simple attribute of
Scipy
-objects (anduncon_gradients_handle
stays?)