I’ve been doing some tests and I think I have been able to resolve the error. What I do now is calling .detach() on the output tensor before using .item<>() on it. This is very weird to me, as I used NoGradGuard AND as torch objects should be thread safe when reading anyways. The input tensors were valid and contiguous, I haven’t found any problems with them. I still don’t exactly know what the problem was, but at least it works now. Thank you for the tips