def METHOD_NAME(self, x, padding_mask):
    if padding_mask is None or padding_mask.size(1) == x.size(1):
        return padding_mask
    diff = self.downsample - padding_mask.size(1) % self.downsample
    if 0 < diff < self.downsample:
        padding_mask = F.pad(padding_mask, (0, diff), value=True)
    padding_mask = padding_mask.view(padding_mask.size(0), -1, self.downsample)
    padding_mask = padding_mask.all(-1)
    if padding_mask.size(1) > x.size(1):
        padding_mask = padding_mask[:, : x.size(1)]
    assert x.size(1) == padding_mask.size(
        1
    ), f"{x.size(1), padding_mask.size(1), diff, self.downsample}"
    return padding_mask