TFF 연합 학습에 DP 더하기
TFF 연합 학습에 DP 더하기
TensorFlow Federated를 이용해 이미지 분류 모델을 연합 훈련하는 공식 튜토리얼이에요. 연합 학습(FL)과 차분 프라이버시(DP)를 함께 적용하는 실전 예제를 제공해요. EMNIST 같은 데이터는 연합 시나리오를 흉내 낼 수 있게 클라이언트별로 분할돼 있어요.
손으로 따라 해보기
import tensorflow_federated as tff
source, _ = tff.simulation.datasets.emnist.load_data()
trainer = tff.learning.algorithms.build_weighted_fed_avg( # 또는 DP 클라이언트 옵티마이저
tff_model, client_optimizer_fn=tff.learning.optimizers.build_sgdm(learning_rate=0.1))
state = trainer.initialize()
for _ in range(5):
result = trainer.next(state, train_data)
state, metrics = result.state, result.metrics
각 라운드마다 클라이언트의 로컬 갱신이 서버로 보내져 평균되어 전역 모델을 개선해요. DP 결합 시 클라이언트 갱신에 노이즈가 더해져 프라이버시가 지켜져요.