code: def test_hier_neighbor_allreduce_dynamic_move_dst_weight(
      hier_setup, dtype, dim
  ):
      rank, size, local_rank, local_size = hier_setup
      machine_rank = (rank - local_rank) // local_size
      machine_size = size // local_size
      # This particular value is chosen such that the local allreduce will result in the machine rank.
      # For example, there are 8 nodes with 4 nodes per machine.
      # The allreduce result from node 0 to 3 will be 0, and the one from node 4 to 7 will 1.
      tensor = torch.FloatTensor(*([23] * dim)).fill_(
          (rank - (local_size - 1) / 2.0) / local_size
      )
      name = "hier_neighbor_allreduce_tensor_{}_{}".format(dim, dtype)
      tensor = cast_and_place(tensor, dtype)
  
      reduced_tensor = bf.hierarchical_neighbor_allreduce(
          tensor,
          self_weight=0.0,
          src_machine_weights={(machine_rank + 1) % machine_size: 0.5},
          dst_machine_weights={(machine_rank - 1) % machine_size: 2.0},
          name=name,
      )
      expected_value = (machine_rank + 1) % machine_size
      assert (
          list(reduced_tensor.shape) == [23] * dim
      ), "bf.hierarchical_neighbor_allreduce (hier_NA) produces incorrect reduced shape"
      assert (
          reduced_tensor.data - expected_value
      ).abs().max() < EPSILON, "bf.hierarchical_neighbor_allreduce (hier_NA) produces incorrect reduced tensor"
  
imports: import itertools
  import os
  import numpy
  import pytest
  import torch
  import networkx
  import bluefog.torch
  from common import mpi_env_rank_and_size
label_desc: Use image node_id 11 for calling a global function with example usage: test_hier_neighbor_allreduce_dynamic_move_dst_weight(hier_setup, dtype, dim) without return types