Issue 1:
Issue description

torch.min and torch.max ignores nan in cuda case and crash with pure nan tensor.

Code example

>>> import torch
>>> a = torch.Tensor(4, 3).fill_(1)
>>> a = a.cuda()
>>> a[1, 2] = float('nan')
>>> a
tensor([[ 1., 1., 1.],
[ 1., 1., nan.],
[ 1., 1., 1.],
[ 1., 1., 1.]], device='cuda:0')
>>> torch.max(a)
tensor(1., device='cuda:0')
>>> torch.min(a)
tensor(1., device='cuda:0')
>>> a = torch.Tensor(4, 3).fill_(float('nan'))
>>> a = a.cuda()
>>> torch.max(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 57, in __repr__
return torch._tensor_str._str(self)
File "anaconda3/lib/python3.6/site-packages/torch/_tensor_str.py", line 218, in _str
fmt, scale, sz = _number_format(self)
File "anaconda3/lib/python3.6/site-packages/torch/_tensor_str.py", line 96, in _number_format
if value != math.ceil(value.item()):
RuntimeError: Overflow when unpacking long
>>> torch.min(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 57, in __repr__
return torch._tensor_str._str(self)
File "anaconda3/lib/python3.6/site-packages/torch/_tensor_str.py", line 218, in _str
fmt, scale, sz = _number_format(self)
File "anaconda3/lib/python3.6/site-packages/torch/_tensor_str.py", line 96, in _number_format
if value != math.ceil(value.item()):
RuntimeError: Overflow when unpacking long

System Info

PyTorch or Caffe2: PyTorch

How you installed PyTorch (conda, pip, source): conda

Build command you used (if compiling from source):

OS: Ubuntu 16.04

PyTorch version: 0.4.0

Python version: 3.6.3

CUDA/cuDNN version: 8 / 5

GPU models and configuration: GTX 1050 Ti

GCC version (if compiling from source):

CMake version:

Versions of any other relevant libraries:

Issue 2:
On master:

>>> x.max()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ssnl/sftp/pytorch/torch/tensor.py", line 53, in __repr__
return torch._tensor_str._str(self)
File "/home/ssnl/sftp/pytorch/torch/_tensor_str.py", line 302, in _str
strt = _vector_str(self.unsqueeze(0))
File "/home/ssnl/sftp/pytorch/torch/_tensor_str.py", line 270, in _vector_str
fmt, scale, sz = _number_format(self)
File "/home/ssnl/sftp/pytorch/torch/_tensor_str.py", line 95, in _number_format
if value != math.ceil(value.item()):
RuntimeError: Overflow when unpacking long
>>> x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ssnl/sftp/pytorch/torch/tensor.py", line 53, in __repr__
return torch._tensor_str._str(self)
File "/home/ssnl/sftp/pytorch/torch/_tensor_str.py", line 306, in _str
strt = _matrix_str(self)
File "/home/ssnl/sftp/pytorch/torch/_tensor_str.py", line 215, in _matrix_str
min_sz=5 if not print_full_mat else 0)
File "/home/ssnl/sftp/pytorch/torch/_tensor_str.py", line 95, in _number_format
if value != math.ceil(value.item()):
RuntimeError: Overflow when unpacking long
>>> x.max().item()
1.8446744073709552e+19
>>> x.dtype
torch.float32

This is a regression as printing this tensor works in 0.3.1. Assigning to @li-roy as you are taking care of the printing issue. Reported in #6136