class_docstr: Inference engine subclass to run inference with ctranslate2.
  
  Args:
      opt: inference options
class_docstr_tok: ["Inference","engine","subclass","to","run","inference","with","ctranslate2",".","Args",":","opt",":","inference","options"]
code: def __init__(self, opt):
      import ctranslate2
      import pyonmttok
  
      super().__init__(opt)
      self.opt = opt
      self.logger = init_logger(opt.log_file)
      assert self.opt.world_size <= 1, "World size must be less than 1."
      self.device_id = opt.gpu
      if opt.world_size == 1:
          self.device_index = opt.gpu_ranks
          self.device = "cuda"
      else:
          self.device_index = 0
          self.device = "cpu"
      self.transforms_cls = get_transforms_cls(self.opt._all_transform)
      # Build translator
      if opt.model_task == ModelTask.LANGUAGE_MODEL:
          self.translator = ctranslate2.Generator(
              opt.models[0],
              device=self.device,
              device_index=self.device_index,
          )
      else:
          self.translator = ctranslate2.Translator(
              self.opt.models[0],
              device=self.device,
              device_index=self.device_index,
          )
      # Build vocab
      vocab_path = opt.src_subword_vocab
      with open(vocab_path, "r") as f:
          vocab = json.load(f)
      vocabs = {}
      src_vocab = pyonmttok.build_vocab_from_tokens(vocab)
      vocabs["src"] = src_vocab
      vocabs["tgt"] = src_vocab
      vocabs["data_task"] = "lm"
      vocabs["decoder_start_token"] = "<s>"
      self.vocabs = vocabs
      # Build transform pipe
      transforms = make_transforms(
          opt, self.transforms_cls, self.vocabs
      )
      self.transform = TransformPipe.build_from(transforms.values())
  
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 InferenceEngineCT2 object from inherited base classes: InferenceEngine with example: obj = InferenceEngineCT2(opt)