Repository: Lightning-AI/pytorch-lightning

Issue:
Broken ddp_cpu backend
## 🐛 Bug

Broken on current master.

### To Reproduce

```python
def test(tmpdir):
    import pytorch_lightning as pl
    trainer = pl.Trainer(
        default_root_dir=tmpdir,
        max_epochs=3,
        limit_train_batches=10,
        limit_val_batches=10,
        distributed_backend="ddp_cpu",
    )
    model = DummyModule() # Linear layer on MNIST
    trainer.fit(model)
```

Error:

```
E       -- Process 0 terminated with the following error:
E       Traceback (most recent call last):
E         File "/home/carmocca/projects/PyLaia/venv/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
E           fn(i, *args)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/accelerators/ddp_cpu_spawn_backend.py", line 137, in ddp_train
E           results = self.train_or_test()
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/accelerators/base_backend.py", line 43, in train_or_test
E           results = self.trainer.train()
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/trainer/trainer.py", line 464, in train
E           self.run_sanity_check(self.get_model())
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/trainer/trainer.py", line 649, in run_sanity_check
E           _, eval_results = self.run_evaluation(test_mode=False, max_batches=self.num_sanity_val_batches)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/trainer/trainer.py", line 571, in run_evaluation
E           output = self.evaluation_loop.evaluation_step(test_mode, batch, batch_idx, dataloader_idx)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/trainer/evaluation_loop.py", line 149, in evaluation_step
E           output = self.trainer.accelerator_backend.validation_step(args)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/accelerators/ddp_cpu_spawn_backend.py", line 157, in validation_step
E           output = self.training_step(args)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/accelerators/ddp_cpu_spawn_backend.py", line 153, in training_step
E           output = self.trainer.model(*args)
E         File "/home/carmocca/projects/PyLaia/venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
E           result = self.forward(*input, **kwargs)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/overrides/data_parallel.py", line 209, in forward
E           warn_missing_output(fx_called)
E         File "/home/carmocca/projects/PyLaia/venv/src/pytorch-lightning/pytorch_lightning/overrides/data_parallel.py", line 228, in warn_missing_output
E           warning_cache.warn(m)
E       UnboundLocalError: local variable 'm' referenced before assignment
```

### Expected behavior

Does not fail


Discussion:

Resolving patch:
diff --git a/pytorch_lightning/overrides/data_parallel.py b/pytorch_lightning/overrides/data_parallel.py
--- a/pytorch_lightning/overrides/data_parallel.py
+++ b/pytorch_lightning/overrides/data_parallel.py
@@ -206,26 +206,16 @@ def forward(self, *inputs, **kwargs):  # pragma: no-cover
                 self.reducer.prepare_for_backward([])
 
         if output is None:
-            warn_missing_output(fx_called)
-
-            m = f'{fx_called} returned None. Did you forget to re'
+            warn_missing_output(f'{fx_called} returned None. Did you forget to re')
         return output
 
 
 def warn_missing_output(fx_called):
     if fx_called == 'training_step':
-        m = """
-            Your training_step returned None. You should instead do:
-            return loss
-            or
-            return TrainResult
-        """
+        warning_cache.warn("Your training_step returned None. You should instead do:\n"
+                           "`return loss`\n or\n `return TrainResult`")
     elif fx_called in ['validation_step', 'test_step']:
-        m = f"""
-            Your {fx_called} returned None. You should instead do:
-            return EvalResult
-        """
-    warning_cache.warn(m)
+        warning_cache.warn(f"Your {fx_called} returned None. You should instead do:\n `return EvalResult")
 
 
 def parallel_apply(modules, inputs, kwargs_tup=None, devices=None):  # pragma: no-cover


Test patch: