据我了解(基于在线阅读),Tensorflow的session.run()发布了Python GIL(全局解释器锁),该功能通常会阻止多线程在Python中最佳工作。如果是这样,那么如果我并行运行多个会话,那么多线程应该会带来显着的性能优势?
我实现了以下代码,但是它的运行速度仍然与顺序运行相同。我在某个地方实施不正确吗?还是我的理解不正确?
def perform_inference_threaded_second(sess, input_list, output):
output.append(np.asarray(sess.run(y_op, {x_inp: input_list})).astype(np.float32))
def perform_inference_threaded_parent_second(input_list):
inference_parent_start = time.perf_counter()
output = []
thread_list = []
for model_idx in range(len(model_names)):
sess = cr_sessions[model_idx]
with sess.as_default():
with curr_graph.as_default():
t = threading.Thread(target=perform_inference_threaded_second, args=(sess, input_list, output))
thread_list.append(t)
t.start() # start thread execution
for t in thread_list:
t.join() # block until the thread is finished
return output