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.
      """
  
      self.manifest = ctx.manifest
      properties = ctx.system_properties
      model_dir = properties.get("model_dir")
  
      # settings for model compiliation and loading
      seed = ctx.model_yaml_config["handler"]["manual_seed"]
      tp_degree = ctx.model_yaml_config["handler"]["tp_degree"]
      amp = ctx.model_yaml_config["handler"]["amp"]
      model_name = ctx.model_yaml_config["handler"]["model_name"]
  
      # allocate "tp_degree" number of neuron cores to the worker process
      os.environ["NEURON_RT_NUM_CORES"] = str(tp_degree)
      try:
          num_neuron_cores_available = (
              torch_neuronx.xla_impl.data_parallel.device_count()
          )
          assert num_neuron_cores_available >= int(tp_degree)
      except (RuntimeError, AssertionError) as error:
          raise RuntimeError(
              "Required number of neuron cores for tp_degree "
              + str(tp_degree)
              + " are not available: "
              + str(error)
          )
  
      torch.manual_seed(seed)
      self.tokenizer = AutoTokenizer.from_pretrained(
          model_name, return_tensors="pt"
      )
      self.tokenizer.pad_token = self.tokenizer.eos_token
  
      logger.info("Starting to compile the model")
  
      self.batch_size = ctx.model_yaml_config["batchSize"]
      self.model = OPTForSampling.from_pretrained(
          model_dir,
          batch_size=self.batch_size,
          tp_degree=tp_degree,
          amp=amp,
      )
      self.model.to_neuron()
      logger.info("Model has been successfully compiled")
  
      self.max_length = ctx.model_yaml_config["handler"]["max_length"]
  
      self.initialized = True
  
file_path: serve/examples/large_models/inferentia2/opt/inf2_handler.py
imports: import logging
  import os
  from abc import ABC
  import torch
  import torch_neuronx
  import transformers
  from transformers import AutoTokenizer
  from transformers_neuronx.opt.model import OPTForSampling
  from ts.torch_handler.base_handler import BaseHandler
label_desc: Use image node_id 2 for calling the LLMHandler obj's underlying member method code with example usage: obj.initialize(ctx) without return types