Repository: pytorch
Issue: [libtorch]Same model in CUDA and CPU got different result?
Labels: module: cpp,module: nn,triaged

## 🐛 Bug

I have already asked questions in the forum, the link is as follows,
https://discuss.pytorch.org/t/why-same-model-in-cuda-and-cpu-got-different-result/56241

I happened in the same program, using the same model, switching between the GPU and the CPU, and the results were different.

My libtorch version is libtorch1.2.0_GPU.
## To Reproduce

Steps to reproduce the behavior:

1.load model:

```c++
	torch::NoGradGuard no_grad_guard;
	if (isCUDA) {
		module = torch::jit::load(model_path, torch::kCUDA);
	}
	else {
		module = torch::jit::load(model_path);
	}
```

2.forward:
```c++
	if (isCUDA) {
		output = module.forward({ tensor_image.to(torch::kCUDA)});
	}
	else {
		output = module.forward({ tensor_image });
	}
```
3.treat output:
```c++
	}else if (output.isTuple()) {
		cout << "output isTuple!" << '\n';
		auto ouputTuple=output.toTuple();

		cout << "tuple_size:" << ouputTuple.use_count()<< '\n';
		torch::Tensor out_tensor = ouputTuple->elements()[0].toTensor();
		torch::Tensor out_tensor1 = ouputTuple->elements()[1].toTensor();
		cout << "out_tensor:" << out_tensor.sizes() << '\n';//out_tensor:[1, 288, 384, 2]  576,768
		cout << "out_tensor1:" << out_tensor1.sizes() << '\n';//out_tensor1:[1, 32, 288, 384]

		torch::Tensor score;
		if (isCUDA) {

			torch::Tensor new_out_tensor = out_tensor.cpu();// .to(torch::kCPU).detach();
			score = new_out_tensor.squeeze(0);// [288, 384, 2]
		}
		else {
			score = out_tensor.squeeze(0);// [288, 384, 2]
		}
```

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

GPU and CPU should have the same output.

## Environment

Collecting environment information...
PyTorch version: 1.2.0
Is debug build: No
CUDA used to build PyTorch: 10.0

OS: Microsoft Windows 10 專業版
GCC version: Could not collect
CMake version: version 3.14.4

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.0.130
GPU models and configuration:
GPU 0: GeForce RTX 2080 Ti
GPU 1: GeForce RTX 2080 Ti

Nvidia driver version: 426.00
cuDNN version: Could not collect

Versions of relevant libraries:
[pip3] numpy==1.16.4+mkl
[pip3] numpydoc==0.8.0
[pip3] torch==1.2.0
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.4.0
[pip3] torchviz==0.0.1
[conda] blas                      1.0                         mkl
[conda] mkl                       2019.1                      144
[conda] mkl-service               1.1.2            py36hb782905_5
[conda] mkl_fft                   1.0.6            py36h6288b17_0
[conda] mkl_random                1.0.2            py36h343c172_0
[conda] numpy                     1.16.4+mkl               pypi_0    pypi
[conda] torch                     1.1.0                    pypi_0    pypi
[conda] torchsummary              1.5.1                    pypi_0    pypi
[conda] torchvision               0.4.0                    pypi_0    pypi
[conda] torchviz                  0.0.1                    pypi_0    pypi




cc @suo @yf225