opacus icon indicating copy to clipboard operation
opacus copied to clipboard

TypeError: __init__() missing 1 required positional argument: 'module'

Open JeffffffFu opened this issue 4 years ago • 7 comments

image

JeffffffFu avatar Jan 30 '22 07:01 JeffffffFu

I fully follow the textbook

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

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, )

but it's error

JeffffffFu avatar Jan 31 '22 12:01 JeffffffFu

Hi Jeff,

Can you give a complete example, e.g., by sharing a colab notebook, so we can try to reproduce this? What model exactly are you using?

cheers Graham

gcormode avatar Jan 31 '22 12:01 gcormode

Duplicate of #336

karthikprasad avatar Jan 31 '22 19:01 karthikprasad

Hi @jeff19960430

It'd would be indeed helpful if you could share the full notebook and the environment. From the first glance it looks like you have older version of opacus installed. Please double check that your opacus version is >=1.0.0. We've changed the API in 1.0.0 and the notebook you're following using the updated interface.

Please feel free to reopen the issue if this doesn't help

igorshh avatar Jan 31 '22 22:01 igorshh

thank you , I find the probolem is the verion of the opacus.but I have two question in the new API: 1 、 the q (ratio of sammple ) = batch_size/sample_size ? 2、 for every empoch, should I need to resample and assemble the data and reinvoke the PrivacyEngine() interface ?

JeffffffFu avatar Feb 01 '22 02:02 JeffffffFu

  1. That's correct, yes. In the new API you don't need to provide sample rate explicitly, instead we derive it from the DataLoader object you provide

  2. No, you don't need to recreate PrivacyEngine for every epoch. Privacy budget is tracked across the entire length of training, which could involve multiple epochs. Additionally, if you're using make_private method, you don't need to worry about sampling: the data loader object returned from make_private already uses the appropriate mechanism

Also just a reminder: you can always ask opacus-related questions and ask for support on PyTorch forums: https://discuss.pytorch.org/c/opacus/29

igorshh avatar Feb 01 '22 11:02 igorshh

You mean I just have all the training data into the data loader ready and it will automatically sample in each epoch

JeffffffFu avatar Feb 02 '22 01:02 JeffffffFu