docstr: Layer-wise inference algorithm to compute GNN node embeddings.
docstr_tok: ["Layer-wise","inference","algorithm","to","compute","GNN","node","embeddings","."]
code: def inference(self, g, device, batch_size):
      """Layer-wise inference algorithm to compute GNN node embeddings."""
      feat = g.ndata["feat"]
      sampler = MultiLayerFullNeighborSampler(
          1, prefetch_node_feats=["feat"]
      )
      dataloader = DataLoader(
          g,
          torch.arange(g.num_nodes()).to(g.device),
          sampler,
          device=device,
          batch_size=batch_size,
          shuffle=False,
          drop_last=False,
          num_workers=0,
      )
      buffer_device = torch.device("cpu")
      pin_memory = buffer_device != device
      for l, layer in enumerate(self.layers):
          y = torch.empty(
              g.num_nodes(),
              self.hid_size,
              device=buffer_device,
              pin_memory=pin_memory,
          )
          feat = feat.to(device)
          for input_nodes, output_nodes, blocks in tqdm.tqdm(
              dataloader, desc="Inference"
          ):
              x = feat[input_nodes]
              h = layer(blocks[0], x)
              if l != len(self.layers) - 1:
                  h = F.relu(h)
              y[output_nodes] = h.to(buffer_device)
          feat = y
      return y
  
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 3 for calling the SAGE obj's underlying member method code with example usage: obj.inference(g, device, batch_size) and returns: y