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

Support 3D input for MKL-DNN softmax operator #14818

Merged
merged 13 commits into from
May 17, 2019

Conversation

TaoLv
Copy link
Member

@TaoLv TaoLv commented Apr 27, 2019

Description

  1. to support 3D softmax layers in GluonNLP BERT (need Update MKL-DNN submodule to v0.19 #14783 for better performance)
  2. fix in-place softmax
  3. remove ctx.is_train check so the cpp test for softmax can work
  4. enhance the checks in SupportMKLDNNSoftmax

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

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

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

@TaoLv
Copy link
Member Author

TaoLv commented Apr 27, 2019

@pengzhao-intel
Copy link
Contributor

@TaoLv thanks for the PR.

Is there a test for the 1D softmax and could you show the performance of MKL-DNN primitive against original implementation?

Copy link
Contributor

@pengzhao-intel pengzhao-intel left a comment

Choose a reason for hiding this comment

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

LGTM :)

@TaoLv
Copy link
Member Author

TaoLv commented Apr 27, 2019

Tests should be covered by
https://github.com/apache/incubator-mxnet/blob/master/tests/python/unittest/test_operator.py#L4697
and
https://github.com/apache/incubator-mxnet/blob/master/tests/cpp/operator/mkldnn_operator_test.cc#L1288.
I used below code snippet for performance benchmarking:

def test_performance():
    shapes = [(1024,), (96, 512), (96, 128, 128), (96, 256, 256), (1, 8, 1024, 1024)]
    for sh in shapes:
        a = mx.nd.random.uniform(shape=sh)
        # warm up
        b = mx.nd.softmax(a, axis=-1)
        b.wait_to_read()

        tic = time.time()
        for i in range(1000):
            b = mx.nd.softmax(a, axis=-1)
            b.wait_to_read()

        toc = time.time()
        print("softmax %s, take %f ms" % (sh, (toc - tic)/1000*1000.0))

Some performance numbers as following:
mxnet==1.5.0b20190426

softmax (1024,), take 0.103340 ms
softmax (96, 512), take 0.127465 ms
softmax (96, 128, 128), take 1.655400 ms
softmax (96, 256, 256), take 6.369653 ms
softmax (1, 8, 1024, 1024), take 11.450656 ms

This PR with MKL-DNN backend:

softmax (1024,), take 0.062743 ms
softmax (96, 512), take 0.104104 ms
softmax (96, 128, 128), take 0.385350 ms
softmax (96, 256, 256), take 0.463220 ms
softmax (1, 8, 1024, 1024), take 1.704757 ms

@TaoLv TaoLv changed the title Support 3D input for MKL-DNN softmax operator [WIP] Support 3D input for MKL-DNN softmax operator Apr 28, 2019
@TaoLv
Copy link
Member Author

TaoLv commented Apr 28, 2019

Pending on MKL-DNN update for better performance~

@TaoLv
Copy link
Member Author

TaoLv commented May 4, 2019

Fallback all softmax operations when axis != last dimension because they are not optimized in MKL-DNN.

@pengzhao-intel
Copy link
Contributor

@TaoLv I have merged the MKL-DNN 0.19 and please rebase the code and see if everything is OK :)

@TaoLv TaoLv changed the title [WIP] Support 3D input for MKL-DNN softmax operator Support 3D input for MKL-DNN softmax operator May 16, 2019
@pengzhao-intel
Copy link
Contributor

@TaoLv please rebase and retrigger again the CI issue is fixed now.

@pengzhao-intel
Copy link
Contributor

Merging now :) Thanks for your contribution.

@pengzhao-intel pengzhao-intel merged commit 8d6ac4a into apache:master May 17, 2019
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
* add 3d softmax

* fix

* handle req type

* clean code

* remove check

* check axis

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

Successfully merging this pull request may close these issues.

2 participants