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

[MXNET-995] Constant Initializer for ND Array #12677

Closed
wants to merge 3 commits into from

Conversation

ChaiBapchya
Copy link
Contributor

Description

Allows 1D (constant) to be used to initialize an NDArray or Symbol
Fixes #12672 and #12676

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://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

Changes

  • Checks if the input is a scalar of the type int/float and converts it into a list for NDArray
  • Unit test for checking initialization with NDArray as well as Symbol API (using bind and eval functions)
  • Mismatch of the Value error shapes changed

@vandanavk
Copy link
Contributor

@mxnet-label-bot [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Sep 26, 2018
@@ -2479,6 +2479,8 @@ def array(source_array, ctx=None, dtype=None):
if isinstance(source_array, NDArray):
dtype = source_array.dtype if dtype is None else dtype
else:
if isinstance(source_array, (float, int)):
Copy link
Member

Choose a reason for hiding this comment

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

mx.base.numeric_types is better

Copy link
Member

Choose a reason for hiding this comment

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

my concern here is that you implicitly converted 0-d array(constant) to 1-d array here, which may not be very appropriate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my logic was since MXNet NDArray needs a 1d array minimum, I should convert constant. Else, is there a way I can do constant initialization support? Would be great to get some help in that direction.

@@ -869,7 +869,7 @@ def _sync_copyfrom(self, source_array):
source_array = np.ascontiguousarray(source_array, dtype=self.dtype)
if source_array.shape != self.shape:
raise ValueError('Shape inconsistent: expected %s vs got %s'%(
str(self.shape), str(source_array.shape)))
str(source_array.shape), str(self.shape)))
Copy link
Member

Choose a reason for hiding this comment

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

why switch the order of expected vs got?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have a look at #12676
I found it to be odd. Hence created an issue and fixed it in this PR
Don't you think so?

Copy link
Contributor Author

@ChaiBapchya ChaiBapchya Sep 28, 2018

Choose a reason for hiding this comment

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

@zhreshold could you confirm if the above issue (#12676 ) is right or not? coz the value error it gave sounded confusing due to mismatched shapes. Thanks

@arogozhnikov
Copy link
Contributor

Please check that this case was resolved by PR #12678 too.

@ChaiBapchya
Copy link
Contributor Author

Ah, alright. So I'll take mine down then. Thanks for your contribution.

@ChaiBapchya ChaiBapchya deleted the constant_initializer branch October 10, 2018 02:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ndarray construction can't import zero-dimensional numpy arrays
5 participants