class_docstr: Parallelization process class
  
  Args:
      model (nn.Module): model weights
      fp16: (bool): whether use FP16 or not.
      rank (int): current GPU rank
      num_gpus (int): number of gpus for parallelization
      inputs_queue (mp.Queue): input data queue from user
      outputs_queue (mp.Queue): output data queue from model
      parallel_mutex (mp.Event): mutex object to notify parallelization state
      inference_mutex (mp.Event): mutex object to notify inference state
      verbose (str): turn on gpu summary
      backend (str): distributed process backend
      custom_policies (Union[Policy, List[Policy]]): user customized policy objects
  
  Notes:
      ParallelProcess object handles below two tasks.
  
      1) Parallelize the model
      2) Handle the inference state
class_docstr_tok: ["Parallelization","process","class","Args",":","model","(","nn.Module",")",":","model","weights","fp16",":","(","bool",")",":","whether","use","FP16","or","not",".","rank","(","int",")",":","current","GPU","rank","num_gpus","(","int",")",":","number","of","gpus","for","parallelization","inputs_queue","(","mp.Queue",")",":","input","data","queue","from","user","outputs_queue","(","mp.Queue",")",":","output","data","queue","from","model","parallel_mutex","(","mp.Event",")",":","mutex","object","to","notify","parallelization","state","inference_mutex","(","mp.Event",")",":","mutex","object","to","notify","inference","state","verbose","(","str",")",":","turn","on","gpu","summary","backend","(","str",")",":","distributed","process","backend","custom_policies","(","Union","[","Policy",",","List","[","Policy","]","]",")",":","user","customized","policy","objects","Notes",":","ParallelProcess","object","handles","below","two","tasks",".","1",")","Parallelize","the","model","2",")","Handle","the","inference","state"]
docstr: Handle inference state.
  If an inference request is occurred from main process,
  Infer the model and pass the output to main process.
  
  Args:
      model (nn.Module): model weight
docstr_tok: ["Handle","inference","state",".","If","an","inference","request","is","occurred","from","main","process",",","Infer","the","model","and","pass","the","output","to","main","process",".","Args",":","model","(","nn.Module",")",":","model","weight"]
code: def inference(self, model: nn.Module) -> None:
      """
      Handle inference state.
      If an inference request is occurred from main process,
      Infer the model and pass the output to main process.
  
      Args:
          model (nn.Module): model weight
      """
      if self.seed is None:
          seed = torch.tensor(int(time())).cuda()
          dist.broadcast(seed, src=0)
          seed = seed.item()
      else:
          seed = self.seed
  
      torch.manual_seed(seed)
      np.random.seed(seed)
      random.seed(seed)
  
      with suppress():
          torch.backends.cudnn.deterministic = True
          torch.backends.cudnn.benchmark = False
  
      while True:
          try:
              self.inference_mutex.wait()
              self.inference_mutex.clear()
              device = torch.cuda.current_device()
  
              # consumer part
              inputs, kwargs, fn_name = self.inputs_queue.get()
              inputs_, kwargs_ = [], {}
  
              for i in inputs:
                  if torch.is_tensor(i):
                      i = i.clone().to(device)
                  inputs_.append(i)
  
              for k in kwargs:
                  if torch.is_tensor(kwargs[k]):
                      kwargs[k] = kwargs[k].clone().to(device)
                  kwargs_[k] = kwargs[k]
  
              if fn_name not in self._memory_logger:
                  function_ = getattr(model, fn_name)
                  n_params = len(signature(function_).parameters)
  
                  if n_params > 0:
                      outputs = function_(
                          *inputs_,
                          **kwargs_,
                      )
                  else:
                      outputs = function_()
              else:
                  outputs = (
                      f"cuda:{device}",
                      str(self._memory_logger[fn_name](device)),
                  )
  
              if fn_name in ["cuda", "cpu", "to"]:
                  break
  
              # check picklable
              outputs = self.check_picklable(outputs)
  
              if isinstance(outputs, types.GeneratorType):
                  outputs = list(outputs)
  
              # producer part
              self.outputs_queue.put(outputs)
  
          except BaseException:
              traceback.print_exc()
              break
  
imports: import copyreg
  import io
  import os
  import pickle
  import random
  import traceback
  import types
  from contextlib import suppress
  from dataclasses import _is_dataclass_instance, asdict
  from inspect import signature
  from time import time
  from typing import Any, List, Union
  import numpy
  import torch
  import torch.distributed
  import torch.multiprocessing
  import torch.nn
  from transformers.file_utils import ModelOutput
  from parallelformers.parallel.engine import ParallelEngine
  from parallelformers.policies.base import Policy
label_desc: Use image node_id 4 for calling the ParallelProcess obj's underlying member method code with example usage: obj.inference(model) without return types