Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

ENAS bug IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) #2091

Closed
marsggbo opened this issue Feb 23, 2020 · 2 comments · Fixed by #2107
Closed
Assignees
Labels

Comments

@marsggbo
Copy link
Contributor

In ENAS example, when lstm_num_layers=1, the code can run successfully. However, when I set lstm_num_layers=2, then it raises the following error: IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

@marsggbo
Copy link
Contributor Author

I solve this problem by modifying the output shape in the forward function, as below:

class StackedLSTMCell(nn.Module):
    def __init__(self, layers, size, bias):
        super().__init__()
        self.lstm_num_layers = layers
        self.lstm_modules = nn.ModuleList([nn.LSTMCell(size, size, bias=bias)
                                           for _ in range(self.lstm_num_layers)])

    def forward(self, inputs, hidden):
        prev_c, prev_h = hidden
        next_c, next_h = [], []
        for i, m in enumerate(self.lstm_modules):
            curr_c, curr_h = m(inputs, (prev_c[i], prev_h[i]))
            next_c.append(curr_c)
            next_h.append(curr_h)
            inputs = curr_h[-1].view(1,-1) # here
        return next_c, next_h

@ultmaster
Copy link
Contributor

Great! Since you've solved the problem, would you like to submit a pull request? Thanks.

@scarlett2018 scarlett2018 added user raised good first issue Good for newcomers bug Something isn't working labels Feb 24, 2020
@scarlett2018 scarlett2018 linked a pull request Feb 28, 2020 that will close this issue
ultmaster pushed a commit that referenced this issue Feb 29, 2020
* fix EnasMutator LSTMCell forward bug

fix issue #2091

* add comment

Co-authored-by: QuanluZhang <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants