Skip to content

Commit

Permalink
[sparsity] sparsifier step tests (pytorch#60107)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#60107

Unit tests for sparsifier `step`

Test Plan:
`buck test mode/dev-nosan //caffe2/test:ao -- TestWeightNormSparsifier`

https://pxl.cl/1LhQP

Reviewed By: z-a-f

Differential Revision: D29167029

fbshipit-source-id: 053027ca92701097406372ef0f81d79ef28380aa
  • Loading branch information
kazhou authored and facebook-github-bot committed Jul 7, 2021
1 parent 8881b9d commit 5e83fef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/ao/sparsity/test_sparsifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,17 @@ def test_step(self):
model = Model()
sparsifier = WeightNormSparsifier(sparsity_level=0.5)
sparsifier.prepare(model, config=[model.linear])
for g in sparsifier.module_groups:
# Before step
module = g['module']
assert (1.0 - module.parametrizations['weight'][0].mask.mean()) == 0 # checking sparsity level is 0
sparsifier.enable_mask_update = True
sparsifier.step()
self.assertAlmostEqual(model.linear.parametrizations['weight'][0].mask.mean().item(), 0.5, places=2)
for g in sparsifier.module_groups:
# After step
module = g['module']
assert (1.0 - module.parametrizations['weight'][0].mask.mean()) > 0 # checking sparsity level has increased

def test_prepare(self):
model = Model()
Expand Down

0 comments on commit 5e83fef

Please sign in to comment.