sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

Using MXNet LSTM with SageMaker

Open aodhan-domhnaill opened this issue 8 years ago • 2 comments

Going off of the MNIST Example for MXNet, I need to have a function like,

def save(net, model_dir):
    # save the model
    y = net(mx.sym.var('data'))
    y.save('%s/model.json' % model_dir)
    net.collect_params().save('%s/model.params' % model_dir)

But, if I try this with an LSTM I get an error. The minimal code to reproduce the bug is,

import mxnet as mx
from mxnet import gluon

net = gluon.rnn.LSTM(100)
net(mx.sym.var('dats'))

which gives,

$ python shape_error.py 
Traceback (most recent call last):
  File "shape_error.py", line 5, in <module>
    net(mx.sym.var('dats'))
  File "/usr/local/lib/python3.6/site-packages/mxnet/gluon/block.py", line 304, in __call__
    return self.forward(*args)
  File "/usr/local/lib/python3.6/site-packages/mxnet/gluon/rnn/rnn_layer.py", line 173, in forward
    batch_size = inputs.shape[self._layout.find('N')]
AttributeError: 'Symbol' object has no attribute 'shape'

How do I solve this?

aodhan-domhnaill avatar Jan 20 '18 00:01 aodhan-domhnaill

I'm looking into this issue and will respond here with updates.

owen-t avatar Jan 22 '18 17:01 owen-t

@aidan-plenert-macdonald this is more of an mxnet usage issue than a SageMaker one. I've updated your mxnet issue with a suggested workaround and will close this ticket.

jesterhazy avatar Jan 25 '18 19:01 jesterhazy