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","."]
code: def _create_stopping_criteria(self, req_id, max_new_tokens=25):
      class StoppingCriteria(object):
          def __init__(
              self,
              cache,
              req_id,
              stop_token,
              max_new_tokens,
          ):
              self.req_id = req_id
              self.cache = cache
              self.max_new_tokens = max_new_tokens
              self.stop_token = stop_token
  
          def __call__(self, res):
              self.max_new_tokens -= 1
  
              if (
                  self.max_new_tokens == 0
                  or res["ids"][-1] == self.stop_token
              ):
                  self.clean_up()
                  return True
              return False
  
          def clean_up(self):
              del self.cache[self.req_id]
  
      return StoppingCriteria(
          self.context.cache,
          req_id,
          self.tokenizer.eos_id,
          max_new_tokens,
      )
  
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 16 for calling the LlamaHandler obj's underlying member method code with example usage: obj._create_stopping_criteria(req_id, max_new_tokens) and returns: StoppingCriteria, False, True