有人可以解释以下TensorFlow术语
inter_op_parallelism_threads
intra_op_parallelism_threads
或者,请提供正确解释来源的链接。
我通过改变参数进行了一些测试,但结果并不一致,无法得出结论。
inter_op_parallelism_threads
和intra_op_parallelism_threads
选项记录在source of the tf.ConfigProto
protocol buffer中。这些选项配置TensorFlow用于并行执行的两个线程池,如注释所描述:
// The execution of an individual op (for some op types) can be
// parallelized on a pool of intra_op_parallelism_threads.
// 0 means the system picks an appropriate number.
int32 intra_op_parallelism_threads = 2;
// Nodes that perform blocking operations are enqueued on a pool of
// inter_op_parallelism_threads available in each process.
//
// 0 means the system picks an appropriate number.
//
// Note that the first Session created in the process sets the
// number of threads for all future sessions unless use_per_session_threads is
// true or session_inter_op_thread_pool is configured.
int32 inter_op_parallelism_threads = 5;
运行TensorFlow图时,有几种可能的并行形式,这些选项提供了一些控制多核CPU并行性:
tf.matmul()
)或缩减(例如tf.reduce_sum()
),TensorFlow将通过使用intra_op_parallelism_threads
线程调度线程池中的任务来执行它。因此,此配置选项控制单个操作的最大并行加速。请注意,如果并行运行多个操作,这些操作将共享此线程池。inter_op_parallelism_threads
线程的线程池同时运行它们。如果这些操作具有多线程实现,则它们(在大多数情况下)将共享相同的线程池以实现操作内并行性。最后,两个配置选项都采用默认值0
,这意味着“系统选择一个合适的数字”。目前,这意味着每个线程池在您的计算机中每个CPU核心都有一个线程。
要从计算机获得最佳性能,请更改tensorflow后端的并行度线程和OpenMP设置,如下所示(来自here):
import tensorflow as tf
#Assume that the number of cores per socket in the machine is denoted as NUM_PARALLEL_EXEC_UNITS
# when NUM_PARALLEL_EXEC_UNITS=0 the system chooses appropriate settings
config = tf.ConfigProto(intra_op_parallelism_threads=NUM_PARALLEL_EXEC_UNITS,
inter_op_parallelism_threads=2,
allow_soft_placement=True,
device_count = {'CPU': NUM_PARALLEL_EXEC_UNITS})
session = tf.Session(config=config)