【问题标题】:How implement differential privacy in federated learning如何在联邦学习中实现差分隐私
【发布时间】:2021-12-16 08:49:25
【问题描述】:

我是联邦学习的初学者。 我尝试将高斯噪声添加到 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

【问题讨论】:

    标签: tensorflow-federated


    【解决方案1】:

    【讨论】:

    • 感谢您的回复。我阅读了教程并进行了模拟。我想在客户端更新中查看每个客户端的渐变。我可以看看吗?
    • 你这是什么意思?客户培训只是一步?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 2013-05-21
    相关资源
    最近更新 更多