Reputation: 317
Currently my approach is to have one computational graph defined for computation 1 (which is computed twice for the two different inputs), and a second computation graph defined for computation 2, which is run only once with the inputs from the first computation (in this case I compute the difference of the outputs of computation 1, but I'm looking for a solution for a more generic problem). Then I run the computation 1 twice, get the results in a Numpy array and then pass them to graph 2 for the second computation. However, this has the disadvantage that I have to run separate Tensorflow sessions for each computation and move data back-and-forth between the GPU and the RAM.
Batching the two initial inputs to computation 1 is not an option either, because their sizes might be different (however, the size of the output is always the same).
In other words, I would need some kind of persistence between two Tensorflow sessions without the need to store the data outside between the sessions, or, alternatively, have two copies of the same graph in the same session, but not parallel with each other since then it would take too much memory.
Upvotes: 1
Views: 64
Reputation: 5206
Try using eager execution and tf.contrib.eager.defun to build your graphs (search for usages of defun in the tensorflow codebase to see examples of this). Eager execution lets you persistent tensors on-device without fetching them and without the need to worry about sessions.
Upvotes: 1