装了很多天的TFF,偷懒想要直接PIP直接安装,但因为想要基于这个框架实现自己的魔改,踩了很多的坑,dockerfile也试过了,反正就。。安装版本赶不上它更新迭代的速度。。好吧,,暂时信了是程序员就源码安装吧,其实也挺简单的,就是bazel 安装起来又费了很多功夫,,假如也是始终连不上或者resource11 等的问题,,出现各种各样的错误,,于是,后来,我也放弃了,,apt install bazel,,直接下载源码编译吧,,果然是程序员就信源码安装吧,一次通过。 踩过的坑、报过的错,没有专门记录,百度也没找到实质性的解决方案,假如这样,就直接手动编译安装。。
下面记录下对TFF框架的部分学习理解:
致敬:https://github.com/google-research/federated
首先读了差分隐私相关的代码:
emnist FLAG的记录值:
Key | Value |
---|---|
model | 模型类型,选取cnn、2nn |
client_per_round | 每轮参与训练的客户端数,默认为10 |
client_epochs_per_round | 每次参与的客户本地训练轮数,默认为1 |
client_batch_size | 每次参与的客户本地训练的batch值,默认为20 |
uniform_weighting | 是否平均每个用户的权重,如果每个不是,就是根据用户的数据量设置权重,默认为false |
clip | 好像就是平常DP里面所说的 ϵ \epsilon ϵ,默认值为0.05 |
noise_multiplier | 好像就是平常DP里面所说的 σ \sigma σ,默认值为none,即没用上DP |
adaptive_clip_learning_rate | 如题 |
target_unclipped_quantile | 如题 |
clipped_count_budget_allocation | The fraction of privacy budget to use for estimating clipped counts,难道是 δ \delta δ? |
per_vector_clipping | 独立地设置每个weight的clip值,而不是整个model的 |
total_rounds | 训练轮数,默认值为200 |
experiment_name | 实验名称,方便后续去查找记录 |
root_output_dir | 实验记录存在哪里 |
write_metrics_with_bz2 | 以什么方式存放你的实验结果 |
rounds_per_eval | 多少轮评估模型 |
rounds_per_checkpoint | 多少轮checkpoint模型 |
rounds_per_profile | 多频繁运行实验的TF profile |
记录下emnist的TensorFlow federated下DP的main 函数分析:
- 下载数据集,处理数据集。训练集的处理方法:shuffle打乱,重复client_epochs_per_round次,分成client_batch_size个batch,选择每个用户最多可允许的max_batches_per_client数,映射处理emnist数据集。
- 选择所用的模型FLAGS.model,损失函数和评价指标
- 如果uniform_weighting,则返回1,否则client_weight_fn为None
- 声明model_fn
- tff.utils.build_dp_query
- tff.learning.framework.weights_type_from_model
- tff.utils.build_dp_aggregate_process
tf_computation:
Decorates/wraps Python functions and defuns as TFF TensorFlow computations
federated_computation:
Decorates/wraps Python functions as TFF federated/composite computations
先发出来好了,有新的事情要忙了,改天再写