class_docstr: Create a graph pool in advance to accelerate graph building phase in Transformer.
docstr: args:
      n: maximum length of input sequence.
      m: maximum length of output sequence.
docstr_tok: ["args",":","n",":","maximum","length","of","input","sequence",".","m",":","maximum","length","of","output","sequence","."]
code: def __init__(self, n=50, m=50):
      """
      args:
          n: maximum length of input sequence.
          m: maximum length of output sequence.
      """
      print("start creating graph pool...")
      tic = time.time()
      self.n, self.m = n, m
      g_pool = [
          [dgl.graph(([], [])) for _ in range(m)] for _ in range(n)
      ]
      num_edges = {
          "ee": np.zeros((n, n)).astype(int),
          "ed": np.zeros((n, m)).astype(int),
          "dd": np.zeros((m, m)).astype(int),
      }
      for i, j in itertools.product(range(n), range(m)):
          src_length = i + 1
          tgt_length = j + 1
  
          g_pool[i][j].add_nodes(src_length + tgt_length)
          enc_nodes = th.arange(src_length, dtype=th.long)
          dec_nodes = th.arange(tgt_length, dtype=th.long) + src_length
  
          # enc -> enc
          us = enc_nodes.unsqueeze(-1).repeat(1, src_length).view(-1)
          vs = enc_nodes.repeat(src_length)
          g_pool[i][j].add_edges(us, vs)
          num_edges["ee"][i][j] = len(us)
          # enc -> dec
          us = enc_nodes.unsqueeze(-1).repeat(1, tgt_length).view(-1)
          vs = dec_nodes.repeat(src_length)
          g_pool[i][j].add_edges(us, vs)
          num_edges["ed"][i][j] = len(us)
          # dec -> dec
          indices = th.triu(th.ones(tgt_length, tgt_length)) == 1
          us = dec_nodes.unsqueeze(-1).repeat(1, tgt_length)[indices]
          vs = dec_nodes.unsqueeze(0).repeat(tgt_length, 1)[indices]
          g_pool[i][j].add_edges(us, vs)
          num_edges["dd"][i][j] = len(us)
  
      print(
          "successfully created graph pool, time: {0:0.3f}s".format(
              time.time() - tic
          )
      )
      self.g_pool = g_pool
      self.num_edges = num_edges
  
file_path: dgl/examples/pytorch/transformer/dataset/graph.py
imports: import itertools
  import time
  from collections import *
  import numpy
  import torch
  import dgl
label_desc: Use image node_id 1 to create a new GraphPool object  with example: obj = GraphPool(n, m)