Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[BUGFIX] fix unknown parameter shapes when np_shape is turned on. #15097

Merged
merged 9 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add more comments.
  • Loading branch information
zheng-da committed Jun 2, 2019
commit fab40d40e11c6d83c2c14c19d695e41940b9d25f
3 changes: 3 additions & 0 deletions python/mxnet/gluon/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def shape(self):
if self._shape is None:
return None
elif is_np_shape():
# Parameters shouldn't be zero-size. If one of its dimension is 0,
# it means the parameter isn't initialized. In the NumPy semantics,
# the unknown dimension should be marked with -1.
return tuple(i if i != 0 else -1 for i in self._shape)
szha marked this conversation as resolved.
Show resolved Hide resolved
zheng-da marked this conversation as resolved.
Show resolved Hide resolved
else:
return self._shape
Expand Down
5 changes: 4 additions & 1 deletion python/mxnet/gluon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ def __exit__(self, ptype, value, trace):
self.detach()

def shape_is_known(shape):
"""Check whether a shape is completely known w/ or w/o np semantics."""
"""Check whether a shape is completely known with or without np semantics.

Please see the doc of is_np_shape for more details.
"""
if shape is None:
return False
unknown_dim_size = -1 if is_np_shape() else 0
Expand Down
4 changes: 4 additions & 0 deletions python/mxnet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def is_np_shape():
the shapes of zero-size tensors. This is turned off by default for keeping
backward compatibility.

In the NumPy shape semantics, `-1` indicates an unknown size. For example,
`(-1, 2, 2)` means that the size of the first dimension is unknown. Its size
may be inferred during shape inference.

Please note that this is designed as an infrastructure for the incoming
MXNet-NumPy operators. Legacy operators registered in the modules
`mx.nd` and `mx.sym` are not guaranteed to behave like their counterparts
Expand Down