首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在联邦学习中实现差别化隐私

如何在联邦学习中实现差别化隐私
EN

Stack Overflow用户
提问于 2021-12-16 08:49:25
回答 1查看 116关注 0票数 1

我是联邦学习的初学者。我试图在client_updata中的梯度中加入高斯噪声。如果有人想做,请教我怎么做。提前谢谢你。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-12-17 09:04:37

参见教程:TFF中的差分隐私

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70376178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档