Pytorch 0.4 is not released yet. It is still under development and partially available if you compile from master.
Ok I think the problem is that your input a is 2D of size (1, something) and thus nonzero() returns a tensor with 2 coordinates with one which is always 0. If you make your input a 1D tensor, then nonzero() will return a 10x1 tensor which will be transformed into a vector of size 10 which you can then use to index your tensor.
For the detach(), I’m not sure why you would want to use the inplace version. The regular version should work here.