parameters: (self)
return_statement: return bprop
docstring: Backpropagator for _MirrorMiniStepOperator, do allreduce or allgather for the devices in the group,
      allgather for sparse feature.
docstring_summary: Backpropagator for _MirrorMiniStepOperator, do allreduce or allgather for the devices in the group,
      allgather for sparse feature.
docstring_tokens: Backpropagator for _MirrorMiniStepOperator do allreduce or allgather for the devices in the group allgather for sparse feature .
function: def get_bprop_mirror_mini_step_operator(self):
      """
      Backpropagator for _MirrorMiniStepOperator, do allreduce or allgather for the devices in the group,
      allgather for sparse feature.
      """
      group = self.group
      dev_num = self.dev_num
      mean_flag = self.mean_flag
  
      all_reduce = AllReduce(group=group)
      mul = P.Mul()
      cast = P.Cast()
  
      fusion = self.get_attr_dict()["fusion"]
      all_reduce.add_prim_attr("fusion", fusion)
      if hasattr(self, 'parameter'):
          parameter = self.parameter
          all_reduce.add_prim_attr("parameter", parameter)
  
      if self.instance_name:
          instance_name = "grad_mirror" + self.instance_name
          all_reduce.set_prim_instance_name(instance_name)
      do_mirror = self.get_attr_dict()["do_mirror"]
  
      def bprop(x, z, out, dout):
          if mean_flag:
              if F.issubclass_(F.typeof(dout), mstype.tensor):
                  if do_mirror:
                      z = F.depend(z, F.assign_add(z, dout))
                      real_grad = all_reduce(z)
                      dx = real_grad
                  else:
                      dx = dout
                  float_one = F.scalar_cast(1.0, F.dtype(dx))
                  num = F.scalar_cast(dev_num, F.dtype(dx))
                  dx = mul(dx, cast(F.scalar_to_array(float_one/num), F.dtype(dx)))
              else:
                  dx = zeros_like(x)  # The grad accumulation do not support row tensor now
          else:
              if F.issubclass_(F.typeof(dout), mstype.tensor):
                  if do_mirror:
                      z = F.depend(z, F.assign_add(z, dout))
                      real_grad = all_reduce(z)
                      dx = real_grad
                  else:
                      dx = dout
              else:
                  dx = zeros_like(x)  # The grad accumulation do not support row tensor now
  
          return (dx, zeros_like(z))
      return bprop
function_tokens: def get_bprop_mirror_mini_step_operator ( self ) : group = self . group dev_num = self . dev_num mean_flag = self . mean_flag all_reduce = AllReduce ( group = group ) mul = P . Mul ( ) cast = P . Cast ( ) fusion = self . get_attr_dict ( ) [ "fusion" ] all_reduce . add_prim_attr ( "fusion" , fusion ) if hasattr ( self , 'parameter' ) : parameter = self . parameter all_reduce . add_prim_attr ( "parameter" , parameter ) if self . instance_name : instance_name = "grad_mirror" + self . instance_name all_reduce . set_prim_instance_name ( instance_name ) do_mirror = self . get_attr_dict ( ) [ "do_mirror" ] def bprop ( x , z , out , dout ) : if mean_flag : if F . issubclass_ ( F . typeof ( dout ) , mstype . tensor ) : if do_mirror : z = F . depend ( z , F . assign_add ( z , dout ) ) real_grad = all_reduce ( z ) dx = real_grad else : dx = dout float_one = F . scalar_cast ( 1.0 , F . dtype ( dx ) ) num = F . scalar_cast ( dev_num , F . dtype ( dx ) ) dx = mul ( dx , cast ( F . scalar_to_array ( float_one / num ) , F . dtype ( dx ) ) ) else : dx = zeros_like ( x ) # The grad accumulation do not support row tensor now else : if F . issubclass_ ( F . typeof ( dout ) , mstype . tensor ) : if do_mirror : z = F . depend ( z , F . assign_add ( z , dout ) ) real_grad = all_reduce ( z ) dx = real_grad else : dx = dout else : dx = zeros_like ( x ) # The grad accumulation do not support row tensor now return ( dx , zeros_like ( z ) ) return bprop