code: def from_nested_tensor(
      x: Tensor,
      return_batch: bool = False,
  ) -> Union[Tensor, Tuple[Tensor, Tensor]]:
      r"""Given a `nested PyTorch tensor
      <https://pytorch.org/docs/stable/nested.html>`__, creates a contiguous
      batch of tensors
      :math:`\mathbf{X} \in \mathbb{R}^{(N_1 + \ldots + N_B) \times *}`, and
      optionally a batch vector which assigns each element to a specific example.
      Reverse operation of :meth:`to_nested_tensor`.
  
      Args:
          x (torch.Tensor): The nested input tensor. The size of nested tensors
              need to match except for the first dimension.
          return_batch (bool, optional): If set to :obj:`True`, will also return
              the batch vector :math:`\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N`.
              (default: :obj:`False`)
      """
      if not x.is_nested:
          raise ValueError(
              "Input tensor in 'from_nested_tensor' is not nested"
          )
  
      sizes = x._nested_tensor_size()
  
      for dim, (a, b) in enumerate(zip(sizes[0, 1:], sizes.t()[1:])):
          if not torch.equal(a.expand_as(b), b):
              raise ValueError(
                  f"Not all nested tensors have the same size "
                  f"in dimension {dim + 1} "
                  f"(expected size {a.item()} for all tensors)"
              )
  
      out = x.contiguous().values()
      out = out.view(-1, *sizes[0, 1:].tolist())
  
      if not return_batch:
          return out
  
      batch = torch.arange(x.size(0), device=x.device)
      batch = batch.repeat_interleave(sizes[:, 0].to(batch.device))
  
      return out, batch
  
imports: from typing import Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch_geometric.utils import scatter
label_desc: Use image node_id 2 for calling a global function with example usage: from_nested_tensor(x, return_batch) and returns: out,  batch, out