Lightning-AI / Lightning-AI/pytorch-lightning

MLFlow Logger log_model parameter not working correctly when using multiple ModelCheckpoint

Open
#17,097 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

### Bug description

MLFlow Logger parameter 'log_model' is not working as expected when multiple ModelCheckpoint are used.
When set to 'True' we expect it to save one checkpoint per ModelCheckpoint used at the end of the training. But what we get is only one of the model checkpoints is logged.
****

### How to reproduce the bug

```python
- Define pl.Trainer with 2 checkpoint callbacks (1 "LastCheckpoint", without save_top k + 1 BestCheckpoint, with save_top k=n>1)
- Define MLFlowLogger with log_model set to True
- get only 1 checkpoint as a result in MLFlow

This is probably due to after_save_checkpoint() from MLFlowLogger that overwrite checkpoint_callback everytime, losing the one of the two ModelCheckpoint reference. It may be necessary to use a list here.
```

### 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):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
```

### More info

_No response_

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

Reproduce the issue with two ModelCheckpoint callbacks and MLFlowLogger(log_model=True), then inspect MLFlowLogger.after_save_checkpoint() and how it tracks checkpoint callbacks. Confirm the fix by verifying that one checkpoint from each ModelCheckpoint is logged in MLflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.