code: def test_adjacency(monkeypatch):
      new_groups = []
  
      data_parallel_size = 32
      pipeline_length = 8
      model_parallel_size = 4
  
      class MockDistribued:
          def get_rank(self):
              return 0
  
          def is_initialized(self):
              return True
  
          def get_world_size(self):
              return (
                  data_parallel_size
                  * pipeline_length
                  * model_parallel_size
              )
  
          def new_group(self, args, backend=None):
              new_groups.append(args.copy())
              return ()
  
      monkeypatch.setattr(torch, "distributed", MockDistribued())
  
      mpu.initialize_model_parallel(
          model_parallel_size, pipeline_length
      )
  
      from collections import defaultdict
  
      buckets = defaultdict(list)
  
      for group in new_groups:
          buckets[len(group)].append(group)
  
      assert sorted(list(buckets.keys())) == [
          model_parallel_size,
          pipeline_length,
          data_parallel_size,
      ]
  
      assert (
          len(buckets[model_parallel_size])
          == pipeline_length * data_parallel_size
      )
      assert (
          len(buckets[data_parallel_size])
          == model_parallel_size * pipeline_length
      )
      assert (
          len(buckets[pipeline_length])
          == model_parallel_size * data_parallel_size
      )
  
      # Check that model_parallel groups are contiguous
      for group in buckets[model_parallel_size]:
          assert sorted(group) == group
          assert list(range(group[0], group[-1] + 1)) == group
  
imports: import torch
  from fairscale.fair_dev.testing.testing import dist_init, spawn_for_all_world_sizes
  from fairscale.nn.model_parallel import initialize
label_desc: Use image node_id 5 for calling a global function with example usage: test_adjacency(monkeypatch) and returns: int, True, unknown, 