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

Fix dumps for Constant initializer #15150

Merged
merged 6 commits into from
Jul 19, 2019
Merged

Fix dumps for Constant initializer #15150

merged 6 commits into from
Jul 19, 2019

Conversation

abhinavs95
Copy link
Contributor

Description

Fixes #12404
Override the dumps method for Constant initializer to take care of NDArray input.

@abhinavs95 abhinavs95 requested a review from szha as a code owner June 4, 2019 18:21
@abhinavs95 abhinavs95 changed the title update dumps for const init Fix dumps for Constant initializer Jun 4, 2019
@piyushghai
Copy link
Contributor

@mxnet-label-bot Add [pr-awaiting-review, NDArray]

@marcoabreu marcoabreu added NDArray pr-awaiting-review PR is waiting for code review labels Jun 4, 2019
@abhinavs95
Copy link
Contributor Author

@szha @anirudhacharya Could you take a look? Thanks.

@anirudhacharya
Copy link
Member

@abhinavs95 can you please add a ut for this?

@abhinavs95
Copy link
Contributor Author

@anirudhacharya added test.


def test_const_init_dumps():
# test NDArray input
init = mx.init.Constant(mx.nd.ones(5))
Copy link
Member

Choose a reason for hiding this comment

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

it might be good if we could randomize the shape and dimension for this test and test it for different dimensions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added randomized shape and dimension for the array in test, it can take values between 1 and 10 with 1D to 5D shapes.


def test_const_init_dumps():
# test NDArray input
init = mx.init.Constant(mx.nd.ones(5))
Copy link
Member

@anirudhacharya anirudhacharya Jun 7, 2019

Choose a reason for hiding this comment

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

in line 29 test_variable_init and other initializer tests are written differently. can we follow a similar pattern of declaring a sym variable and binding it to a module and initializing the params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am just checking the function of dumps() in the test I have added, is creating a module still required? test_rsp_const_init in line 48 already does that for Constant initializers.

Copy link
Member

Choose a reason for hiding this comment

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

test_rsp_const_init does the following -
https://github.com/apache/incubator-mxnet/blob/master/tests/python/unittest/test_init.py#L52-L57

The reason I am asking this change is because I think that will be a more comprehensive test and will check the whole flow, and it will test the initializer the way it will actually be used in production. This change should enable serializing and deserializing an ndarray object.

Just check once with a committer who will merge this code. Everything else LGTM.

@vandanavk
Copy link
Contributor

Is this PR good to go? @abhinavs95 @anirudhacharya

python/mxnet/initializer.py Outdated Show resolved Hide resolved
@karan6181
Copy link
Contributor

@abhinavs95 is this PR good to go for merge?

@abhinavs95
Copy link
Contributor Author

@karan6181 yes its good to go from my side

@szha szha merged commit da71324 into apache:master Jul 19, 2019
@szha
Copy link
Member

szha commented Jul 19, 2019

Merged. Thanks for the fix @abhinavs95

anirudhacharya pushed a commit to anirudhacharya/mxnet that referenced this pull request Aug 20, 2019
* update dumps for const init

* add test

* fix for numpy input

* randomize test array shape and dim

* fix test

* replace type with isinstance
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
NDArray pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

init.Constant does not work in symbol
8 participants