class_docstr: Inference engine subclass to run inference with `translate.py`.
  
  Args:
      opt: inference options
class_docstr_tok: ["Inference","engine","subclass","to","run","inference","with","`","translate.py","`",".","Args",":","opt",":","inference","options"]
code: def __init__(self, opt):
      import torch
      from onmt.translate.translator import build_translator
  
      super().__init__(opt)
      self.opt = opt
      self.logger = init_logger(opt.log_file)
  
      if opt.world_size > 1:
          mp = torch.multiprocessing.get_context("spawn")
          # Create a thread to listen for errors in the child processes.
          self.error_queue = mp.SimpleQueue()
          self.error_handler = ErrorHandler(self.error_queue)
          self.queue_instruct = []
          self.queue_result = []
          self.procs = []
  
          for device_id in range(opt.world_size):
              self.queue_instruct.append(mp.Queue())
              self.queue_result.append(mp.Queue())
              self.procs.append(
                  mp.Process(
                      target=spawned_infer,
                      args=(
                          opt,
                          device_id,
                          self.error_queue,
                          self.queue_instruct[device_id],
                          self.queue_result[device_id],
                      ),
                      daemon=False,
                  )
              )
              self.procs[device_id].start()
              self.error_handler.add_child(self.procs[device_id].pid)
      else:
          self.device_id = opt.gpu
          self.translator = build_translator(
              opt, self.device_id, logger=self.logger, report_score=True
          )
          self.transforms_cls = get_transforms_cls(opt._all_transform)
          self.vocabs = self.translator.vocabs
  
imports: import json
  from onmt.constants import CorpusTask, DefaultTokens, ModelTask
  from onmt.inputters.dynamic_iterator import build_dynamic_dataset_iter
  from onmt.utils.distributed import ErrorHandler, spawned_infer
  from onmt.utils.logging import init_logger
  from onmt.transforms import get_transforms_cls, make_transforms, TransformPipe
label_desc: Use image node_id 1 to create a new InferenceEnginePY object from inherited base classes: InferenceEngine with example: obj = InferenceEnginePY(opt)