Repository: Lightning-AI/pytorch-lightning

Issue:
Use isinstance() instead of type() in trainer.distrib_parts.check_gpus_data_type
<!-- 
### 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

When instantiating a `Trainer` object, it makes sense to be able to pass a subclass of `list`.
Ideally, this would be something even more general like `collections.abc.Sequence`, but I'm not too familiar with Lightning's codebase and that change would have a greater likelihood of breaking things.

### To Reproduce
Instantiate a `Trainer` with the `gpus` parameter being a subclass of `list`.

#### Code sample
```python
>>> from pytorch_lightning import Trainer
>>> class MyList(list):
...     pass
... 
>>> gpus = MyList([0])
>>> t = Trainer(gpus=gpus)
```

This produces

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda/miniconda3/envs/ai/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 366, in __init__
    self.data_parallel_device_ids = parse_gpu_ids(self.gpus)
  File "/opt/anaconda/miniconda3/envs/ai/lib/python3.7/site-packages/pytorch_lightning/trainer/distrib_parts.py", line 613, in parse_gpu_ids
    check_gpus_data_type(gpus)
  File "/opt/anaconda/miniconda3/envs/ai/lib/python3.7/site-packages/pytorch_lightning/trainer/distrib_parts.py", line 561, in check_gpus_data_type
    raise MisconfigurationException("GPUs must be int, string or list of ints or None.")
pytorch_lightning.utilities.debugging.MisconfigurationException: GPUs must be int, string or list of ints or None.
```
### Expected behavior

`Trainer` is instantiated normally as it would had a list been passed.

### Environment
 - PyTorch Version: 1.4.0
 - PyTorch Lightning Version: 0.7.1
 - OS: Ubuntu 19.10
 - How you installed PyTorch: `pip`
 - Python version: 3.7

### Potential Fix

In `pytorch_lightning/trainer/distrib_parts.py` check types using `isinstance()` instead of `type()`:
```python
def check_gpus_data_type(gpus):
    # if gpus is not None and type(gpus) not in (int, str, list):
    if gpus is not None and not isinstance(gpus, (int, str, list)):
        raise MisconfigurationException("GPUs must be int, string or list of ints or None.")
```

I'll put in a PR if this change sounds good


Discussion:
Hi! thanks for your contribution!, great first issue!
I do like this shift from `type` to an `isinstance` which extend accepted types also to child...
as always a good PR is always welcome
cc: @PyTorchLightning/core-contributors @jeremyjordan 

Resolving patch:
diff --git a/pytorch_lightning/trainer/distrib_parts.py b/pytorch_lightning/trainer/distrib_parts.py
--- a/pytorch_lightning/trainer/distrib_parts.py
+++ b/pytorch_lightning/trainer/distrib_parts.py
@@ -566,7 +566,7 @@ def check_gpus_data_type(gpus):
     :return: return unmodified gpus variable
     """
 
-    if gpus is not None and type(gpus) not in (int, str, list):
+    if gpus is not None and (not isinstance(gpus, (int, str, list)) or isinstance(gpus, bool)):
         raise MisconfigurationException("GPUs must be int, string or list of ints or None.")
 
 


Test patch: