opacus icon indicating copy to clipboard operation
opacus copied to clipboard

Patch for DSGAN example

Open Koukyosyumei opened this issue 3 years ago • 16 comments

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

batchsize_32 batchsize_64

2. Examples of generated images

batch size 64

  • original implementation

fake_samples_epoch_022

  • solution 1

fake_samples_epoch_021

batch size 32

  • original implementation

fake_samples_epoch_024 (1)

  • solution 1

fake_samples_epoch_021 (1)

  • solution 2

fake_samples_epoch_020

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.

Koukyosyumei avatar Sep 03 '22 12:09 Koukyosyumei

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!

facebook-github-bot avatar Sep 03 '22 12:09 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar Sep 03 '22 13:09 facebook-github-bot

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.

Koukyosyumei avatar Sep 05 '22 10:09 Koukyosyumei

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 05 '22 13:09 facebook-github-bot

@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 06 '22 07:09 facebook-github-bot

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 06 '22 07:09 facebook-github-bot

@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.

romovpa avatar Sep 06 '22 17:09 romovpa

@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 09 '22 16:09 facebook-github-bot

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 09 '22 16:09 facebook-github-bot

@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 avatar Sep 09 '22 16:09 Koukyosyumei

@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 09 '22 16:09 facebook-github-bot

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 09 '22 16:09 facebook-github-bot

@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 10 '22 00:09 facebook-github-bot

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 10 '22 00:09 facebook-github-bot

@Koukyosyumei has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 10 '22 09:09 facebook-github-bot

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 10 '22 09:09 facebook-github-bot