You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/07/16 20:20:36 UTC

[GitHub] jonomon opened a new issue #11772: load_parameters expecting parameters that don't exist

jonomon opened a new issue #11772: load_parameters expecting parameters that don't exist
URL: https://github.com/apache/incubator-mxnet/issues/11772
 
 
   Using the following code:
   
   ```python
   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()
               for _ in range(2):
                   lstm = mx.gluon.rnn.LSTM(200, 1, bidirectional=True)
                   lstm.collect_params().initialize(mx.init.Xavier(), ctx=ctx)
                   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.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")
   
       import pdb; pdb.set_trace();    
   
   ```
   
   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 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services