Created by: wojtuss
This is a cherry-pick of the fix: https://github.com/PaddlePaddle/Paddle/pull/21059
test=release/1.6