gpt4 book ai didi

python - 更改 TensorFlow 中的默认 GPU

转载 作者:IT老高 更新时间:2023-10-28 21:06:14 25 4
gpt4 key购买 nike

根据文档,默认 GPU 是 id 最低的:

If you have more than one GPU in your system, the GPU with the lowest ID will be selected by default.

是否可以通过命令行或一行代码更改此默认设置?

最佳答案

Suever's answer正确显示了如何将您的操作固定到特定的 GPU。但是,如果您在同一台机器上运行多个 TensorFlow 程序,建议您设置 CUDA_VISIBLE_DEVICES环境变量以在启动进程之前公开不同的 GPU。否则,TensorFlow 将尝试在所有可用的 GPU 上分配几乎全部内存,这会阻止其他进程使用这些 GPU(即使当前进程没有使用它们)。

请注意,如果您使用 CUDA_VISIBLE_DEVICES,则设备名称为 "/gpu:0""/gpu:1" 等。指当前进程中的第 0 个和第 1 个 可见 设备。

关于python - 更改 TensorFlow 中的默认 GPU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36668467/

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