class_docstr: Writes model logits to a file.
  
  The class is designed for use in an asynchronous process spawned by torch.multiprocessing.spawn, e.g.
    logits_writer = LogitsWriter(...)
    logits_writer_ctx = torch.multiprocessing.spawn(logits_writer.run, join=False)
    logits_writer_ctx.join()
class_docstr_tok: ["Writes","model","logits","to","a","file",".","The","class","is","designed","for","use","in","an","asynchronous","process","spawned","by","torch.multiprocessing.spawn",",","e.g",".","logits_writer","=","LogitsWriter","(","...",")","logits_writer_ctx","=","torch.multiprocessing.spawn","(","logits_writer.run",",","join=False",")","logits_writer_ctx.join","(",")"]
code: def run(self, process_index):
      open_options = self._get_open_options()
      with PathManager.open(self.output_path, **open_options) as fout:
          gzip_fout = (
              gzip.GzipFile(mode="wb", fileobj=fout)
              if self.use_gzip
              else None
          )
  
          while True:
              raw_input_tuple, model_outputs = self.results.get()
              if model_outputs is None:
                  # None means shutdown
                  break
  
              if self.ndigits_precision:
                  model_outputs = round_seq(
                      model_outputs, self.ndigits_precision
                  )
  
              # multi-encoder output
              if isinstance(model_outputs, tuple):
                  self._write(
                      fout,
                      gzip_fout,
                      zip(*raw_input_tuple, *model_outputs),
                  )
              # single encoder output
              elif isinstance(model_outputs, list):
                  self._write(
                      fout,
                      gzip_fout,
                      zip(*raw_input_tuple, model_outputs),
                  )
              else:
                  raise Exception(
                      "Expecting tuple or tensor types for model_outputs"
                  )
  
          if self.use_gzip:
              gzip_fout.close()
  
imports: import gzip
  import json
  import os
  import sys
  import traceback
  from typing import Any, Dict, get_type_hints, IO, Iterator, List, Optional, Tuple, Union
  import torch
  from pytext.common.constants import Stage
  from pytext.config import ExportConfig, PyTextConfig, TestConfig
  from pytext.config.component import ComponentType, create_component, create_exporter
  from pytext.data.data import Batcher
  from pytext.data.data_handler import CommonMetadata
  from pytext.metric_reporters.channel import Channel
  from pytext.task import create_task, get_latest_checkpoint_path, load, NewTask, save, Task_Deprecated
  from pytext.task.disjoint_multitask import NewDisjointMultitask
  from pytext.trainers import TrainingState
  from pytext.utils import cuda, distributed, precision, round_seq, set_random_seeds, timing
  from pytext.utils.file_io import PathManager
label_desc: Use image node_id 2 for calling the LogitsWriter obj's underlying member method code with example usage: obj.run(process_index) without return types