As I aforementioned you don’t really need to create your custom backward if you can write ops in function of pytorch ops.
torch.max already provides proper backward. Obviously the gradients flow through those features which are maximum.
I don’t understand at all what do you mean by
Given  input  of shape  (1, 7) , I would like to perform MaxPooling, but not with a fixed window size, however on a custom set of windows. For example: [0, 1, 2], [1, 2, 3], [2, 4], [3, 5], [4, 5, 6].
Do you have a kernel size of 3 and then 2 and then3 again for a 2D input?
You can slide a kernel using torch.fold