code: def _step(self) -> bool:
      # Generate the next step output.
      model_output = self._decode(
          self.seqs[:, self.step_nr - 1 : self.step_nr]
      )
  
      self.state_bag.increment_step_nr()
  
      logits = model_output.logits
  
      if self.temperature != 1.0:
          logits /= self.temperature
  
      # (N, 1, V)
      lprobs = log_softmax(logits, dim=-1, dtype=torch.float32)
  
      # (N, 1, V) -> (N, V)
      lprobs.squeeze_(1)
  
      if lprobs.isnan().any():
          raise RuntimeError(
              f"The model has produced one or more NaN probabilities at step {self.step_nr}. The sequence generator cannot continue."
          )
  
      # If we are generating the last possible step, force it to be EOS
      # regardless of its score.
      if self.step_nr == self.max_seq_len - 1:
          lprobs[:, : self.eos_idx]       = -torch.inf  # fmt: skip
          lprobs[:,   self.eos_idx + 1 :] = -torch.inf  # fmt: skip
      else:
          # Process `lprobs` in-place if requested.
          for processor in self.step_processors:
              processor(
                  self.seqs[:, : self.step_nr], lprobs, lprob=True
              )
  
          # Apply UNK penalty.
          if self.unk_idx is not None:
              lprobs[:, self.unk_idx] -= self.unk_penalty
  
          # Never allow PAD.
          if self.pad_idx is not None:
              lprobs[:, self.pad_idx] = -torch.inf
  
          # Do not allow EOS till we reach the minimum sequence length.
          if self.step_nr < self.min_seq_len - 1:
              lprobs[:, self.eos_idx] = -torch.inf
  
      batch_offset = 0
  
      new_beam_sizes: List[int] = []
  
      beam_next_step_list: List[BeamStep] = []
  
      # We split the batch by `beam_sizes` and treat each beam separately.
      for beam_idx, (beam_lprobs, beam_step_scores) in enumerate(
          zip(
              lprobs.split(self.beam_sizes),
              self.step_scores.split(self.beam_sizes),
          )
      ):
          beam_next_step = self._search_beam(
              beam_idx, batch_offset, beam_lprobs, beam_step_scores
          )
  
          # Bump the beam batch offset to the next beam.
          batch_offset += self.beam_sizes[beam_idx]
  
          # Check if the beam is terminated.
          if beam_next_step is None:
              continue
  
          beam_size = len(beam_next_step.seq_indices)
  
          # We should have terminated the beam if there are no sequences.
          assert beam_size > 0
  
          new_beam_sizes.append(beam_size)
  
          beam_next_step_list.append(beam_next_step)
  
      # No beam left, we can return.
      if len(new_beam_sizes) == 0:
          return False
  
      self.beam_sizes = new_beam_sizes
  
      # (N_new)
      next_step = BeamStep.merge(beam_next_step_list)
  
      self._reorder_state(next_step.seq_indices)
  
      # Record the current step.
      self.seqs[:, self.step_nr] = next_step.vocab_indices
  
      # Record the scores of the current step.
      self.step_scores[:, self.step_nr] = next_step.scores
  
      if self.step_hooks:
          seqs = self.seqs[:, : self.step_nr + 1]
  
          step_scores = self.step_scores[:, : self.step_nr + 1]
  
          for hook in self.step_hooks.values():
              hook(
                  self.prompt_indices, seqs, step_scores, prefill=False
              )
  
      return True
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Dict, List, Optional, Sequence, Tuple, Union, final
  import torch
  from torch import Tensor
  from torch.nn.functional import log_softmax
  from fairseq2.data import VocabularyInfo
  from fairseq2.generation.generator import Hypothesis, Seq2SeqGenerator, Seq2SeqGeneratorOutput, SequenceGenerator, SequenceGeneratorOutput, StepHook
  from fairseq2.generation.step_processor import StepProcessor
  from fairseq2.models.decoder import DecoderModel
  from fairseq2.models.encoder_decoder import EncoderDecoderModel
  from fairseq2.models.sequence import SequenceModelOutput
  from fairseq2.nn.incremental_state import IncrementalStateBag
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.typing import finaloverride, override
label_desc: Use image node_id 5 for calling the _BeamSearchSequenceGeneratorOpBase obj's underlying member method code with example usage: obj._step() and returns: True, False