code: def _get_topk_logprobs(
      logprobs: torch.Tensor,
      num_logprobs: Optional[int],
  ) -> List[Dict[int, float]]:
      num_seqs = logprobs.size(0)
      if num_logprobs is None or num_logprobs == 0:
          return [{} for _ in range(num_seqs)]
  
      all_topk_logprobs, all_topk_ids = torch.topk(
          logprobs, num_logprobs, dim=-1
      )
      all_topk_logprobs = all_topk_logprobs.cpu()
      all_topk_ids = all_topk_ids.cpu()
      all_token_to_logprob = []
      for topk_logprobs, topk_ids in zip(
          all_topk_logprobs, all_topk_ids
      ):
          token_to_logprob: Dict[int, float] = {}
          for token_id, logprob in zip(topk_ids, topk_logprobs):
              token_to_logprob[token_id.item()] = logprob.item()
          all_token_to_logprob.append(token_to_logprob)
      return all_token_to_logprob
  
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 8 for calling a global function with example usage: _get_topk_logprobs(logprobs, num_logprobs) and returns: all_token_to_logprob, unknown