Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when training at LSTM mode #41

Open
monilouise opened this issue Apr 15, 2022 · 3 comments
Open

Error when training at LSTM mode #41

monilouise opened this issue Apr 15, 2022 · 3 comments

Comments

@monilouise
Copy link

monilouise commented Apr 15, 2022

When I run the command:

run_bert_harem.py" --bert_model C:/bert-base-portuguese-cased --labels_file data/classes-selective.txt --do_train --train_file data/FirstHAREM-selective-train.json --valid_file data/FirstHAREM-selective-dev.json --freeze_bert --pooler sum --no_crf --num_train_epochs 100 --per_gpu_train_batch_size 2 --gradient_accumulation_steps 8 --do_eval --eval_file data/MiniHAREM-selective.json --output_dir output_bert-lstm_selective

the following error occurs:

Traceback (most recent call last):
File "(...)\portuguese-bert\ner_evaluation\run_bert_harem.py", line 129, in
main(load_and_cache_examples,
File "(...)\portuguese-bert\ner_evaluation\trainer.py", line 737, in main
train(
File "(...)\portuguese-bert\ner_evaluation\trainer.py", line 242, in train
outs = model(input_ids, segment_ids,
File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "(...)\portuguese-bert\ner_evaluation\model.py", line 483, in forward
lstm_out = self.forward_lstm(
File "(...)\portuguese-bert\ner_evaluation\model.py", line 439, in forward_lstm
packed_sequence, sorted_ixs = self._pack_bert_encoded_sequence(
File "(...)\portuguese-bert\ner_evaluation\model.py", line 403, in _pack_bert_encoded_sequence
packed_sequence = torch.nn.utils.rnn.pack_padded_sequence(
File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\utils\rnn.py", line 249, in pack_padded_sequence
_VF._pack_padded_sequence(input, lengths, batch_first)
RuntimeError: 'lengths' argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

What could be wrong? Why can't the training occur in a GPU environment?

@fabiocapsouza
Copy link
Contributor

Hi @monilouise, which version of Pytorch are you using? If you are not using 1.1.0 (version the code was written for), the function pack_padded_sequence inputs were changed to accept CPU tensor for the length argument. Add a .to('cpu') on forward_lstm method and it will probably work.

@monilouise
Copy link
Author

Hi @fabiocapsouza , my Pytorch version is 1.11.0.

I'll try your suggestion, thanks.

@fabiocapsouza
Copy link
Contributor

@monilouise Have you tried the suggestion? If you have, please let us know if it worked :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants