C10::error "cudnn filters (a.k.a. weights) must be contiguous in memory_format

My code works fine on one thread, but as soon as I use multiple threads for inference, the c10 error from the title is thrown from time to time. I have no idea what it means and why my weights would not be contiguous. I am using torch::NoGradGuard during every evaluation.

The net I am using is a fairly standard convnet.

I assume the error is raised here, which would point to the input tensor, which isn’t contiguous in memory.
I don’t know how you are using multiple threads but would check if you are passing valid tensors around.

1 Like

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 :slight_smile: