Lightning-AI / Lightning-AI/pytorch-lightning
TensorBoardLogger has the wrong epoch numbers much more than the fact
Nobody has claimed this yet.
- 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:


### 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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