Lightning-AI / Lightning-AI/pytorch-lightning

TensorBoardLogger has the wrong epoch numbers much more than the fact

Open
#19,828 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug logger: tensorboard ver: 2.1.x
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Bug description

I used the following code to log the metrics, but I found that the epoch recorded in the tensorboard logger is much more than it should have:

def training_step(self, batch, batch_idx):
x, y = batch
y_hat = self.forward(x)
loss = torch.sqrt(self.loss_fn(y_hat,y))
self.log("train_loss", loss, logger=True, prog_bar=True, on_epoch=True)
return loss

def validation_step(self, batch, batch_idx):
x, y = batch
y_hat = self.forward(x)
loss = torch.sqrt(self.loss_fn(y_hat,y))
self.log("valid_loss", loss, logger=True, prog_bar=True, on_epoch=True)
return loss

pl.Train(..., logger=TensorBoardLogger(save_dir='store',version=log_path), ....)

In the configure, I set max_epoch=10000, but in the logger, I got epoches more than 650k:
![d9dc51214ca78a81ba849ff967f459f](https://github.com/Lightning-AI/pytorch-lightning/assets/80281876/68971f90-9ff3-41eb-a688-564cdabcf1f7)
![image](https://github.com/Lightning-AI/pytorch-lightning/assets/80281876/436f5029-5820-4df7-8106-d708193b7f46)

### What version are you seeing the problem on?

v2.1

### How to reproduce the bug

```python
def training_step(self, batch, batch_idx):
x, y = batch
y_hat = self.forward(x)
loss = torch.sqrt(self.loss_fn(y_hat,y))
self.log("train_loss", loss, logger=True, prog_bar=True, on_epoch=True)
return loss

def validation_step(self, batch, batch_idx):
x, y = batch
y_hat = self.forward(x)
loss = torch.sqrt(self.loss_fn(y_hat,y))
self.log("valid_loss", loss, logger=True, prog_bar=True, on_epoch=True)
return loss

pl.Train(..., logger=TensorBoardLogger(save_dir='store',version=log_path), ....) # u can use any path you like
```

### Error messages and logs

```
# Error messages and logs here please
```

### Environment

Current environment

```
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0): 2.1.3
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9): 2.1.2
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source): pip
#- Running environment of LightningApp (e.g. local, cloud):
```

### More info

_No response_

cc @lantiga

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report provides no repository file or test to follow. Start by reproducing the shown training_step and validation_step with TensorBoardLogger, then compare the configured max_epoch with the epoch or step values written to TensorBoard. Done means the logger reports the expected epoch range and a regression test covers the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.