allanj / ner_incomplete_annotation

125 stars 33 forks source link

Cannot train on GPU #8

Closed mjstrobl closed 3 years ago

mjstrobl commented 3 years ago

Hi,

I tried to run main.py with the cuda:0 device, but I always get this error:

RuntimeError: 'lengths' argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

Do you have an idea what could cause that? I couldn't figure it out. CPU training works fine.

Thanks!

allanj commented 3 years ago

This is caused by the update of PyTorch.

You can set it to cpu tensor for length https://github.com/allanj/ner_incomplete_annotation/blob/master/model/bilstm_encoder.py#L69 For this one, replace char_seq_lens with char_seq_lens.cpu()

https://github.com/allanj/ner_incomplete_annotation/blob/master/model/bilstm_encoder.py#L79 For this one, replace sorted_seq_len with sorted_seq_len.cpu()