Repository: pytorch
Issue: torch.cuda.nccl.init_rank does not handle "uid" properly, causing runtime error
Labels: module: cuda,triaged,module: nccl

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

``torch.cuda.nccl.init_rank`` does not handle argument ``uid`` properly, causing runtime error (expected 128 bytes, found 14xxxxxxxxxxxxx)
> "14xxxxxxxxxxxxx" is a 15-digit 10-based integer around 140T

After some research, I found ``id_len`` [python_nccl.cpp#L99](https://github.com/pytorch/pytorch/blob/master/torch/csrc/cuda/python_nccl.cpp#L99) is defined as a 64-bit integer, but later at [python_nccl.cpp#L102](https://github.com/pytorch/pytorch/blob/master/torch/csrc/cuda/python_nccl.cpp#L102) ``PyArg_ParseTuple`` treats it as an ``int`` (32-bit), resulting in the higher 4 bytes of ``id_len`` remains uninitialized.

## To Reproduce

Steps to reproduce the behavior:

1. minimum reproduce
```python
import torch


def create_func(dev: int, uid: bytes):
    rank  = 0
    nrank = 1
    with torch.cuda.device(dev):
        c = torch.cuda.nccl.init_rank(nrank, uid, rank)
    return c


if __name__ == '__main__':
   dev = 0
   uid = torch.cuda.nccl.unique_id()
   print('uid =', uid)
   print('dev =', dev)
   print('calling create_func')

   comm = create_func(dev, uid)  # error happens here
   print('comm:', comm)  # expect to be a nccl communicator, likely found None

```
2. save above code as "repr.py" and run
```shell
python repr.py
```

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

``comm`` is expected to be a ``capsure`` of ``Communicator``, but likely found ``None`` with error message (here is a possible example)
> [~/tmp]$ python3 repr.py
> uid = b"\x02\x00\x82rdb0o\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xac\xbf\x16\x18\xd8\xada\x02\x00\x00\x00\x00\xa0\xb1\xa5\xf3\x17\x7f\x00\x00\xb8\xb1\xa5\xf3\x17\x7f\x00\x00p\xb1\xa5\xf3\x17\x7f\x00\x00\x00Y\x97\x02\x00\x00\x00\x00\x1b\xbb\xefH\xa2\t\xe7p]5\x00\x00\x18\x7f\x00\x00\x00\x97\x1a\xfd\x17\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00p\xb1\xa5\xf3\x17\x7f\x00\x00\x08\xf7\xf1\x84\x18\x7f\x00\x00Z\xfe:\xcb\x08'h?"
> dev = 0
> calling create_func
> Traceback (most recent call last):
>   File "repr.py", line 19, in <module>
>     comm = create_func(dev, uid)  # error happens here
>   File "repr.py", line 8, in create_func
>     c = torch.cuda.nccl.init_rank(nrank, uid, rank)
>   File "/env/python36/lib/python3.6/site-packages/torch/cuda/nccl.py", line 39, in init_rank
>     return torch._C._nccl_init_rank(num_ranks, uid, rank)
> RuntimeError: invalid unqiue_id (expected 128 bytes, got 139741055942784)


<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - PyTorch Version 1.3.1+cu92
 - OS (e.g., Linux): Centos 7
 - How you installed PyTorch (`conda`, `pip`, source): `pip` (wheel package url is [here](https://download.pytorch.org/whl/cu92/torch-1.3.1%2Bcu92-cp36-cp36m-linux_x86_64.whl))
 - Build command you used (if compiling from source): N/A
 - Python version: 3.6
 - CUDA/cuDNN version: shipped with wheel package (9.2.148)
 - GPU models and configuration: 8 x P40
 - Any other relevant information: N/A

## Additional context

<!-- Add any other context about the problem here. -->


cc @ngimel