code: def sample(
      self, logits, temperature, top_k, top_p, min_p, typical, num=1
  ):
      # torch.manual_seed(42)
  
      if logits.dim() == 3:
          logits = logits[0, -1, :]
      elif logits.dim() == 2:
          logits = logits[-1, :]
      else:
          raise ValueError("Bad logits dimension")
  
      # Disallow tokens
  
      if self.disallowed_tokens is not None:
          logits[self.disallowed_tokens] = float("-inf")
  
      # Base probabilities
  
      logits /= temperature
      logits += 1e-8
      probs = torch.softmax(logits, dim=-1)
  
      # Top K
  
      if top_k == 0:
          top_probs, top_indices = torch.sort(probs, descending=True)
      else:
          top_probs, top_indices = torch.topk(probs, top_k)
          top_probs = F.normalize(top_probs, p=1, dim=-1)
  
      # Top P
  
      if top_p > 0.0:
          num_top_p_probs = 0
          cum_prob = top_probs[0].item()
          while True:
              num_top_p_probs += 1
              if num_top_p_probs == top_probs.shape[-1]:
                  break
              if top_probs[num_top_p_probs].item() < min_p:
                  break
              cum_prob += top_probs[num_top_p_probs].item()
              if cum_prob > top_p:
                  break
  
          top_probs = top_probs[:num_top_p_probs]
          top_probs = F.normalize(top_probs, p=1, dim=-1)
          top_indices = top_indices[:num_top_p_probs]
  
      # Locally typical sampling
  
      if typical > 0.0:
          epsilon = 1e-10
          log_probs = (top_probs + epsilon).log()
          neg_entropy = (top_probs * log_probs).sum()
          entropy_dev = (neg_entropy - log_probs).abs()
          _, entropy_dev_order = torch.sort(entropy_dev)
  
          top_probs = top_probs.gather(-1, entropy_dev_order)
          top_indices = top_indices.gather(-1, entropy_dev_order)
  
          num_typical_probs = 0
          cum_prob = top_probs[0].item()
          while True:
              num_typical_probs += 1
              if num_typical_probs == top_probs.shape[-1]:
                  break
              cum_prob += top_probs[num_typical_probs].item()
              if cum_prob > typical:
                  break
  
          top_probs = top_probs[:num_typical_probs]
          top_probs = F.normalize(top_probs, p=1, dim=-1)
          top_indices = top_indices[:num_typical_probs]
  
      # Multinomial sampling from top_probs, kept in same order as top_indices
  
      sampled_ind = torch.multinomial(
          top_probs,
          top_probs.shape[-1]
          if num == -1
          else min(num, top_probs.shape[-1]),
      )
      sampled_tokens = top_indices[sampled_ind]
      sampled_probs = top_probs[
          sampled_ind
      ]  # Return probs before second norm
  
      if sampled_tokens.shape[0] > 1:
          sampled_tokens, ind = sampled_tokens.sort()
          sampled_probs = sampled_probs[ind]
  
      return sampled_tokens.unsqueeze(0), sampled_probs.unsqueeze(0)
  
imports: import cuda_ext
  from model import ExLlama, ExLlamaCache
  from lora import ExLlamaLora
  import torch
  import torch.nn.functional
label_desc: Use image node_id 6 for calling the ExLlamaGenerator obj's underlying member method code with example usage: obj.sample(logits, temperature, top_k, top_p, min_p, typical, num) and returns: sampled_tokens,  sampled_probs