Allennlp: GPU for Named Entity Recognition

Created on 3 Aug 2018  路  6Comments  路  Source: allenai/allennlp

I'm trying to execute the NER model (https://s3-us-west-2.amazonaws.com/allennlp/models/ner-model-2018.04.26.tar.gz) in GPU, but it's not using GPU(rather normal CPU) in Azure NV6.

Most helpful comment

as a fairly hacky solution, you can use:

model_url = "s3-us-west-2.amazonaws.com/allennlp/models/ner-model-2018.04.26.tar.gz"
predictor = Predictor.from_path(model_path)
predictor._model = predictor._model.cuda()
result = predictor.predict(sentence=some_text)

All 6 comments

what's the exact command you're running?

I sometimes have to add CUDA_VISIBLE_DEVICES=0 at the beginning of the bash command (and replace 0 with whichever GPU you want to use). I don't know if it can help....

from allennlp.predictors import Predictor

model_url = "https://s3-us-west-2.amazonaws.com/allennlp/models/ner-model-2018.04.26.tar.gz"
predictor = Predictor.from_path(model_path)
result = predictor.predict(sentence=some_text)

What changes should I do (in python)?

as a fairly hacky solution, you can use:

model_url = "s3-us-west-2.amazonaws.com/allennlp/models/ner-model-2018.04.26.tar.gz"
predictor = Predictor.from_path(model_path)
predictor._model = predictor._model.cuda()
result = predictor.predict(sentence=some_text)

Predictor.from_path should really take a cuda_device parameter, I'll open an issue for that.

In the meantime, just do

archive = load_archive(model_path, cuda_device=0)
predictor = Predictor.from_archive(archive)

(or use Nelson's hack)

Thanx for the help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

epwalsh picture epwalsh  路  4Comments

stefan-it picture stefan-it  路  4Comments

2509dk picture 2509dk  路  3Comments

flyaway1217 picture flyaway1217  路  4Comments

DeNeutoy picture DeNeutoy  路  4Comments