Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread safety #76

Open
alimoeeny opened this issue Oct 27, 2022 · 2 comments
Open

Thread safety #76

alimoeeny opened this issue Oct 27, 2022 · 2 comments

Comments

@alimoeeny
Copy link
Contributor

Hi @galeone
Thanks for all the hard work.
Was wondering if tfgo.Model is "thread safe".
Specifically can I call tfgo.Exec from different goroutines ? are there any considerations ? I assume I at least need to keep the scopes separate?
Thank you again for keeping this repo up to date.

@galeone
Copy link
Owner

galeone commented Oct 27, 2022

Hi @alimoeeny thank you for the kind words!

Honestly, I have never tested multiple inferences of the same model in multiple go routines. I guess, being the forward pass handled by the C library, the TensorFlow backend should already handle the concurrency - but it's just a guess.

Now that I'm thinking about it (keep this message as a stream of consciousness from my side lol), I guess it's instead the exact opposite. The thread safety is left to the user in the C library - and this would make sense.

Because the nature of the SavedModel is complex. There could be SavedModel stateful (where, for example, the TensorFlow program updates internal tf.Variable nodes), or SavedModel stateless (the serialization of some tf.* operation without a state).

For this reason, the best thing to do is to left to the user the hassle of handling the multi-threading stuff.

If your SavedModel is stateless, who cares about thread safety, otherwise you should handle it 🤔

Keep this message for what it is - just some thoughts about this topic. The best thing to do is to experiment. If you can do it, everyone that uses tfgo will benefit from your tests (right now I'm busy working on a different Go software 😅 )

@alimoeeny
Copy link
Contributor Author

thank you very much @galeone
I'll post to this thread if I discovered any concrete information, either from the docs or by experimentation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants