class_docstr: TorchWriter uses PyTorch file writers and summary operations to write
  out tfevent files containing scalar batch metrics. It creates
  an instance of ``torch.utils.tensorboard.SummaryWriter`` which can be
  accessed via the ``writer`` field and configures the SummaryWriter
  to write to the correct directory inside the trial container.
  
  Usage example:
  
   .. code-block:: python
  
      from determined.tensorboard.metric_writers.pytorch import TorchWriter
  
      class MyModel(PyTorchTrial):
          def __init__(self, context):
              ...
              self.logger = TorchWriter()
  
          def train_batch(self, batch, epoch_idx, batch_idx):
              self.logger.writer.add_scalar('my_metric', np.random.random(), batch_idx)
  
  .. warning::
  
      TorchWriter() has been deprecated and will be removed in a future version.
  
      Users are encouraged to switch to one of the following depending on use case:
          - Trials Users, see ``determined.pytorch.PyTorchTrialContext.get_tensorboard_writer()``
          - CoreAPI Users, create a ``torch.utils.tensorboard.SummaryWriter()`` object
            and pass ``core_context.train.get_tensorboard_path()`` as the log_dir
class_docstr_tok: ["TorchWriter","uses","PyTorch","file","writers","and","summary","operations","to","write","out","tfevent","files","containing","scalar","batch","metrics",".","It","creates","an","instance","of","``","torch.utils.tensorboard.SummaryWriter","``","which","can","be","accessed","via","the","``","writer","``","field","and","configures","the","SummaryWriter","to","write","to","the","correct","directory","inside","the","trial","container",".","Usage","example",":","..","code-block",":",":","python","from","determined.tensorboard.metric_writers.pytorch","import","TorchWriter","class","MyModel","(","PyTorchTrial",")",":","def","__init__","(","self",",","context",")",":","...","self.logger","=","TorchWriter","(",")","def","train_batch","(","self",",","batch",",","epoch_idx",",","batch_idx",")",":","self.logger.writer.add_scalar","(","'my_metric","'",",","np.random.random","(",")",",","batch_idx",")","..","warning",":",":","TorchWriter","(",")","has","been","deprecated","and","will","be","removed","in","a","future","version",".","Users","are","encouraged","to","switch","to","one","of","the","following","depending","on","use","case",":","-","Trials","Users",",","see","``","determined.pytorch.PyTorchTrialContext.get_tensorboard_writer","(",")","``","-","CoreAPI","Users",",","create","a","``","torch.utils.tensorboard.SummaryWriter","(",")","``","object","and","pass","``","core_context.train.get_tensorboard_path","(",")","``","as","the","log_dir"]
code: def __init__(self) -> None:
      warnings.warn(
          "TorchWriter() has been deprecated and will be removed in a future version.\n \
              Users are encouraged to switch to one of the following depending on use case:\n \
              - Trials Users, see determined.pytorch.PyTorchTrialContext.get_tensorboard_writer()\n \
              - CoreAPI Users, create a torch.utils.tensorboard.SummaryWriter() object\n \
                and pass core_context.train.get_tensorboard_path() as the log_dir",
          FutureWarning,
          stacklevel=2,
      )
      super().__init__()
  
file_path: determined/harness/determined/tensorboard/metric_writers/pytorch.py
imports: import warnings
  from typing import Any, Union
  import numpy
  import torch
  from packaging import version
  from determined import tensorboard
  from torch.utils.tensorboard import SummaryWriter
label_desc: Use image node_id 1 to create a new TorchWriter object from inherited base classes: _TorchWriter with example: obj = TorchWriter()