From 6579432ff663d1402754409286618fea502f6940 Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Tue, 27 Apr 2021 10:33:48 +0800 Subject: [PATCH] Fix grad calculation bug in tensor_array_to_tensor (#32558) --- paddle/fluid/operators/tensor_array_to_tensor_op.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/tensor_array_to_tensor_op.cc b/paddle/fluid/operators/tensor_array_to_tensor_op.cc index 620231eb2e2..eb20e1c2cd2 100644 --- a/paddle/fluid/operators/tensor_array_to_tensor_op.cc +++ b/paddle/fluid/operators/tensor_array_to_tensor_op.cc @@ -250,8 +250,12 @@ class LoDTensorArray2TensorGradOp : public framework::OperatorBase { auto dout_name = Input(framework::GradVarName("Out")); std::vector grad_names; + // NOTE(Aurelius84): Generating grad base name by Input("X") instead of + // fixed string to avoid incorrectly sharing same var's allocation in + // multi-thread that will cause wrong calculation result. + std::string grad_base_name = base_name + "_temp_grad_"; - LodTensorVectorResizeFromLodTensorArray(scope, "grad_name", Input("X"), + LodTensorVectorResizeFromLodTensorArray(scope, grad_base_name, Input("X"), &grad_names); auto use_stack = Attr("use_stack"); -- GitLab