【问题标题】:When is it advantageous to use theano's scan function什么时候使用theano的scan功能比较好
【发布时间】:2016-03-07 03:59:30
【问题描述】:

我一直在阅读有关扫描的 Theano 文档,发现自己被两个看似矛盾的陈述弄糊涂了。

http://deeplearning.net/software/theano/tutorial/loop.html#scan上,scan的优势之一列举如下:

Slightly faster than using a for loop in Python with a compiled Theano function.

但是,在http://deeplearning.net/software/theano/library/scan.html#lib-scan,在优化扫描使用的一节中,它说:

 Scan makes it possible to define simple and compact graphs that can do
 the same work as much larger and more complicated graphs. However, it 
 comes with a significant overhead. As such, **when performance is the 
 objective, a good rule of thumb is to perform as much of the computation 
 as possible outside of Scan**. This may have the effect of increasing 
 memory usage but can also reduce the overhead introduces by using Scan.

在这里,我对“性能”的解读是速度的同义词。因此,一旦编译完成,我对扫描何时/是否会导致更短的运行时间感到困惑。

【问题讨论】:

    标签: theano


    【解决方案1】:

    如果您的表达式本质上需要一个 for 循环,那么您有时有两种选择:

    1. 使用 python for 循环构建表达式
    2. 使用扫描构建表达式

    选项 1 仅在您事先知道 for 循环的长度时才有效。您的 for 循环的长度可能取决于在脚本编写时不可用的符号变量。在这种情况下,您需要使用扫描。虽然通常你可以用任何一种方式来表述问题(参见 tensorflow 中没有扫描)。

    关于时间性能,已经有很多结果表明,这真的取决于哪个问题更快。

    【讨论】:

    • 如果符号变量的值在脚本编写时不可用,难道没有办法用 theano 函数替换该变量,该函数将在运行时计算该变量的值?
    猜你喜欢
    • 1970-01-01
    • 2011-02-21
    • 2013-11-08
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-06
    • 1970-01-01
    相关资源
    最近更新 更多