Hi,
The error message mentions python function because you were using python, but it is not specific to python. So moving to cpp won’t bring you any benefit. In general, for autograd related tasks, you can do everything from python.
Note though that this has been updated in master and this error does not exist anymore.
But your custom function is still missing calls to mark_dirty() as it is modifying some inputs inplace.
And because you modify input inplace, you need to return it as is but here you return a view of it. So that won’t work properly.
The problem here is that buffer is modified inplace by your function. But this buffer that is the input to the next Linear is also saved by that Linear because it needs its value for backward. So if you reuse the buffer again later, the previous linear won’t have access to the value it needs to compute the backward. And so you will go back to the original issue that you cannot change the buffer inplace because it is needed.