class_docstr: ## Evaluation Harness Adapter
  
  This is based on the [adapter from EleutherAI/gpt-neox](https://github.com/EleutherAI/gpt-neox/blob/main/eval_tasks/eval_adapter.py)
docstr: ### Get log-likelihoods of the next tokens
  
  :param requests: List of requests containing the context and the expected continuation.
  :param disable_tqdm: If True, disable tqdm progress bar.
docstr_tok: ["#","#","#","Get","log-likelihoods","of","the","next","tokens",":","param","requests",":","List","of","requests","containing","the","context","and","the","expected","continuation",".",":","param","disable_tqdm",":","If","True",",","disable","tqdm","progress","bar","."]
code: def _loglikelihood_tokens(self, requests, disable_tqdm=False):
      """
      ### Get log-likelihoods of the next tokens
  
      :param requests: List of requests containing the context and the expected continuation.
      :param disable_tqdm: If True, disable tqdm progress bar.
      """
  
      # For results
      res = []
  
      # Reorder the requests in the descending order of the lengths,
      # so that sequences with similar lengths are close
      def _collate(x):
          toks = x[1] + x[2]
          return -len(toks), tuple(toks)
  
      reord = utils.Reorderer(requests, _collate)
  
      # Loop through requests with `batch_size` number of requests at a time
      for chunk in utils.chunks(
          tqdm(reord.get_reordered(), disable=disable_tqdm),
          self.batch_size,
      ):
          # To store the inputs for the batch
          inps = []
          # The continuations for the batch
          continuations = []
          # Lengths of the input sequences
          inplens = []
          # Padded length for the batch
          padded_length = None
          # Loop through each request in the chunk and collect them into PyTorch tensors with paddings
          for _, context_enc, continuation_enc in chunk:
              # Concatenate the context and continuation
              inp = context_enc + continuation_enc
              # Truncate from left if the size exceeds the `max_length`
              inp = inp[-(self.max_length + 1) :]
              # Remove final token
              inp = inp[:-1]
              # Create a tensor
              inp = torch.tensor(inp, dtype=torch.long)
              # Input length
              inplen = inp.shape[0]
  
              # Determine the padded length.
              # Shorter sequences will get padded.
              if padded_length is None:
                  padded_length = int(math.ceil(inplen / 32)) * 32
              # padded_length = padded_length if padded_length is not None else inplen
  
              # Padding
              padding = torch.zeros(
                  padded_length - inplen, dtype=torch.long
              )
  
              # Add padding
              inp = torch.cat([inp, padding], dim=0)
  
              inps.append(inp)
              continuations.append(continuation_enc)
              inplens.append(inplen)
  
          # Get model logits
          logits = self._model_call(torch.stack(inps))
  
          # Get log softmaxes
          multi_logits = F.log_softmax(logits, dim=-1)
  
          # Loop through the input/output pairs of the batch
          for logits, inplen, cont_toks in zip(
              multi_logits, inplens, continuations
          ):
              # Get number of predicted tokens
              contlen = len(cont_toks)
              # Get logits of those
              logits = logits[inplen - contlen : inplen]
              # Get the tokens with the highest probabilities
              greedy_tokens = logits.argmax(dim=-1)
              # Get the target tokens
              cont_toks = torch.tensor(cont_toks, dtype=torch.long).to(
                  logits.device
              )
              # Whether there's an exact match
              max_equal = (greedy_tokens == cont_toks).all()
              # Log-likelihoods of the target tokens
              logits = torch.gather(logits, 1, cont_toks[:, None])
              # Add the total log-likelihoods and whether there was a match to the results
              res.append((float(logits.sum()), bool(max_equal)))
  
      # Re-order and return results
      return reord.get_original(res)
  
imports: import math
  from typing import List
  import torch
  import torch.nn.functional
  from lm_eval import tasks, evaluator, utils
  from lm_eval.base import BaseLM
  from tokenizers import Tokenizer
  from torch import nn
  from tqdm import tqdm
  from labml import monit
  from labml_nn.neox.tokenizer import get_tokenizer
label_desc: Use image node_id 13 for calling the EvalHarnessAdapter obj's underlying member method code with example usage: obj._loglikelihood_tokens(requests, disable_tqdm) and returns: reord, unknown,  tuple