class_docstr: Transformers handler class for sequence, token classification and question answering.
class_docstr_tok: ["Transformers","handler","class","for","sequence",",","token","classification","and","question","answering","."]
docstr: Basic text preprocessing, based on the user's choice of application mode.
  Args:
      requests (list): A list of dictionaries with a "data" or "body" field, each
                      containing the input text to be processed.
  Returns:
      tuple: A tuple with two tensors: the batch of input ids and the batch of
          attention masks.
docstr_tok: ["Basic","text","preprocessing",",","based","on","the","user","'s","choice","of","application","mode",".","Args",":","requests","(","list",")",":","A","list","of","dictionaries","with","a","``","data","''","or","``","body","''","field",",","each","containing","the","input","text","to","be","processed",".","Returns",":","tuple",":","A","tuple","with","two","tensors",":","the","batch","of","input","ids","and","the","batch","of","attention","masks","."]
code: def preprocess(self, requests):
      """
      Basic text preprocessing, based on the user's choice of application mode.
      Args:
          requests (list): A list of dictionaries with a "data" or "body" field, each
                          containing the input text to be processed.
      Returns:
          tuple: A tuple with two tensors: the batch of input ids and the batch of
              attention masks.
      """
      self._clean_cache()
      prefill, decode = [], []
  
      for req_id, req_data in zip(
          self.context.request_ids.values(), requests
      ):
          # Tokenizer requests which are not prefilled yet
          if not req_id in self.context.cache:
              data = req_data.get("data") or req_data.get("body")
              input_data = self._prepare_input_data(data)
  
              self.context.cache[req_id] = {
                  "stopping_criteria": self._create_stopping_criteria(
                      req_id,
                      max_new_tokens=min(
                          self.max_new_tokens,
                          input_data.get(
                              "max_new_tokens", self.max_new_tokens
                          ),
                      ),
                  ),
                  "encoded": input_data["encoded"],
                  "prompt_length": input_data["encoded"].size(-1),
                  "text": input_data["prompt"],
              }
              prefill.append(req_id)
          else:
              decode.append(req_id)
      return prefill, decode
  
imports: import json
  import logging
  import os
  import sys
  import time
  from abc import ABC
  from typing import List
  import packaging.version
  import requests
  import torch
  import transformers
  from ts.torch_handler.base_handler import BaseHandler
  from generate import sample_top_p
  from llama2 import Llama
label_desc: Use image node_id 3 for calling the LlamaHandler obj's underlying member method code with example usage: obj.preprocess(requests) and returns: prefill,  decode