Skip to content

Commit

Permalink
Type check lint fixes (#599)
Browse files Browse the repository at this point in the history
Summary:
## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Docs change / refactoring / dependency upgrade

## Motivation and Context / Related issue

Fixing flake8 lint issue detected in https://app.circleci.com/pipelines/github/pytorch/opacus/2835/workflows/1318787a-42c8-42a2-aba5-85e32eac7d2a/jobs/16079

## How Has This Been Tested (if it applies)

CI

## 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: #599

Reviewed By: JohnlNguyen

Differential Revision: D47936830

Pulled By: karthikprasad

fbshipit-source-id: 800f18ebfaf10ff65e9ceb2a0dbb9f182efee759
  • Loading branch information
Karthik Prasad authored and facebook-github-bot committed Aug 1, 2023
1 parent 7b28054 commit 79bdfac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions opacus/grad_sample/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def compute_conv_grad_sample(
return ret

# get activations and backprops in shape depending on the Conv layer
if type(layer) == nn.Conv2d:
if type(layer) is nn.Conv2d:
activations = unfold2d(
activations,
kernel_size=layer.kernel_size,
padding=layer.padding,
stride=layer.stride,
dilation=layer.dilation,
)
elif type(layer) == nn.Conv1d:
elif type(layer) is nn.Conv1d:
activations = activations.unsqueeze(-2) # add the H dimension
# set arguments to tuples with appropriate second element
if layer.padding == "same":
Expand All @@ -77,7 +77,7 @@ def compute_conv_grad_sample(
stride=(1, layer.stride[0]),
dilation=(1, layer.dilation[0]),
)
elif type(layer) == nn.Conv3d:
elif type(layer) is nn.Conv3d:
activations = unfold3d(
activations,
kernel_size=layer.kernel_size,
Expand Down
2 changes: 1 addition & 1 deletion opacus/privacy_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _prepare_model(
if (
module.batch_first != batch_first
or module.loss_reduction != loss_reduction
or type(module) != get_gsm_class(grad_sample_mode)
or type(module) is not get_gsm_class(grad_sample_mode)
):
raise ValueError(
f"Pre-existing GradSampleModule doesn't match new arguments."
Expand Down

0 comments on commit 79bdfac

Please sign in to comment.