class_docstr: TensorBoard handler to log metrics, model/optimizer parameters, gradients during the training and validation.
  
  By default, this class favors `tensorboardX <https://github.com/lanpa/tensorboardX>`_ package if installed:
  
  .. code-block:: bash
  
      pip install tensorboardX
  
  otherwise, it falls back to using
  `PyTorch's SummaryWriter
  <https://pytorch.org/docs/stable/tensorboard.html>`_
  (>=v1.2.0).
  
  Args:
      args: Positional arguments accepted from
          `SummaryWriter
          <https://pytorch.org/docs/stable/tensorboard.html>`_.
      kwargs: Keyword arguments accepted from
          `SummaryWriter
          <https://pytorch.org/docs/stable/tensorboard.html>`_.
          For example, `log_dir` to setup path to the directory where to log.
  
  Examples:
      .. code-block:: python
  
          from ignite.contrib.handlers.tensorboard_logger import *
  
          # Create a logger
          tb_logger = TensorboardLogger(log_dir="experiments/tb_logs")
  
          # Attach the logger to the trainer to log training loss at each iteration
          tb_logger.attach_output_handler(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              tag="training",
              output_transform=lambda loss: {"loss": loss}
          )
  
          # Attach the logger to the evaluator on the training dataset and log NLL, Accuracy metrics after each epoch
          # We setup `global_step_transform=global_step_from_engine(trainer)` to take the epoch
          # of the `trainer` instead of `train_evaluator`.
          tb_logger.attach_output_handler(
              train_evaluator,
              event_name=Events.EPOCH_COMPLETED,
              tag="training",
              metric_names=["nll", "accuracy"],
              global_step_transform=global_step_from_engine(trainer),
          )
  
          # Attach the logger to the evaluator on the validation dataset and log NLL, Accuracy metrics after
          # each epoch. We setup `global_step_transform=global_step_from_engine(trainer)` to take the epoch of the
          # `trainer` instead of `evaluator`.
          tb_logger.attach_output_handler(
              evaluator,
              event_name=Events.EPOCH_COMPLETED,
              tag="validation",
              metric_names=["nll", "accuracy"],
              global_step_transform=global_step_from_engine(trainer)),
          )
  
          # Attach the logger to the trainer to log optimizer's parameters, e.g. learning rate at each iteration
          tb_logger.attach_opt_params_handler(
              trainer,
              event_name=Events.ITERATION_STARTED,
              optimizer=optimizer,
              param_name='lr'  # optional
          )
  
          # Attach the logger to the trainer to log model's weights norm after each iteration
          tb_logger.attach(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              log_handler=WeightsScalarHandler(model)
          )
  
          # Attach the logger to the trainer to log model's weights as a histogram after each epoch
          tb_logger.attach(
              trainer,
              event_name=Events.EPOCH_COMPLETED,
              log_handler=WeightsHistHandler(model)
          )
  
          # Attach the logger to the trainer to log model's gradients norm after each iteration
          tb_logger.attach(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              log_handler=GradsScalarHandler(model)
          )
  
          # Attach the logger to the trainer to log model's gradients as a histogram after each epoch
          tb_logger.attach(
              trainer,
              event_name=Events.EPOCH_COMPLETED,
              log_handler=GradsHistHandler(model)
          )
  
          # We need to close the logger when we are done
          tb_logger.close()
  
      It is also possible to use the logger as context manager:
  
      .. code-block:: python
  
          from ignite.contrib.handlers.tensorboard_logger import *
  
          with TensorboardLogger(log_dir="experiments/tb_logs") as tb_logger:
  
              trainer = Engine(update_fn)
              # Attach the logger to the trainer to log training loss at each iteration
              tb_logger.attach_output_handler(
                  trainer,
                  event_name=Events.ITERATION_COMPLETED,
                  tag="training",
                  output_transform=lambda loss: {"loss": loss}
              )
code: def __getattr__(self, attr: Any) -> Any:
      return getattr(self.writer, attr)
  
imports: from typing import Any, Callable, List, Optional, Union
  from torch.optim import Optimizer
  from ignite.contrib.handlers.base_logger import BaseLogger, BaseOptimizerParamsHandler, BaseOutputHandler, BaseWeightsHandler, BaseWeightsScalarHandler
  from ignite.engine import Engine, Events
  from ignite.handlers import global_step_from_engine
label_desc: Use image node_id 2 for calling the TensorboardLogger obj's underlying member method code with example usage: obj.__getattr__(attr) and returns: getattr