Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

load_parameters expecting parameters that don't exist #11772

Closed
jonomon opened this issue Jul 16, 2018 · 2 comments · Fixed by #11776
Closed

load_parameters expecting parameters that don't exist #11772

jonomon opened this issue Jul 16, 2018 · 2 comments · Fixed by #11776

Comments

@jonomon
Copy link

jonomon commented Jul 16, 2018

Using the following code:

import numpy as np
import mxnet as mx
from mxnet import nd, autograd, gluon

ctx = mx.gpu(0)

class Network(gluon.Block):
    def __init__(self, **kwargs):
        super(Network, self).__init__(**kwargs)
        with self.name_scope():
            self.encoders = gluon.nn.Sequential()
            with self.encoders.name_scope():
                for _ in range(2):
                    lstm = mx.gluon.rnn.LSTM(200, 1, bidirectional=True)
                    self.encoders.add(lstm)

    def forward(self, x):
        for i in range(2):
            x = self.encoders[i](x)
        return x

if __name__ == "__main__":
    net = Network()
    net.initialize(mx.init.Xavier(), ctx=ctx)
    net.hybridize()
    x = np.random.rand(32, 10, 10)
    x = nd.array(x).as_in_context(ctx)
    
    net(x)

    ## Working
    # net.save_params("tmp.params")

    # net2 = Network()
    # net2.load_params("tmp.params")

    ## NOT WORKING
    net.save_parameters("tmp.params")

    net2 = Network()
    net2.load_parameters("tmp.params")

where multiple LSTMs are added into gluon.nn,sequential, the function load_parameters crashes with the error message:

AssertionError: Parameter 'encoders.0.network1_lstm0_l0_i2h_weight' is missing in file 'tmp.params', which contains parameters: 'encoders.0.network0_lstm0_l0_i2h_weight', 'encoders.0.network0_lstm0_r0_i2h_weight', 'encoders.0.network0_lstm0_l0_h2h_weight', ..., 'encoders.1._unfused.0.r_cell.i2h_weight', 'encoders.1._unfused.0.r_cell.h2h_weight', 'encoders.1._unfused.0.r_cell.i2h_bias', 'encoders.1._unfused.0.r_cell.h2h_bias'. Set allow_missing=True to ignore missing parameters.

Note that there is no error when save_params and load_params was used.

Environment info (Required)

  • mxnet: 1.3.0
  • Ubuntu 16.04.4 LTS
  • Python version 3.6

@piiswrong

@anirudh2290
Copy link
Member

tested that on 1.2.1 this works fine.

@safrooze safrooze mentioned this issue Jul 17, 2018
6 tasks
@safrooze
Copy link
Contributor

Looks like the change in #10989 introduces this regression. This change is not included in 1.2.0 or 1.2.1.

@szha szha mentioned this issue Jul 17, 2018
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants