class_docstr: Contains runtime information for any Determined workflow that uses the ``PyTorch`` API.
  
  With this class, users can do the following things:
  
  1. Wrap PyTorch models, optimizers, and LR schedulers with their Determined-compatible
     counterparts using :meth:`wrap_model`, :meth:`wrap_optimizer`, :meth:`wrap_lr_scheduler`,
     respectively. The Determined-compatible objects are capable of transparent
     distributed training, checkpointing and exporting, mixed-precision training,
     and gradient aggregation.
  2. Configure apex amp by calling :meth:`configure_apex_amp` (optional).
  3. Calculate the gradients with :meth:`backward` on a specified loss.
  4. Run an optimization step with :meth:`step_optimizer`.
  5. Functionalities inherited from :class:`determined.TrialContext`, including getting
     the runtime information and properly handling training data in distributed training.
class_docstr_tok: ["Contains","runtime","information","for","any","Determined","workflow","that","uses","the","``","PyTorch","``","API",".","With","this","class",",","users","can","do","the","following","things",":","1",".","Wrap","PyTorch","models",",","optimizers",",","and","LR","schedulers","with","their","Determined-compatible","counterparts","using",":","meth",":","`","wrap_model","`",",",":","meth",":","`","wrap_optimizer","`",",",":","meth",":","`","wrap_lr_scheduler","`",",","respectively",".","The","Determined-compatible","objects","are","capable","of","transparent","distributed","training",",","checkpointing","and","exporting",",","mixed-precision","training",",","and","gradient","aggregation",".","2",".","Configure","apex","amp","by","calling",":","meth",":","`","configure_apex_amp","`","(","optional",")",".","3",".","Calculate","the","gradients","with",":","meth",":","`","backward","`","on","a","specified","loss",".","4",".","Run","an","optimization","step","with",":","meth",":","`","step_optimizer","`",".","5",".","Functionalities","inherited","from",":","class",":","`","determined.TrialContext","`",",","including","getting","the","runtime","information","and","properly","handling","training","data","in","distributed","training","."]
docstr: This function returns an instance of ``torch.utils.tensorboard.SummaryWriter``
  
  Trials users who wish to log to TensorBoard can use this writer object.
  We provide and manage a writer in order to save and upload TensorBoard
  files automatically on behalf of the user.
  
  Usage example:
  
  .. code-block:: python
  
     class MyModel(PyTorchTrial):
         def __init__(self, context):
             ...
             self.writer = context.get_tensorboard_writer()
  
         def train_batch(self, batch, epoch_idx, batch_idx):
             self.writer.add_scalar('my_metric', np.random.random(), batch_idx)
             self.writer.add_image('my_image', torch.ones((3,32,32)), batch_idx)
code: def get_tensorboard_writer(self) -> Any:
      """
      This function returns an instance of ``torch.utils.tensorboard.SummaryWriter``
  
      Trials users who wish to log to TensorBoard can use this writer object.
      We provide and manage a writer in order to save and upload TensorBoard
      files automatically on behalf of the user.
  
      Usage example:
  
      .. code-block:: python
  
         class MyModel(PyTorchTrial):
             def __init__(self, context):
                 ...
                 self.writer = context.get_tensorboard_writer()
  
             def train_batch(self, batch, epoch_idx, batch_idx):
                 self.writer.add_scalar('my_metric', np.random.random(), batch_idx)
                 self.writer.add_image('my_image', torch.ones((3,32,32)), batch_idx)
      """
  
      if self._tbd_writer is None:
          # As of torch v1.9.0, torch.utils.tensorboard has a bug that is exposed by setuptools
          # 59.6.0.  The bug is that it attempts to import distutils then access distutils.version
          # without actually importing distutils.version.  We can workaround this by prepopulating
          # the distutils.version submodule in the distutils module.
          #
          # Except, starting with python 3.12 distutils isn't available at all.
          try:
              import distutils.version  # noqa: F401
          except ImportError:
              pass
  
          from torch.utils.tensorboard import SummaryWriter
  
          self._tbd_writer = SummaryWriter(self.get_tensorboard_path())  # type: ignore
  
      return self._tbd_writer
  
imports: import contextlib
  import logging
  import pathlib
  import warnings
  from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union
  import torch
  from torch import nn
  import determined
  from determined import profiler, pytorch, util
  from determined.horovod import hvd
label_desc: Use image node_id 41 for calling the PyTorchTrialContext obj's underlying member method code with example usage: obj.get_tensorboard_writer() and returns: self