@yessyw
Correct me if I am wrong, what you want to do is to apply your calculated gradient to the original input tensor, right? If your gradient apply logic is not trivial, you can make your own optimizer, but if you just want to do simple operation, you can do it directly.
eg. if you want to add your gradient to input tensor, you can just do input + grad where input is your input tensor and grad is the calculated gradient. Same as what you do in python.