Created by: tensor-tang
Inspired by https://github.com/PaddlePaddle/Paddle/pull/3337#discussion_r131963133