ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more


Differentially private subclass of tf.compat.v1.train.GradientDescentOptimizer.

You can use this as a differentially private replacement for tf.compat.v1.train.GradientDescentOptimizer. Note that you must ensure that any loss processed by this optimizer comes in vector form.

This is the fully general form of the optimizer that allows you to define your own privacy mechanism. If you are planning to use the standard Gaussian mechanism, it is simpler to use the more specific DPGradientDescentGaussianOptimizer class instead.

When instantiating this optimizer, you need to supply several DP-related arguments followed by the standard arguments for GradientDescentOptimizer.


# Create GaussianSumQuery.
dp_sum_query = gaussian_query.GaussianSumQuery(l2_norm_clip=1.0, stddev=0.5)

# Create optimizer.
opt = DPGradientDescentOptimizer(dp_sum_query, 1, False, <standard arguments>)

When using the optimizer, be sure to pass in the loss as a rank-one tensor with one entry for each example.

# Compute loss as a tensor. Do not call tf.reduce_mean as you
# would with a standard optimizer.
loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
    labels=labels, logits=logits)

train_op = opt.minimize(loss, global_step=global_step)

dp_sum_query DPQuery object, specifying differential privacy mechanism to use.
num_microbatches Number of microbatches into which each minibatch is split. If None, will default to the size of the minibatch, and per-example gradients will be computed.
unroll_microbatches If true, processes microbatches within a Python loop instead of a tf.while_loop. Can be used if using a tf.while_loop raises an exception.
*args These will be passed on to the base class __init__ method.
**kwargs These will be passed on to the base class __init__ method.