---
title: tensorboard
description: Log to local or remote file system in TensorBoard format.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.loggers.tensorboard
---
# tensorboard {#tensorboard}

Classes

- [`TensorBoardLogger`](#lightning.pytorch.loggers.tensorboard.TensorBoardLogger) — Log to local or remote file system in TensorBoard format.

## TensorBoard Logger {#tensorboard-logger}

### `class lightning.pytorch.loggers.tensorboard.TensorBoardLogger(save_dir, name='lightning_logs', version=None, log_graph=False, default_hp_metric=True, prefix='', sub_dir=None, **kwargs)` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger}

Bases: [`Logger`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.loggers.logger.md#lightning.pytorch.loggers.logger.Logger "lightning.pytorch.loggers.logger.Logger"), [`TensorBoardLogger`](/docs/fabric/stable/api/generated/lightning.fabric.loggers.TensorBoardLogger#lightning.fabric.loggers.TensorBoardLogger "(in lightning v2.7.0.dev)")

Log to local or remote file system in [TensorBoard](https://www.tensorflow.org/tensorboard) format.

Implemented using `SummaryWriter`. Logs are saved to `os.path.join(save_dir, name, version)`. This is the default logger in Lightning, it comes preinstalled.

This logger supports logging to remote filesystems via `fsspec`. Make sure you have it installed and you don’t have tensorflow (otherwise it will use tf.io.gfile instead of fsspec).

Example:

```python
from lightning.pytorch import Trainer
from lightning.pytorch.loggers import TensorBoardLogger

logger = TensorBoardLogger("tb_logs", name="my_model")
trainer = Trainer(logger=logger)
```

Parameters:

*   **save\_dir** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – Save directory
    
*   **name** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]) – Experiment name. Defaults to `'default'`. If it is the empty string then no per-experiment subdirectory is used.
    
*   **version** (`Union`\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. If it is a string then it is used as the run-specific subdirectory name, otherwise `'version_${version}'` is used.
    
*   **log\_graph** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Adds the computational graph to tensorboard. This requires that the user has defined the self.example\_input\_array attribute in their model.
    
*   **default\_hp\_metric** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Enables a placeholder metric with key hp\_metric when log\_hyperparams is called without a metric (otherwise calls to log\_hyperparams without a metric are ignored).
    
*   **prefix** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – A string to put at the beginning of metric keys.
    
*   **sub\_dir** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)"), [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Sub-directory to group TensorBoard logs. If a sub\_dir argument is passed then logs are saved in `/save_dir/name/version/sub_dir/`. Defaults to `None` in which logs are saved in `/save_dir/name/version/`.
    
*   **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional arguments used by `tensorboardX.SummaryWriter` can be passed as keyword arguments in this logger. To automatically flush to disk, max\_queue sets the size of the queue for pending logs before flushing. flush\_secs determines how many seconds elapses before flushing.
    

#### `after_save_checkpoint(checkpoint_callback)` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.after_save_checkpoint}

Called after model checkpoint callback saves a new checkpoint.

Parameters:

**checkpoint\_callback** ([`ModelCheckpoint`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.callbacks.ModelCheckpoint.md#lightning.pytorch.callbacks.ModelCheckpoint "lightning.pytorch.callbacks.model_checkpoint.ModelCheckpoint")) – the model checkpoint callback instance

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `finalize(status)` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.finalize}

Do any processing that is necessary to finalize an experiment.

Parameters:

**status** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Status that the experiment finished with (e.g. success, failed, aborted)

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `log_graph(model, input_array=None)` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.log_graph}

Record model graph.

Parameters:

*   **model** ([`LightningModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.module.LightningModule")) – the model with an implementation of `forward`.
    
*   **input\_array** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]) – input passes to model.forward
    

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `log_hyperparams(params, metrics=None, step=None)` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.log_hyperparams}

Record hyperparameters. TensorBoard logs with and without saved hyperparameters are incompatible, the hyperparameters are then not displayed in the TensorBoard. Please delete or move the previously saved logs to display the new ones with hyperparameters.

Parameters:

*   **params** (`Union`\[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\], [`Namespace`](https://docs.python.org/3/library/argparse.html#argparse.Namespace "(in Python v3.15)")\]) – A dictionary-like container with the hyperparameters
    
*   **metrics** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]\]) – Dictionary with metric names as keys and measured quantities as values
    
*   **step** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Optional global step number for the logged metrics
    

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `save()` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.save}

Save log data.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `property log_dir: str` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.log_dir}

The directory for this run’s tensorboard checkpoint.

By default, it is named `'version_${self.version}'` but it can be overridden by passing a string value for the constructor’s version parameter instead of `None` or an int.

#### `property root_dir: str` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.root_dir}

Parent directory for all tensorboard checkpoint subdirectories.

If the experiment name parameter is an empty string, no experiment subdirectory is used and the checkpoint will be saved in “save\_dir/version”

#### `property save_dir: str` {#lightning.pytorch.loggers.tensorboard.TensorBoardLogger.save_dir}

Gets the save directory where the TensorBoard experiments are saved.

Returns:

The local path to the save directory where the TensorBoard experiments are saved.

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
