stanfordnlp / stanza

Stanford NLP Python library for tokenization, sentence segmentation, NER, and parsing of many human languages
https://stanfordnlp.github.io/stanza/
Other
7.29k stars 893 forks source link

Unexpected key(s) in state_dict: "SOS_tensor" on Apple M1 with torch #1216

Closed rjalexa closed 1 year ago

rjalexa commented 1 year ago

Describe the bug When launching my project on Apple M1 hardware I get the following error:

(isagog-ai-py3.10) (base) bob@Roberts-Mac-mini isagog-ai % python src/isagog_api/nlp_api.py
2023-03-14 16:05:29 INFO: Loading these models for language: it (Italian):
========================
| Processor | Package  |
------------------------
| tokenize  | combined |
| mwt       | combined |
| ner       | fbk      |
========================

2023-03-14 16:05:29 INFO: Use device: cpu
2023-03-14 16:05:29 INFO: Loading: tokenize
2023-03-14 16:05:29 INFO: Loading: mwt
Traceback (most recent call last):
  File "/Users/bob/Documents/work/code/isagog-ai/src/isagog_api/nlp_api.py", line 14, in <module>
    from isagog_ai.nlp_it import StanzaLanguageProcessorIt
  File "/Users/bob/Documents/work/code/isagog-ai/src/isagog_ai/nlp_it.py", line 29, in <module>
    "entity": stanza.Pipeline(
  File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/core.py", line 278, in __init__
    self.processors[processor_name] = NAME_TO_PROCESSOR_CLASS[processor_name](config=curr_processor_config,
  File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/processor.py", line 173, in __init__
    self._set_up_model(config, pipeline, use_gpu)
  File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/mwt_processor.py", line 21, in _set_up_model
    self._trainer = Trainer(model_file=config['model_path'], use_cuda=use_gpu)
  File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/models/mwt/trainer.py", line 36, in __init__
    self.load(model_file, use_cuda)
  File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/models/mwt/trainer.py", line 149, in load
    self.model.load_state_dict(checkpoint['model'])
  File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1671, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Seq2SeqModel:
    Unexpected key(s) in state_dict: "SOS_tensor".

Expected behavior Service launching just like with the exact same project on Intel.

Environment (please complete the following information):

AngledLuffa commented 1 year ago

This is not my experience. I have a Mac, and I can load the Italian pipeline just fine. Of course, there's the question of what versions are being run. I did this on a MacBook Air (M2, 2022), with an Apple M2 (not used because of pytorch mps bugs), OS version 12.6.3. Python 3.9.6, Stanza 1.5.0. So, my suggestion is that I'll try updating my OS, and you try updating Stanza, and we'll see if either of us gets different results.

On Tue, Mar 14, 2023 at 9:00 AM Robert Alexander @.***> wrote:

Describe the bug When launching my project on Apple M1 hardware I get the following error:

(isagog-ai-py3.10) (base) @.*** isagog-ai % python src/isagog_api/nlp_api.py 2023-03-14 16:05:29 INFO: Loading these models for language: it (Italian):

| Processor | Package |

| tokenize | combined | | mwt | combined | | ner | fbk |

2023-03-14 16:05:29 INFO: Use device: cpu 2023-03-14 16:05:29 INFO: Loading: tokenize 2023-03-14 16:05:29 INFO: Loading: mwt Traceback (most recent call last): File "/Users/bob/Documents/work/code/isagog-ai/src/isagog_api/nlp_api.py", line 14, in from isagog_ai.nlp_it import StanzaLanguageProcessorIt File "/Users/bob/Documents/work/code/isagog-ai/src/isagog_ai/nlp_it.py", line 29, in "entity": stanza.Pipeline( File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/core.py", line 278, in init self.processors[processor_name] = NAME_TO_PROCESSOR_CLASS[processor_name](config=curr_processor_config, File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/processor.py", line 173, in init self._set_up_model(config, pipeline, use_gpu) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/mwt_processor.py", line 21, in _set_up_model self._trainer = Trainer(model_file=config['model_path'], use_cuda=use_gpu) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/models/mwt/trainer.py", line 36, in init self.load(model_file, use_cuda) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/models/mwt/trainer.py", line 149, in load self.model.load_state_dict(checkpoint['model']) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1671, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Seq2SeqModel: Unexpected key(s) in state_dict: "SOS_tensor".

Expected behavior Service launching just like with the exact same project on Intel.

Environment (please complete the following information):

  • OS: MacOS Ventura 13.2.1
  • Python version: 3.10.9
  • Stanza version: 1.4.2

— Reply to this email directly, view it on GitHub https://github.com/stanfordnlp/stanza/issues/1216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2AYWNA43S72AMPETEP5Q3W4CI2TANCNFSM6AAAAAAV2URTZM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AngledLuffa commented 1 year ago

I can confirm that updating to Ventura 13.2.1 does not start causing problems for me running an Italian pipeline

On Tue, Mar 14, 2023 at 12:54 PM John Bauer @.***> wrote:

This is not my experience. I have a Mac, and I can load the Italian pipeline just fine. Of course, there's the question of what versions are being run. I did this on a MacBook Air (M2, 2022), with an Apple M2 (not used because of pytorch mps bugs), OS version 12.6.3. Python 3.9.6, Stanza 1.5.0. So, my suggestion is that I'll try updating my OS, and you try updating Stanza, and we'll see if either of us gets different results.

On Tue, Mar 14, 2023 at 9:00 AM Robert Alexander @.***> wrote:

Describe the bug When launching my project on Apple M1 hardware I get the following error:

(isagog-ai-py3.10) (base) @.*** isagog-ai % python src/isagog_api/nlp_api.py 2023-03-14 16:05:29 INFO: Loading these models for language: it (Italian):

| Processor | Package |

| tokenize | combined | | mwt | combined | | ner | fbk |

2023-03-14 16:05:29 INFO: Use device: cpu 2023-03-14 16:05:29 INFO: Loading: tokenize 2023-03-14 16:05:29 INFO: Loading: mwt Traceback (most recent call last): File "/Users/bob/Documents/work/code/isagog-ai/src/isagog_api/nlp_api.py", line 14, in from isagog_ai.nlp_it import StanzaLanguageProcessorIt File "/Users/bob/Documents/work/code/isagog-ai/src/isagog_ai/nlp_it.py", line 29, in "entity": stanza.Pipeline( File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/core.py", line 278, in init self.processors[processor_name] = NAME_TO_PROCESSOR_CLASS[processor_name](config=curr_processor_config, File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/processor.py", line 173, in init self._set_up_model(config, pipeline, use_gpu) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/pipeline/mwt_processor.py", line 21, in _set_up_model self._trainer = Trainer(model_file=config['model_path'], use_cuda=use_gpu) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/models/mwt/trainer.py", line 36, in init self.load(model_file, use_cuda) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/stanza/models/mwt/trainer.py", line 149, in load self.model.load_state_dict(checkpoint['model']) File "/Users/bob/Documents/work/code/isagog-ai/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1671, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Seq2SeqModel: Unexpected key(s) in state_dict: "SOS_tensor".

Expected behavior Service launching just like with the exact same project on Intel.

Environment (please complete the following information):

  • OS: MacOS Ventura 13.2.1
  • Python version: 3.10.9
  • Stanza version: 1.4.2

— Reply to this email directly, view it on GitHub https://github.com/stanfordnlp/stanza/issues/1216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2AYWNA43S72AMPETEP5Q3W4CI2TANCNFSM6AAAAAAV2URTZM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rjalexa commented 1 year ago

Thank you very much. I should have mentioned that I am running 1.5.0 and previously 1.4.2 italian tasks without problems too. I am starting to believe torch is the problem here since on those two projects I believe I was using only TF. Traveling now will report back later.

AngledLuffa commented 1 year ago

Is that backwards? We only use torch in our models, not TF.

rjalexa commented 1 year ago

You're right. In any case updating to Stanza 1.5.0 apparently fixed the problem, so I'd thank you and close.