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

Conversation

zheng-da
Copy link
Contributor

@zheng-da zheng-da commented May 29, 2019

Description

When np_shape is turned on, the unknown parameter shapes should be -1 instead of 0. So when a parameter is created but isn't initialized, the dimension of unknown size is -1 when np_shape is turned on, and is 0, otherwise.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

@zheng-da zheng-da requested a review from szha as a code owner May 29, 2019 21:45
python/mxnet/gluon/parameter.py Show resolved Hide resolved
tests/python/unittest/test_gluon.py Outdated Show resolved Hide resolved
@reminisce
Copy link
Contributor

@reminisce
Copy link
Contributor

I'm worried about this line
https://github.com/apache/incubator-mxnet/blob/5fc4fc53df74f276aafa51208142e657e9cfe42d/python/mxnet/gluon/parameter.py#L168

Users may notice that we started to use -1 to represent unknown dim size in np shape semantics and some of them in practice may use shapes like (-1, 10) to create parameters for deferred initialization, instead of (0, 10). In those cases, we need to support that unknown dim size can be either 0 or -1, so this line should become

all(j in (-1, 0, i) for i, j in zip(new_shape, self._shape))

when is_np_shape = True.

@szha What do you think?

@abhinavs95
Copy link
Contributor

@mxnet-label-bot add [Gluon]

@szha
Copy link
Member

szha commented May 30, 2019

@reminisce I had similar concern though I thought the API doc should do the job. another option is to expose an internal interface for infer_shape to use, instead of piggybacking on the .shape attribute

@roywei
Copy link
Member

roywei commented May 31, 2019

@reminisce @szha @zheng-da what's the next step here? There is nothing to prevent users from using -1 as unknown dim. so maybe state clearly in comment or API doc and note experimental?

@reminisce
Copy link
Contributor

I think it would be safer to note np_shape as experimental and still under development.

@zheng-da
Copy link
Contributor Author

zheng-da commented Jun 1, 2019

where should we document -1 is unknown dim and is experimental?

Copy link
Member

@roywei roywei left a comment

Choose a reason for hiding this comment

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

I believe for NP shape APIs, it's already documented as experimental, so just add some comments in this PR about -1 and refer to the np documentation here https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/util.py#L84

python/mxnet/gluon/parameter.py Show resolved Hide resolved
python/mxnet/gluon/utils.py Outdated Show resolved Hide resolved
@szha szha merged commit 360f8d0 into apache:master Jun 2, 2019
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
…ache#15097)

* fix.

* add test.

* fix test.

* check unknown shape correctly.

* fix test.

* fix.

* fix.

* add more comments.

* add doc.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants