gpt4 book ai didi

python - 从命令行强制 TensorFlow-GPU 使用 CPU

转载 作者:行者123 更新时间:2023-11-28 18:24:29 25 4
gpt4 key购买 nike

我在运行 Ubuntu 14.04.4 LTS x64 的服务器上安装了 TensorFlow-GPU 1.0.0。

我知道我可以使用 CUDA_VISIBLE_DEVICES隐藏一个或多个 GPU。有时,我想隐藏所有 GPU,以便基于 TensorFlow 的程序只使用 CPU。结果,我试了一下

username@server:/scratch/coding/src$ CUDA_VISIBLE_DEVICES="" python my_script.py 

但这给了我错误信息:

E tensorflow/stream_executor/cuda/cuda_driver.cc:509] failed call to cuInit: CUDA_ERROR_NO_DEVICE

这是我使用的 ConfigProto:

session_conf = tf.ConfigProto(
device_count={'CPU': 1, 'GPU': 1},
allow_soft_placement=True,
log_device_placement=False
)
sess = tf.Session(config=session_conf)

我知道我可以使用 device_count={'GPU': 0} 来阻止基于 TensorFlow 的程序使用 GPU,但我想知道这是否可以在启动时从命令行实现程序(不改变 ConfigProto)。

根据文档,选项 allow_soft_placement=True 应该让 TensorFlow 自动选择现有且受支持的设备来运行操作,以防指定的设备不​​存在。

当我看到这条消息时,我的第一 react 是 CUDA 至少需要一个 GPU 才能成功加载,但我 read即使机器没有 GPU,也可以安装 GPU 驱动程序并在机器上使用 TensorFlow-GPU。


这是我用于测试的 my_script.py 脚本:

import tensorflow as tf
a = tf.constant(1, name = 'a')
b = tf.constant(3, name = 'b')
c = tf.constant(9, name = 'c')
d = tf.add(a, b, name='d')
e = tf.add(d, c, name='e')

session_conf = tf.ConfigProto(
device_count={'CPU': 1, 'GPU': 1},
allow_soft_placement=True,
log_device_placement=False
)
sess = tf.Session(config=session_conf)
print(sess.run([d, e]))

最佳答案

我认为“E”应该是“W”或“I”,这只是一条信息性消息,不应影响您程序的运行

关于python - 从命令行强制 TensorFlow-GPU 使用 CPU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42422042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com