Skip to content

Commit

Permalink
Fix missing default dim param in weight norm interface decomp (pytorc…
Browse files Browse the repository at this point in the history
  • Loading branch information
eellison authored and pytorchmergebot committed Jan 31, 2024
1 parent e426924 commit e87ac82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions test/test_decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,14 @@ def test_weight_norm_interface(self, device):
self.assertTrue(torch.allclose(ref[0], res[0]))
self.assertTrue(torch.allclose(ref[1], res[1]))

inp = torch.rand([30, 10], device=device)
inp2 = torch.rand([30, 1], device=device)

self.assertEqual(
torch.ops.aten._weight_norm_interface(inp, inp2),
torch._decomp.decompositions._weight_norm_interface(inp, inp2)
)

@unittest.skipIf(TEST_WITH_ASAN, "Skipped under ASAN")
@onlyCPU
@skipIfCrossRef
Expand Down
2 changes: 1 addition & 1 deletion torch/_decomp/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4421,7 +4421,7 @@ def squeeze_default(self: Tensor, dim: Optional[int] = None):


@register_decomposition(torch.ops.aten._weight_norm_interface)
def _weight_norm_interface(x, y, dim):
def _weight_norm_interface(x, y, dim=0):
# https://github.com/pytorch/pytorch/blob/852f8526c52190125446adc9a6ecbcc28fb66182/aten/src/ATen/native/WeightNorm.cpp#L58
keep_dim = tuple(i for i in range(len(x.shape)) if i != dim)
norm = x.norm(2, keep_dim, keepdim=True)
Expand Down

0 comments on commit e87ac82

Please sign in to comment.