def Pack(flatten, nmap_list):
  """Packs the list of tensors according to `.NestedMap` in `nmap_list`.

  `Pack` is loosely the inverse of `Flatten`.

  Args:
    flatten: A list of tensors.
    nmap_list: A list of `.NestedMap`.

  Returns:
    A list of `.NestedMap`, say ret is the returned list. We have

      1. len(ret) == len(nmap_list);
      2. recursively, ret[i] has the same keys as nmap_list[i];
      3. Flatten(ret) == flatten;
  """
  if not isinstance(flatten, (list, tuple)):
    flatten = [flatten]
  ret = []
  for x in nmap_list:
    # x needs num values from the head of flatten.
    num = len(x.Flatten())
    ret += [x.Pack(flatten[:num])]
    flatten = flatten[num:]
  assert not flatten, ('flatten does not match nmap_list.')
  return ret