---
title: NeptuneLogger
description: Log using Neptune.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/reference/generated/lightning.pytorch.loggers.NeptuneLogger
---
# NeptuneLogger {#neptunelogger}

### `class lightning.pytorch.loggers.NeptuneLogger(*, api_key=None, project=None, name=None, run=None, log_model_checkpoints=True, prefix='training', **neptune_run_kwargs)` {#lightning.pytorch.loggers.NeptuneLogger}

Bases: [`Logger`](/docs/pytorch/2.5.5/optional-api/api/lightning.pytorch.loggers.logger.md#lightning.pytorch.loggers.logger.Logger "lightning.pytorch.loggers.logger.Logger")

Log using [Neptune](https://docs.neptune.ai/integrations/lightning/).

Install it with pip:

```bash
pip install neptune
```

or conda:

```bash
conda install -c conda-forge neptune-client
```

**Quickstart**

Pass a NeptuneLogger instance to the Trainer to log metadata with Neptune:

```python
from lightning.pytorch import Trainer
from lightning.pytorch.loggers import NeptuneLogger
import neptune

neptune_logger = NeptuneLogger(
    api_key=neptune.ANONYMOUS_API_TOKEN,  # replace with your own
    project="common/pytorch-lightning-integration",  # format "workspace-name/project-name"
    tags=["training", "resnet"],  # optional
)
trainer = Trainer(max_epochs=10, logger=neptune_logger)
```

**How to use NeptuneLogger?**

Use the logger anywhere in your [`LightningModule`](/docs/pytorch/2.5.5/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.LightningModule") as follows:

```python
from neptune.types import File
from lightning.pytorch import LightningModule


class LitModel(LightningModule):
    def training_step(self, batch, batch_idx):
        # log metrics
        acc = ...
        self.append("train/loss", loss)

    def any_lightning_module_function_or_hook(self):
        # log images
        img = ...
        self.logger.experiment["train/misclassified_images"].append(File.as_image(img))

        # generic recipe
        metadata = ...
        self.logger.experiment["your/metadata/structure"] = metadata
```

Note that the syntax `self.logger.experiment["your/metadata/structure"].append(metadata)` is specific to Neptune and extends the logger capabilities. It lets you log various types of metadata, such as scores, files, images, interactive visuals, and CSVs. Refer to the [Neptune docs](https://docs.neptune.ai/logging/methods) for details. You can also use the regular logger methods `log_metrics()`, and `log_hyperparams()` with NeptuneLogger.

**Log after fitting or testing is finished**

You can log objects after the fitting or testing methods are finished:

```python
neptune_logger = NeptuneLogger(project="common/pytorch-lightning-integration")

trainer = pl.Trainer(logger=neptune_logger)
model = ...
datamodule = ...
trainer.fit(model, datamodule=datamodule)
trainer.test(model, datamodule=datamodule)

# Log objects after `fit` or `test` methods
# model summary
neptune_logger.log_model_summary(model=model, max_depth=-1)

# generic recipe
metadata = ...
neptune_logger.experiment["your/metadata/structure"] = metadata
```

**Log model checkpoints**

If you have [`ModelCheckpoint`](/docs/pytorch/2.5.5/optional-api/api/lightning.pytorch.callbacks.ModelCheckpoint.md#lightning.pytorch.callbacks.ModelCheckpoint "lightning.pytorch.callbacks.ModelCheckpoint") configured, the Neptune logger automatically logs model checkpoints. Model weights will be uploaded to the “model/checkpoints” namespace in the Neptune run. You can disable this option with:

```python
neptune_logger = NeptuneLogger(log_model_checkpoints=False)
```

**Pass additional parameters to the Neptune run**

You can also pass `neptune_run_kwargs` to add details to the run, like `tags` or `description`:

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

neptune_logger = NeptuneLogger(
    project="common/pytorch-lightning-integration",
    name="lightning-run",
    description="mlp quick run with pytorch-lightning",
    tags=["mlp", "quick-run"],
)
trainer = Trainer(max_epochs=3, logger=neptune_logger)
```

Check [run documentation](https://docs.neptune.ai/api/neptune/#init_run) for more info about additional run parameters.

**Details about Neptune run structure**

Runs can be viewed as nested dictionary-like structures that you can define in your code. Thanks to this you can easily organize your metadata in a way that is most convenient for you.

The hierarchical structure that you apply to your metadata is reflected in the Neptune web app.

See also

*   Read about [what objects you can log to Neptune](https://docs.neptune.ai/logging/what_you_can_log/).
    
*   Check out an [example run](https://app.neptune.ai/o/common/org/pytorch-lightning-integration/e/PTL-1/all) with multiple types of metadata logged.
    
*   For more detailed examples, see the [user guide](https://docs.neptune.ai/integrations/lightning/).
    

Parameters:

*   **api\_key** ([`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)")\]) – Optional. Neptune API token, found on [https://www.neptune.ai](https://www.neptune.ai) upon registration. You should save your token to the NEPTUNE\_API\_TOKEN environment variable and leave the api\_key argument out of your code. Instructions: [Setting your API token](https://docs.neptune.ai/setup/setting_api_token/).
    
*   **project** ([`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)")\]) – Optional. Name of a project in the form “workspace-name/project-name”, for example “tom/mask-rcnn”. If `None`, the value of NEPTUNE\_PROJECT environment variable is used. You need to create the project on [https://www.neptune.ai](https://www.neptune.ai) first.
    
*   **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)")\]) – Optional. Editable name of the run. The run name is displayed in the Neptune web app.
    
*   **run** (`Union`\[`Run`, `Handler`, [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Optional. Default is `None`. A Neptune `Run` object. If specified, this existing run will be used for logging, instead of a new run being created. You can also pass a namespace handler object; for example, `run["test"]`, in which case all metadata is logged under the “test” namespace inside the run.
    
*   **log\_model\_checkpoints** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")\]) – Optional. Default is `True`. Log model checkpoint to Neptune. Works only if `ModelCheckpoint` is passed to the `Trainer`.
    
*   **prefix** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Optional. Default is `"training"`. Root namespace for all metadata logging.
    
*   **\*\*neptune\_run\_kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional arguments like `tags`, `description`, `capture_stdout`, etc. used when a run is created.
    

Raises:

*   [**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If the required Neptune package is not installed.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If an argument passed to the logger’s constructor is incorrect.
    

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

Automatically log checkpointed model. Called after model checkpoint callback saves a new checkpoint.

Parameters:

**checkpoint\_callback** (`Checkpoint`) – 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.NeptuneLogger.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_hyperparams(params)` {#lightning.pytorch.loggers.NeptuneLogger.log_hyperparams}

Log hyperparameters to the run.

Hyperparameters will be logged under the “<prefix>/hyperparams” namespace.

Note

You can also log parameters by directly using the logger instance: `neptune_logger.experiment["model/hyper-parameters"] = params_dict`.

In this way you can keep hierarchical structure of the parameters.

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)")\]) – dict. Python dictionary structure with parameters.

Return type:

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

Example:

```python
from lightning.pytorch.loggers import NeptuneLogger
import neptune

PARAMS = {
    "batch_size": 64,
    "lr": 0.07,
    "decay_factor": 0.97,
}

neptune_logger = NeptuneLogger(
    api_key=neptune.ANONYMOUS_API_TOKEN,
    project="common/pytorch-lightning-integration"
)

neptune_logger.log_hyperparams(PARAMS)
```

#### `log_metrics(metrics, step=None)` {#lightning.pytorch.loggers.NeptuneLogger.log_metrics}

Log metrics (numeric values) in Neptune runs.

Parameters:

*   **metrics** ([`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)"), `Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`float`](https://docs.python.org/3/builtins/functions.html#float "(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)")\]) – Step number at which the metrics should be recorded
    

Return type:

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

#### `property experiment: neptune.Run` {#lightning.pytorch.loggers.NeptuneLogger.experiment}

Actual Neptune run object. Allows you to use neptune logging features in your [`LightningModule`](/docs/pytorch/2.5.5/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.LightningModule").

Example:

```python
class LitModel(LightningModule):
    def training_step(self, batch, batch_idx):
        # log metrics
        acc = ...
        self.logger.experiment["train/acc"].append(acc)

        # log images
        img = ...
        self.logger.experiment["train/misclassified_images"].append(File.as_image(img))
```

Note that the syntax `self.logger.experiment["your/metadata/structure"].append(metadata)` is specific to Neptune and extends the logger capabilities. It lets you log various types of metadata, such as scores, files, images, interactive visuals, and CSVs. Refer to the [Neptune docs](https://docs.neptune.ai/logging/methods) for more detailed explanations. You can also use the regular logger methods `log_metrics()`, and `log_hyperparams()` with NeptuneLogger.

#### `property name: Optional[str]` {#lightning.pytorch.loggers.NeptuneLogger.name}

Return the experiment name or ‘offline-name’ when exp is run in offline mode.

#### `property save_dir: Optional[str]` {#lightning.pytorch.loggers.NeptuneLogger.save_dir}

Gets the save directory of the experiment which in this case is `None` because Neptune does not save locally.

Returns:

the root directory where experiment logs get saved

#### `property version: Optional[str]` {#lightning.pytorch.loggers.NeptuneLogger.version}

Return the experiment version.

It’s Neptune Run’s short\_id

---

**Navigation**

- Parent: [Generated](/docs/pytorch/2.5.5/reference/generated.md)
