# tff.learning.optimizers.check_weights_gradients_match

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Checks that weights and non-none gradients match.

    tff.learning.optimizers.check_weights_gradients_match(
        weights: _Structure[tf.Tensor],
        gradients: _Structure[Union[tf.Tensor, None]]
    ) -> None

This check is meant to be used in the `next` method of implemented
[`tff.learning.optimizers.Optimizer`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/optimizers/Optimizer) to check whether the provided weights and
gradients match, and provide easy and more informative error message.

To match behavior of [`tf.keras.optimizers`](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers), this check will only be applied
to gradient leaves that are not `None`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `weights` | A structure of tensors. |
| `gradients` | A structure of tensors. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `weights` and `gradients` do not have the same structure, or if the tensors in the structures do not have the same shapes and dtypes, at some leaf where `gradients` is not `None`. |

<br />