Skip to content

Commit

Permalink
fix: fix tensorflow on gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-wang committed May 6, 2020
1 parent a37e9d7 commit d650e72
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions jina/executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,8 @@ def post_init(self):
def _set_device(self):
if self._backend == 'tensorflow':
import tensorflow as tf
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
self._device = gpus[0] if self.on_gpu else cpus
# set before loading model
self._device = gpus[0] if self.on_gpu else []
elif self._backend == 'paddlepaddle':
import paddle.fluid as fluid
self._device = fluid.CUDAPlace(0) if self.on_gpu else fluid.CPUPlace()
Expand Down Expand Up @@ -626,7 +624,7 @@ def __init__(self, *args, **kwargs):

def pre_set_device(self):
import tensorflow as tf
tf.config.experimental.set_visible_devices(self._device)
tf.config.experimental.set_visible_devices(devices=self._device, device_type='GPU')


class BasePaddleExecutor(BaseFrameworkExecutor):
Expand Down

0 comments on commit d650e72

Please sign in to comment.