parameters: (self)
docstring: Sync from the desc on the c++ end. This method is used to synchronize
          the c++ desc instance generated by backward.
docstring_summary: Sync from the desc on the c++ end. This method is used to synchronize
          the c++ desc instance generated by backward.
docstring_tokens: Sync from the desc on the c ++ end . This method is used to synchronize the c ++ desc instance generated by backward .
function: def _sync_with_cpp(self):
          """
          Sync from the desc on the c++ end. This method is used to synchronize
          the c++ desc instance generated by backward.
          """
          # sync variables from cpp
          for var in self.desc.all_vars():
              if not self.has_var(var.name()):
                  is_stop_gradient = False
                  if var.has_stop_gradient():
                      is_stop_gradient = var.stop_gradient()
                  if var.has_is_parameter() and var.is_parameter():
                      self.create_parameter(
                          name=var.name(),
                          desc=var,
                          type=var.type(),
                          shape=var.shape(),
                          dtype=var.dtype(),
                          stop_gradient=is_stop_gradient)
                  else:
                      self.create_var(
                          name=var.name(),
                          desc=var,
                          type=var.type(),
                          stop_gradient=is_stop_gradient)
  
          # sync variables removed from c++ end
          for var in list(self.vars.keys()):
              if not self.desc.find_var(cpt.to_bytes(var)):
                  self.vars.pop(var)
  
          # sync operators from cpp
          ops_in_cpp = []
          for op_idx in range(0, self.desc.op_size()):
              ops_in_cpp.append(self.desc.op(op_idx))
  
          if len(self.ops) != 0:
              first_op_in_python = self.ops[0].desc
              last_op_in_python = self.ops[len(self.ops) - 1].desc
              start_index = None
              end_index = None
              for index in range(len(ops_in_cpp)):
                  if first_op_in_python == ops_in_cpp[index]:
                      start_index = index
                  if last_op_in_python == ops_in_cpp[index]:
                      end_index = index
              assert start_index is not None
              assert end_index is not None
              assert start_index <= end_index
          else:
              start_index = 0
              end_index = -1
  
          # sync ops append to the head of cpp_ops
          for index in range((start_index - 1 - 1), -1, -1):
              op_desc = ops_in_cpp[index]
              op = Operator(self, op_desc)
              self.ops.insert(0, op)
  
          # sync ops append to the end of cpp_ops
          for index in range((end_index + 1), len(ops_in_cpp)):
              op_desc = ops_in_cpp[index]
              op = Operator(self, op_desc)
              self.ops.append(op)
  
          # sync ops removed from c++ end
          if end_index != -1 and end_index < len(self.ops):
              ops_in_cpp_index = 0
              ops_in_python_index = 0
              while ops_in_python_index < len(
                      self.ops) and ops_in_cpp_index < len(ops_in_cpp):
                  if self.ops[ops_in_python_index].desc != ops_in_cpp[
                          ops_in_cpp_index]:
                      del self.ops[ops_in_python_index]
                  else:
                      ops_in_cpp_index += 1
                      ops_in_python_index += 1
  
          assert len(self.ops) == len(ops_in_cpp)
          for index in range(len(self.ops)):
              assert self.ops[index].desc == ops_in_cpp[index]
function_tokens: def _sync_with_cpp ( self ) : # sync variables from cpp for var in self . desc . all_vars ( ) : if not self . has_var ( var . name ( ) ) : is_stop_gradient = False if var . has_stop_gradient ( ) : is_stop_gradient = var . stop_gradient ( ) if var . has_is_parameter ( ) and var . is_parameter ( ) : self . create_parameter ( name = var . name ( ) , desc = var , type = var . type ( ) , shape = var . shape ( ) , dtype = var . dtype ( ) , stop_gradient = is_stop_gradient ) else : self . create_var ( name = var . name ( ) , desc = var , type = var . type ( ) , stop_gradient = is_stop_gradient ) # sync variables removed from c++ end for var in list ( self . vars . keys ( ) ) : if not self . desc . find_var ( cpt . to_bytes ( var ) ) : self . vars . pop ( var ) # sync operators from cpp ops_in_cpp = [ ] for op_idx in range ( 0 , self . desc . op_size ( ) ) : ops_in_cpp . append ( self . desc . op ( op_idx ) ) if len ( self . ops ) != 0 : first_op_in_python = self . ops [ 0 ] . desc last_op_in_python = self . ops [ len ( self . ops ) - 1 ] . desc start_index = None end_index = None for index in range ( len ( ops_in_cpp ) ) : if first_op_in_python == ops_in_cpp [ index ] : start_index = index if last_op_in_python == ops_in_cpp [ index ] : end_index = index assert start_index is not None assert end_index is not None assert start_index <= end_index else : start_index = 0 end_index = - 1 # sync ops append to the head of cpp_ops for index in range ( ( start_index - 1 - 1 ) , - 1 , - 1 ) : op_desc = ops_in_cpp [ index ] op = Operator ( self , op_desc ) self . ops . insert ( 0 , op ) # sync ops append to the end of cpp_ops for index in range ( ( end_index + 1 ) , len ( ops_in_cpp ) ) : op_desc = ops_in_cpp [ index ] op = Operator ( self , op_desc ) self . ops . append ( op ) # sync ops removed from c++ end if end_index != - 1 and end_index < len ( self . ops ) : ops_in_cpp_index = 0 ops_in_python_index = 0 while ops_in_python_index < len ( self . ops ) and ops_in_cpp_index < len ( ops_in_cpp ) : if self . ops [ ops_in_python_index ] . desc != ops_in_cpp [ ops_in_cpp_index ] : del self . ops [ ops_in_python_index ] else : ops_in_cpp_index += 1 ops_in_python_index += 1 assert len ( self . ops ) == len ( ops_in_cpp ) for index in range ( len ( self . ops ) ) : assert self . ops [ index ] . desc == ops_in_cpp [ index ]