Closed prabhakar267 closed 4 years ago
Hey @prabhakar267,
Sorry you're experiencing some issues. Can you tell me which version of pytorch you are using? I cannot reproduce the issue with openkiwi==0.1.2
and torch > 1.1
.
torch==1.4.0
Sorry for the late response. Unfortunately I haven't had the opportunity to test this. However I believe this issue has been fixed on #44. Can you try to install openkiwi from master?
I will test this shortly and tag a new version if my suspicions are confirmed.
@captainvera I installed from master branch, the error message changed
Traceback (most recent call last):
File "using_kiwi_gpu.py", line 50, in <module>
'target': target_texts
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/kiwi/predictors/predictor.py", line 106, in predict
return self.run(dataset, batch_size)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/kiwi/predictors/predictor.py", line 116, in run
model_pred = self.model.predict(batch)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/kiwi/models/model.py", line 119, in predict
model_out = self(batch)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/kiwi/models/predictor_estimator.py", line 324, in forward
model_out_tgt = self.predictor_tgt(batch)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/kiwi/models/predictor.py", line 243, in forward
source_embeddings = self.embedding_source(source)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/torch/nn/modules/sparse.py", line 114, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "/home/ubuntu/anaconda3/envs/kiwi/lib/python3.6/site-packages/torch/nn/functional.py", line 1467, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected object of backend CPU but got backend CUDA for argument #3 'index'
Hey @prabhakar267,
What I did to try to reproduce your issue:
I installed openkiwi from master in a new virtual env. Downloaded the pretrained models available on the releases.
Used this config:
seed: 42
gpu-id: 0
debug: True
model: estimator
load-model: pre_trained/estimator/target_1/model.torch
wmt18-format: False
test-source: data/wmt19/en_de.nmt/test.src
test-target: data/wmt19/en_de.nmt/test.mt
valid-batch-size: 16
output-dir: tmp_out
I had no errors and was able to run the whole thing.
I then uninstalled openkiwi and pip installed it. Using the same config+model I was able to reproduce your original issue, confirming my suspicions. I'll tag a new version to fix the pip package.
On the other hand, your final error is kind of weird. The bug popped up in a completely different place. To help me reproduce it, can you tell me how you're calling kiwi? And can you try to use one of the pre-trained models to see if they work?
I'm getting the error using the predictor-estimator model.
model = kiwi.load_model('trained_models/estimator_en_de.torch/estimator_en_de.torch')
model._device = torch.device("cuda")
source_texts = ...
target_texts = ...
predictions = model.predict({
'source': source_texts,
'target': target_texts
})
print(predictions)
Hey @prabhakar267 , sorry for the late response. I was away from work.
Thanks for sending the example script! I wasn't considering that use case and though you were using kiwi as a terminal tool, not as a python package.
The variable you are calling model (like we do on our examples) is actually from the Predicter
class. Furthermore, our code wasn't ready for a change of the _device
variable after initialization.
What you would have to do is:
model = kiwi.load_model('trained_models/estimator_en_de.torch/estimator_en_de.torch')
model.model.to("cuda")
model._device = torch.device("cuda")
Of course this makes to sense from a design perspective. There's a PR #61 that adds an interface similar to PyTorch. Once that's merged you can do:
model = kiwi.load_model('trained_models/estimator_en_de.torch/estimator_en_de.torch')
mode.to("cuda")
With this, all predictions will be made using the GPU.
Hope this solves your issue.
edit: closed issue by mistake
Hey @prabhakar267,
Changes have been merged to master :) let me know if you have any other problem,
Cheers
@prabhakar267, let us know if this is not solved.
To Reproduce
I used the following config for predicting using the predictor-estimator model and I got some error when using GPU. I'm using it on a multi GPU machine but want to run only on one GPU.
Environment (please complete the following information):
openkiwi==0.1.2
Python 3.6.2