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

refactor regression ops to nnvm interface#9540

Merged
eric-haibin-lin merged 7 commits intoapache:masterfrom
ZiyueHuang:sparse_reg
Jan 27, 2018
Merged

refactor regression ops to nnvm interface#9540
eric-haibin-lin merged 7 commits intoapache:masterfrom
ZiyueHuang:sparse_reg

Conversation

@ZiyueHuang
Copy link
Copy Markdown
Member

@ZiyueHuang ZiyueHuang commented Jan 24, 2018

Description

refactor regression operators to nnvm interface (then I will add sparse support for these operators in a separate PR later).

Fix the docs. Please see #9528.

Add unittest for MAERegressionOutput.

cc @eric-haibin-lin @sxjscience

Checklist

Essentials

  • Passed code style checking (make lint)
  • 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
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • refactor, existing unit tests for LinearRegressionOutput and LogisticRegressionOutput. Add unittest for MAERegressionOutput.

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

Comment thread src/operator/regression_output.cc Outdated
// inputs are in_label and out_data, outputs are data_grad and label_grad
return std::vector<std::pair<int, int> >{{1, 0}};
})
.set_attr<FCompute>("FCompute<cpu>", RegressionBackward<cpu, mshadow_op::minus>);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can consider creating a macro (like in https://github.com/apache/incubator-mxnet/blob/master/src/operator/tensor/elemwise_binary_op.h#L554-L569) for defining regression OPs as most of the codes are similar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Comment thread src/operator/regression_output-inl.h Outdated
mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
MSHADOW_REAL_TYPE_SWITCH(inputs[reg_enum::kData].type_flag_, DType, {
MXNET_ASSIGN_REQ_SWITCH(req[reg_enum::kOut], Req, {
DType* in_data = inputs[reg_enum::kData].dptr<DType>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: const

Comment thread src/operator/regression_output-inl.h Outdated
// outputs are data_grad, label_grad
MSHADOW_REAL_TYPE_SWITCH(inputs[1].type_flag_, DType, {
MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
DType* in_label = inputs[0].dptr<DType>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: const

Comment thread src/operator/regression_output.cc Outdated

By default, gradients of this loss function are scaled by factor `1/n`, where n is the number of training examples.
The parameter `grad_scale` can be used to change this scale to `grad_scale/n`.
By default, gradients of this loss function are scaled by factor `1/m`, where m is the number of dimensions of a training example.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

number of dimensions is a bit confusing to me. For shape (3,4), my first thought of num dimension is two (2-D shape). Is "number of features" clearer?

Comment thread src/operator/regression_output.cc Outdated
// inputs are in_label and out_data, outputs are data_grad and label_grad
return std::vector<std::pair<int, int> >{{1, 0}};
})
.set_attr<FCompute>("FCompute<cpu>", RegressionBackward<cpu, mshadow_op::minus>);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@ZiyueHuang
Copy link
Copy Markdown
Member Author

Thanks for the comments. Updated.

Comment thread src/operator/regression_output.cc Outdated

By default, gradients of this loss function are scaled by factor `1/n`, where n is the number of training examples.
The parameter `grad_scale` can be used to change this scale to `grad_scale/n`.
By default, gradients of this loss function are scaled by factor `1/m`, where m is the number of features of a training example.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the word features is not very appropriate. We can use regression outputs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated

@sxjscience
Copy link
Copy Markdown
Member

Added some minor docstring comments. The PR looks good.

Copy link
Copy Markdown
Member

@eric-haibin-lin eric-haibin-lin left a comment

Choose a reason for hiding this comment

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

"Add unittest for MAERegressionOutput."
Where is the test?

@ZiyueHuang
Copy link
Copy Markdown
Member Author

Seems that I mistakenly checkout that test file... Added back.

@eric-haibin-lin eric-haibin-lin merged commit c6d97d6 into apache:master Jan 27, 2018
eric-haibin-lin pushed a commit that referenced this pull request Jan 28, 2018
* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test
@ZiyueHuang ZiyueHuang deleted the sparse_reg branch January 30, 2018 06:24
eric-haibin-lin added a commit that referenced this pull request Mar 27, 2018
* Bump 1.1 (#192)

* bump

* also update base.h

* revert website changes

* Update index.html

* update news.md (#191)

* Update NEWS.md

* Update README.md

* refactor regression ops to nnvm interface (#9540)

* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test

* Update KEYS

* Update NEWS.md

* fixed links that were missng ndarray folder path (#9618)

* Fixed 4 broken links (#9698)

* Fixed 4 broken links

* fixed pylint for long line disable and 1 broken link

* Update NEWS.md

* Update NOTICE (#9706)

* revert acc changes (#9731)

* Revert "avoid per-batch blocking in metric (#9636)"

This reverts commit 3fe694e.

* Revert "proper flatten in acc (#9619)"

This reverts commit ed823b2.

* Revert "use nd for accuracy calculation (#9583)"

This reverts commit f5f1b91.

* keep doc change

* PGP keys add liuyizhi AT apache.org (#9728)

* Add my key (#9736)

* [REVIEW REQUIRED] Revert PR #9484 & add additional dependency licenses to LICENSE file (#9701)

* Revert "[Review Required] Fixing Licenses: Cleaning up the Top Level LICENSE file (#9484)"

This reverts commit 8930d96.

* Some more LICENSE fixes

* Adding some more packages to the LICENSE file

* Adding dependencies of dependencies

* update navbar model zoo link (#9749)

* update navbar model zoo link

* update

* initial commit

* clean up

* refactor

* fix test
jinhuang415 pushed a commit to jinhuang415/incubator-mxnet that referenced this pull request Mar 30, 2018
* Bump 1.1 (apache#192)

* bump

* also update base.h

* revert website changes

* Update index.html

* update news.md (apache#191)

* Update NEWS.md

* Update README.md

* refactor regression ops to nnvm interface (apache#9540)

* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test

* Update KEYS

* Update NEWS.md

* fixed links that were missng ndarray folder path (apache#9618)

* Fixed 4 broken links (apache#9698)

* Fixed 4 broken links

* fixed pylint for long line disable and 1 broken link

* Update NEWS.md

* Update NOTICE (apache#9706)

* revert acc changes (apache#9731)

* Revert "avoid per-batch blocking in metric (apache#9636)"

This reverts commit 3fe694e.

* Revert "proper flatten in acc (apache#9619)"

This reverts commit ed823b2.

* Revert "use nd for accuracy calculation (apache#9583)"

This reverts commit f5f1b91.

* keep doc change

* PGP keys add liuyizhi AT apache.org (apache#9728)

* Add my key (apache#9736)

* [REVIEW REQUIRED] Revert PR apache#9484 & add additional dependency licenses to LICENSE file (apache#9701)

* Revert "[Review Required] Fixing Licenses: Cleaning up the Top Level LICENSE file (apache#9484)"

This reverts commit 8930d96.

* Some more LICENSE fixes

* Adding some more packages to the LICENSE file

* Adding dependencies of dependencies

* update navbar model zoo link (apache#9749)

* update navbar model zoo link

* update

* initial commit

* clean up

* refactor

* fix test
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* Bump 1.1 (apache#192)

* bump

* also update base.h

* revert website changes

* Update index.html

* update news.md (apache#191)

* Update NEWS.md

* Update README.md

* refactor regression ops to nnvm interface (apache#9540)

* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test

* Update KEYS

* Update NEWS.md

* fixed links that were missng ndarray folder path (apache#9618)

* Fixed 4 broken links (apache#9698)

* Fixed 4 broken links

* fixed pylint for long line disable and 1 broken link

* Update NEWS.md

* Update NOTICE (apache#9706)

* revert acc changes (apache#9731)

* Revert "avoid per-batch blocking in metric (apache#9636)"

This reverts commit 3fe694e.

* Revert "proper flatten in acc (apache#9619)"

This reverts commit ed823b2.

* Revert "use nd for accuracy calculation (apache#9583)"

This reverts commit f5f1b91.

* keep doc change

* PGP keys add liuyizhi AT apache.org (apache#9728)

* Add my key (apache#9736)

* [REVIEW REQUIRED] Revert PR apache#9484 & add additional dependency licenses to LICENSE file (apache#9701)

* Revert "[Review Required] Fixing Licenses: Cleaning up the Top Level LICENSE file (apache#9484)"

This reverts commit 8930d96.

* Some more LICENSE fixes

* Adding some more packages to the LICENSE file

* Adding dependencies of dependencies

* update navbar model zoo link (apache#9749)

* update navbar model zoo link

* update

* initial commit

* clean up

* refactor

* fix test
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* Bump 1.1 (apache#192)

* bump

* also update base.h

* revert website changes

* Update index.html

* update news.md (apache#191)

* Update NEWS.md

* Update README.md

* refactor regression ops to nnvm interface (apache#9540)

* refactor regression ops

* fix err for instantiation of minus_sign

* remove useless header file init_op.h

* replace with macro and address other comments

* update

* minor revise docs

* add mae test

* Update KEYS

* Update NEWS.md

* fixed links that were missng ndarray folder path (apache#9618)

* Fixed 4 broken links (apache#9698)

* Fixed 4 broken links

* fixed pylint for long line disable and 1 broken link

* Update NEWS.md

* Update NOTICE (apache#9706)

* revert acc changes (apache#9731)

* Revert "avoid per-batch blocking in metric (apache#9636)"

This reverts commit 3fe694e.

* Revert "proper flatten in acc (apache#9619)"

This reverts commit ed823b2.

* Revert "use nd for accuracy calculation (apache#9583)"

This reverts commit f5f1b91.

* keep doc change

* PGP keys add liuyizhi AT apache.org (apache#9728)

* Add my key (apache#9736)

* [REVIEW REQUIRED] Revert PR apache#9484 & add additional dependency licenses to LICENSE file (apache#9701)

* Revert "[Review Required] Fixing Licenses: Cleaning up the Top Level LICENSE file (apache#9484)"

This reverts commit 8930d96.

* Some more LICENSE fixes

* Adding some more packages to the LICENSE file

* Adding dependencies of dependencies

* update navbar model zoo link (apache#9749)

* update navbar model zoo link

* update

* initial commit

* clean up

* refactor

* fix test
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants