From 2815d6192e69379cc19804ebd418d861236999bf Mon Sep 17 00:00:00 2001 From: r1chardf1d0 Date: Thu, 2 Mar 2023 10:31:45 +0800 Subject: [PATCH] fix maskedfill bprop in dynamic rank --- .../mindspore/ops/_grad_experimental/grad_array_ops.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mindspore/python/mindspore/ops/_grad_experimental/grad_array_ops.py b/mindspore/python/mindspore/ops/_grad_experimental/grad_array_ops.py index e8697092956..587f32e1db3 100644 --- a/mindspore/python/mindspore/ops/_grad_experimental/grad_array_ops.py +++ b/mindspore/python/mindspore/ops/_grad_experimental/grad_array_ops.py @@ -142,7 +142,12 @@ def get_bprop_masked_select(self): dinput = mul_op(dout, (1 - mask)) dvalue = mul_op(dout, mask) dinput, dvalue = binop_grad_common(input_data, mask, dinput, dvalue) - dvalue = sum_op(dvalue) + # for dynamic rank, reduce axis should be calc + if F.is_sequence_shape_unknown(P.Shape()(dvalue)): + axis = P.Range()(Tensor(0), dyn_rank(dvalue), Tensor(1)) + dvalue = sum_op(dvalue, axis) + else: + dvalue = sum_op(dvalue) dinput = F.cast(dinput, F.dtype(input_data)) if is_instance_op(value, mstype.number): dvalue = 0