-
Notifications
You must be signed in to change notification settings - Fork 2
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
RuntimeError: Input, output and indices must be on the current device #5
Comments
Hi @cpuyyp, Thanks for using the repo and raising the issue. Kind regards |
Hi @cpuyyp, I tested that this works indeed on a GPU notebook on Google Cloud. # Store the encoding on the GPU.
input_ids = input_ids.to(flair_model_wrapper.device)
Will test this on my laptop tomorrow just to see if I will not break anything on a CPU-only machine. |
In my case your explanation helped (I had to edit the function manually as you proposed after cloning your repo, so I guess this solution is not in the repo yet?), but I still needed to state clearly before the type of flair.device (flair.device = 'cuda') before starting everything. It's a great thing you achieved @robinvanschaik ! I was looking for a solution like this for some time now already. Thanks a lot! Question: if I am to use your code/repo, is there any research publication you would like me to cite? |
Hi @krzysztoffiok, I am glad to hear that you find this repo useful! :) You are right. For some reason I never got around to actually pushing this to the master. It is possible that I might have some free time soon. In the meantime I would definitely welcome a pull request that will solve this issue! Regarding citing this repo; I am not affiliated with any academic institution, nor do I write any (academic) papers. In that regard this was a hobby project. Is there a way I could facilitate you in making sure this work is properly cited? Then I will add a snippet to the markdown file on the front page. Cheers |
Hi @robinvanschaik , Thank you for a very quick merge :) I have created another pull request to force the user to clearly state the device they will be using. For me it helped. |
Hi @krzysztoffiok, Thanks for contributing with your pull requests! Keep them coming. Are you willing to reflect your changes in the tutorial in the readme.md as well? I believe that we can close this issue after this has been updated. Afterwards I can create a new release as soon as this has been updated. The Generated DOI will reflect the new release as well, which should help with citing the code. Cheers. |
OK I will do that. BTW, I have also noticed that, presumably for some slightly older model versions (this is my guess of the reason), there is a new error (see below). It happened with other models that I've fine-tuned ~9 months ago and not only Albert but also BERT and RoBERTa fine-tuned at the same time. If I'm correct that this is a package version issue, I guess interpret-flair should clearly state which version of huggingface transformers and flair and captum to use. AttributeError Traceback (most recent call last) ~/env/flair06/respect/data/models/respect_5k_final_respect_values_0/interpretation_package/interpret_flair.py in interpret_sentence(flair_model_wrapper, lig, sentence, target_label, visualization_list, n_steps, estimation_method, internal_batch_size) ~/env/flair06/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) ~/env/flair06/respect/data/models/respect_5k_final_respect_values_0/interpretation_package/flair_model_wrapper.py in forward(self, input_ids) ~/env/flair06/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) ~/env/flair06/lib/python3.7/site-packages/transformers/modeling_albert.py in forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, output_attentions, output_hidden_states, return_dict) ~/env/flair06/lib/python3.7/site-packages/transformers/configuration_utils.py in use_return_dict(self) AttributeError: 'AlbertConfig' object has no attribute 'return_dict' |
@krzysztoffiok You are definitely right. I should have added a requirements.txt to the repository with pinned versions. This would make it more reproducible. |
@robinvanschaik do you think we could meet online about the functionality of interpret-flair package? I'm not that much familiar with practical use of IG method and its various parameters, so if you had the time to clarify some aspects that would greatly help me to get proper results. I have tried for a while and it didn't work as straightforward as I would expect. Please contact me at krzysztof.fiok at gmail.com if you agree. |
Hi Robin,
I found an error when I test with the pre-trained sentiment model from Flair. Simply loading with
And the rest is the same as yours. I got this error when I call the function interpret_sentence.
I test and print out the device. It turns out that the variable input_ids in function interpret_sentence is on cpu. My clumsy solution is to add
after line
There might be other internal solutions.
BTW, this work helps a lot!
The text was updated successfully, but these errors were encountered: