docstr: Test batched greedy decoding using non-batched decoding as a reference
docstr_tok: ["Test","batched","greedy","decoding","using","non-batched","decoding","as","a","reference"]
code: def test_batched_greedy_decoding_preserve_alignments(
      self, test_data_dir, loop_labels: bool
  ):
      """Test batched greedy decoding using non-batched decoding as a reference"""
      model, encoded, encoded_len = get_model_encoder_output(
          test_data_dir, "stt_en_conformer_transducer_small"
      )
  
      search_algo = greedy_decode.GreedyBatchedRNNTInfer(
          model.decoder,
          model.joint,
          blank_index=model.joint.num_classes_with_blank - 1,
          max_symbols_per_step=5,
          preserve_alignments=True,
          loop_labels=loop_labels,
      )
  
      etalon_search_algo = greedy_decode.GreedyRNNTInfer(
          model.decoder,
          model.joint,
          blank_index=model.joint.num_classes_with_blank - 1,
          max_symbols_per_step=5,
          preserve_alignments=True,
      )
  
      enc_out = encoded
      enc_len = encoded_len
  
      with torch.no_grad():
          hyps: list[rnnt_utils.Hypothesis] = search_algo(
              encoder_output=enc_out, encoded_lengths=enc_len
          )[0]
          hyp = decode_text_from_greedy_hypotheses(
              hyps, model.decoding
          )[0]
          etalon_hyps: list[rnnt_utils.Hypothesis] = etalon_search_algo(
              encoder_output=enc_out, encoded_lengths=enc_len
          )[0]
          etalon_hyp = decode_text_from_greedy_hypotheses(
              etalon_hyps, model.decoding
          )[0]
  
          assert hyp.alignments is not None
          assert etalon_hyp.alignments is not None
  
          assert hyp.text == etalon_hyp.text
          assert len(hyp.alignments) == len(etalon_hyp.alignments)
  
          for t in range(len(hyp.alignments)):
              t_u = []
              for u in range(len(hyp.alignments[t])):
                  logp, label = hyp.alignments[t][u]
                  assert torch.is_tensor(logp)
                  assert torch.is_tensor(label)
                  etalon_logp, etalon_label = etalon_hyp.alignments[t][
                      u
                  ]
                  assert label == etalon_label
                  assert torch.allclose(
                      logp, etalon_logp, atol=1e-4, rtol=1e-4
                  )
  
                  t_u.append(int(label))
  
imports: import os
  from functools import lru_cache
  import pytest
  import torch
  from omegaconf import DictConfig
  from nemo.collections.asr.models import ASRModel
  from nemo.collections.asr.modules import RNNTDecoder, RNNTJoint
  from nemo.collections.asr.parts.mixins import mixins
  from nemo.collections.asr.parts.submodules import rnnt_beam_decoding
  from nemo.collections.asr.parts.submodules import rnnt_greedy_decoding
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTBPEDecoding, RNNTDecoding, RNNTDecodingConfig
  from nemo.collections.asr.parts.utils import rnnt_utils
  from nemo.core.utils import numba_utils
  from nemo.core.utils.numba_utils import __NUMBA_MINIMUM_VERSION__
label_desc: Use image node_id 4 for calling the TestRNNTDecoding obj's underlying member method code with example usage: obj.test_batched_greedy_decoding_preserve_alignments(test_data_dir, loop_labels) without return types