opacus
opacus copied to clipboard
Patch for DSGAN example
Types of changes
- Bug fix (non-breaking change which fixes an issue)
Motivation and Context / Related issue
I would like to solve #418. I quickly implemented two solutions suggested in the forum. Though I have created two separate py scripts for the solutions, I will experiment with the model performance of each solution and merge the better one. Since this is the first PR for opacus, any suggestions and help are welcome!
How Has This Been Tested (if it applies)
1. Loss (and accuracy)
The losses of the original implementation, solution 1, and solution 2 correspond to green, yellow, and blur lines. Due to the memory limitation, solution 2 works only batch size = 32for my environment (google colab).

2. Examples of generated images
batch size 64
- original implementation

- solution 1

batch size 32
- original implementation

- solution 1

- solution 2

3. Final $\epsilon$
batch size 64
| $\epsilon$ | |
|---|---|
| original | 4.82 |
| solution 1 | 3.36 |
Checklist
- [x] The documentation is up-to-date with the changes I made.
- [x] I have read the CONTRIBUTING document and completed the CLA (see CONTRIBUTING).
- [ ] All tests passed, and additional code has been covered with new tests.
Hi @Koukyosyumei!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
I have run both scripts and found that only patch_1 (clipping gradients for both fake and real data) works. I think it is reasonable that the second approach, which uses two optimizers, makes the gradients for actual data too small compared to real data due to the gradient clipping. I also tried applying clip_grad_norm, but it did not work at least for the current parameters. Also, the second approach has to consume more memory than the first one. Thus, I suggest using the first solution.
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@Koukyosyumei Thank you very much for working on this! May I ask you to provide some quantified results for the run that can show that the new version works correctly? You can put them in the testing section of this PR.
@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@romovpa
I am sorry for the late reply. As suggested in the test section, solution 1 gives better loss, synthesized images, and $\epsilon$ than others. I also notice that #474 has already tackled this issue. If this PR is not necessary, please close it.
@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.