internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Lightning-AI/pytorch-lightning

Issue:
"limit_train_batches" not receiving float value
<!-- 
### 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

error: argument --limit_train_batches: invalid int value: '0.3'

### To Reproduce
 Just put any float value after '--limit_train_batches' or '--val_check_interval'

I am using the latest master branch. 0.9.rc14

I think this issue is related to the fix of #2943 


Discussion:
@Borda i think you have to do that thing again to enable both floats and ints from add_argparse_args

Resolving patch:
diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py
--- a/pytorch_lightning/trainer/trainer.py
+++ b/pytorch_lightning/trainer/trainer.py
@@ -766,8 +766,16 @@ def use_type(x):
                 use_type = arg_types[0]
 
             if arg == 'gpus' or arg == 'tpu_cores':
-                use_type = Trainer._allowed_type
-                arg_default = Trainer._arg_default
+                use_type = Trainer._gpus_allowed_type
+                arg_default = Trainer._gpus_arg_default
+
+            # hack for types in (int, float)
+            if len(arg_types) == 2 and int in set(arg_types) and float in set(arg_types):
+                use_type = Trainer._int_or_float_type
+
+            # hack for track_grad_norm
+            if arg == 'track_grad_norm':
+                use_type = float
 
             parser.add_argument(
                 f'--{arg}',
@@ -780,18 +788,24 @@ def use_type(x):
 
         return parser
 
-    def _allowed_type(x) -> Union[int, str]:
+    def _gpus_allowed_type(x) -> Union[int, str]:
         if ',' in x:
             return str(x)
         else:
             return int(x)
 
-    def _arg_default(x) -> Union[int, str]:
+    def _gpus_arg_default(x) -> Union[int, str]:
         if ',' in x:
             return str(x)
         else:
             return int(x)
 
+    def _int_or_float_type(x) -> Union[int, float]:
+        if '.' in str(x):
+            return float(x)
+        else:
+            return int(x)
+
     @classmethod
     def parse_argparser(cls, arg_parser: Union[ArgumentParser, Namespace]) -> Namespace:
         """Parse CLI arguments, required for custom bool types."""


Test patch:
Repository: Lightning-AI/pytorch-lightning

Issue:
When auto_sceale_batch_size and auto_lr_find are both enabled, lr find is called with every batch search
is this a bug or feature? I think lr find should be called after batch size search is done.


Discussion:
Hi! thanks for your contribution!, great first issue!
@SkafteNicki mind have look? 🐰 
@Borda this is definitely a bug, it should be added to the list of attributes that are stored and altered before the search and then restored after the search:
https://github.com/PyTorchLightning/pytorch-lightning/blob/ccc923cbb01af7776f2472056b264758a6745871/pytorch_lightning/trainer/training_tricks.py#L213-L249
I will send a bugfix.
or @LeeJZh are interested in sending fix? 🦝 

Resolving patch:
diff --git a/pytorch_lightning/trainer/training_tricks.py b/pytorch_lightning/trainer/training_tricks.py
--- a/pytorch_lightning/trainer/training_tricks.py
+++ b/pytorch_lightning/trainer/training_tricks.py
@@ -213,6 +213,7 @@ def scale_batch_size(self,
     def __scale_batch_dump_params(self):
         # Prevent going into infinite loop
         self.__dumped_params = {
+            'auto_lr_find': self.auto_lr_find,
             'max_steps': self.max_steps,
             'weights_summary': self.weights_summary,
             'logger': self.logger,
@@ -226,6 +227,7 @@ def __scale_batch_dump_params(self):
 
     def __scale_batch_reset_params(self, model, steps_per_trial):
         self.auto_scale_batch_size = None  # prevent recursion
+        self.auto_lr_find = False  # avoid lr find being called multiple times
         self.max_steps = steps_per_trial  # take few steps
         self.weights_summary = None  # not needed before full run
         self.logger = DummyLogger()
@@ -237,6 +239,7 @@ def __scale_batch_reset_params(self, model, steps_per_trial):
         self.model = model  # required for saving
 
     def __scale_batch_restore_params(self):
+        self.auto_lr_find = self.__dumped_params['auto_lr_find']
         self.max_steps = self.__dumped_params['max_steps']
         self.weights_summary = self.__dumped_params['weights_summary']
         self.logger = self.__dumped_params['logger']


Test patch:
Repository: Lightning-AI/pytorch-lightning

Issue:
What's the true meaning of gpus argument in Trainer
Hello, I have a question to the "gpus" argument for the Trainer() class. I don't think the documentation is clear in my view. From the docs, I only know that "gpus: Which GPUs to train on.". However, from the link here: https://pytorch-lightning.readthedocs.io/en/latest/multi_gpu.html, I get different answer. 
1. 
DEFAULT (int) specifies how many GPUs to use
Trainer(gpus=k)
2. 
train on 32 GPUs (4 nodes)
trainer = Trainer(gpus=8, distributed_backend='ddp', num_nodes=4)

Does the gpus mean number of gpu per node or total number of gpus in use?




Discussion:
Hi! thanks for your contribution!, great first issue!
number of gpus per node.
@PursueHappinessDirectly mind send a PR with clarifying docs?

Resolving patch:
diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py
--- a/pytorch_lightning/trainer/trainer.py
+++ b/pytorch_lightning/trainer/trainer.py
@@ -230,7 +230,7 @@ def __init__(
 
             num_nodes: number of GPU nodes for distributed training.
 
-            gpus: Which GPUs to train on.
+            gpus: number of gpus to train on (int) or which GPUs to train on (list or str) applied per node
 
             auto_select_gpus:
 


Test patch:
Repository: Lightning-AI/pytorch-lightning

Issue:
auto_scale_batch_size won't reset current_epoch
## 🐛 Bug

When `auto_scale_batch_size` is enabled, the model is initially trained with varying batch sizes. When training begins, `trainer.current_epoch` equals 1 instead of 0.

### To Reproduce

Either observe the progress bar or use a simple callback to track the epoch number, once with  `auto_scale_batch_size`  enabled and once with  `auto_scale_batch_size` disabled.

```
from pytorch_lightning import Callback

class PrintCallback(Callback):
    
    def __init__(self):
        self.observed_epochs = []
        
    def on_train_epoch_start(self, trainer, pl_module):
        print(f'Current Epoch: {trainer.current_epoch}')
        self.observed_epochs.append(trainer.current_epoch)

```


Discussion:

Resolving patch:
diff --git a/pytorch_lightning/tuner/batch_size_scaling.py b/pytorch_lightning/tuner/batch_size_scaling.py
--- a/pytorch_lightning/tuner/batch_size_scaling.py
+++ b/pytorch_lightning/tuner/batch_size_scaling.py
@@ -123,6 +123,7 @@ def __scale_batch_dump_params(trainer):
     # Prevent going into infinite loop
     trainer.__dumped_params = {
         'auto_lr_find': trainer.auto_lr_find,
+        'current_epoch': trainer.current_epoch,
         'max_steps': trainer.max_steps,
         'weights_summary': trainer.weights_summary,
         'logger': trainer.logger,
@@ -138,6 +139,7 @@ def __scale_batch_dump_params(trainer):
 def __scale_batch_reset_params(trainer, model, steps_per_trial):
     trainer.auto_scale_batch_size = None  # prevent recursion
     trainer.auto_lr_find = False  # avoid lr find being called multiple times
+    trainer.current_epoch = 0
     trainer.max_steps = steps_per_trial  # take few steps
     trainer.weights_summary = None  # not needed before full run
     trainer.logger = DummyLogger()
@@ -151,6 +153,7 @@ def __scale_batch_reset_params(trainer, model, steps_per_trial):
 
 def __scale_batch_restore_params(trainer):
     trainer.auto_lr_find = trainer.__dumped_params['auto_lr_find']
+    trainer.current_epoch = trainer.__dumped_params['current_epoch']
     trainer.max_steps = trainer.__dumped_params['max_steps']
     trainer.weights_summary = trainer.__dumped_params['weights_summary']
     trainer.logger = trainer.__dumped_params['logger']


Test patch:
diff --git a/tests/trainer/test_trainer_tricks.py b/tests/trainer/test_trainer_tricks.py
--- a/tests/trainer/test_trainer_tricks.py
+++ b/tests/trainer/test_trainer_tricks.py
@@ -182,7 +182,8 @@ def test_trainer_reset_correctly(tmpdir):
                           'callbacks',
                           'checkpoint_callback',
                           'early_stop_callback',
-                          'limit_train_batches']
+                          'limit_train_batches',
+                          'current_epoch']
 
     attributes_before = {}
     for ca in changed_attributes:
Repository: Lightning-AI/pytorch-lightning

Issue:
Cometml Logger epoch is not set.
<!-- 
### 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

While logging using comet ml there is an argument to set epoch https://www.comet.ml/docs/python-sdk/Experiment/#experimentlog_metrics
The info is available in metrics dict, but instead of passing it as an arg, it is passed as metrics value. I will suply a PR in a moment




Discussion:

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
@@ -229,7 +229,10 @@ def log_metrics(
             if is_tensor(val):
                 metrics[key] = val.cpu().detach()
 
-        self.experiment.log_metrics(metrics, step=step)
+        metrics_without_epoch = metrics.copy()
+        epoch = metrics_without_epoch.pop('epoch', None)
+
+        self.experiment.log_metrics(metrics_without_epoch, step=step, epoch=epoch)
 
     def reset_experiment(self):
         self._experiment = None


Test patch:
diff --git a/tests/loggers/test_comet.py b/tests/loggers/test_comet.py
--- a/tests/loggers/test_comet.py
+++ b/tests/loggers/test_comet.py
@@ -105,3 +105,13 @@ def test_comet_logger_dirs_creation(tmpdir, monkeypatch):
 
     assert trainer.checkpoint_callback.dirpath == (tmpdir / 'test' / version / 'checkpoints')
     assert set(os.listdir(trainer.checkpoint_callback.dirpath)) == {'epoch=0.ckpt'}
+
+
+def test_comet_epoch_logging(tmpdir, monkeypatch):
+    """ Test that CometLogger removes the epoch key from the metrics dict and passes it as argument. """
+    import atexit
+    monkeypatch.setattr(atexit, "register", lambda _: None)
+    with patch("pytorch_lightning.loggers.comet.CometOfflineExperiment.log_metrics") as log_metrics:
+        logger = CometLogger(project_name="test", save_dir=tmpdir)
+        logger.log_metrics({"test": 1, "epoch": 1}, step=123)
+        log_metrics.assert_called_once_with({"test": 1}, epoch=1, step=123)
Repository: Lightning-AI/pytorch-lightning

Issue:
Validation step returns trainresult instead of evalresult
## 📚 Documentation

https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/core/lightning.py#L412



Discussion:

Resolving patch:
diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py
--- a/pytorch_lightning/core/lightning.py
+++ b/pytorch_lightning/core/lightning.py
@@ -409,7 +409,7 @@ def validation_step(self, *args, **kwargs) -> EvalResult:
                 (only if multiple val datasets used)
 
         Return:
-            :class:`~pytorch_lightning.core.step_result.TrainResult`
+            :class:`~pytorch_lightning.core.step_result.EvalResult`
 
         .. code-block:: python
 
@@ -493,7 +493,7 @@ def validation_step_end(self, *args, **kwargs) -> EvalResult:
                 for each batch part.
 
         Return:
-            :class:`~pytorch_lightning.core.step_result.TrainResult`
+            :class:`~pytorch_lightning.core.step_result.EvalResult`
 
         .. code-block:: python
 
@@ -561,7 +561,7 @@ def validation_epoch_end(
                 are multiple dataloaders, a list containing a list of outputs for each dataloader.
 
         Return:
-            :class:`~pytorch_lightning.core.step_result.TrainResult`
+            :class:`~pytorch_lightning.core.step_result.EvalResult`
 
         Note:
             If you didn't define a :meth:`validation_step`, this won't be called.
@@ -619,7 +619,7 @@ def test_step(self, *args, **kwargs) -> EvalResult:
                 (only if multiple test datasets used).
 
         Return:
-            :class:`~pytorch_lightning.core.step_result.TrainResult`
+            :class:`~pytorch_lightning.core.step_result.EvalResult`
 
         .. code-block:: python
 
@@ -694,7 +694,7 @@ def test_step_end(self, *args, **kwargs) -> EvalResult:
             batch_parts_outputs: What you return in :meth:`test_step` for each batch part.
 
         Return:
-            :class:`~pytorch_lightning.core.step_result.TrainResult`
+            :class:`~pytorch_lightning.core.step_result.EvalResult`
 
         .. code-block:: python
 
@@ -763,7 +763,7 @@ def test_epoch_end(
                 are multiple dataloaders, a list containing a list of outputs for each dataloader
 
         Return:
-            :class:`~pytorch_lightning.core.step_result.TrainResult`
+            :class:`~pytorch_lightning.core.step_result.EvalResult`
 
         Note:
             If you didn't define a :meth:`test_step`, this won't be called.


Test patch:
Repository: Lightning-AI/pytorch-lightning

Issue:
add support for 1.7 nightly
## 🚀 Feature
 
@ydcjeff created a CI with Conda to have tested with nighly 1.7 but in #3074 some tests were failing for 1.7 some let's move it as separate work

### Motivation

be continuously compatible even with new PT versions when they come

### ToDo

- [ ] uncomment CI and enable 1.7 testing
- [ ] fix test so 1.7 passes


Discussion:

Resolving patch:
diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py
--- a/pytorch_lightning/core/lightning.py
+++ b/pytorch_lightning/core/lightning.py
@@ -51,9 +51,13 @@
     XLA_AVAILABLE = True
 
 
-class LightningModule(
-    ABC, DeviceDtypeModuleMixin, GradInformation, ModelIO, ModelHooks, DataHooks, Module
-):
+class LightningModule(ABC, DeviceDtypeModuleMixin, GradInformation, ModelIO, ModelHooks, DataHooks, Module):
+    # Below is for property support of JIT in PyTorch 1.7
+    # since none of them is important when using JIT, we are going to ignore them.
+    # https://github.com/pytorch/pytorch/commit/e7d782e724c76bb0572023d52ee7438a40a7a262#diff-ff4f8670281cd1eb4e09329cc1dcb43b
+    __ignored_properties__ = ['datamodule', 'example_input_array',
+                              'hparams', 'on_gpu'] + DeviceDtypeModuleMixin.__ignored_properties__
+
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
 
@@ -755,7 +759,6 @@ def test_end(self, outputs):
     def test_epoch_end(
         self, outputs: Union[EvalResult, List[EvalResult]]
     ) -> EvalResult:
-
         """
         Called at the end of a test epoch with the output of all test steps.
 
diff --git a/pytorch_lightning/utilities/device_dtype_mixin.py b/pytorch_lightning/utilities/device_dtype_mixin.py
--- a/pytorch_lightning/utilities/device_dtype_mixin.py
+++ b/pytorch_lightning/utilities/device_dtype_mixin.py
@@ -19,6 +19,7 @@
 
 
 class DeviceDtypeModuleMixin(Module):
+    __ignored_properties__ = ['device', 'dtype']
 
     def __init__(self):
         super().__init__()


Test patch:
Repository: Lightning-AI/pytorch-lightning

Issue:
DataModules should have a reference to the Trainer
## 🚀 Feature
The DataModule should have a reference to the Trainer, so attributes on the Trainer can be accessed during prepare_data, setup, and the dataloader methods. 

cc @nateraw 

### Motivation
Further uncouple datamodules and lightning modules. For instance, it can be useful for DataModules to know what the current epoch is during training. If I want to use the DataModules, I don't have access to this. However this is readily available if I define my `train_dataloader` in the LightningModule instead. 


### Pitch
We can follow the same setup that LightningModules have and how the trainer is initialized for them



Discussion:

Resolving patch:
diff --git a/pytorch_lightning/trainer/connectors/data_connector.py b/pytorch_lightning/trainer/connectors/data_connector.py
--- a/pytorch_lightning/trainer/connectors/data_connector.py
+++ b/pytorch_lightning/trainer/connectors/data_connector.py
@@ -14,7 +14,7 @@
 
 from pytorch_lightning.core.datamodule import LightningDataModule
 from pytorch_lightning.utilities.exceptions import MisconfigurationException
-from typing import List, Union
+from typing import List, Optional, Union
 from torch.utils.data import DataLoader
 from pytorch_lightning.utilities.model_utils import is_overridden
 
@@ -101,7 +101,7 @@ def attach_dataloaders(self, model, train_dataloader=None, val_dataloaders=None,
         if test_dataloaders is not None:
             model.test_dataloader = _PatchDataLoader(test_dataloaders)
 
-    def attach_datamodule(self, model, datamodule, stage):
+    def attach_datamodule(self, model, datamodule: Optional[LightningDataModule], stage: str) -> None:
 
         # We use datamodule if it's been provided on .fit or .test, otherwise we check model for it
         datamodule = datamodule or getattr(model, 'datamodule', None)
@@ -122,6 +122,7 @@ def attach_datamodule(self, model, datamodule, stage):
                 model.transfer_batch_to_device = datamodule.transfer_batch_to_device
 
             self.trainer.datamodule = datamodule
+            datamodule.trainer = self.trainer
 
 
 class _PatchDataLoader(object):


Test patch:
diff --git a/tests/core/test_datamodules.py b/tests/core/test_datamodules.py
--- a/tests/core/test_datamodules.py
+++ b/tests/core/test_datamodules.py
@@ -255,6 +255,32 @@ def test_full_loop(tmpdir):
     assert result['test_acc'] > 0.8
 
 
+def test_trainer_attached_to_dm(tmpdir):
+    reset_seed()
+
+    dm = TrialMNISTDataModule(tmpdir)
+
+    model = EvalModelTemplate()
+
+    trainer = Trainer(
+        default_root_dir=tmpdir,
+        max_epochs=3,
+        weights_summary=None,
+        deterministic=True,
+    )
+
+    # fit model
+    result = trainer.fit(model, dm)
+    assert result == 1
+    assert dm.trainer is not None
+
+    # test
+    result = trainer.test(datamodule=dm)
+    result = result[0]
+    assert dm.trainer is not None
+
+
+
 @pytest.mark.skipif(torch.cuda.device_count() < 1, reason="test requires multi-GPU machine")
 def test_full_loop_single_gpu(tmpdir):
     reset_seed()
Repository: Lightning-AI/pytorch-lightning

Issue:
cloud_io's `load` should use fsspec for compatibility with more storage systems
## 🐛 Bug

There's an inconsistency in which paths Lightning supports with `load` vs what `fsspec` can support: https://github.com/PyTorchLightning/pytorch-lightning/blob/b4256df121fae1955c78895cf32e2e4c66b6603d/pytorch_lightning/utilities/cloud_io.py#L27

This code should use `fsspec` to try to open the file. If there isn't a valid filesystem registered, then fallback to calling torch.hub.load. cc @awaelchli 

### To Reproduce

Pass a URL supported by `fsspec` but not torch.load(...) and try calling `cloud_io`'s `load` with it




Discussion:

Resolving patch:
diff --git a/pytorch_lightning/utilities/cloud_io.py b/pytorch_lightning/utilities/cloud_io.py
--- a/pytorch_lightning/utilities/cloud_io.py
+++ b/pytorch_lightning/utilities/cloud_io.py
@@ -25,9 +25,11 @@
 
 
 def load(path_or_url: str, map_location=None):
-    if urlparse(path_or_url).scheme == "" or Path(path_or_url).drive:  # no scheme or with a drive letter
-        return torch.load(path_or_url, map_location=map_location)
-    return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location)
+    if path_or_url.startswith("http"):
+        return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location)
+    fs = get_filesystem(path_or_url)
+    with fs.open(path_or_url, "rb") as f:
+        return torch.load(f, map_location=map_location)
 
 
 def get_filesystem(path: pathlike):


Test patch:
Repository: Lightning-AI/pytorch-lightning

Issue:
DataModules should have a reference to the Trainer
## 🚀 Feature
The DataModule should have a reference to the Trainer, so attributes on the Trainer can be accessed during prepare_data, setup, and the dataloader methods. 

cc @nateraw 

### Motivation
Further uncouple datamodules and lightning modules. For instance, it can be useful for DataModules to know what the current epoch is during training. If I want to use the DataModules, I don't have access to this. However this is readily available if I define my `train_dataloader` in the LightningModule instead. 


### Pitch
We can follow the same setup that LightningModules have and how the trainer is initialized for them



Discussion:

Resolving patch:
diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py
--- a/pytorch_lightning/trainer/trainer.py
+++ b/pytorch_lightning/trainer/trainer.py
@@ -53,6 +53,7 @@
 from pytorch_lightning.trainer.connectors.precision_connector import PrecisionConnector
 from pytorch_lightning.trainer.connectors.profiler_connector import ProfilerConnector
 from pytorch_lightning.trainer.connectors.data_connector import DataConnector
+from pytorch_lightning.utilities.cloud_io import load as pl_load
 from pytorch_lightning.utilities.model_utils import is_overridden
 from pytorch_lightning.trainer import docstrings
 from pytorch_lightning.trainer.properties import TrainerProperties
@@ -569,7 +570,7 @@ def __test_using_best_weights(self, ckpt_path, test_dataloaders):
                 )
                 return {}
 
-            ckpt = torch.load(ckpt_path, map_location=lambda storage, loc: storage)
+            ckpt = pl_load(ckpt_path, map_location=lambda storage, loc: storage)
             model.load_state_dict(ckpt['state_dict'])
 
         # attach dataloaders


Test patch: