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 using DeepSpeed.
  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","using","DeepSpeed",".","Args",":","ctx","(","context",")",":","It","is","a","JSON","Object","containing","information","pertaining","to","the","model","artifacts","parameters","."]
code: def initialize(self, ctx: Context):
      """In this initialize function, the HF large model is loaded and
      partitioned using DeepSpeed.
      Args:
          ctx (context): It is a JSON Object containing information
          pertaining to the model artifacts parameters.
      """
      super().initialize(ctx)
      model_dir = ctx.system_properties.get("model_dir")
      self.max_length = int(
          ctx.model_yaml_config["handler"]["max_length"]
      )
      self.max_new_tokens = int(
          ctx.model_yaml_config["handler"]["max_new_tokens"]
      )
      model_name = ctx.model_yaml_config["handler"]["model_name"]
      model_path = ctx.model_yaml_config["handler"]["model_path"]
      seed = int(ctx.model_yaml_config["handler"]["manual_seed"])
      torch.manual_seed(seed)
  
      logger.info("Model %s loading tokenizer", ctx.model_name)
  
      self.tokenizer = AutoTokenizer.from_pretrained(model_name)
      self.tokenizer.pad_token = self.tokenizer.eos_token
      config = AutoConfig.from_pretrained(model_name)
      with torch.device("meta"):
          self.model = AutoModelForCausalLM.from_config(
              config, torch_dtype=torch.float16
          )
      self.model = self.model.eval()
  
      ds_engine = get_ds_engine(self.model, ctx)
      self.model = ds_engine.module
      logger.info("Model %s loaded successfully", ctx.model_name)
      self.initialized = True
  
file_path: serve/examples/large_models/deepspeed/custom_handler.py
imports: import logging
  from abc import ABC
  import torch
  import transformers
  from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
  from ts.context import Context
  from ts.handler_utils.distributed.deepspeed import get_ds_engine
  from ts.torch_handler.distributed.base_deepspeed_handler import BaseDeepSpeedHandler
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