Repository: Lightning-AI/pytorch-lightning

Issue:
'Trainer' object has no attribute 'proc_rank'
<!-- 
### 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

<!-- A clear and concise description of what the bug is. -->
1st epoch runs to completion and the above error is thrown in the is_logger() method.

### To Reproduce


<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
```
AttributeError                            Traceback (most recent call last)

<ipython-input-14-1b9ebf437115> in <module>()
      3 trainer = pl.Trainer(**train_params)
      4 
----> 5 trainer.fit(model)

8 frames

<ipython-input-3-bb983543bb31> in is_logger(self)
      8 
      9   def is_logger(self):
---> 10     return self.trainer.proc_rank <= 0
     11 
     12   def forward(

AttributeError: 'Trainer' object has no attribute 'proc_rank'
```


#### Code sample
<!-- Ideally attach a minimal code sample to reproduce the decried issue. 
Minimal means having the shortest code but still preserving the bug. -->
```
class T5FineTuner(pl.LightningModule):
  def __init__(self, hparams):
    super(T5FineTuner, self).__init__()
    self.hparams = hparams
    
    self.model = T5ForConditionalGeneration.from_pretrained(hparams.model_name_or_path)
    self.tokenizer = T5Tokenizer.from_pretrained(hparams.tokenizer_name_or_path)
  
  def is_logger(self):
    return self.trainer.proc_rank <= 0
  
  def forward(
      self, input_ids, attention_mask=None, decoder_input_ids=None, decoder_attention_mask=None, lm_labels=None
  ):
    return self.model(
        input_ids,
        attention_mask=attention_mask,
        decoder_input_ids=decoder_input_ids,
        decoder_attention_mask=decoder_attention_mask,
        lm_labels=lm_labels,
    )

  def _step(self, batch):
    lm_labels = batch["target_ids"]
    lm_labels[lm_labels[:, :] == self.tokenizer.pad_token_id] = -100

    outputs = self(
        input_ids=batch["source_ids"],
        attention_mask=batch["source_mask"],
        lm_labels=lm_labels,
        decoder_attention_mask=batch['target_mask']
    )

    loss = outputs[0]

    return loss

  def training_step(self, batch, batch_idx):
    loss = self._step(batch)

    tensorboard_logs = {"train_loss": loss}
    return {"loss": loss, "log": tensorboard_logs}
  
  def training_epoch_end(self, outputs):
    avg_train_loss = torch.stack([x["loss"] for x in outputs]).mean()
    tensorboard_logs = {"avg_train_loss": avg_train_loss}
    return {"avg_train_loss": avg_train_loss, "log": tensorboard_logs, 'progress_bar': tensorboard_logs}

  def validation_step(self, batch, batch_idx):
    loss = self._step(batch)
    return {"val_loss": loss}
  
  def validation_epoch_end(self, outputs):
    avg_loss = torch.stack([x["val_loss"] for x in outputs]).mean()
    tensorboard_logs = {"val_loss": avg_loss}
    return {"avg_val_loss": avg_loss, "log": tensorboard_logs, 'progress_bar': tensorboard_logs}

  def configure_optimizers(self):
    "Prepare optimizer and schedule (linear warmup and decay)"

    model = self.model
    no_decay = ["bias", "LayerNorm.weight"]
    optimizer_grouped_parameters = [
        {
            "params": [p for n, p in model.named_parameters() if not any(nd in n for nd in no_decay)],
            "weight_decay": self.hparams.weight_decay,
        },
        {
            "params": [p for n, p in model.named_parameters() if any(nd in n for nd in no_decay)],
            "weight_decay": 0.0,
        },
    ]
    optimizer = AdamW(optimizer_grouped_parameters, lr=self.hparams.learning_rate, eps=self.hparams.adam_epsilon)
    self.opt = optimizer
    return [optimizer]
  
  def optimizer_step(self, epoch, batch_idx, optimizer, optimizer_idx, second_order_closure=None):
    if self.trainer.use_tpu:
      xm.optimizer_step(optimizer)
    else:
      optimizer.step()
    optimizer.zero_grad()
    self.lr_scheduler.step()
  
  def get_tqdm_dict(self):
    tqdm_dict = {"loss": "{:.3f}".format(self.trainer.avg_loss), "lr": self.lr_scheduler.get_last_lr()[-1]}

    return tqdm_dict

  def train_dataloader(self):
    train_dataset = get_dataset(tokenizer=self.tokenizer, type_path="train", args=self.hparams)
    dataloader = DataLoader(train_dataset, batch_size=self.hparams.train_batch_size, drop_last=True, shuffle=True, num_workers=4)
    t_total = (
        (len(dataloader.dataset) // (self.hparams.train_batch_size * max(1, self.hparams.n_gpu)))
        // self.hparams.gradient_accumulation_steps
        * float(self.hparams.num_train_epochs)
    )
    scheduler = get_linear_schedule_with_warmup(
        self.opt, num_warmup_steps=self.hparams.warmup_steps, num_training_steps=t_total
    )
    self.lr_scheduler = scheduler
    return dataloader

  def val_dataloader(self):
    val_dataset = get_dataset(tokenizer=self.tokenizer, type_path="val", args=self.hparams)
    return DataLoader(val_dataset, batch_size=self.hparams.eval_batch_size, num_workers=4)

```

### Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

### Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/PyTorchLightning/pytorch-lightning/master/tests/collect_env_details.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/PyTorchLightning/pytorch-lightning/master/tests/collect_env_details.py
# For security purposes, please check the contents of collect_env_details.py before running it.
python collect_env_details.py
```

 - PyTorch Version (e.g., 1.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.6.9
 - CUDA/cuDNN version: 10.1
 - GPU models and configuration: nVidia K80
 - Any other relevant information:

### Additional context

<!-- Add any other context about the problem here. -->
This code does run in 0.7.6 version, but  it breaks in the latest release



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

Resolving patch:
diff --git a/pytorch_lightning/trainer/deprecated_api.py b/pytorch_lightning/trainer/deprecated_api.py
--- a/pytorch_lightning/trainer/deprecated_api.py
+++ b/pytorch_lightning/trainer/deprecated_api.py
@@ -104,3 +104,17 @@ def overfit_pct(self, pct):
         rank_zero_warn("Attribute `train_percent_check` is now set by `overfit_batches` since v0.8.0"
                        " and this method will be removed in v0.10.0", DeprecationWarning)
         self.overfit_batches = pct
+
+    @property
+    def proc_rank(self) -> int:
+        """Back compatibility, will be removed in v0.10.0"""
+        rank_zero_warn("Attribute `proc_rank` is now set by `global_rank` since v0.8.0"
+                       " and this method will be removed in v0.10.0", DeprecationWarning)
+        return self.global_rank
+
+    @proc_rank.setter
+    def proc_rank(self, rank):
+        """Back compatibility, will be removed in v0.10.0"""
+        rank_zero_warn("Attribute `proc_rank` is now set by `global_rank` since v0.8.0"
+                       " and this method will be removed in v0.10.0", DeprecationWarning)
+        self.global_rank = rank


Test patch:
diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py
--- a/tests/test_deprecated.py
+++ b/tests/test_deprecated.py
@@ -44,6 +44,12 @@ def test_tbd_remove_in_v0_10_0_trainer():
     with pytest.deprecated_call(match='v0.10.0'):
         assert trainer.test_percent_check == rnd_val
 
+    trainer = Trainer()
+    with pytest.deprecated_call(match='v0.10.0'):
+        trainer.proc_rank = 0
+    with pytest.deprecated_call(match='v0.10.0'):
+        assert trainer.proc_rank == trainer.global_rank
+
 
 def test_tbd_remove_in_v0_9_0_trainer():
     # test show_progress_bar set by progress_bar_refresh_rate