tff.learning.optimizers.check_weights_gradients_match
Stay organized with collections
Save and categorize content based on your preferences.
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
to check whether the provided weights and
gradients match, and provide easy and more informative error message.
To match behavior of tf.keras.optimizers
, this check will only be applied
to gradient leaves that are not None
.
Args |
weights
|
A structure of tensors.
|
gradients
|
A structure of tensors.
|
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 .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.learning.optimizers.check_weights_gradients_match\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [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) |\n\nChecks that weights and non-none gradients match. \n\n tff.learning.optimizers.check_weights_gradients_match(\n weights: _Structure[tf.Tensor],\n gradients: _Structure[Union[tf.Tensor, None]]\n ) -\u003e None\n\nThis check is meant to be used in the `next` method of implemented\n[`tff.learning.optimizers.Optimizer`](../../../tff/learning/optimizers/Optimizer) to check whether the provided weights and\ngradients match, and provide easy and more informative error message.\n\nTo match behavior of [`tf.keras.optimizers`](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers), this check will only be applied\nto gradient leaves that are not `None`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|-------------------------|\n| `weights` | A structure of tensors. |\n| `gradients` | A structure of tensors. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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`. |\n\n\u003cbr /\u003e"]]