Repository: Lightning-AI/pytorch-lightning

Issue:
CometLogger failing without save_dir
<!-- 
### 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

Cometmllogger with api key and  without save dir results in error.
This happens due to this if https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/loggers/comet.py#L135
_save_dir is not set and later train loop tries to read it and fails.
This can be fixed by setting _save_dir to None. I will supply PR in a moment

### To Reproduce

Steps to reproduce the behavior:
```
    model = LightningModel({})
    comet_logger = CometLogger(
        api_key=KEY,
        workspace="workspace"
    )

    trainer = Trainer(logger=comet_logger)
    trainer.fit(model)
```
<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->




<!-- A clear and concise description of what you expected to happen. -->


Traceback (most recent call last):
trainer.fit(model)
File "/python3.8/site-packages/pytorch_lightning/trainer/states.py", line 48, in wrapped_fn
result = fn(self, *args, **kwargs)
File "/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1073, in fit
results = self.accelerator_backend.train(model)
File "/python3.8/site-packages/pytorch_lightning/accelerators/gpu_backend.py", line 51, in train
results = self.trainer.run_pretrain_routine(model)
File "/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1239, in run_pretrain_routine
self.train()
File "/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 363, in train
self.on_train_start()
File "/python3.8/site-packages/pytorch_lightning/trainer/callback_hook.py", line 111, in on_train_start
callback.on_train_start(self, self.get_model())
File "/python3.8/site-packages/pytorch_lightning/utilities/distributed.py", line 27, in wrapped_fn
return fn(*args, **kwargs)
File "/python3.8/site-packages/pytorch_lightning/callbacks/model_checkpoint.py", line 296, in on_train_start
save_dir = trainer.logger.save_dir or trainer.default_root_dir
File "/python3.8/site-packages/pytorch_lightning/loggers/comet.py", line 253, in save_dir
return self._save_dir

### Additional context

<!-- Add any other context about the problem here. -->

CometLogger failing without save_dir
<!-- 
### 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

Cometmllogger with api key and  without save dir results in error.
This happens due to this if https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/loggers/comet.py#L135
_save_dir is not set and later train loop tries to read it and fails.
This can be fixed by setting _save_dir to None. I will supply PR in a moment

### To Reproduce

Steps to reproduce the behavior:
```
    model = LightningModel({})
    comet_logger = CometLogger(
        api_key=KEY,
        workspace="workspace"
    )

    trainer = Trainer(logger=comet_logger)
    trainer.fit(model)
```
<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->




<!-- A clear and concise description of what you expected to happen. -->


Traceback (most recent call last):
trainer.fit(model)
File "/python3.8/site-packages/pytorch_lightning/trainer/states.py", line 48, in wrapped_fn
result = fn(self, *args, **kwargs)
File "/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1073, in fit
results = self.accelerator_backend.train(model)
File "/python3.8/site-packages/pytorch_lightning/accelerators/gpu_backend.py", line 51, in train
results = self.trainer.run_pretrain_routine(model)
File "/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1239, in run_pretrain_routine
self.train()
File "/python3.8/site-packages/pytorch_lightning/trainer/training_loop.py", line 363, in train
self.on_train_start()
File "/python3.8/site-packages/pytorch_lightning/trainer/callback_hook.py", line 111, in on_train_start
callback.on_train_start(self, self.get_model())
File "/python3.8/site-packages/pytorch_lightning/utilities/distributed.py", line 27, in wrapped_fn
return fn(*args, **kwargs)
File "/python3.8/site-packages/pytorch_lightning/callbacks/model_checkpoint.py", line 296, in on_train_start
save_dir = trainer.logger.save_dir or trainer.default_root_dir
File "/python3.8/site-packages/pytorch_lightning/loggers/comet.py", line 253, in save_dir
return self._save_dir

### Additional context

<!-- Add any other context about the problem here. -->



Discussion:
Hi! thanks for your contribution!, great first issue!
Hi! thanks for your contribution!, great first issue!

Resolving patch:
diff --git a/pytorch_lightning/loggers/comet.py b/pytorch_lightning/loggers/comet.py
--- a/pytorch_lightning/loggers/comet.py
+++ b/pytorch_lightning/loggers/comet.py
@@ -139,6 +139,7 @@ def __init__(self,
         elif api_key is not None:
             self.mode = "online"
             self.api_key = api_key
+            self._save_dir = None
         elif save_dir is not None:
             self.mode = "offline"
             self._save_dir = save_dir


Test patch: