Reputation: 27592
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?
Upvotes: 5
Views: 2152
Reputation: 126184
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.
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.
Upvotes: 6