-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utility to test the correctness of per sample gradients #484
Comments
More context. The first and essential step of DP-SGD implementation is computing per-sample gradients. While Opacus provides various approaches to do so (hooks, ExpandedWeights, functorch) and performs some level of model validation, it is still possible to end up with wrong per-sample gradients which Opacus will not notify you of. There are multiple potential scenarios why it's possible, but one stands out as the most important. Opacus has an implicit requirement that any input model always maintain batch dimension as the first dimension throughout the forward() method (or second if There's, however, one approach that we already use to verify correctness of the per-sample computation: compare against microbatches. By definition, "per-sample gradient" is a gradient you would get if a given sample was the only one in a batch. It is, however, quite easy to split the batch into N micro-batches of size 1 and use these gradients to verify Here's how we do it for our unit test: link The idea of this new feature is to expose similar utility to an end user to let them check that:
|
Hi, any updates on #532 ? (Just lurking but it seems that the PR was left behind for some reason) |
@aaossa @karthikprasad Thanks for reminding! I'll try to merge soon. |
Summary: ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [x] Docs change / refactoring / dependency upgrade ## Motivation and Context / Related issue Implementation of the utility described in #484. Refactored the code to avoid code duplicates. ## How Has This Been Tested (if it applies) Added the new utility as a test case for existing tests stored in `tests.grad_samples`. ## 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**). - [x] All tests passed, and additional code has been covered with new tests. Pull Request resolved: #532 Reviewed By: karthikprasad Differential Revision: D40797432 Pulled By: ffuuugor fbshipit-source-id: 923009d6f7f6d4c34bce9f4af39945fdf9ff9d57
Seems like this should be closed since #532 contents were already merged (again, just lurking my notifications and found this) |
Let us keep it, since we may want to pursue a better plan. |
For custom grad_samplers or functorch-based implementation
The text was updated successfully, but these errors were encountered: