-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better validator for matching parameters (#489)
Summary: This PR resolves #477 and addresses various issues regarding parameter validation ## Background As identified in #432, we want to warn the user if optimizer parameters are different from model parameters (e.g. because the module has been replaced by the ModuleValidator). Optimizer expects the weights to have `.grad_sample` attribute populated by the `GradSampleModule`, so there's no sense in having optimizer with different set of params to the input model ### Issue 1: Comparing values One problem with how we do it currently is that we're looking for the wrong thing. We use `torch.eq`, which performs elementwise comparison and will output True for identical tensors. The problem is - we don't need identical, we need the *exact same object* - so that optimizer can read per-sample gradients computed by the GradSampleModule. ### Issue 2: Frozen layers When freezing some model layers, people are free to choose how to initialize their optimizer: with all `model.parameters()` or only those which are not frozen - it doesn't have any material difference on the training process. However, if they do the latter, opacus will complain that model and optimizer weights are mismatched. ### This PR In this PR we address both issues by: 1) Checking if the optimizer parameters is a *subset* of model parameters (not including some model params in the optimizer is perfectly fine) 2) using `in` operator, which checks object and not its value 3) Adding extra tests to cover issues described above Pull Request resolved: #489 Reviewed By: karthikprasad Differential Revision: D39171324 Pulled By: ffuuugor fbshipit-source-id: a9d77c745b83433a74ec64fc4d5817406e4972b0
- Loading branch information
1 parent
c1d1f43
commit 2b0876b
Showing
2 changed files
with
88 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters