ljynlp/W2NER

Is it possible to run W2NER on CPU?

Bzrm opened this issue · 2 comments

Bzrm commented

I'm trying to run W2NER on CPU with frozen transformer weights. I've already frozen the layers and checked it on GPU and it works. But after changing to CPU and modifying all .cuda() to .cpu() or .to('cpu') in main.py I'm facing the problem - loss becomes nan after first epoch of training. Can you please explain how to modify your code to make it run on CPU?

I have no idea what causes the issue because I've run W2NER on CPU and it worked when I modified all .cuda() to .cpu(). You can try to run W2NER with a few data on CPU and look out which layer or instance produced nan.

Hello and thx a lot for sharing this awesome project!

I also faced problems after modifying .cuda() to .cpu(). Besides this I didn't have any other amendment. I downloaded your processed data "resume-zh" and simply used " python3 main.py --config ./config/resume-zh.json ".

Any suggestion please? I put the information below. The key problem is that no evaluation results of the entities are generated.

=================
2022-11-28 19:07:54 - INFO: Building Model
Some weights of the model checkpoint at bert-base-chinese were not used when initializing BertModel: ['cls.predictions.transform.LayerNorm.bias', 'cls.predictions.transform.dense.bias', 'cls.predictions.transform.dense.weight', 'cls.predictions.transform.LayerNorm.weight', 'cls.seq_relationship.weight', 'cls.predictions.bias', 'cls.seq_relationship.bias', 'cls.predictions.decoder.weight']

  • This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
  • This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transformers/optimization.py:310: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set no_deprecation_warning=True to disable this warning
    FutureWarning,
    2022-11-28 19:08:01 - INFO: Epoch: 0
    [W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
    [W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
    [W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
    [W ParallelNative.cpp:229] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/metrics/_classification.py:1318: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use zero_division parameter to control this behavior.
    _warn_prf(average, modifier, msg_start, len(result))
    2022-11-29 00:56:13 - INFO: EVAL Label F1 [0.99353707 0. 0. 0. 0. 0.
  1.     0.         0.         0.        ]
    

2022-11-29 00:56:13 - INFO:
+--------+--------+-----------+--------+
| EVAL 0 | F1 | Precision | Recall |
+--------+--------+-----------+--------+
| Label | 0.0994 | 0.0987 | 0.1000 |
| Entity | 0.0000 | 0.0000 | 0.0000 |
+--------+--------+-----------+--------+