code: def train(args, device, g, reverse_eids, seed_edges, model):
      # create sampler & dataloader
      sampler = NeighborSampler(
          [15, 10, 5], prefetch_node_feats=["feat"]
      )
      sampler = as_edge_prediction_sampler(
          sampler,
          exclude="reverse_id",
          reverse_eids=reverse_eids,
          negative_sampler=negative_sampler.Uniform(1),
      )
      use_uva = args.mode == "mixed"
      dataloader = DataLoader(
          g,
          seed_edges,
          sampler,
          device=device,
          batch_size=512,
          shuffle=True,
          drop_last=False,
          num_workers=0,
          use_uva=use_uva,
      )
      opt = torch.optim.Adam(model.parameters(), lr=0.0005)
      for epoch in range(10):
          model.train()
          total_loss = 0
          for it, (
              input_nodes,
              pair_graph,
              neg_pair_graph,
              blocks,
          ) in enumerate(dataloader):
              x = blocks[0].srcdata["feat"]
              pos_score, neg_score = model(
                  pair_graph, neg_pair_graph, blocks, x
              )
              score = torch.cat([pos_score, neg_score])
              pos_label = torch.ones_like(pos_score)
              neg_label = torch.zeros_like(neg_score)
              labels = torch.cat([pos_label, neg_label])
              loss = F.binary_cross_entropy_with_logits(score, labels)
              opt.zero_grad()
              loss.backward()
              opt.step()
              total_loss += loss.item()
              if (it + 1) == 1000:
                  break
          print(
              "Epoch {:05d} | Loss {:.4f}".format(
                  epoch, total_loss / (it + 1)
              )
          )
  
file_path: dgl/examples/pytorch/graphsage/link_pred.py
imports: import argparse
  import dgl
  import dgl.nn
  import torch
  import torch.nn
  import torch.nn.functional
  import tqdm
  from dgl.dataloading import as_edge_prediction_sampler, DataLoader, MultiLayerFullNeighborSampler, negative_sampler, NeighborSampler
  from ogb.linkproppred import DglLinkPropPredDataset, Evaluator
label_desc: Use image node_id 4 for calling a global function with example usage: train(args, device, g, reverse_eids, seed_edges, model) without return types