code: def compute_mrr(
      model,
      evaluator,
      node_emb,
      src,
      dst,
      neg_dst,
      device,
      batch_size=500,
  ):
      """Compute Mean Reciprocal Rank (MRR) in batches."""
      rr = torch.zeros(src.shape[0])
      for start in tqdm.trange(
          0, src.shape[0], batch_size, desc="Evaluate"
      ):
          end = min(start + batch_size, src.shape[0])
          all_dst = torch.cat(
              [dst[start:end, None], neg_dst[start:end]], 1
          )
          h_src = node_emb[src[start:end]][:, None, :].to(device)
          h_dst = (
              node_emb[all_dst.view(-1)]
              .view(*all_dst.shape, -1)
              .to(device)
          )
          pred = model.predictor(h_src * h_dst).squeeze(-1)
          input_dict = {
              "y_pred_pos": pred[:, 0],
              "y_pred_neg": pred[:, 1:],
          }
          rr[start:end] = evaluator.eval(input_dict)["mrr_list"]
      return rr.mean()
  
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 2 for calling a global function with example usage: compute_mrr(model, evaluator, node_emb, src, dst, neg_dst, device, batch_size) and returns: rr