leezu opened a new pull request #11573: Add stable nrm2 Reducer
URL: https://github.com/apache/incubator-mxnet/pull/11573
 
 
   ## Description ##
   The mxnet L2 norm implementation is currently prone to under/overflow when 
called on NDArrays with very small or large elements. This PR adds a stable L2 
norm reducer and switches the dense `norm` operator to make use of it.
   
   The implementation follows the [Blas nrm2 reference 
implementation](http://www.netlib.org/blas/snrm2.f).
   
   As  a final rescaling step is necessary  at the end of the reduction, this 
PR also introduces a new `Finalize` method for Reducers. This method is a noop 
for all previous reducers. A separate PR needs to add the `Finalize` method to 
the maximum and minimum reducers in mshadow.
   
   ## 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](https://issues.apache.org/jira/projects/MXNET/issues) 
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)
   - [X] 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
   - [X] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [X] Improve numerical stability for L2 norm in `norm()` operator
   
   ### Comments ###
   - The test_norm() test was currently disabled 
(https://github.com/apache/incubator-mxnet/issues/11509). It is enabled in this 
PR. Maybe using a different norm2 implementation will fix the flakiness of the 
test..
   - I tried avoiding the need to add the `Finalize` method to all existing 
reducers (i.e. maximum, minimum, sum, product, nansum, nanprod) using 
[SFINAE](https://en.cppreference.com/w/cpp/language/sfinae) but it didn't get 
it to work immediately (the Finalize() would correctly be skipped if it the 
respective reducer didn't implement it, but for unknown reasons was also 
skipped if the reducer implemented it). As there are not many reducers, I added 
the method for now.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to