code: def _apply_top_p_top_k(
      logits: torch.Tensor,
      top_ps: List[float],
      top_ks: List[int],
  ) -> torch.Tensor:
      p = torch.tensor(top_ps, dtype=logits.dtype, device=logits.device)
      k = torch.tensor(top_ks, dtype=torch.int, device=logits.device)
      logits_sort, logits_idx = logits.sort(dim=-1, descending=True)
  
      # Apply top-p.
      probs_sort = logits_sort.softmax(dim=-1)
      probs_sum = probs_sort.cumsum(dim=-1)
      top_p_mask = (probs_sum - probs_sort) > p.unsqueeze(dim=1)
      logits_sort[top_p_mask] = -float("inf")
  
      # Apply top-k.
      # Create a mask for the top-k elements.
      top_k_mask = torch.arange(
          logits_idx.shape[-1], device=logits_idx.device
      )
      top_k_mask = top_k_mask.expand(logits_idx.shape[0], -1)
      top_k_mask = top_k_mask >= k.unsqueeze(dim=1)
      logits_sort[top_k_mask] = -float("inf")
  
      # Re-sort the probabilities.
      logits = torch.gather(
          logits_sort, dim=-1, index=torch.argsort(logits_idx, dim=-1)
      )
      return logits
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  from bigdl.llm.vllm.model_executor.input_metadata import InputMetadata
  from bigdl.llm.vllm.sampling_params import SamplingParams, SamplingType
  from bigdl.llm.vllm.sequence import SamplerOutput, SequenceGroupMetadata, SequenceData, SequenceOutputs
  import time
label_desc: Use image node_id 7 for calling a global function with example usage: _apply_top_p_top_k(logits, top_ps, top_ks) and returns: logits