PyTorch most basic working element is a tensor. So, when you are loading your data set through enumerate(train_iterator) you are already dealing with tensors. Basically what you have to do is just not transform into Numpy (erase it detach().numpy()).
Then the underlying problem is how to deal with a custom loss. The simplest way is to create your own custom function inverse and call it inside your code. You just have to rewrite using standard torch operations functions, rather than use numpy operations. Something like this:
def inv_var(y1, y2):
       y_hat = torch.sum( (y_1/y_1.var() ), ( y_2/y_2.var()) ) /  torch.sum( (1 /y_1.var() ), ( 1/y_2.var())  )
return y_hat





Later on you need to write more complex loss functions I suggest:
http://pytorch.org/docs/notes/extending.html#extending-torch-autograd 1. However in this case I don´t see a necessity for it.
Cheers,