Implementation + Training of a special architecture

Yasser: <p>Hello !  <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=12" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"><br>
I have some questions to ask about this implementation below :<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/c/6c5ce6a6df8d6abf44fba0dde54f3618075b4322.png" data-download-href="https://discuss.pytorch.org/uploads/default/6c5ce6a6df8d6abf44fba0dde54f3618075b4322" title="Untitled Diagram"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6c5ce6a6df8d6abf44fba0dde54f3618075b4322_2_387x500.png" alt="Untitled Diagram" data-base62-sha1="fsCBApWuMW6LFR7pD4ES4slru2S" width="387" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6c5ce6a6df8d6abf44fba0dde54f3618075b4322_2_387x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6c5ce6a6df8d6abf44fba0dde54f3618075b4322_2_580x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6c5ce6a6df8d6abf44fba0dde54f3618075b4322_2_774x1000.png 2x" data-dominant-color="FAFAFA"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Untitled Diagram</span><span class="informations">1085×1401 29 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>As you can see it looks like a Sequence-to-one model, but in this case I have multiple and distinct LSTMs in the encoding part, each LSTM processes a part of the multivariate time series data I have in the input, and all the hidden states of these multiple LSTMs are concatenated and given as an input to the LSTM_ALL , and since I have a regression problem in this case I used the MAE Loss to train the model.<br>
My questions are :<br>
1- is this implementation of the 53 independent LSTMs is correct :</p>
<pre><code class="lang-auto">self.list_lstm_su = nn.ModuleList(
            [
                nn.LSTM(
                    self.input_dim_su,
                    hidden_dim_su,
                    layer_dim_su,
                    batch_first=True,
                    dropout=dropout,
                )
                for _ in range(53)
            ]
        )
</code></pre>
<p>2- If that’s correct, does this procedure below will work properly in the forward method and not cause some problems during backprop :</p>
<pre><code class="lang-auto">concat_hidden_states = torch.zeros(x.size(0),7, self.hidden_dim_su

        for i, lstm in enumerate(self.list_lstm_su):
            concat_result = torch.cat(
                (embed_days, x[:, :, np.r_[3:8, 8 + (i * 314) : 8 + (i + 1) * 314]]), 2
            )
            concat_result = concat_result.float()
            out, _ = lstm(
                concat_result,
                (h0_su.detach(), c0_su.detach()),
            )

            concat_hidden_states = torch.cat((concat_hidden_states, out), 2)
</code></pre>
<p>3- My last question is about the implementation itself, I think that this loss function doesn’t reflect the problem I’m trying to optimize, because as you can see in the architecture, the target is composed of 159 values, each 3 successive value comes actually from one of the LSTMs in the encoding part so if let’s say  I have a predicted vector where 158 values are equal to the ones in the label, my error loss is still not equal to zero and the error will backpropagate through all the LSTMs but actually only one LSTM is doing something wrong, because I still need one value to be equal to the one in label.<br>
Thank you very much for your help <img src="https://discuss.pytorch.org/images/emoji/apple/smile.png?v=12" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/smile.png?v=12" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>