pytorch / opacus

Training PyTorch models with differential privacy
https://opacus.ai
Apache License 2.0
1.68k stars 338 forks source link

Support for torch compiled models #575

Closed tudorcebere closed 11 months ago

tudorcebere commented 1 year ago

🚀 Feature

Firstly, thanks for the awesome tool!

Torch 2.0 is around the corner and I was curios if opacus will support compiled models, so we can benefit from the awesome speedups. Is this sometimething on the roadmap of the library?

Colab to show the error: https://colab.research.google.com/drive/1fmwrgg1NR1qII7TWPZeyGJddUickxudQ?usp=sharing

alexandresablayrolles commented 1 year ago

Thanks for flagging. I would recommend to use functorch for this use case (i.e. grad_sample_mode='no_op' and use vmap to compute gradients, see https://github.com/pytorch/opacus/blob/main/examples/cifar10.py for an eaxmple).

mshubhankar commented 8 months ago

I'm trying to use fmodel for my usecase in a similar fashion as in the cifar10.py example but I'm getting the following error when trying to run predictions = fmodel(params, batch)

AttributeError: 'Tensor' object has no attribute '_forward_counter'

@alexandresablayrolles @HuanyuZhang have there been any recent updates that is breaking the code?