mali19064 / LSTM-CRF-pytorch-faster

A more than 1000X faster paralleled LSTM-CRF implementation modified from the slower version in the Pytorch official tutorial (URL:https://pytorch.org/tutorials/beginner/nlp/advanced_tutorial.html).
204 stars 50 forks source link

RuntimeError when using torch.full() in PyTorch 1.7 #3

Open ghost opened 3 years ago

ghost commented 3 years ago

when I run LSTM_CRF_faster_parallel.py I meet this error:

Traceback (most recent call last):
    loss = model.neg_log_likelihood_parallel(sentence_in_pad, targets_pad)
  File ".\bi_lstm_crf_faster_parallel.py", line 306, in neg_log_likelihood_parallel
    gold_score = self._score_sentence_parallel(feats, tags)
    tags = torch.cat([torch.full([tags.shape[0],1],self.tag_to_ix[START_TAG]).long(),tags],dim=1)        
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out` arguments is currently unsupported. In PyTorch 1.7, when `dtype` and `out` are not set a bool fill value will return a tensor of torch.bool dtype, and an integral fill value will return a tensor of torch.long dtype.

as the latest doc says, I think line 201

tags = torch.cat([torch.full([tags.shape[0],1],self.tag_to_ix[START_TAG]).long(),tags],dim=1)

should be changed to

tags = torch.cat([torch.full([tags.shape[0],1],self.tag_to_ix[START_TAG], dtype=torch.long),tags],dim=1)

🤗

mali19064 commented 3 years ago

Thanks for your correction, this problem is caused by pytorch version update, i have modified the code according to your suggestion

codegodliu commented 3 years ago

How to manually deploy the GPU?