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: In this initialize function, the BERT model is loaded and
  the Layer Integrated Gradients Algorithm for Captum Explanations
  is initialized here.
  Args:
      ctx (context): It is a JSON Object containing information
      pertaining to the model artifacts parameters.
docstr_tok: ["In","this","initialize","function",",","the","BERT","model","is","loaded","and","the","Layer","Integrated","Gradients","Algorithm","for","Captum","Explanations","is","initialized","here",".","Args",":","ctx","(","context",")",":","It","is","a","JSON","Object","containing","information","pertaining","to","the","model","artifacts","parameters","."]
code: def initialize(self, ctx):
      """In this initialize function, the BERT model is loaded and
      the Layer Integrated Gradients Algorithm for Captum Explanations
      is initialized here.
      Args:
          ctx (context): It is a JSON Object containing information
          pertaining to the model artifacts parameters.
      """
      self.manifest = ctx.manifest
      properties = ctx.system_properties
      model_dir = properties.get("model_dir")
  
      self.device = torch.device(
          "cuda:" + str(properties.get("gpu_id"))
          if torch.cuda.is_available()
          and properties.get("gpu_id") is not None
          else "cpu"
      )
      # Loading the model and tokenizer from checkpoint and config files based on the user's choice of mode
      # further setup config can be added.
      with zipfile.ZipFile(model_dir + "/model.zip", "r") as zip_ref:
          zip_ref.extractall(model_dir + "/model")
  
      # read configs for the mode, model_name, etc. from setup_config.json
      setup_config_path = os.path.join(model_dir, "setup_config.json")
      if os.path.isfile(setup_config_path):
          with open(setup_config_path) as setup_config_file:
              self.setup_config = json.load(setup_config_file)
      else:
          logger.warning("Missing the setup_config.json file.")
  
      self.model = BloomForCausalLM.from_pretrained(
          model_dir + "/model",
          revision=self.setup_config["revision"],
          max_memory={
              int(key) if key.isnumeric() else key: value
              for key, value in self.setup_config["max_memory"].items()
          },
          low_cpu_mem_usage=self.setup_config["low_cpu_mem_usage"],
          device_map=self.setup_config["device_map"],
          offload_folder=self.setup_config["offload_folder"],
          offload_state_dict=self.setup_config["offload_state_dict"],
          torch_dtype=TORCH_DTYPES[self.setup_config["torch_dtype"]],
      )
  
      self.tokenizer = BloomTokenizerFast.from_pretrained(
          model_dir + "/model", return_tensors="pt"
      )
  
      self.model.eval()
      logger.info(
          "Transformer model from path %s loaded successfully",
          model_dir,
      )
  
      self.initialized = True
  
file_path: serve/examples/large_models/Huggingface_accelerate/custom_handler.py
imports: import json
  import logging
  import os
  import zipfile
  from abc import ABC
  import torch
  import transformers
  from transformers import BloomForCausalLM, BloomTokenizerFast
  from ts.torch_handler.base_handler import BaseHandler
label_desc: Use image node_id 2 for calling the TransformersSeqClassifierHandler obj's underlying member method code with example usage: obj.initialize(ctx) without return types