BentoML icon indicating copy to clipboard operation
BentoML copied to clipboard

bug: AttributeError in LSTM when loading model

Open cprocak3 opened this issue 2 years ago • 1 comments
trafficstars

Describe the bug

I am getting the following error when loading a model:

Traceback (most recent call last): File "example.py", line 4, in model = SequenceTagger.load('ner-ontonotes-fast') File "/miniconda3/envs/py38/lib/python3.8/site-packages/flair/nn.py", line 88, in load state = torch.load(f, map_location='cpu') File "/miniconda3/envs/py38/lib/python3.8/site-packages/torch/serialization.py", line 815, in load return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) File "/miniconda3/envs/py38/lib/python3.8/site-packages/torch/serialization.py", line 1043, in _legacy_load result = unpickler.load() File "/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/rnn.py", line 325, in setstate for w in self._flat_weights] File "miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1614, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'LSTM' object has no attribute '_flat_weights'

To reproduce

  1. Paste the following in a file (example.py) `import bentoml from flair.models import SequenceTagger

model = SequenceTagger.load('ner-ontonotes-fast') model_tag = bentoml.picklable_model.save_model('bento-ner', model)`

  1. Run python example.py
  2. Error will be outputted

Expected behavior

A bento should be created which can be later containerized with docker.

Environment

bentoml: 1.0.16 flair: 0.8 python: 3.8

cprocak3 avatar Mar 30 '23 13:03 cprocak3

For models from flair, we'd recommend using a custom Runnable implementation instead of the Pickable module: https://docs.bentoml.com/en/latest/concepts/runner.html#custom-runner

parano avatar Oct 31 '23 18:10 parano