Hi,
I’m writing a Pytorch CUDA extension, which processes a tensor point-wise.
As a tensor is recommended to be made contiguous before calling CUDA kernel, and I try to avoid calling tensor.contiguous() where possible.
One scenario is that a 3D tensor x is not contiguous, but x.view(-1) is contiguous, so in the Python code I try the following, which triggers the above “RuntimeError: No grad accumulator for a saved leaf!” error message.
class myfunc(Function):
    @staticmethod
    def forward(ctx, x):
        x = x.view(-1).contiguous() # this is what causes the error !
        ctx.save_for_backward(x)
        return mycppclass.forward(x)
        
    @staticmethod
    def backward(ctx, dy):
        return mycppclass.backward(dy.contiguous(), *ctx.saved_variables)

Any suggestions?
Thank you!