@teja5832 Do you have an equivalent Python code that you successfully ran? Looking at the C++ code you shared there seems to be some issues (e.g. out.backward should be called with gradients). It would be best if we work out the correct logic in Python first, and then translate it to C++.