nnsum icon indicating copy to clipboard operation
nnsum copied to clipboard

Test problem

Open CrystalWLH opened this issue 5 years ago • 8 comments

I have trained the model using given command, when I use the given command of testing, I have encountered the following problem. AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings'

CrystalWLH avatar Apr 30 '19 03:04 CrystalWLH

Can you give me the whole error message and the exact command you are running? Thanks!

On Mon, Apr 29, 2019, 11:21 PM CrystalWLH [email protected] wrote:

I have trained the model using given command, when I use the given command of testing, I have encountered the following problem. AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kedz/nnsum/issues/7, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZOM36DCAZL3ER5IS5ACDPS63LLANCNFSM4HJIHGKQ .

kedz avatar Apr 30 '19 03:04 kedz

My training command is python script_bin/train_model.py \ --trainer --train-inputs 'data/inputs/train/' \ --train-labels 'data/labels/train/' \ --valid-inputs 'data/inputs/valid/' \ --valid-labels 'data/labels/valid/' \ --valid-refs 'data/human/valid/' \ --weight \ --epochs 50 \ --gpu 3 \ --model 'result/model' \ --results 'result/valid_score' \ --seed 12345678 \ --emb --embedding-size 200 \ --enc cnn \ --ext s2s --bidirectional My testing command is python script_bin/eval_model.py \ --inputs 'data/inputs/test/' \ --refs 'data/human/test/' \ --model 'result/model.pth' \ --results 'result/exp1/test_score' \ --summary-length 100 \ --batch-size 32

The error message is Loading model...Traceback (most recent call last): File "script_bin/eval_model.py", line 92, in <module> main() File "script_bin/eval_model.py", line 41, in main vocab = model.embeddings.vocab AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings'

CrystalWLH avatar Apr 30 '19 03:04 CrystalWLH

Thanks! Can you run the following commands and send me the output:

import torch
model = torch.load("result/model.pth", map_location=lambda storage, loc: storage)
print(model)

kedz avatar May 01 '19 03:05 kedz

The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here).

To fix, change the nnsum code here from:

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name)

to

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name, 
                                 save_as_state_dict=False)

markusdr avatar May 13 '19 22:05 markusdr

Hello, I used AMI dataset to test the code without GPU, and I met this problem:

INFO:root: Model parameter initialization finished.

INFO:ignite.engine.engine.Engine:Engine run starting with max_epochs=50.
INFO:ignite.engine.engine.Engine:Epoch[1] Complete. Time taken: 00:00:00
ERROR:ignite.engine.engine.Engine:Engine run is terminating due to exception: Loss must have at least one example before it can be computed.
Traceback (most recent call last):
  File "script_bin/train_model.py", line 79, in <module>
    main()
  File "script_bin/train_model.py", line 76, in main
    results_path=args["trainer"]["results"])
  File "/home/constant/anaconda3/lib/python3.7/site-packages/nnsum-1.0-py3.7.egg/nnsum/trainer/labels_mle_trainer.py", line 164, in labels_mle_trainer
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 359, in run
    self._handle_exception(e)
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 324, in _handle_exception
    raise e
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 350, in run
    self._fire_event(Events.EPOCH_COMPLETED)
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/engine/engine.py", line 259, in _fire_event
    func(self, *(event_args + args), **kwargs)
  File "/home/constant/anaconda3/lib/python3.7/site-packages/ignite/metrics/metric.py", line 68, in completed
    result = self.compute()
  File "/home/constant/anaconda3/lib/python3.7/site-packages/nnsum-1.0-py3.7.egg/nnsum/metrics/loss.py", line 21, in compute
ignite.exceptions.NotComputableError: Loss must have at least one example before it can be computed

Is it the problem caused by not using GPU? Thanks for your help!

tlifcen avatar Aug 17 '19 02:08 tlifcen

The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here).

To fix, change the nnsum code here from:

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name)

to

    checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                                 require_empty=False, score_name=metric_name, 
                                 save_as_state_dict=False)

I changed the code as your suggestion, but the code does not work, either. There is still the following error: AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings' Do you have other methods to solve the problem? Thanks for your reply!

tlifcen avatar Sep 03 '19 05:09 tlifcen

Can you give me the versions of python, torch, and ignite that you are using, along with the commandline arguments you are using? I can't reproduce this error.

Thanks! Chris

On Tue, Sep 3, 2019 at 1:06 AM tlifcen [email protected] wrote:

The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here https://github.com/pytorch/ignite/commit/79e5233438d46ebfd205b7942866ccdcd990efda#diff-18cd1a3c06de70b0e34b8fcf32940b30 ).

To fix, change the nnsum code here https://github.com/kedz/nnsum/blob/master/nnsum/trainer/labels_mle_trainer.py#L244 from:

checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                             require_empty=False, score_name=metric_name)

to

checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func,
                             require_empty=False, score_name=metric_name,
                             save_as_state_dict=False)

I changed the code as your suggestion, but the code does not work, either. There is still the following error: AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings' Do you have other methods to solve the problem? Thanks for your reply!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kedz/nnsum/issues/7?email_source=notifications&email_token=ABAZOM4PUXUSAJT4QUFUQH3QHXWDNA5CNFSM4HJIHGK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5XAVXQ#issuecomment-527305438, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZOMZKVFULGHZTOLS3NPLQHXWDNANCNFSM4HJIHGKQ .

-- Chris Kedzie PhD Student, Dept. of Computer Science Columbia University email: [email protected] web: www.cs.columbia.edu/~kedzie

kedz avatar Sep 06 '19 04:09 kedz

Can you give me the versions of python, torch, and ignite that you are using, along with the commandline arguments you are using? I can't reproduce this error. Thanks! Chris On Tue, Sep 3, 2019 at 1:06 AM tlifcen @.***> wrote: The error comes because newer versions of ignite save model checkpoints as state_dict by default (see here <pytorch/ignite@79e5233#diff-18cd1a3c06de70b0e34b8fcf32940b30> ). To fix, change the nnsum code here https://github.com/kedz/nnsum/blob/master/nnsum/trainer/labels_mle_trainer.py#L244 from: checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func, require_empty=False, score_name=metric_name) to checkpoint = ModelCheckpoint(dirname, prefix, score_function=_score_func, require_empty=False, score_name=metric_name, save_as_state_dict=False) I changed the code as your suggestion, but the code does not work, either. There is still the following error: AttributeError: 'collections.OrderedDict' object has no attribute 'embeddings' Do you have other methods to solve the problem? Thanks for your reply! — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#7?email_source=notifications&email_token=ABAZOM4PUXUSAJT4QUFUQH3QHXWDNA5CNFSM4HJIHGK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5XAVXQ#issuecomment-527305438>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZOMZKVFULGHZTOLS3NPLQHXWDNANCNFSM4HJIHGKQ . -- Chris Kedzie PhD Student, Dept. of Computer Science Columbia University email: [email protected] web: www.cs.columbia.edu/~kedzie

I used python3.6.9, torch0.4.1 and ignite0.2.0. And the environment is Ubuntu 16.04 LTS. I used the following command to test the code:

python script_bin/eval_model.py \
  --inputs /home/constant/data/Constant-TL/dataset/summarization/nnsum/reddit/reddit/inputs/test \
  --refs /home/constant/data/Constant-TL/dataset/summarization/nnsum/reddit/reddit/human-extracts/test \
  --model ../dataset/summarization/nnsum/reddit_model_95_rouge-2=0.65826.pth \
  --results ../dataset/summarization/nnsum/reddit/test_score \
  --summary-length 100 

Thanks for your reply!

tlifcen avatar Oct 13 '19 01:10 tlifcen