After having ridden the how to 2 about extending autograd, I’m trying to do a little experiment:
from torch.autograd import Function
import torch

class MyCustomOp(Function):                            
                                                                
    @staticmethod                                               
    def forward(ctx, mat):                                      
        indices = mat.sum(2)                                    
        ctx.save_for_bacward(mat.shape, indices)                
        # just return something and save stuffs for later

        return indices                                          
                                                                
    @staticmethod                                               
    def backward(ctx, grad_indices):                            
        mat_shape, indices = ctx.saved_tensors                  
                                                                
        # just some random computation using saved tensors      
        grad_mat = indices[..., None].expand(mat_shape)         
        return grad_mat                                         

MyCustomOp.apply(torch.rand(10, 10, 10, 10))

However, I get: AttributeError: 'MyCustomOpBackward' object has no attribute 'save_for_bacward'
What’s wrong?
Torch version 1.4.0.