在GPU上运行时,Tensorflow CPU代码错误

时间:2020-08-30 01:13:51

标签: python tensorflow

我正在尝试使用OpenAI code训练一个深层网络,该网络可以在具有Tensorflow 2 CPU的服务器上正常运行。但是,当我尝试在装有Cuda和cuDNN的GPU机器上运行完全相同的代码时,会得到以下输出:

value = self.visit(value)
  File "/usr/lib/python3.6/ast.py", line 253, in visit
    return visitor(node)
  File "/usr/lib/python3.6/ast.py", line 317, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.6/ast.py", line 253, in visit
    return visitor(node)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/autograph/pyct/qual_names.py", line 232, in visit_Subscript
    if not isinstance(s, gast.Index):
AttributeError: module 'gast' has no attribute 'Index'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/autograph/impl/api.py", line 423, in converted_call
    experimental_optional_features=options.optional_features)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/autograph/impl/api.py", line 528, in to_graph
    entity, e.__class__.__name__, str(e)))
tensorflow.python.autograph.impl.api.ConversionError: converting <bound method DEEPQ.step of <tensorflow.python.eager.function.TfMethodTarget object at 0x7ff11c611748>>: AttributeError: module 'gast' has no attribute 'Index'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "openai.py", line 252, in <module>
    action, _, _, _ = enabled_network.step(tf.constant(obs), update_eps=update_eps, **kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 414, in __call__
    self._initialize(args, kwds, add_initializers_to=initializer_map)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 357, in _initialize
    *args, **kwds))
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 1349, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 1652, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 1545, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py", line 715, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 307, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 2158, in bound_method_wrapper
    return wrapped_fn(*args, **kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py", line 702, in wrapper
    ), args, kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/autograph/impl/api.py", line 446, in converted_call
    return _call_unconverted(f, args, kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/autograph/impl/api.py", line 249, in _call_unconverted
    return f.__self__.call(args, kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 2120, in call
    return wrapped_fn(self.weakrefself_target__(), *args, **kwargs)
  File "/home/user1/dqn/baselines/deepq/deepq_learner.py", line 148, in step
    if update_eps >= 0:
  File "/home/user1/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 690, in __bool__
    raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.

对如何解决此问题有任何见解?这似乎是python 3.6错误?

以下是我的图形卡详细信息和Cuda版本。 nvidia-smi的输出:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.66       Driver Version: 450.66       CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  TITAN V             Off  | 00000000:03:00.0 Off |                  N/A |
| 29%   43C    P8    26W / 250W |    112MiB / 12063MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      6463      G   /usr/lib/xorg/Xorg                 33MiB |
|    0   N/A  N/A      6643      G   /usr/bin/gnome-shell               76MiB |
+-----------------------------------------------------------------------------+

0 个答案:

没有答案