加载TensorFlow后派生一个python进程 [英] forking a python process after loading TensorFlow
问题描述
tf.Session()
是不安全的,这意味着在TensorFlow
加载到内存中时分叉一个进程后系统的行为是未知的.
tf.Session()
is not fork
safe which means that the behavior of the system after forking a process while TensorFlow
is loaded into the memory is unknown.
在多个进程之间共享多个设备(在一台计算机上)是否有解决办法?
is there any work around for sharing multiple devices (on a single machine), between multiple processes?
推荐答案
在多个进程之间共享TensorFlow运行时的标准方法是使用
The standard way to share a TensorFlow runtime between multiple processes is to use the distributed TensorFlow support, which also works on a single machine.
在一个过程中,您可以通过运行以下代码来启动服务器:
In one process, you can start a server by running the following code:
import tensorflow as tf
server = tf.train.Server.create_local_server()
print server.target # for other processes to connect
server.join()
默认情况下,此过程将拥有计算机上的所有设备.
This process will own all of the devices on the machine, by default.
在其他过程中,您可以创建连接到服务器的tf.Session
对象:
In the other processes, you can create tf.Session
objects that connect to the server:
sess = tf.Session("grpc://localhost:...") # Use value of `server.target`.
这些会话可以像进程内会话一样使用.
These sessions can be used just like in-process sessions.
这篇关于加载TensorFlow后派生一个python进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!