code: def invert_permutation(indices: torch.Tensor) -> torch.Tensor:
      """Produces a tensor of reverse permutation for a given indices.
  
      Based on https://github.com/k2-fsa/snowfall/blob/master/snowfall/common.py
      """
      ans = torch.zeros(
          indices.shape, device=indices.device, dtype=indices.dtype
      )
      ans[indices.to(dtype=torch.long)] = torch.arange(
          0,
          indices.shape[0],
          device=indices.device,
          dtype=indices.dtype,
      )
      return ans
  
imports: import os
  import struct
  from pickle import UnpicklingError
  from typing import List, Optional, Tuple, Union
  import torch
  from nemo.core.utils.k2_guard import k2
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling a global function with example usage: invert_permutation(indices) and returns: ans