code: def sample_top_p(probs, p):
      """
      Perform top-p (nucleus) sampling on a probability distribution.
  
      Args:
          probs (torch.Tensor): Probability distribution tensor.
          p (float): Probability threshold for top-p sampling.
  
      Returns:
          torch.Tensor: Sampled token indices.
  
      Note:
          Top-p sampling selects the smallest set of tokens whose cumulative probability mass
          exceeds the threshold p. The distribution is renormalized based on the selected tokens.
  
      """
      probs_sort, probs_idx = torch.sort(probs, dim=-1, descending=True)
      probs_sum = torch.cumsum(probs_sort, dim=-1)
      mask = probs_sum - probs_sort > p
      probs_sort[mask] = 0.0
      probs_sort.div_(probs_sort.sum(dim=-1, keepdim=True))
      next_token = torch.multinomial(probs_sort, num_samples=1)
      next_token = torch.gather(probs_idx, -1, next_token)
      return next_token
  
label_desc: Use image node_id 1 for calling a global function with example usage: sample_top_p(probs, p) and returns: next_token