class_docstr: Prevents a provided list of banned sequences from being generated.
class_docstr_tok: ["Prevents","a","provided","list","of","banned","sequences","from","being","generated","."]
docstr: :param banned_seqs:
      The list of banned sequences.
docstr_tok: [":","param","banned_seqs",":","The","list","of","banned","sequences","."]
code: def __init__(self, banned_seqs: Sequence[Tensor]) -> None:
      """
      :param banned_seqs:
          The list of banned sequences.
      """
      batch_size = len(banned_seqs)
  
      if batch_size == 0:
          self._banned_seqs = None
          self._banned_mask = None
  
          return
  
      max_seq_len = 0
      min_seq_len = sys.maxsize
  
      seq_lens: List[int] = []
  
      for idx, seq in enumerate(banned_seqs):
          seq_len = len(seq)
          if seq_len == 0:
              raise ValueError(
                  f"`banned_seqs[{idx}]` must not be empty."
              )
  
          seq_lens.append(seq_len)
  
          max_seq_len = max(seq_len, max_seq_len)
          min_seq_len = min(seq_len, min_seq_len)
  
      device = banned_seqs[0].device
  
      # (N, S)
      self._banned_seqs = torch.zeros(
          (batch_size, max_seq_len), device=device, dtype=torch.int64
      )
  
      if max_seq_len != min_seq_len:
          # (N, S)
          self._banned_mask = torch.full(
              (batch_size, max_seq_len), True, device=device
          )
      else:
          self._banned_mask = None
  
      for row, seq in enumerate(banned_seqs):
          if self._banned_mask is None:
              self._banned_seqs[row] = seq
          else:
              self._banned_seqs[row, -seq_lens[row] :] = seq
              self._banned_mask[row, -seq_lens[row] :] = False
  
file_path: fairseq2/src/fairseq2/generation/step_processor.py
imports: import sys
  from abc import ABC, abstractmethod
  from typing import List, Optional, Sequence, final
  import torch
  from torch import Tensor
  from torch.nn.functional import pad
  from fairseq2.typing import finaloverride
label_desc: Use image node_id 1 to create a new BannedSequenceProcessor object from inherited base classes: StepProcessor with example: obj = BannedSequenceProcessor(banned_seqs)