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.

AssertionError: compute_gradients() on the differentially private optimizer was not called.

See original GitHub issue

I randomly run into the following error:

AssertionError: compute_gradients() on the differentially private optimizer was not called.

The reason is unknown, as the above error does not seem to appear if I restart the notebook a couple of times or re-run the script.

Additional logs:

WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.optimizer
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.global_step
WARNING:tensorflow:A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-24-c057947b86a8> in <module>()
----> 1 fed_learn('resnet', 10, True)

11 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
    966           except Exception as e:  # pylint:disable=broad-except
    967             if hasattr(e, "ag_error_metadata"):
--> 968               raise e.ag_error_metadata.to_exception(e)
    969             else:
    970               raise

AssertionError: in user code:

    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:571 train_function  *
        outputs = self.distribute_strategy.run(
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:951 run  **
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
        return fn(*args, **kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:541 train_step  **
        self.trainable_variables)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:1814 _minimize
        optimizer.apply_gradients(zip(gradients, trainable_variables))
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/optimizers.py:775 apply_gradients
        self.optimizer.apply_gradients(grads, global_step=self.iterations)
    /usr/local/lib/python3.6/dist-packages/tensorflow_privacy/privacy/optimizers/dp_optimizer.py:183 apply_gradients
        'compute_gradients() on the differentially private optimizer was not'

    AssertionError: compute_gradients() on the differentially private optimizer was not called. Which means that the training is not differentially private. It happens for example in Keras training in TensorFlow 2.0+.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
galenmandrewcommented, May 21, 2020

Yes, fixing TFP to work with keras optimizers in TF 2.0 is a high priority feature for us now, although I don’t have a specific date I can promise you it will be finished.

2reactions
mayankshah1607commented, May 22, 2020

Fixed it. I used this helper function as a wrapper around the TFP optimizer, and used that in model.fit instead, and it worked. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add noise (differential privacy) to clients weights in ...
AssertionError : Neither _compute_gradients() or get_gradients() on the differentially private optimizer was called. This means the training is ...
Read more >
tf.keras.optimizers.Optimizer | TensorFlow v2.11.0
Calling minimize() takes care of both computing the gradients and applying them to the variables. If you want to process the gradients before...
Read more >
Tensorflow.js tf.train.Optimizer class .computeGradients ...
Executes f() and computes the gradient of the scalar output of f() with respect to the list of trainable variables provided by varList....
Read more >
Machine Learning with Differential Privacy in TensorFlow
Intuitively, a model trained with differential privacy should not be ... calling optimizers.dp_optimizer.make_gaussian_optimizer_class() .
Read more >
How does Tensorflow `tf.train.Optimizer` compute gradients?
It's not numerical differentiation, it's automatic differentiation. This is one of the main reasons for tensorflow's existence: by ...
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