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

Using GPU #2

Closed
perdix opened this issue Feb 27, 2019 · 2 comments
Closed

Using GPU #2

perdix opened this issue Feb 27, 2019 · 2 comments

Comments

@perdix
Copy link

perdix commented Feb 27, 2019

Great Tutorial!
It would be very cool, if you can describe how to use the GPU to run it faster.

@0xpantera
Copy link

It's fairly easy to move the model to the GPU. Try the following:
Get the device you have:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

Instantiate your model:

model = LstmClassifier(word_embeddings, encoder, vocab)

Move the model to the GPU:

model = model.to(device)

Additionally the Allennlp Trainer has an option to pass the cuda_device. So you would have something like the following:

trainer = Trainer(model=model,
                  optimizer=optimizer,
                  iterator=iterator,
                  train_dataset=train_dataset,
                  validation_dataset=dev_dataset,
                  patience=10,
                  num_epochs=20,
                  cuda_device=device.index)

That's it!

@perdix
Copy link
Author

perdix commented Jul 18, 2019

Thanks a lot! 👍

@perdix perdix closed this as completed Jul 18, 2019
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