A bit late to the party, but I just created this:

class GlobalMaxPooling1D(nn.Module):
def __init__(self, data_format='channels_last'):
    super(GlobalMaxPooling1D, self).__init__()
    self.data_format = data_format
    self.step_axis = 1 if self.data_format == 'channels_last' else 2

def forward(self, input):
    return torch.max(input, axis=self.step_axis).values


Based on

  
      github.com
  
  
    keras-team/keras/blob/master/keras/layers/pooling.py#L557 11

            input_shape = K.int_shape(inputs)
            broadcast_shape = [-1, input_shape[steps_axis], 1]
            mask = K.reshape(mask, broadcast_shape)
            inputs *= mask
            return K.sum(inputs, axis=steps_axis) / K.sum(mask, axis=steps_axis)
        else:
            return K.mean(inputs, axis=steps_axis)


    def compute_mask(self, inputs, mask=None):
        return None




class GlobalMaxPooling1D(_GlobalPooling1D):
    """Global max pooling operation for temporal data.


    # Arguments
        data_format: A string,
            one of `"channels_last"` (default) or `"channels_first"`.
            The ordering of the dimensions in the inputs.
            `"channels_last"` corresponds to inputs with shape
            `(batch, steps, features)` while `"channels_first"`