GitHub-HongweiZhang / prediction-flow

Deep-Learning based CTR models implemented by PyTorch
MIT License
250 stars 52 forks source link

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

Closed Jeriousman closed 2 years ago

Jeriousman commented 2 years ago

Describe the bug When I run DIEN model, I get this error. I tried lengths.cpu(), lengths.to('cpu') but none of them work. Would you provide a solution for this?

DIEN_augru
HBox(children=(FloatProgress(value=0.0, description='training routine', max=2.0, style=ProgressStyle(descripti…
HBox(children=(FloatProgress(value=0.0, description='train', max=8486.0, style=ProgressStyle(description_width…
HBox(children=(FloatProgress(value=0.0, description='valid', max=947.0, style=ProgressStyle(description_width=…
GPU is available, transfer model to GPU.
Traceback (most recent call last):

  File "<ipython-input-47-cf075d4611bd>", line 18, in <module>
    scores1, model_loss_curves1 = run(models)

  File "<ipython-input-47-cf075d4611bd>", line 9, in run
    train_loader, valid_loader, notebook=True, auxiliary_loss_rate=1)

  File "/home/hojun/anaconda3/envs/ai/lib/python3.6/site-packages/prediction_flow/pytorch/functions.py", line 57, in fit
    pred = model(batch)

  File "/home/hojun/anaconda3/envs/ai/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)

  File "/home/hojun/anaconda3/envs/ai/lib/python3.6/site-packages/prediction_flow/pytorch/dien.py", line 100, in forward
    query, pos_hist, keys_length, neg_hist))

  File "/home/hojun/anaconda3/envs/ai/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)

  File "/home/hojun/anaconda3/envs/ai/lib/python3.6/site-packages/prediction_flow/pytorch/nn/interest.py", line 235, in forward
    enforce_sorted=False)

  File "/home/hojun/anaconda3/envs/ai/lib/python3.6/site-packages/torch/nn/utils/rnn.py", line 244, 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

Additional context Pytorch 1.7.1v

GitHub-HongweiZhang commented 2 years ago

sorry for that. The lib doesn't support torch 1.7.x

GitHub-HongweiZhang commented 2 years ago

the same issue as https://github.com/GitHub-HongweiZhang/prediction-flow/issues/35

Jeriousman commented 2 years ago

Thank you for your prompt reply. Okay then pytorch version should be the problem. Thank you!

Jeriousman commented 2 years ago

Well, I upgraded to 1.8.1-cu101 pytorch, but it is still not working. Can you tell me which version should I have to make it work?

GitHub-HongweiZhang commented 2 years ago

I think it should work at 1.4.x. sorry, I am too busy recently. I don't have time to update it.