Hi,
This error has been improved on master. If you use a nightly built, it should raise an error directly at the place where the faulty inplace op is 
This happens because you modify inplace a view of a leaf Tensor and such inplace op is not allowed. In this case I guess this is your z.
Note that if you don’t actually need the .grad field on z, you can create it with requires_grad=False and that should solve the error.