class_docstr: Parallelformers end-point function
  
  Args:
      model (nn.Module): Huggingface pre-trained transformer model.
      fp16: (bool): whether use FP16 or not.
      num_gpus (int): number of GPU for parallelization.
      master_addr (str): master process address for process communication (default='127.0.0.1')
      master_port (int): master process port for process communication (default=29500)
      backend (str): distributed backend (default='nccl')
      verbose (str): logging current gpu states (one of ['detail', 'simple', None]
      init_method (str): multiprocess initialization method. (It is safe to set `init_method` to `spawn`.)
      daemon (bool): whether make process daemon or not (default=True)
  
  Notes:
      We want to use this object as a simple function rather than a class.
      So we broke the PEP8 rules and set class names that start with a lowercase letter.
  
  Examples:
      >>> # 1. Import Huggingface and Parallelformers modules
      >>> from transformers import AutoModelForCausalLM, AutoTokenizer
      >>> from parallelformers import parallelize
  
      >>> # 2. Create Huggingface model and tokenizer.
      >>> model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-2.7B")
      >>> tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
  
      >>> # 3. Parallelize using Parallelformers.
      >>> parallelize(model, num_gpus=4, fp16=True)
  
      >>> # 4. Do inference as usual.
      >>> inputs = tokenizer("Parallelformers is", return_tensors="pt")
      >>> outputs = model.generate(**inputs, num_beams=5, no_repeat_ngram_size=4)
      >>> print(f"Output: {tokenizer.batch_decode(outputs)[0]}")
      'Output: Parallelformers is an open-source library for parallel programming ...'
docstr: Transfers the input passed to the main process to another process,
  and transfers the output to the main process and outputs it to the user.
  
  Args:
      inputs (Any): inputs of model
      kwargs (Dict): arguments of model
      func (str): name of method that hijacked
  
  Returns:
      Any: outputs of model
docstr_tok: ["Transfers","the","input","passed","to","the","main","process","to","another","process",",","and","transfers","the","output","to","the","main","process","and","outputs","it","to","the","user",".","Args",":","inputs","(","Any",")",":","inputs","of","model","kwargs","(","Dict",")",":","arguments","of","model","func","(","str",")",":","name","of","method","that","hijacked","Returns",":","Any",":","outputs","of","model"]
code: def hijack(
      self,
      inputs: Any,
      kwargs: Dict,
      func: str,
  ) -> Any:
      """
      Transfers the input passed to the main process to another process,
      and transfers the output to the main process and outputs it to the user.
  
      Args:
          inputs (Any): inputs of model
          kwargs (Dict): arguments of model
          func (str): name of method that hijacked
  
      Returns:
          Any: outputs of model
      """
      try:
          for i_mutex, i_queue in zip(
              self.inference_mutexes,
              self.inputs_queues,
          ):
              inputs = self._deallocate(inputs)
  
              for k in kwargs:
                  kwargs[k] = self._deallocate(kwargs[k])
  
              i_queue.put((inputs, kwargs, func))
              i_mutex.set()
              # producer part
  
          if func in ["to", "cpu", "cuda"]:
              self.deparallelize()
  
              if func == "cpu":
                  self.model = self.model.cpu(*inputs, **kwargs)
              elif func == "cuda":
                  self.model = self.model.cuda(*inputs, **kwargs)
              else:
                  self.model = self.model.to(*inputs, **kwargs)
  
              return self.model
          else:
              outputs = []
              for o_queue in self.outputs_queues:
                  output = o_queue.get()
                  outputs.append(output)
                  # consumer part
  
              if func in self._memory_logger:
                  final_output = dict(outputs)
              else:
                  final_output = outputs[0]
  
              # non-picklable object to original dataclass
              if (
                  isinstance(final_output, dict)
                  and "orig_dataclass_type" in final_output
              ):
                  orig_dataclass_type = final_output[
                      "orig_dataclass_type"
                  ]
                  del final_output["orig_dataclass_type"]
  
                  final_output = from_dict(
                      orig_dataclass_type,
                      final_output,
                      config=Config(check_types=False),
                  )
  
              return final_output
  
      except BaseException:
          traceback.print_exc()
          self.deparallelize()
  
imports: import os
  import traceback
  from contextlib import suppress
  from dataclasses import _is_dataclass_instance
  from typing import Any, Dict
  import torch
  import torch.multiprocessing
  from dacite import Config, from_dict
  from torch import nn
  from transformers.file_utils import ModelOutput
  from parallelformers.parallel.process import ParallelProcess
  from parallelformers.utils import rgetattr, rsetattr
label_desc: Use image node_id 9 for calling the parallelize obj's underlying member method code with example usage: obj.hijack(inputs, kwargs, func) and returns: self, final_output