Calling .backward() from within a C++ extension hangs.
Tried on Ubuntu and Arch, one with CUDA and one CPU optimized, pytorch version 1.3 (stable) and python 3.7.
Here is the basic c++ example (say diff.cpp)
#include <torch/extension.h>

void backw(torch::Tensor tens) {
    tens.backward({}, true, true);
}

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("backw", &backw, "DIFF backw");
}

With setup.py:
from setuptools import setup, Extension
from torch.utils import cpp_extension

setup(name='diff_cpp',
      ext_modules=[cpp_extension.CppExtension('diff_cpp', ['diff.cpp'])],
      cmdclass={'build_ext': cpp_extension.BuildExtension})

and installing it as python setup.py install, the following will hang:
import torch
import diff_cpp  # fine
x = torch.tensor([1.0, 2.0])
y = torch.sum(x)
diff_cpp.backw(y)  # hangs

I couldn’t yet find out where it hangs, interrupting the process doesn’t work and I have to kill the process.