code: def test_node_dataloader(idtype, sampler_name, mode, use_ddp):
      if mode != "cpu" and F.ctx() == F.cpu():
          pytest.skip("UVA and GPU sampling require a GPU.")
      if use_ddp:
          if os.name == "nt":
              pytest.skip(
                  "PyTorch 1.13.0+ has problems in Windows DDP..."
              )
          dist.init_process_group(
              "gloo" if F.ctx() == F.cpu() else "nccl",
              "tcp://127.0.0.1:12347",
              world_size=1,
              rank=0,
          )
      g1 = dgl.graph(([0, 0, 0, 1, 1], [1, 2, 3, 3, 4])).astype(idtype)
      g1.ndata["feat"] = F.copy_to(F.randn((5, 8)), F.cpu())
      g1.ndata["label"] = F.copy_to(F.randn((g1.num_nodes(),)), F.cpu())
      if mode in ("cpu", "uva_cpu_indices"):
          indices = F.copy_to(
              F.arange(0, g1.num_nodes(), idtype), F.cpu()
          )
      else:
          indices = F.copy_to(
              F.arange(0, g1.num_nodes(), idtype), F.cuda()
          )
      if mode == "pure_gpu":
          g1 = g1.to(F.cuda())
  
      use_uva = mode.startswith("uva")
  
      sampler = {
          "full": dgl.dataloading.MultiLayerFullNeighborSampler(2),
          "neighbor": dgl.dataloading.MultiLayerNeighborSampler([3, 3]),
          "neighbor2": dgl.dataloading.MultiLayerNeighborSampler(
              [3, 3]
          ),
          "labor": dgl.dataloading.LaborSampler([3, 3]),
      }[sampler_name]
      for num_workers in [0, 1, 2] if mode == "cpu" else [0]:
          dataloader = dgl.dataloading.DataLoader(
              g1,
              indices,
              sampler,
              device=F.ctx(),
              batch_size=g1.num_nodes(),
              num_workers=num_workers,
              use_uva=use_uva,
              use_ddp=use_ddp,
          )
          for input_nodes, output_nodes, blocks in dataloader:
              _check_device(input_nodes)
              _check_device(output_nodes)
              _check_device(blocks)
              _check_dtype(input_nodes, idtype, "dtype")
              _check_dtype(output_nodes, idtype, "dtype")
              _check_dtype(blocks, idtype, "idtype")
  
      g2 = dgl.heterograph(
          {
              ("user", "follow", "user"): (
                  [0, 0, 0, 1, 1, 1, 2],
                  [1, 2, 3, 0, 2, 3, 0],
              ),
              ("user", "followed-by", "user"): (
                  [1, 2, 3, 0, 2, 3, 0],
                  [0, 0, 0, 1, 1, 1, 2],
              ),
              ("user", "play", "game"): (
                  [0, 1, 1, 3, 5],
                  [0, 1, 2, 0, 2],
              ),
              ("game", "played-by", "user"): (
                  [0, 1, 2, 0, 2],
                  [0, 1, 1, 3, 5],
              ),
          }
      ).astype(idtype)
      for ntype in g2.ntypes:
          g2.nodes[ntype].data["feat"] = F.copy_to(
              F.randn((g2.num_nodes(ntype), 8)), F.cpu()
          )
      if mode in ("cpu", "uva_cpu_indices"):
          indices = {
              nty: F.copy_to(g2.nodes(nty), F.cpu())
              for nty in g2.ntypes
          }
      else:
          indices = {
              nty: F.copy_to(g2.nodes(nty), F.cuda())
              for nty in g2.ntypes
          }
      if mode == "pure_gpu":
          g2 = g2.to(F.cuda())
  
      batch_size = max(g2.num_nodes(nty) for nty in g2.ntypes)
      sampler = {
          "full": dgl.dataloading.MultiLayerFullNeighborSampler(2),
          "neighbor": dgl.dataloading.MultiLayerNeighborSampler(
              [{etype: 3 for etype in g2.etypes}] * 2
          ),
          "neighbor2": dgl.dataloading.MultiLayerNeighborSampler(
              [3, 3]
          ),
          "labor": dgl.dataloading.LaborSampler([3, 3]),
      }[sampler_name]
      for num_workers in [0, 1, 2] if mode == "cpu" else [0]:
          dataloader = dgl.dataloading.DataLoader(
              g2,
              indices,
              sampler,
              device=F.ctx(),
              batch_size=batch_size,
              num_workers=num_workers,
              use_uva=use_uva,
              use_ddp=use_ddp,
          )
          assert isinstance(iter(dataloader), Iterator)
          for input_nodes, output_nodes, blocks in dataloader:
              _check_device(input_nodes)
              _check_device(output_nodes)
              _check_device(blocks)
              _check_dtype(input_nodes, idtype, "dtype")
              _check_dtype(output_nodes, idtype, "dtype")
              _check_dtype(blocks, idtype, "idtype")
  
      if use_ddp:
          dist.destroy_process_group()
  
imports: import os
  import unittest
  from collections.abc import Iterator, Mapping
  from functools import partial
  import backend
  import dgl
  import dgl.ops
  import numpy
  import pytest
  import torch
  import torch.distributed
  import torch.multiprocessing
  from utils import parametrize_idtype
label_desc: Use image node_id 10 for calling a global function with example usage: test_node_dataloader(idtype, sampler_name, mode, use_ddp) without return types