在推理服务中使用 tf.Session 是否线程安全? [英] Is it thread-safe when using tf.Session in inference service?

查看:35
本文介绍了在推理服务中使用 tf.Session 是否线程安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我们已经使用 TensorFlow 来训练和导出模型.我们可以用这个模型来实现推理服务,就像 tensorflow/serving 所做的那样.

Now we have used TensorFlow to train and export an model. We can implement the inference service with this model just like how tensorflow/serving does.

我有一个关于 tf.Session 对象是否线程安全的问题.如果是这样,我们可以在启动后初始化对象,并使用单例对象来处理并发请求.

I have a question about whether the tf.Session object is thread-safe or not. If it's true, we may initialize the object after starting and use the singleton object to process the concurrent requests.

推荐答案

tf.Session 对象对于 Session.run() 来自多个线程的调用.

The tf.Session object is thread-safe for Session.run() calls from multiple threads.

在 TensorFlow 0.10 之前,图形修改不是线程安全的.这在 0.10 版本中已修复,因此您可以在调用 Session.run() 的同时向图中添加节点,尽管出于性能原因不建议这样做;相反,建议调用 sess.graph.finalize() 在从多线程使用会话之前,防止意外的内存泄漏.

Before TensorFlow 0.10 graph modification was not thread-safe. This was fixed in the 0.10 release, so you can add nodes to the graph concurrently with Session.run() calls, although this is not advised for performance reasons; instead, it is recommended to call sess.graph.finalize() before using the session from multiple threads, to prevent accidental memory leaks.

这篇关于在推理服务中使用 tf.Session 是否线程安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆