docstr: This test might seem trivial. However, interacting with the scripted
  sequence generator crosses the Torchscript boundary, which can lead
  to weird behavior. If the incremental states don't get properly
  reset, the model will produce garbage _after_ the first call, which
  is a pain to debug when you only catch it after training.
docstr_tok: ["This","test","might","seem","trivial",".","However",",","interacting","with","the","scripted","sequence","generator","crosses","the","Torchscript","boundary",",","which","can","lead","to","weird","behavior",".","If","the","incremental","states","do","n't","get","properly","reset",",","the","model","will","produce","garbage","_after_","the","first","call",",","which","is","a","pain","to","debug","when","you","only","catch","it","after","training","."]
code: def test_reset_incremental_states(self):
      """
      This test might seem trivial. However, interacting with the scripted
      sequence generator crosses the Torchscript boundary, which can lead
      to weird behavior. If the incremental states don't get properly
      reset, the model will produce garbage _after_ the first call, which
      is a pain to debug when you only catch it after training.
      """
      tensorizers = get_tensorizers()
  
      # Avoid numeric issues with quantization by setting a known seed.
      torch.manual_seed(42)
  
      model = Seq2SeqModel.from_config(
          Seq2SeqModel.Config(
              source_embedding=WordEmbedding.Config(embed_dim=512),
              target_embedding=WordEmbedding.Config(embed_dim=512),
          ),
          tensorizers,
      )
  
      # Get sample inputs using a data source.
      schema = {
          "source_sequence": str,
          "dict_feat": Gazetteer,
          "target_sequence": str,
      }
      data = Data.from_config(
          Data.Config(
              source=TSVDataSource.Config(
                  train_filename=TEST_FILE_NAME,
                  field_names=[
                      "source_sequence",
                      "dict_feat",
                      "target_sequence",
                  ],
              )
          ),
          schema,
          tensorizers,
      )
      data.batcher = Batcher(1, 1, 1)
      raw_batch, batch = next(
          iter(data.batches(Stage.TRAIN, load_early=True))
      )
      inputs = model.arrange_model_inputs(batch)
  
      model.eval()
      outputs = model(*inputs)
      pred, scores = model.get_pred(outputs, {"stage": Stage.TEST})
  
      # Verify that the incremental states reset correctly.
      decoder = model.sequence_generator.beam_search.decoder_ens
      decoder.reset_incremental_states()
      self.assertDictEqual(decoder.incremental_states, {"0": {}})
  
      # Verify that the model returns the same predictions.
      new_pred, new_scores = model.get_pred(
          outputs, {"stage": Stage.TEST}
      )
      self.assertEqual(new_scores, scores)
  
imports: import unittest
  import torch
  from pytext.common.constants import Stage
  from pytext.data import Batcher
  from pytext.data.data import Data
  from pytext.data.sources.data_source import Gazetteer
  from pytext.data.sources.tsv import TSVDataSource
  from pytext.data.tensorizers import ByteTokenTensorizer, GazetteerTensorizer, initialize_tensorizers, TokenTensorizer
  from pytext.models.embeddings import ContextualTokenEmbedding, DictEmbedding, WordEmbedding
  from pytext.models.seq_models.rnn_encoder import LSTMSequenceEncoder
  from pytext.models.seq_models.rnn_encoder_decoder import RNNModel
  from pytext.models.seq_models.seq2seq_model import Seq2SeqModel
  from pytext.utils.test import import_tests_module
label_desc: Use image node_id 2 for calling the Seq2SeqModelEvalTests obj's underlying member method code with example usage: obj.test_reset_incremental_states() without return types