如何在多核上运行Keras? [英] How to run Keras on multiple cores?

查看:129
本文介绍了如何在多核上运行Keras?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在集群上使用Keras和Tensorflow后端(创建神经网络).我如何在群集上(在多个内核上)以多线程方式运行它,还是Keras自动完成此操作?例如,在Java中,可以创建多个线程,每个线程都在一个内核上运行.

I'm using Keras with Tensorflow backend on a cluster (creating neural networks). How can I run it in a multi-threaded way on the cluster (on several cores) or is this done automatically by Keras? For example in Java one can create several threads, each thread running on a core.

如果可能,应使用多少个内核?

If possible, how many cores should be used?

推荐答案

Tensorflow会自动在单台计算机上可用的多个内核上运行计算.

Tensorflow automatically runs the computations on as many cores as are available on a single machine.

如果您有分布式集群,请确保遵循 https://www.tensorflow上的说明.org/how_tos/distributed/来配置集群. (例如,正确创建tf.ClusterSpec等)

If you have a distributed cluster, be sure you follow the instructions at https://www.tensorflow.org/how_tos/distributed/ to configure the cluster. (e.g. create the tf.ClusterSpec correctly, etc.)

为帮助调试,您可以在会话上使用log_device_placement配置选项,以使Tensorflow打印出实际放置计算的位置. (注意:这适用于GPU和分布式Tensorflow.)

To help debug, you can use the log_device_placement configuration options on the session to have Tensorflow print out where the computations are actually placed. (Note: this works for both GPUs as well as distributed Tensorflow.)

# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

请注意,虽然Tensorflow的计算放置算法在小型计算图上运行良好,但通过在特定设备中手动放置计算,您可能能够在大型计算图上获得更好的性能. (例如,使用with tf.device(...):块.)

Note that while Tensorflow's computation placement algorithm works fine for small computational graphs, you might be able to get better performance on large computational graphs by manually placing the computations in specific devices. (e.g. using with tf.device(...): blocks.)

这篇关于如何在多核上运行Keras?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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