Thank you very much for your help.
I realize I wasn’t very clear. The forward pass on this operations is fine (although you’re right, I can save a few hundred Mb) but the backward pass is problematic. The memory usages I gave to you were observed during the backward pass. I suspect it does operations somehow quadratic in pred size, but I don’t know any workaround, and I’m going to need to save much more than a few hundreds Mb to make it fit on my 12Gb gpu. Do you know how to save memory for the backward pass in this case ? I’m not against any solution which trades memory for time