From ffda38356a1d51c1bced19c1c1bfdced3756c891 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 20 Sep 2017 19:16:35 -0500 Subject: [PATCH] Add util function to enable GPU --- spacy/util.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spacy/util.py b/spacy/util.py index a55eed2f8..429d9bae5 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -14,6 +14,7 @@ import numpy import io import dill from collections import OrderedDict +from thinc.neural._classes.model import Model import msgpack import msgpack_numpy @@ -557,3 +558,14 @@ def minify_html(html): RETURNS (unicode): "Minified" HTML. """ return html.strip().replace(' ', '').replace('\n', '') + + +def use_gpu(gpu_id): + import cupy.cuda.device + from thinc.neural.ops import CupyOps + device = cupy.cuda.device.Device(gpu_id) + device.use() + Model.ops = CupyOps() + Model.Ops = CupyOps + return device +