小编Edo*_*doG的帖子

从不同进程导入 Tensorflow 2.0 gpu

我正在开发一个项目,其中我有一个 python 模块,它实现了迭代过程,并且一些计算是由 GPU 使用 TensorFlow 2.0 执行的。该模块在单个进程中独立使用时可以正常工作。

由于我必须使用不同的参数执行多次运行,所以我想并行化调用,但是当我从不同的进程调用模块(导入张量流)时,我得到了 的CUDA_ERROR_OUT_OF_MEMORY无限循环CUDA_ERROR_NOT_INITIALIZED,因此生成的进程永远挂起。

当然,我尝试限制 GPU 内存,如果我从不同的解释器运行两个不同的 python 脚本,它可以正常工作,但在我的情况下似乎不起作用。

特别是,如果我使用

import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
    try:
       # Currently, memory growth needs to be the same across GPUs
        for gpu in gpus:
            tf.config.experimental.set_memory_growth(gpu, True)
            logical_gpus = tf.config.experimental.list_logical_devices('GPU')
            print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
    except RuntimeError as e:
        # Memory growth must be set before GPUs have been initialized
        print(e)
Run Code Online (Sandbox Code Playgroud)

我得到 的无限循环CUDA_ERROR_NOT_INITIALIZED,而如果我使用:

physical_devices = …
Run Code Online (Sandbox Code Playgroud)

python-3.x python-multiprocessing tensorflow tensorflow2.0

5
推荐指数
0
解决办法
708
查看次数