Issue 1:
🐛 Bug

When using PyTorch1.3 C++ distribution in Visual Studio 2017 and follow the tutorial of loading a TorchScript model from C++ described here https://pytorch.org/tutorials/advanced/cpp_export.html

It all works fine as long as the model and the tensor data stays on the CPU, but as soon as I try to move the model to GPU (CUDA) via

.to(at::kCUDA) I'll get a crash when using the debug version of the libraries. and I'll get a crash later in the release version in the .forward method

To Reproduce

Steps to reproduce the behavior:

Use the code from the tutorial page above

Download latest Windows10 debug version from website

Create a new VS2017 project and use the code snippets above

Use the include/libraries from the debug version

Try to run the code inside VS2017

Stacktrace:

torch.dll!at::native::DispatchStub<void (__cdecl*)(at::TensorIterator & __ptr64,bool),at::native::copy_stub>::operator()<at::TensorIterator & __ptr64,bool & __ptr64>(c10::DeviceType device_type, at::TensorIterator & <args_0>, bool & <args_1>) Line 74	C++
torch.dll!at::native::copy_impl(at::Tensor & self, const at::Tensor & src, bool non_blocking) Line 148	C++
torch.dll!at::native::copy_(at::Tensor & self, const at::Tensor & src, bool non_blocking) Line 157	C++
torch.dll!at::TypeDefault::copy_(at::Tensor & self, const at::Tensor & src, bool non_blocking) Line 1246	C++
torch.dll!c10::detail::WrapRuntimeKernelFunctor_<at::Tensor & __ptr64 (__cdecl*)(at::Tensor & __ptr64,at::Tensor const & __ptr64,bool),at::Tensor & __ptr64,c10::guts::typelist::typelist<at::Tensor & __ptr64,at::Tensor const & __ptr64,bool> >::operator()(at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 24	C++
torch.dll!c10::detail::wrap_kernel_functor_unboxed_<c10::detail::WrapRuntimeKernelFunctor_<at::Tensor & __ptr64 (__cdecl*)(at::Tensor & __ptr64,at::Tensor const & __ptr64,bool),at::Tensor & __ptr64,c10::guts::typelist::typelist<at::Tensor & __ptr64,at::Tensor const & __ptr64,bool> >,at::Tensor & __ptr64 __cdecl(at::Tensor & __ptr64,at::Tensor const & __ptr64,bool)>::call(c10::OperatorKernel * functor, at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 261	C++
torch.dll!c10::KernelFunction::callUnboxedOnly<at::Tensor & __ptr64,at::Tensor & __ptr64,at::Tensor const & __ptr64,bool>(at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 95	C++
torch.dll!c10::impl::OperatorEntry::callUnboxedOnly::__l2::<lambda>(const c10::DispatchTable & dispatchTable) Line 68	C++
torch.dll!c10::LeftRight<c10::DispatchTable>::read<at::Tensor & <lambda>(const c10::DispatchTable &) >(c10::impl::OperatorEntry::callUnboxedOnly::__l2::at::Tensor & <lambda>(const c10::DispatchTable &) && readFunc) Line 74	C++
torch.dll!c10::impl::OperatorEntry::callUnboxedOnly<at::Tensor & __ptr64,at::Tensor & __ptr64,at::Tensor const & __ptr64,bool>(c10::TensorTypeId dispatchKey, at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 70	C++
torch.dll!c10::Dispatcher::callUnboxedOnly<at::Tensor & __ptr64,at::Tensor & __ptr64,at::Tensor const & __ptr64,bool>(const c10::OperatorHandle & op, c10::TensorTypeId dispatchKey, at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 177	C++
torch.dll!at::Tensor::copy_(const at::Tensor & src, bool non_blocking) Line 746	C++
torch.dll!torch::autograd::VariableType::copy_(at::Tensor & self, const at::Tensor & src, bool non_blocking) Line 151	C++
torch.dll!c10::detail::WrapRuntimeKernelFunctor_<at::Tensor & __ptr64 (__cdecl*)(at::Tensor & __ptr64,at::Tensor const & __ptr64,bool),at::Tensor & __ptr64,c10::guts::typelist::typelist<at::Tensor & __ptr64,at::Tensor const & __ptr64,bool> >::operator()(at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 24	C++
torch.dll!c10::detail::wrap_kernel_functor_unboxed_<c10::detail::WrapRuntimeKernelFunctor_<at::Tensor & __ptr64 (__cdecl*)(at::Tensor & __ptr64,at::Tensor const & __ptr64,bool),at::Tensor & __ptr64,c10::guts::typelist::typelist<at::Tensor & __ptr64,at::Tensor const & __ptr64,bool> >,at::Tensor & __ptr64 __cdecl(at::Tensor & __ptr64,at::Tensor const & __ptr64,bool)>::call(c10::OperatorKernel * functor, at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 261	C++
torch.dll!c10::KernelFunction::callUnboxedOnly<at::Tensor & __ptr64,at::Tensor & __ptr64,at::Tensor const & __ptr64,bool>(at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 95	C++
torch.dll!c10::impl::OperatorEntry::callUnboxedOnly::__l2::<lambda>(const c10::DispatchTable & dispatchTable) Line 68	C++
torch.dll!c10::LeftRight<c10::DispatchTable>::read<at::Tensor & <lambda>(const c10::DispatchTable &) >(c10::impl::OperatorEntry::callUnboxedOnly::__l2::at::Tensor & <lambda>(const c10::DispatchTable &) && readFunc) Line 74	C++
torch.dll!c10::impl::OperatorEntry::callUnboxedOnly<at::Tensor & __ptr64,at::Tensor & __ptr64,at::Tensor const & __ptr64,bool>(c10::TensorTypeId dispatchKey, at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 70	C++
torch.dll!c10::Dispatcher::callUnboxedOnly<at::Tensor & __ptr64,at::Tensor & __ptr64,at::Tensor const & __ptr64,bool>(const c10::OperatorHandle & op, c10::TensorTypeId dispatchKey, at::Tensor & <args_0>, const at::Tensor & <args_1>, bool <args_2>) Line 177	C++
torch.dll!at::Tensor::copy_(const at::Tensor & src, bool non_blocking) Line 746	C++
torch.dll!at::native::to_impl(const at::Tensor & self, const c10::TensorOptions & options, bool non_blocking) Line 25	C++
torch.dll!at::native::to(const at::Tensor & self, c10::Device device, c10::ScalarType dtype, bool non_blocking, bool copy) Line 63	C++
torch.dll!at::TypeDefault::to(const at::Tensor & self, c10::Device device, c10::ScalarType dtype, bool non_blocking, bool copy) Line 4830	C++
torch.dll!torch::autograd::VariableType::`anonymous namespace'::to(const at::Tensor & self, c10::Device device, c10::ScalarType dtype, bool non_blocking, bool copy) Line 11390	C++
torch.dll!at::ATenOpTable::callUnboxed<at::Tensor,at::Tensor const & __ptr64,c10::Device,enum c10::ScalarType,bool,bool>(const at::Tensor & <args_0>, c10::Device <args_1>, c10::ScalarType <args_2>, bool <args_3>, bool <args_4>) Line 94	C++
torch.dll!at::Tensor::to(c10::Device device, c10::ScalarType dtype, bool non_blocking, bool copy) Line 3387	C++
torch.dll!torch::jit::script::module_state_to(const torch::jit::script::Slot & s, const c10::optional<c10::Device> & device, const c10::optional<enum c10::ScalarType> & dtype, bool non_blocking) Line 123	C++
torch.dll!torch::jit::script::Module::to_impl(const c10::optional<c10::Device> & device, const c10::optional<enum c10::ScalarType> & dtype, bool non_blocking) Line 140	C++
torch.dll!torch::jit::script::Module::to_impl(const c10::optional<c10::Device> & device, const c10::optional<enum c10::ScalarType> & dtype, bool non_blocking) Line 136	C++
torch.dll!torch::jit::script::Module::to_impl(const c10::optional<c10::Device> & device, const c10::optional<enum c10::ScalarType> & dtype, bool non_blocking) Line 136	C++
torch.dll!torch::jit::script::Module::to(c10::Device device, bool non_blocking) Line 79	C++

Expected behavior

Not to crash

Environment

PyTorch Version 1.3

Windows Version	10.0.18362 Build 18362

How you installed : Used the provided windows llibraries

CUDA/cuDNN 10.1/7

GPU 1060ti

Visual Studio 2017 Version 15.9.8

Issue 2:
🐛 Bug

When doing inference using LibTorch in C++ for semantic segmentation on the GPU, i get the following error in debug compilation mode:

cuda_dispatch_ptr INTERNAL ASSERT FAILED at C:\w\1\s\windows\pytorch\aten\src\ATen/native/DispatchStub.h:70, please report a bug to PyTorch. DispatchStub: missing CUDA kernel (operator () at C:\w\1\s\windows\pytorch\aten\src\ATen/native/DispatchStub.h:70)

(no backtrace available)

When I run it in release mode it does not crash and delivers the expected result. Also on the CPU, this assert is not shown.

Environment

PyTorch Version (e.g., 1.0): latest nightly

OS (e.g., Linux): WIndows 10, Visual Studio 19

How you installed PyTorch (conda, pip, source): downloaded prebuild libtorch

Build command you used (if compiling from source):

Python version:

CUDA/cuDNN version: the one included in the prebuild (cuda 10)

GPU models and configuration: Titan X

Any other relevant information: