code: def sync_gradients(parameters):
      grad_var_set = set()
      grad_vars = []
      sparse_grad_vars = []
  
      for param in parameters:
          if param.trainable and (param._grad_ivar() is not None):
              g_var = param._grad_ivar()
              assert (
                  not g_var._is_sparse()
              ), "Now, it doesn't support sparse parameters"
              grad_vars.append(g_var)
              assert g_var not in grad_var_set
              grad_var_set.add(g_var)
  
      coalesced_grads_and_vars = (
          paddle.fluid.dygraph.parallel.build_groups(
              grad_vars, 128 * 1024 * 1024
          )
      )
  
      nranks = paddle.distributed.get_world_size()
      for coalesced_grad, _, _ in coalesced_grads_and_vars:
          # need to div nranks
          div_factor = paddle.to_tensor(
              nranks, dtype=coalesced_grad.dtype
          )
          paddle.fluid.framework._dygraph_tracer().trace_op(
              type="elementwise_div",
              inputs={"X": coalesced_grad, "Y": div_factor},
              outputs={"Out": coalesced_grad},
              attrs={"axis": -1},
          )
  
          paddle.distributed.all_reduce(coalesced_grad)
  
      paddle.fluid.dygraph.parallel._split_tensors(
          coalesced_grads_and_vars
      )
  
label_desc: Use image node_id 2 for calling a global function with example usage: sync_gradients(parameters) without return types