where is your forward? Do you want something like this:
class SuperpixelPooling(nn.Module):
  def __init__(self. input, mask, output):
        super(SuperpixelPooling, self).__init__()
        self.register_buffer('mask', torch.zeros([2222]))
        # do nothing 
        # return nothing
   def forward(self, input):
        mask = self.mask
        output,new_mask  = do_superpixel_pooling(input,mask)
        self.mask = new_mask
        return output