code: def top_p(logits, thres=0.9):
      sorted_logits, sorted_indices = torch.sort(
          logits, descending=True
      )
      cum_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)
  
      sorted_indices_to_remove = cum_probs > (1 - thres)
      sorted_indices_to_remove[:, 1:] = sorted_indices_to_remove[
          :, :-1
      ].clone()
      sorted_indices_to_remove[:, 0] = 0
  
      sorted_logits[sorted_indices_to_remove] = float("-inf")
      return sorted_logits.scatter(1, sorted_indices, sorted_logits)
  
file_path: reformer-pytorch/reformer_pytorch/generative_tools.py
imports: from functools import partial
  import torch
  from torch import nn
  import torch.nn.functional
  from torch.nn.utils.rnn import pad_sequence
  from reformer_pytorch.reformer_pytorch import ReformerLM
  from reformer_pytorch.autopadder import Autopadder
label_desc: Use image node_id 1 for calling a global function with example usage: top_p(logits, thres) and returns: sorted_logits