Skip to content
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

When Using a GPU: HappyTextGeneration.generate_text() Error After Training/Evaluating #220

Closed
EricFillion opened this issue May 6, 2021 · 4 comments
Assignees

Comments

@EricFillion
Copy link
Owner

EricFillion commented May 6, 2021

Reproduction:

  • Connect to a Google Colab environment with a GPU
  • pip install happytransformer==2.2.1
  • Upload a text file called "text.txt"

from happytransformer import HappyGeneration

happy_gen = HappyGeneration()

happy_gen.train("test.txt")

output = happy_gen.generate_text("Artificial intelligence is ")`

Error message: RuntimeError: Input, output and indices must be on the current device

This problem is unique to HappyGeneration(). I have performed similar tests with HappyWordPrediction(), HappyQuestionAnswering() and HappyTextClassification() without finding any errors.

Quick fix: Run the following code in-between training/evaluating and using HappyTextGeneration.generate_text()
happy_gen.model.to("cpu")

@ted537
Copy link
Collaborator

ted537 commented May 6, 2021

The issue doesn't occur with the other HappyTransformers because they use pipelines. Since huggingface manages both the pipelines and the models, we can expect them to be in sync (i.e. both live on the same device). When we initialize our own tensors for use with HuggingFace objects, we must manually ensure that both objects live on the same device.

@ted537
Copy link
Collaborator

ted537 commented May 6, 2021

You probably need to use input_ids = input_ids.to(model._device)

@EricFillion
Copy link
Owner Author

Thanks Ted! I'll try that this weekend.

@EricFillion
Copy link
Owner Author

See #223. Published in version 2.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants