Similar issue with me. Here is my snippet:
        self.scorer = nn.Linear(hidden_dim, 1)
        mat = []
        for i in range(seq2_len):
            temp = []
            for j in range(seq1_len):
                seq2_state = sequence2_[:,i,:]
                seq1_state = sequence1_[:,j,:]
                diff = self.scorer(T.abs(seq1_state - seq2_state)).squeeze()
                temp.append(diff)
            temp = T.stack(temp)
            mat.append(temp)
            
        mat = T.stack(mat)
        mat = T.transpose(T.transpose(mat, 2, 0), 2, 1)

Can you please help me?