def METHOD_NAME(
    self,
    x: torch.Tensor,
    x_lens: torch.Tensor,
    ctc_output: torch.Tensor,
    y_lens: Optional[torch.Tensor] = None,
    blank_id: int = 0,
) -> Tuple[torch.Tensor, torch.Tensor]:
    """
    Args:
        x:
          The shared encoder output with shape [N, T, C].
        x_lens:
          A tensor of shape (batch_size,) containing the number of frames in
          `x` before padding.
        ctc_output:
          The CTC output with shape [N, T, vocab_size].
        y_lens:
          A tensor of shape (batch_size,) containing the number of frames in
          `y` before padding.
        blank_id:
          The blank id of ctc_output.
    Returns:
        out:
          The frame reduced encoder output with shape [N, T', C].
        out_lens:
          A tensor of shape (batch_size,) containing the number of frames in
          `out` before padding.
    """
    N, T, C = x.size()
    padding_mask = make_pad_mask(x_lens, x.size(1))
    non_blank_mask = (ctc_output[:, :, blank_id] < math.log(self.blank_threshlod)) * (~padding_mask) # noqa
    if y_lens is not None:
        # Limit the maximum number of reduced frames
        limit_lens = T - y_lens
        max_limit_len = limit_lens.max().int()
        fake_limit_indexes = torch.topk(
            ctc_output[:, :, blank_id], max_limit_len
        ).indices
        T = (
            torch.arange(max_limit_len)
            .expand_as(
                fake_limit_indexes,
            )
            .to(device=x.device)
        )
        T = torch.remainder(T, limit_lens.unsqueeze(1))
        limit_indexes = torch.gather(fake_limit_indexes, 1, T)
        limit_mask = torch.full_like(
            non_blank_mask,
            False,
            device=x.device,
        ).scatter_(1, limit_indexes, True)
        non_blank_mask = non_blank_mask | ~limit_mask
    out_lens = non_blank_mask.sum(dim=1)
    max_len = out_lens.max()
    pad_lens_list = (
        torch.full_like(
            out_lens,
            max_len.item(),
            device=x.device,
        )
        - out_lens
    )
    max_pad_len = pad_lens_list.max()
    out = F.pad(x, (0, 0, 0, max_pad_len))
    valid_pad_mask = ~make_pad_mask(pad_lens_list)
    total_valid_mask = torch.concat([non_blank_mask, valid_pad_mask], dim=1)
    out = out[total_valid_mask].reshape(N, -1, C)
    return out, out_lens