Shortcuts

TensorBoardLogger

class torchtune.training.metric_logging.TensorBoardLogger(log_dir: str, organize_logs: bool = True, **kwargs)[source]

Logger for use w/ PyTorch’s implementation of TensorBoard (https://pytorch.org/docs/stable/tensorboard.html).

Parameters:
  • log_dir (str) – torch.TensorBoard log directory

  • organize_logs (bool) – If True, this class will create a subdirectory within log_dir for the current run. Having sub-directories allows you to compare logs across runs. When TensorBoard is passed a logdir at startup, it recursively walks the directory tree rooted at logdir looking for subdirectories that contain tfevents data. Every time it encounters such a subdirectory, it loads it as a new run, and the frontend will organize the data accordingly. Recommended value is True. Run tensorboard –logdir my_log_dir to view the logs.

  • **kwargs – additional arguments

Example

>>> from torchtune.training.metric_logging import TensorBoardLogger
>>> logger = TensorBoardLogger(log_dir="my_log_dir")
>>> logger.log("my_metric", 1.0, 1)
>>> logger.log_dict({"my_metric": 1.0}, 1)
>>> logger.close()

Note

This utility requires the tensorboard package to be installed. You can install it with pip install tensorboard. In order to view TensorBoard logs, you need to run tensorboard –logdir my_log_dir in your terminal.

close() None[source]

Close log resource, flushing if necessary. Logs should not be written after close is called.

log(name: str, data: Union[Tensor, ndarray, int, float], step: int) None[source]

Log scalar data.

Parameters:
  • name (str) – tag name used to group scalars

  • data (Scalar) – scalar data to log

  • step (int) – step value to record

log_dict(payload: Mapping[str, Union[Tensor, ndarray, int, float]], step: int) None[source]

Log multiple scalar values.

Parameters:
  • payload (Mapping[str, Scalar]) – dictionary of tag name and scalar value

  • step (int) – step value to record

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources