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

Speedup SequenceMask on GPU #14445

Merged
merged 1 commit into from
Mar 27, 2019
Merged

Conversation

haojin2
Copy link
Contributor

@haojin2 haojin2 commented Mar 16, 2019

Description

As title. Address #14124.

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

  • Customized kernel for GPU

Comments

benchmark results on sample workload from #14124:
forward only: 48.589637756347656 ms -> 0.5544562339782715 ms 87.63x speedup
forward+backward: 97.38378977775574 ms -> 1.224109172821045 ms 79.55x speedup

import mxnet as mx

ctx = mx.gpu(0)

dshape = (8, 512, 768)
seq_length = [18., 35., 34., 100., 110., 194., 512., 10.]
dtype = 'float16'

import random

from mxnet.test_utils import check_speed, rand_ndarray

mx_data = rand_ndarray(dshape).as_in_context(ctx).astype(dtype)
mx_seq_len = mx.nd.array(seq_length).as_in_context(ctx).astype(dtype)

data = mx.sym.Variable("data")
seq_len = mx.sym.Variable("sequence_length")
mx_sym = mx.sym.SequenceMask(data=data, sequence_length=seq_len, use_sequence_length=True, value=0.0, axis=1)

print(check_speed(mx_sym, typ='forward', location={"data": mx_data, "sequence_length": mx_seq_len}, ctx=ctx, N=1000) * 1000)
print(check_speed(mx_sym, typ='whole', location={"data": mx_data, "sequence_length": mx_seq_len}, ctx=ctx, N=1000) * 1000)

@haojin2
Copy link
Contributor Author

haojin2 commented Mar 16, 2019

@eric-haibin-lin @szha for review.

@haojin2 haojin2 force-pushed the speed_sequence_mask branch 2 times, most recently from f312304 to efb4dc1 Compare March 16, 2019 06:40
@karan6181
Copy link
Contributor

@mxnet-label-bot add [CUDA, Operator, Performance, pr-awaiting-review]

@haojin2
Copy link
Contributor Author

haojin2 commented Mar 19, 2019

@eric-haibin-lin @szha ping for review.

Copy link
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.

Nice improvement! Two comments:

src/operator/sequence_mask.cu Outdated Show resolved Hide resolved
src/operator/sequence_mask-inl.h Show resolved Hide resolved
@haojin2
Copy link
Contributor Author

haojin2 commented Mar 25, 2019

@eric-haibin-lin please check

@eric-haibin-lin eric-haibin-lin merged commit 09daf22 into apache:master Mar 27, 2019
@haojin2 haojin2 deleted the speed_sequence_mask branch March 28, 2019 20:15
vdantu pushed a commit to vdantu/incubator-mxnet that referenced this pull request Mar 31, 2019
ZhennanQin pushed a commit to ZhennanQin/incubator-mxnet that referenced this pull request Apr 3, 2019
nswamy pushed a commit that referenced this pull request Apr 5, 2019
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants