我是联邦学习的初学者。我试图在client_updata中的梯度中加入高斯噪声。如果有人想做,请教我怎么做。提前谢谢你。
def client_update(model, dataset, server_weights, client_optimizer):
"""Performs training (using the server model weights) on the client's dataset."""
# Initialize the client model with the current server weights.
client_weights = model.trainable_variables
# Assign the server weights to the client model.
tf.nest.map_structure(lambda x, y: x.assign(y),
client_weights, server_weights)
# Use the client_optimizer to update the local model.
for batch in dataset:
with tf.GradientTape() as tape:
# Compute a forward pass on the batch of data
outputs = model.forward_pass(batch)
# Compute the corresponding gradient
grads = tape.gradient(outputs.loss, client_weights)
grads_and_vars = zip(grads, client_weights)
# Apply the gradient using a client optimizer.
# Update weights
client_optimizer.apply_gradients(grads_and_vars)
return client_weights发布于 2021-12-17 09:04:37
参见教程:TFF中的差分隐私
https://stackoverflow.com/questions/70376178
复制相似问题