Issue 1:
Hello,

I was trying to code example of neural network on CUDA. I have run some examples which they were working on CPU but not on GPU.

Not sure if it's a bug or my mistake.

Please note that CUDA version of MNIST example is working properly.

How to replicate error, just change bias to false. With bias=true I am able to move network model to CUDA.

#include <torch/torch.h>

// Define a new Module.
struct Net : torch::nn::Module {
Net() {
torch::nn::Conv2d conv = torch::nn::Conv2d(torch::nn::Conv2dOptions(3, 16, 3)
.bias(true)
.stride(1)
.padding(1)
);

module->push_back(conv);

register_module("Layer",module);
}

torch::Tensor forward(torch::Tensor x) {
/**SOME FORWARD**/
return x;
}

torch::nn::Sequential module;
};

int main() {
auto net = std::make_shared<Net>();
net->to(at::kCUDA); // It crashes here
}

It will throw

Exception thrown at 0x00007FFB4A2EA839 in Object_detection.exe: Microsoft C++ exception: c10::Error at memory location 0x000000635F0FDE90.
Unhandled exception at 0x00007FFB4A2EA839 in Object_detection.exe: Microsoft C++ exception: c10::Error at memory location 0x000000635F0FDE90.

Thank you very much for any advise.

cc @ezyang @gchanan @zou3519 @jerryzh168 @yf225

Issue 2:
🐛 Bug

If a Linear or Conv module is constructed without bias, a subsequent move to another device fails

To Reproduce

#include <torch/torch.h>

int main(int argc, char** argv) {
torch::nn::Linear test(torch::nn::LinearOptions(10,20).bias(false));
test->to(torch::kCUDA);
return 0;
}

Stack trace

terminate called after throwing an instance of 'c10::Error'
what(): tensor does not have a device (device at /opt/pytorch/c10/core/TensorImpl.h:463)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x6a (0x7fffe51c9b1a in /usr/local/torch/lib/libc10.so)
frame #1: <unknown function> + 0x1fd83a6 (0x7fffe73ba3a6 in /usr/local/torch/lib/libtorch.so)
frame #2: at::native::to(at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) + 0xb36 (0x7fffe8c6b1f6 in /usr/local/torch/lib/libtorch.so)
frame #3: <unknown function> + 0x3c22636 (0x7fffe9004636 in /usr/local/torch/lib/libtorch.so)
frame #4: <unknown function> + 0x5882857 (0x7fffeac64857 in /usr/local/torch/lib/libtorch.so)
frame #5: <unknown function> + 0x3c89f2f (0x7fffe906bf2f in /usr/local/torch/lib/libtorch.so)
frame #6: <unknown function> + 0x25e1277 (0x7fffe79c3277 in /usr/local/torch/lib/libtorch.so)
frame #7: void torch::nn::Module::to_impl<c10::Device&, bool&>(c10::Device&, bool&) + 0x196 (0x7fffeb3a8266 in /usr/local/torch/lib/libtorch.so)
frame #8: torch::nn::Module::to(c10::Device, bool) + 0x18 (0x7fffeb3a2fe8 in /usr/local/torch/lib/libtorch.so)
frame #9: main + 0xba (0x4052e8 in /home/tobi/coar_ws/devel/lib/dgcnn/dev_stuff)
frame #10: __libc_start_main + 0xf0 (0x7fffe4855830 in /lib/x86_64-linux-gnu/libc.so.6)
frame #11: _start + 0x29 (0x405049 in /home/tobi/coar_ws/devel/lib/dgcnn/dev_stuff)

Thread 1 "dev_stuff" received signal SIGABRT, Aborted.
0x00007fffe486a428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 0x00007fffe486a428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007fffe486c02a in __GI_abort () at abort.c:89
#2 0x00007fffe4ea484d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007fffe4ea26b6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007fffe4ea2701 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007fffe4ea2919 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007fffe73ba3fc in at::Tensor::options() const () from /usr/local/torch/lib/libtorch.so
#7 0x00007fffe8c6b1f6 in at::native::to(at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) () from /usr/local/torch/lib/libtorch.so
#8 0x00007fffe9004636 in at::TypeDefault::to(at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) () from /usr/local/torch/lib/libtorch.so
#9 0x00007fffeac64857 in torch::autograd::VariableType::(anonymous namespace)::to(at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) () from /usr/local/torch/lib/libtorch.so
#10 0x00007fffe906bf2f in c10::detail::wrap_kernel_functor_unboxed_<c10::detail::WrapRuntimeKernelFunctor_<at::Tensor (*)(at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>), at::Tensor, c10::guts::typelist::typelist<at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat> > >, at::Tensor (at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>)>::call(c10::OperatorKernel*, at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) () from /usr/local/torch/lib/libtorch.so
#11 0x00007fffe79c3277 in at::Tensor::to(c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) const () from /usr/local/torch/lib/libtorch.so
#12 0x00007fffeb3a8266 in void torch::nn::Module::to_impl<c10::Device&, bool&>(c10::Device&, bool&) () from /usr/local/torch/lib/libtorch.so
#13 0x00007fffeb3a2fe8 in torch::nn::Module::to(c10::Device, bool) [clone .localalias.489] () from /usr/local/torch/lib/libtorch.so
#14 0x00000000004052e8 in main (argc=1, argv=0x7fffffffccc8) at /home/tobi/coar_ws/src/dgcnn/src/dev_stuff.cpp:5

Expected behavior

Getting no error.

Environment

Collecting environment information...
Collecting environment information...
PyTorch version: 1.4.0a0+829499e
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.15.3

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration:
GPU 0: Quadro RTX 6000
GPU 1: Quadro RTX 6000

Nvidia driver version: 418.87.00
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5

Versions of relevant libraries:
[pip3] numpy==1.17.4
[pip3] torch==1.4.0a0+94016b1
[conda] Could not collect

PyTorch Version (e.g., 1.0): 1.4.0a0+829499e

OS (e.g., Linux): Ubuntu 18.04.3 LTS

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

Build command you used (if compiling from source): CFLAGS=' -D_GLICXX_USE_CXX11_ABI ' USE_OPENCV=1 USE_CUDA=1 MAX_JOBS=7 BUILD_TEST=0 python3 setup.py install

Python version: 3.6

CUDA/cuDNN version: CUDA 10.1 / cuDNN 7.6.5

GPU models and configuration: 2x Quadro RTX 6000

cc @ezyang @gchanan @zou3519 @jerryzh168 @yf225