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

Performance optimization of LayerNorm on CPU #15313

Merged
merged 1 commit into from
Jun 21, 2019

Conversation

pengxin99
Copy link
Contributor

@pengxin99 pengxin99 commented Jun 21, 2019

Description

imporve LayerNormLastDim() performance, it will benefit the gluonnlp/bert and maybe other nlp task.

test the performance with both MXNet master and this pr at skx8180-1s with the performance test script , get speedup 1.27X~2.31X.

master branch: 
shape: [1, 128, 768],   time: 0.148154 ms
shape: [8, 128, 768],   time: 0.296437 ms
shape: [32, 128, 768],  time: 0.790932 ms
shape: [1, 128, 1024],  time: 0.237234 ms
shape: [8, 128, 1024],  time: 0.553549 ms
shape: [32, 128, 1024],         time: 1.765041 ms

opt_layernorm branch: 
shape: [1, 128, 768],   time: 0.064805 ms
shape: [8, 128, 768],   time: 0.198420 ms
shape: [32, 128, 768],  time: 0.439751 ms
shape: [1, 128, 1024],  time: 0.121733 ms
shape: [8, 128, 1024],  time: 0.430842 ms
shape: [32, 128, 1024],         time: 1.359872 ms

Through the profiling of gluonnlp/bert/finetune_classifiy.py, get speedup 1.8X~3.37X on LayerNorm op.

@TaoLv @juliusshufan @PatricZhao @eric-haibin-lin

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

@pengzhao-intel
Copy link
Contributor

Thanks for the improvements. Is there a test case to cover this OP?

@TaoLv
Copy link
Member

TaoLv commented Jun 21, 2019

@pengxin99 Thank you for the contribution. Could you change the title and description? I think this PR and the LayerNorm operator is not related to MKL-DNN. Better to call it "Performance optimization of LayerNorm on CPU".

@pengzhao-intel Test should be covered by https://github.com/apache/incubator-mxnet/blob/master/tests/python/unittest/test_operator.py#L3594 and https://github.com/apache/incubator-mxnet/blob/master/tests/python/unittest/test_gluon.py#L741.

@pengxin99 pengxin99 changed the title Improve MLKDNN LayerNormLastDim() performance Performance optimization of LayerNorm on CPU Jun 21, 2019
@eric-haibin-lin eric-haibin-lin merged commit b4ce4e7 into apache:master Jun 21, 2019
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.

4 participants