code: def test_lstm_with_attention_equal_simplenet(
      self, T, forward_only, gc, dc
  ):
      self.Tseq = [T, T // 2, T // 2 + T // 4, T, T // 2 + 1]
      workspace.ResetWorkspace()
      with core.DeviceScope(gc):
          print(
              "Run with device: {}, forward only: {}".format(
                  gc, forward_only
              )
          )
  
          workspace.FeedBlob(
              "seq_lengths",
              np.array([T] * self.batch_size, dtype=np.int32),
          )
          workspace.FeedBlob(
              "target",
              np.random.rand(
                  T, self.batch_size, self.hidden_dim
              ).astype(np.float32),
          )
          workspace.FeedBlob(
              "hidden_init",
              np.zeros(
                  [1, self.batch_size, self.hidden_dim],
                  dtype=np.float32,
              ),
          )
          workspace.FeedBlob(
              "cell_init",
              np.zeros(
                  [1, self.batch_size, self.hidden_dim],
                  dtype=np.float32,
              ),
          )
  
          model = model_helper.ModelHelper(name="lstm")
          model.net.AddExternalInputs(["input"])
  
          init_blobs = []
          (
              hidden_init,
              cell_init,
              encoder_outputs,
          ) = model.net.AddExternalInputs(
              "hidden_init", "cell_init", "encoder_outputs"
          )
  
          awec_init = model.net.AddExternalInputs(
              [
                  "initial_attention_weighted_encoder_context",
              ]
          )
          init_blobs.extend([hidden_init, cell_init])
  
          workspace.FeedBlob(
              awec_init,
              np.random.rand(
                  1, self.batch_size, self.encoder_dim
              ).astype(np.float32),
          )
          workspace.FeedBlob(
              encoder_outputs,
              np.random.rand(
                  1, self.batch_size, self.encoder_dim
              ).astype(np.float32),
          )
  
          outputs = rnn_cell.LSTMWithAttention(
              model=model,
              decoder_inputs="input",
              decoder_input_lengths="seq_lengths",
              initial_decoder_hidden_state=hidden_init,
              initial_decoder_cell_state=cell_init,
              initial_attention_weighted_encoder_context=awec_init,
              encoder_output_dim=self.encoder_dim,
              encoder_outputs=encoder_outputs,
              encoder_lengths=None,
              decoder_input_dim=self.input_dim,
              decoder_state_dim=self.hidden_dim,
              scope="",
              attention_type=AttentionType.Recurrent,
              forward_only=forward_only,
              outputs_with_grads=[0],
          )
          output = outputs[0]
  
          print(outputs)
          loss = model.AveragedLoss(
              model.SquaredL2Distance([output, "target"], "dist"),
              "loss",
          )
          # Add gradient ops
          if not forward_only:
              model.AddGradientOperators([loss])
  
          # init
          for init_blob in init_blobs:
              workspace.FeedBlob(
                  init_blob,
                  np.zeros(
                      [1, self.batch_size, self.hidden_dim],
                      dtype=np.float32,
                  ),
              )
  
          self._compare(model, forward_only)
  
file_path: pytorch/caffe2/python/operator_test/recurrent_net_executor_test.py
imports: from caffe2.proto import caffe2_pb2
  from caffe2.python import model_helper, workspace, core, rnn_cell, test_util
  from caffe2.python.attention import AttentionType
  import numpy
  import unittest
  import caffe2.python.hypothesis_test_util
  import hypothesis.strategies
  from hypothesis import given, settings
label_desc: Use image node_id 2 for calling the TestRNNExecutor obj's underlying member method code with example usage: obj.test_lstm_with_attention_equal_simplenet(T, forward_only, gc, dc) without return types