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 HF large model is loaded and
  partitioned into multiple stages each on one device using PiPPy.
  Args:
      ctx (context): It is a JSON Object containing information
      pertaining to the model artifacts parameters.
docstr_tok: ["In","this","initialize","function",",","the","HF","large","model","is","loaded","and","partitioned","into","multiple","stages","each","on","one","device","using","PiPPy",".","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 HF large model is loaded and
      partitioned into multiple stages each on one device using PiPPy.
      Args:
          ctx (context): It is a JSON Object containing information
          pertaining to the model artifacts parameters.
      """
      super().initialize(ctx)
      self.manifest = ctx.manifest
      properties = ctx.system_properties
      model_dir = properties.get("model_dir")
      self.device = self.local_rank
  
      model_path = ctx.model_yaml_config["handler"]["model_path"]
      seed = ctx.model_yaml_config["handler"]["manual_seed"]
      dtype_str = ctx.model_yaml_config["handler"]["dtype"]
      torch.manual_seed(seed)
  
      dtypes = {
          "fp32": torch.float32,
          "fp16": torch.float16,
          "bf16": torch.bfloat16,
      }
  
      dtype = dtypes.get(dtype_str, torch.float32)
      if dtype != torch.float32 and dtype_str not in dtypes:
          logger.info(
              f"Unsupported data type {dtype_str}, "
              "please submit a PR to support it. Falling back to fp32 now."
          )
  
      skip_init_start = time.perf_counter()
      with torch.device("meta"):
          self.model = AutoModelForCausalLM.from_pretrained(
              model_path, use_cache=False, torch_dtype=dtype
          )
      skip_init_end = time.perf_counter()
      logger.info(
          f" init model time on meta device took {skip_init_end - skip_init_start} seconds"
      )
      self.tokenizer = AutoTokenizer.from_pretrained(
          model_path, return_tensors="pt"
      )
      self.tokenizer.pad_token = self.tokenizer.eos_token
  
      self.max_length = ctx.model_yaml_config["handler"]["max_length"]
      self.max_new_tokens = ctx.model_yaml_config["handler"][
          "max_new_tokens"
      ]
  
      logger.info("Instantiating model Pipeline")
      pippy_compile_time_start = time.perf_counter()
      self.model = get_pipeline_driver(self.model, self.world_size, ctx)
      pippy_compile_time_end = time.perf_counter()
  
      logger.info(
          f" pippy compile time took {pippy_compile_time_end- pippy_compile_time_start} seconds on rank {self.local_rank}"
      )
  
      logger.info(
          "Transformer model from path %s loaded successfully",
          model_dir,
      )
  
      self.initialized = True
  
file_path: serve/examples/large_models/Huggingface_pippy/pippy_handler.py
imports: import logging
  import time
  from abc import ABC
  import packaging.version
  import requests
  import torch
  import transformers
  from transformers import AutoModelForCausalLM, AutoTokenizer
  from ts.handler_utils.distributed.pt_pippy import get_pipeline_driver
  from ts.torch_handler.distributed.base_pippy_handler import BasePippyHandler
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