Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
24617ff3
提交
24617ff3
authored
4月 13, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added doc about the fact that the shape inference can remove expected error.
上级
73ac249c
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
72 行增加
和
6 行删除
+72
-6
shape_info.txt
doc/tutorial/shape_info.txt
+72
-6
没有找到文件。
doc/tutorial/shape_info.txt
浏览文件 @
24617ff3
...
@@ -22,19 +22,85 @@ Currently shape informations are used for 2 things in Theano:
...
@@ -22,19 +22,85 @@ Currently shape informations are used for 2 things in Theano:
.. code-block:: python
.. code-block:: python
import theano
import theano
x = theano.tensor.matrix()
x = theano.tensor.matrix(
'x'
)
f = theano.function([x], (x**2).shape)
f = theano.function([x], (x**2).shape)
theano.printing.debugprint(f)
theano.printing.debugprint(f)
#
MakeVector [@26301776
] '' 2
#
MakeVector [@43860304
] '' 2
#
|Shape_i{0} [@26321296
] '' 1
#
|Shape_i{0} [@43424912
] '' 1
#
| |<TensorType(float64, matrix)> [@26153424
]
#
| |x [@43423568
]
#
|Shape_i{1} [@26322512
] '' 0
#
|Shape_i{1} [@43797968
] '' 0
#
| |<TensorType(float64, matrix)> [@26153424
]
#
| |x [@43423568
]
The output of this compiled function do not contain any multiplication
The output of this compiled function do not contain any multiplication
or power. Theano has removed them to compute directly the shape of the
or power. Theano has removed them to compute directly the shape of the
output.
output.
Shape inference problem
=======================
Theano do shape information propagation in the graph. Sometimes this
can had error. Example:
.. code-block:: python
import numpy
import theano
x = theano.tensor.matrix('x')
y = theano.tensor.matrix('y')
z = theano.tensor.join(0,x,y)
xv = numpy.random.rand(5,4)
yv = numpy.random.rand(3,3)
f = theano.function([x,y], z.shape)
theano.printing.debugprint(f)
#MakeVector [@23910032] '' 4
# |Elemwise{Add{output_types_preference=transfer_type{0}}}[(0, 0)] [@24055120] '' 3
# | |Shape_i{0} [@23154000] '' 1
# | | |x [@23151760]
# | |Shape_i{0} [@23593040] '' 2
# | | |y [@23151888]
# |Shape_i{1} [@23531152] '' 0
# | |x [@23151760]
#MakeVector [@56338064] '' 4
# |Elemwise{Add{output_types_preference=transfer_type{0}}}[(0, 0)] [@56483152] '' 3
# | |Shape_i{0} [@55586128] '' 1
# | | |<TensorType(float64, matrix)> [@55583888]
# | |Shape_i{0} [@56021072] '' 2
# | | |<TensorType(float64, matrix)> [@55584016]
# |Shape_i{1} [@55959184] '' 0
# | |<TensorType(float64, matrix)> [@55583888]
print f(xv,yv)# DONT RAISE AN ERROR AS SHOULD BE.
#[8,4]
f = theano.function([x,y], z)# Don't take the shape.
theano.printing.debugprint(f)
#Join [@44540496] '' 0
# |0 [@44540432]
# |x [@44540240]
# |y [@44540304]
f(xv,yv)
# Raise a dimensions mismatch error.
As you see, when you ask for the shape of some computation(join in the
example), we sometimes compute the shape without executing the
computation(there is no join in the first output or debugprint).
This make the computation of the shape faster, but can hide error. In
the example, the computation of the shape of join is done on the first
theano variable in the join, not on the other.
This can probably happen with many other op as elemwise, dot, ...
You can detect those problem by running the code without this
optimization with the theano flag
`optimizer_excluding=local_shape_to_shape_i`. You can also have the
same effect by running in the mode FAST_COMPILE(won't apply this
optimization and most other optimization too) or DEBUG_MODE(will test
before and after all optimizations(much slower)).
Specifing exact shape
Specifing exact shape
=====================
=====================
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论