code: def modify_logits_for_top_p_filtering(logits, top_p):
      """Set the logits for none top-p values to -inf."""
  
      # First sort and calculate cumulative sum of probabilities.
      sorted_logits, sorted_indices = torch.sort(
          logits, descending=True
      )
      cumulative_probs = sorted_logits.softmax(dim=-1).cumsum(dim=-1)
  
      # Filteration based on the cumulative sum.
      filter_ = cumulative_probs > top_p
      # This shift by 1 is weird and I cannot justify it. This existed
      # in the original implementation:
      #   https://github.com/ari-holtzman/degen/blob/master/gen.py
      # and I guess it is needed so keeping it for now.
      filter_[:, 1:] = filter_[:, :-1].clone()
      # Make sure we at least have one token to select from.
      filter_[..., 0] = 0
  
      # Fill in the filtered part
      filter_ = filter_.scatter(1, sorted_indices, filter_)
      logits.masked_fill_(filter_, float("-Inf"))
  
imports: import torch
label_desc: Use image node_id 2 for calling a global function with example usage: modify_logits_for_top_p_filtering(logits, top_p) without return types