Hello, nice topic !
Do you know if it is possible to change the value of the derivative of maxpooling in the backward fonction ? (@_ju and @albanD)
For example, if F is maxpool1d and x = (1,1,1) then F’(x) = (1/3,1/3,1/3).
class MyMaxPool1d(torch.autograd.Function):
@staticmethod
def forward(ctx, input, kernel_size): 
    """
    In the forward pass we receive a Tensor containing the input and return
    a Tensor containing the output. ctx is a context object that can be used
    to stash information for backward computation. You can cache arbitrary
        objects for use in the backward pass using the ctx.save_for_backward method.
""" 
    
    ctx.save_for_backward(input)
    m = nn.MaxPool1d(kernel_size, stride=1)
    output = m(input)
    return 3*output.sum()

@staticmethod
def backward(ctx, grad_output):
    
    input, = ctx.saved_tensors
    grad_input = grad_output.clone()
    return 2*grad_input, None

if name == ‘main’:
features =  torch.ones(1, 4, 4,requires_grad=True)
result = MyMaxPool1d.apply(features,3)
print(“features:”, features)
result.backward()
I have that error : RuntimeError: Function MyMaxPool1dBackward returned an invalid gradient at index 0 - got [] but expected shape compatible with [1, 4, 4]