diff --git a/paddle/fluid/operators/reduce_ops/reduce_max_op_npu.cc b/paddle/fluid/operators/reduce_ops/reduce_max_op_npu.cc index e3d8d15a305a98cf8b94725df2e1e5e00ada1c46..8b9925a4c20ea54ba8577d48c0f5ae7200aba2d7 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_max_op_npu.cc +++ b/paddle/fluid/operators/reduce_ops/reduce_max_op_npu.cc @@ -141,6 +141,9 @@ class ReduceMaxGradNPUKernel : public framework::OpKernel { Tensor tmp_out, tmp_out_grad; auto tmp_out_dims_vec = x_dims_vec; for (auto d : reduce_dims) { + if (d < 0) { + d += x_dims_vec.size(); + } tmp_out_dims_vec[d] = 1; }