class_docstr: ``TrainContext`` gives access to report training and validation metrics to the Determined master
  during trial tasks.
class_docstr_tok: ["``","TrainContext","``","gives","access","to","report","training","and","validation","metrics","to","the","Determined","master","during","trial","tasks","."]
code: def __init__(
      self,
      session: api.Session,
      trial_id: int,
      run_id: int,
      exp_id: int,
      distributed: core.DistributedContext,
      tensorboard_mode: core.TensorboardMode,
      tensorboard_manager: Optional[tensorboard.TensorboardManager],
      tbd_writer: Optional[tensorboard.BatchMetricWriter],
  ) -> None:
      self._session = session
      self._trial_id = trial_id
      self._run_id = run_id
      self._exp_id = exp_id
      self._distributed = distributed
      if (
          tensorboard_mode != core.TensorboardMode.MANUAL
          and tensorboard_manager is None
      ):
          raise ValueError(
              "either set TensorboardMode.MANUAL, or pass a tensorboard manager."
          )
      self._tensorboard_mode = tensorboard_mode
      self._tensorboard_manager = tensorboard_manager
      self._tbd_writer = tbd_writer
  
imports: import enum
  import logging
  import pathlib
  from typing import Any, Callable, Dict, List, Optional, Set
  import determined
  from determined import core, tensorboard
  from determined.common import api, util
  from determined.common.api import bindings, errors
label_desc: Use image node_id 1 to create a new TrainContext object  with example: obj = TrainContext(session, trial_id, run_id, exp_id, distributed, tensorboard_mode, tensorboard_manager, tbd_writer)