Skip to content

Commit

Permalink
[bug fix] fix spectral_norm bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostxsl committed Aug 19, 2021
1 parent 26213a7 commit 5c87d76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/paddle/fluid/dygraph/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3062,6 +3062,12 @@ def __init__(self,
self._dtype = dtype

self._weight_shape = list(weight_shape)
assert np.prod(self._weight_shape) > 0,\
"Any dimension of `weight_shape` cannot be equal to 0."
assert dim < len(self._weight_shape), \
("The input `dim` should be less than the "
"length of `weight_shape`, but received dim="
"{}".format(dim))
h = self._weight_shape[self._dim]
w = np.prod(self._weight_shape) // h

Expand Down
4 changes: 4 additions & 0 deletions python/paddle/fluid/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3720,6 +3720,10 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None):
# create intput and parameters
inputs = {'Weight': weight}
input_shape = weight.shape
assert weight.numel() > 0, "Any dimension of input cannot be equal to 0."
assert dim < len(input_shape), ("The input `dim` should be less than the "
"rank of `weight`, but received dim="
"{}".format(dim))
h = input_shape[dim]
w = np.prod(input_shape) // h

Expand Down

1 comment on commit 5c87d76

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.