code: def test__native_dist_model_spawn_gloo(init_method, dirname):
      spawn_kwargs = {}
  
      if init_method == "FILE":
          init_method = f"file://{dirname}/shared"
      elif init_method == "CUSTOM_ADDR_PORT":
          init_method = None
          spawn_kwargs["master_addr"] = "0.0.0.0"
          spawn_kwargs["master_port"] = 2345
  
      nproc = (
          torch.cuda.device_count() if torch.cuda.is_available() else 4
      )
      device = torch.device(
          "cuda" if torch.cuda.is_available() else "cpu"
      )
      _test__native_dist_model_spawn(
          "gloo",
          num_workers_per_machine=nproc,
          device=device,
          init_method=init_method,
          **spawn_kwargs,
      )
      if device.type == "cpu":
          spawn_kwargs["start_method"] = "fork"
          _test__native_dist_model_spawn(
              "gloo",
              num_workers_per_machine=nproc,
              device=device,
              init_method=init_method,
              **spawn_kwargs,
          )
  
      if init_method not in [None, "env://"]:
          with pytest.raises(
              ValueError,
              match=r"master_addr should be None if init_method is provided",
          ):
              _test__native_dist_model_spawn(
                  "gloo",
                  num_workers_per_machine=nproc,
                  device=device,
                  init_method=init_method,
                  master_addr="abc",
              )
          with pytest.raises(
              ValueError,
              match=r"master_port should be None if init_method is provided",
          ):
              _test__native_dist_model_spawn(
                  "gloo",
                  num_workers_per_machine=nproc,
                  device=device,
                  init_method=init_method,
                  master_port=123,
              )
  
imports: import os
  import pytest
  import torch
  import torch.distributed
  from ignite.distributed.comp_models import has_native_dist_support
label_desc: Use image node_id 25 for calling a global function with example usage: test__native_dist_model_spawn_gloo(init_method, dirname) without return types