After changing the maximum clipping threshold with opt.privacy_engine.max_grad_norm = max_grad_norm, I find that it still does not work.Even though I read the value of opt.privacy_engine.max_grad_norm as the changed value.
import torch
import torch.nn as nn
from model import LeNet5, MLP, CNN1, CNN2
from opacus import PrivacyEngine
def init_model(model_type, in_channel, n_class):
if model_type == 'LeNet5':
model = LeNet5(in_channel, n_class)
elif model_type == 'MLP':
model = MLP(n_class)
elif model_type == 'CNN1':
model = CNN1(in_channel, n_class)
elif model_type == 'CNN2':
model = CNN2(in_channel, n_class)
else:
raise ValueError(f"Unknown model type {model_type}")
return model
📚 Documentation
After changing the maximum clipping threshold with opt.privacy_engine.max_grad_norm = max_grad_norm, I find that it still does not work.Even though I read the value of opt.privacy_engine.max_grad_norm as the changed value.
import torch import torch.nn as nn
from model import LeNet5, MLP, CNN1, CNN2 from opacus import PrivacyEngine
def init_model(model_type, in_channel, n_class):
def init_optimizer(model, args):
def init_dp_optimizer(model, data_size, args): opt = init_optimizer(model, args) orders = [1 + x / 10. for x in range(1, 100)] + list(range(12, 64)) privacy_engine = PrivacyEngine( model, sample_rate=args.batch_size / data_size, alphas=orders, noise_multiplier=args.noise_multiplier, max_grad_norm=args.l2_norm_clip )
print(f"Using DP-SGD with sigma={args.noise_multiplier} and clipping norm max={args.l2_norm_clip}")
class Client(nn.Module):