Thank you. This works as I requested.
Unfortunately the Backwards pass does not work anymore:
RuntimeError: leaf variable has been moved into the graph interior
Do you have a suggestion on how to overcome this issue?