hiyouga / LLaMA-Factory

Unified Efficient Fine-Tuning of 100+ LLMs (ACL 2024)
https://arxiv.org/abs/2403.13372
Apache License 2.0
34.07k stars 4.2k forks source link

有可能对train函数加上差分隐私的训练处理吗,如果我想对sft微调训练过程中使用opacus加入差分隐私处理,我该怎么做? #5513

Open DSW2001 opened 1 month ago

DSW2001 commented 1 month ago

Reminder

System Info

0.9.0

Reproduction

opacus使用只要对训练函数使用privacy_engine.make_private函数包裹即可,请问对于sft我该去哪里修改?

model = Net() optimizer = SGD(model.parameters(), lr=0.05) data_loader = torch.utils.data.DataLoader(dataset, batch_size=1024)

enter PrivacyEngine

privacy_engine = PrivacyEngine() model, optimizer, data_loader = privacy_engine.make_private( module=model, optimizer=optimizer, data_loader=data_loader, noise_multiplier=1.1, max_grad_norm=1.0, )

Now it's business as usual

Expected behavior

No response

Others

No response

DSW2001 commented 1 month ago

这是opacus函数的具体用法,他应该是只能使用SGD进行修改

define your components as usual

model = Net() optimizer = SGD(model.parameters(), lr=0.05) data_loader = torch.utils.data.DataLoader(dataset, batch_size=1024)

enter PrivacyEngine

privacy_engine = PrivacyEngine() model, optimizer, data_loader = privacy_engine.make_private( module=model, optimizer=optimizer, data_loader=data_loader, noise_multiplier=1.1, max_grad_norm=1.0, )

Now it's business as usual