Is tf.session thread-safe?

816 views
Skip to first unread message

jain....@gmail.com

unread,
Jun 21, 2017, 10:35:11 PM6/21/17
to Discuss
hi
I have come across a few mail threads discussing the same; but not in the exact context which I am looking at:

I tried to run 2 threads, both sharing the same session. One thread ingests data from (say a queue) and calls session.run() to train the model and the other thread runs inferencing using the same session. It seems to run in parallel, but:
1. I am not sure yet (need to verify) if there are thread safety issues (not sure what underlying operations/data structures are for updating model parameters) and if the result returned is correct or not.
2. If it is safe, is there a significant overhead wrt locking and slow down.
3. Are all the model weights updated using one single lock at the end of every training iteration.

Mridul

Yaroslav Bulatov

unread,
Jun 22, 2017, 11:28:48 AM6/22/17
to jain....@gmail.com, Discuss
What you are describing under 1. is a very common scenario used during training, so it should work and be fairly optimized. There's no locking by default, which tends to work OK for gradient descent. Operations like "tf.assign_add" have `use_locking` attribute which you can set to ensure that variable doesn't change between reading and modification.

There's some more discussion on state of locking here: https://github.com/tensorflow/tensorflow/issues/6360

--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/489ded71-051f-4307-a739-dab0493b2db4%40tensorflow.org.

Reply all
Reply to author
Forward
0 new messages