I'm getting the error " Expected a proper Tensor but got None (or an undefined Tensor in C++) for argument #0" while optimizing in my libtorch code

Could you check the stacktrace via gdb to see which line of code is raising the error and which tensor might be undefined? I don’t see any obvious issues in your code so far.