Repository: Lightning-AI/pytorch-lightning

Issue:
WandbLogger warning not logging logs.
<!-- 
### Common bugs:
1. Tensorboard not showing in Jupyter-notebook see [issue 79](https://github.com/PyTorchLightning/pytorch-lightning/issues/79).    
2. PyTorch 1.1.0 vs 1.2.0 support [see FAQ](https://github.com/PyTorchLightning/pytorch-lightning#faq)    
-->

## 🐛 Bug
WandbLogger giving warning: `WARNING Adding to old History rows isn't currently supported. Step 25 < 38` and not logging when I try to use the WandbLogger with k-fold cross-validation because there I am using the same instance of `wandb_logger` but using `trainer.fit` multiple times for different train_dl and valid_dl. Since the step gets repeated in each case, it's not logging anything after the 1st fold is complete even though the log keys are completely different. It was working perfectly with pytorch-lightning v-0.7.4. For now, I have to create separate experiments for each fold which are hard to analyze on wandb.
<!-- A clear and concise description of what the bug is. -->

### To Reproduce
#### Code sample
[Colab Notebook](https://colab.research.google.com/drive/1fg-VVeSB71dWEH1qDvvdXTyfxeU--vsM?usp=sharing)
<!-- Ideally attach a minimal code sample to reproduce the decried issue. 
Minimal means having the shortest code but still preserving the bug. -->

### Expected behavior
It should log even when the global_step is repeated in case if the logs keys are different.
<!-- A clear and concise description of what you expected to happen. -->

### Environment
 - PyTorch Version (e.g., 1.0): 1.5.0
 - OS (e.g., Linux): Linux
 - How you installed PyTorch (`conda`, `pip`, source): pip
 - Build command you used (if compiling from source):
 - Python version: 3.7
 - CUDA/cuDNN version: 10.1
 - GPU models and configuration: Tesla P100-PCIE-16GB
 - Any other relevant information:

### Additional context

<!-- Add any other context about the problem here. -->

WandbLogger warning not logging logs.
<!-- 
### Common bugs:
1. Tensorboard not showing in Jupyter-notebook see [issue 79](https://github.com/PyTorchLightning/pytorch-lightning/issues/79).    
2. PyTorch 1.1.0 vs 1.2.0 support [see FAQ](https://github.com/PyTorchLightning/pytorch-lightning#faq)    
-->

## 🐛 Bug
WandbLogger giving warning: `WARNING Adding to old History rows isn't currently supported. Step 25 < 38` and not logging when I try to use the WandbLogger with k-fold cross-validation because there I am using the same instance of `wandb_logger` but using `trainer.fit` multiple times for different train_dl and valid_dl. Since the step gets repeated in each case, it's not logging anything after the 1st fold is complete even though the log keys are completely different. It was working perfectly with pytorch-lightning v-0.7.4. For now, I have to create separate experiments for each fold which are hard to analyze on wandb.
<!-- A clear and concise description of what the bug is. -->

### To Reproduce
#### Code sample
[Colab Notebook](https://colab.research.google.com/drive/1fg-VVeSB71dWEH1qDvvdXTyfxeU--vsM?usp=sharing)
<!-- Ideally attach a minimal code sample to reproduce the decried issue. 
Minimal means having the shortest code but still preserving the bug. -->

### Expected behavior
It should log even when the global_step is repeated in case if the logs keys are different.
<!-- A clear and concise description of what you expected to happen. -->

### Environment
 - PyTorch Version (e.g., 1.0): 1.5.0
 - OS (e.g., Linux): Linux
 - How you installed PyTorch (`conda`, `pip`, source): pip
 - Build command you used (if compiling from source):
 - Python version: 3.7
 - CUDA/cuDNN version: 10.1
 - GPU models and configuration: Tesla P100-PCIE-16GB
 - Any other relevant information:

### Additional context

<!-- Add any other context about the problem here. -->



Discussion:
@borisdayma 
@borisdayma 

Resolving patch:
diff --git a/pytorch_lightning/loggers/wandb.py b/pytorch_lightning/loggers/wandb.py
--- a/pytorch_lightning/loggers/wandb.py
+++ b/pytorch_lightning/loggers/wandb.py
@@ -128,7 +128,7 @@ def log_hyperparams(self, params: Union[Dict[str, Any], Namespace]) -> None:
 
     @rank_zero_only
     def log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None) -> None:
-        self.experiment.log(metrics, step=step)
+        self.experiment.log({'global_step': step, **metrics} if step is not None else metrics)
 
     @property
     def name(self) -> str:


Test patch:
diff --git a/tests/loggers/test_wandb.py b/tests/loggers/test_wandb.py
--- a/tests/loggers/test_wandb.py
+++ b/tests/loggers/test_wandb.py
@@ -13,11 +13,11 @@ def test_wandb_logger(wandb):
     logger = WandbLogger(anonymous=True, offline=True)
 
     logger.log_metrics({'acc': 1.0})
-    wandb.init().log.assert_called_once_with({'acc': 1.0}, step=None)
+    wandb.init().log.assert_called_once_with({'acc': 1.0})
 
     wandb.init().log.reset_mock()
     logger.log_metrics({'acc': 1.0}, step=3)
-    wandb.init().log.assert_called_once_with({'acc': 1.0}, step=3)
+    wandb.init().log.assert_called_once_with({'global_step': 3, 'acc': 1.0})
 
     logger.log_hyperparams({'test': None})
     wandb.init().config.update.assert_called_once_with({'test': None}, allow_val_change=True)