code: def test_encoder_no_repeat_ngram_dist_processor(self):
      vocab_size = 3
      num_beams = 2
      batch_size = 1
  
      encoder_input_ids = torch.tensor(
          [1, 2, 1, 1], device=torch_device, dtype=torch.long
      )
  
      input_ids = torch.tensor(
          [[1, 2, 1], [8, 0, 2]], device=torch_device, dtype=torch.long
      )
      scores = self._get_uniform_logits(
          batch_size * num_beams, vocab_size
      )
  
      no_repeat_proc_2_gram = EncoderNoRepeatNGramLogitsProcessor(
          2, encoder_input_ids=encoder_input_ids
      )
      no_repeat_proc_3_gram = EncoderNoRepeatNGramLogitsProcessor(
          3, encoder_input_ids=encoder_input_ids
      )
  
      filtered_scores_2_gram = no_repeat_proc_2_gram(
          input_ids, scores.clone()
      )
      filtered_scores_3_gram = no_repeat_proc_3_gram(
          input_ids, scores.clone()
      )
  
      # 2-gram would forbid 1st and 2nd token at 1st beam and 1st token (0) at 2nd beam
      self.assertListEqual(
          torch.isinf(filtered_scores_2_gram).tolist(),
          [[False, True, True], [False, True, False]],
      )
  
      # 3-gram would forbid 1st token at 1st beam and no token at 2nd beam
      self.assertListEqual(
          torch.isinf(filtered_scores_3_gram).tolist(),
          [[False, True, False], [False, False, False]],
      )
  
      # Batched input
      vocab_size = 3
      num_beams = 2
      batch_size = 2
      encoder_input_ids = torch.tensor(
          [[1, 2, 1, 1], [0, 0, 2, 1]],
          device=torch_device,
          dtype=torch.long,
      )
  
      input_ids = torch.tensor(
          [[1, 2, 1], [1, 0, 2], [0, 0, 0], [0, 2, 2]],
          device=torch_device,
          dtype=torch.long,
      )
      scores = self._get_uniform_logits(
          batch_size * num_beams, vocab_size
      )
  
      no_repeat_proc_2_gram = EncoderNoRepeatNGramLogitsProcessor(
          2, encoder_input_ids=encoder_input_ids
      )
      no_repeat_proc_3_gram = EncoderNoRepeatNGramLogitsProcessor(
          3, encoder_input_ids=encoder_input_ids
      )
  
      filtered_scores_2_gram = no_repeat_proc_2_gram(
          input_ids, scores.clone()
      )
      filtered_scores_3_gram = no_repeat_proc_3_gram(
          input_ids, scores.clone()
      )
  
      # 2gram
      # Batch 1
      #   - Beam 1: tokens (1, 2) forbidden
      #   - Beam 2: tokens (1) forbidden
      # Batch 2
      #   - Beam 1: tokens (0, 2) forbidden
      #   - Beam 2: tokens (1) forbidden
      self.assertListEqual(
          torch.isinf(filtered_scores_2_gram).tolist(),
          [
              [False, True, True],
              [False, True, False],
              [True, False, True],
              [False, True, False],
          ],
      )
  
      # Batch 1
      #   - Beam 1: tokens (1) forbidden
      #   - Beam 2: tokens () forbidden
      # Batch 2
      #   - Beam 1: tokens (2) forbidden
      #   - Beam 2: tokens () forbidden
      self.assertListEqual(
          torch.isinf(filtered_scores_3_gram).tolist(),
          [
              [False, True, False],
              [False, False, False],
              [False, False, True],
              [False, False, False],
          ],
      )
  
imports: import unittest
  from typing import List, Union
  from parameterized import parameterized
  from transformers import is_torch_available
  from transformers.testing_utils import require_torch, torch_device
  from ..test_modeling_common import ids_tensor
label_desc: Use image node_id 13 for calling the LogitsProcessorTest obj's underlying member method code with example usage: obj.test_encoder_no_repeat_ngram_dist_processor() without return types