Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a7840844
提交
a7840844
authored
7月 07, 2021
作者:
kc611
提交者:
Brandon T. Willard
7月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added ScanArgs
上级
45a2f784
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
24 行增加
和
13 行删除
+24
-13
dispatch.py
aesara/link/jax/dispatch.py
+1
-1
opt.py
aesara/scan/opt.py
+8
-9
utils.py
aesara/scan/utils.py
+0
-0
scan.rst
doc/extending/scan.rst
+2
-2
test_utils.py
tests/scan/test_utils.py
+13
-1
没有找到文件。
aesara/link/jax/dispatch.py
浏览文件 @
a7840844
...
@@ -17,7 +17,7 @@ from aesara.link.utils import fgraph_to_python
...
@@ -17,7 +17,7 @@ from aesara.link.utils import fgraph_to_python
from
aesara.scalar
import
Softplus
from
aesara.scalar
import
Softplus
from
aesara.scalar.basic
import
Cast
,
Clip
,
Composite
,
Identity
,
ScalarOp
,
Second
from
aesara.scalar.basic
import
Cast
,
Clip
,
Composite
,
Identity
,
ScalarOp
,
Second
from
aesara.scan.op
import
Scan
from
aesara.scan.op
import
Scan
from
aesara.scan.utils
import
scan_args
as
ScanArgs
from
aesara.scan.utils
import
ScanArgs
from
aesara.tensor.basic
import
(
from
aesara.tensor.basic
import
(
Alloc
,
Alloc
,
AllocDiag
,
AllocDiag
,
...
...
aesara/scan/opt.py
浏览文件 @
a7840844
...
@@ -80,11 +80,11 @@ from aesara.graph.opt import GlobalOptimizer, in2out, local_optimizer
...
@@ -80,11 +80,11 @@ from aesara.graph.opt import GlobalOptimizer, in2out, local_optimizer
from
aesara.graph.optdb
import
EquilibriumDB
,
SequenceDB
from
aesara.graph.optdb
import
EquilibriumDB
,
SequenceDB
from
aesara.scan.op
import
Scan
from
aesara.scan.op
import
Scan
from
aesara.scan.utils
import
(
from
aesara.scan.utils
import
(
ScanArgs
,
compress_outs
,
compress_outs
,
expand_empty
,
expand_empty
,
reconstruct_graph
,
reconstruct_graph
,
safe_new
,
safe_new
,
scan_args
,
scan_can_remove_outs
,
scan_can_remove_outs
,
)
)
from
aesara.tensor
import
basic_opt
,
math_opt
from
aesara.tensor
import
basic_opt
,
math_opt
...
@@ -751,9 +751,9 @@ class PushOutScanOutput(GlobalOptimizer):
...
@@ -751,9 +751,9 @@ class PushOutScanOutput(GlobalOptimizer):
op
=
node
.
op
op
=
node
.
op
# Use
scan_args
to parse the inputs and outputs of scan for ease of
# Use
`ScanArgs`
to parse the inputs and outputs of scan for ease of
# use
# use
args
=
scan_a
rgs
(
node
.
inputs
,
node
.
outputs
,
op
.
inputs
,
op
.
outputs
,
op
.
info
)
args
=
ScanA
rgs
(
node
.
inputs
,
node
.
outputs
,
op
.
inputs
,
op
.
outputs
,
op
.
info
)
new_scan_node
=
None
new_scan_node
=
None
clients
=
{}
clients
=
{}
...
@@ -917,7 +917,7 @@ class PushOutScanOutput(GlobalOptimizer):
...
@@ -917,7 +917,7 @@ class PushOutScanOutput(GlobalOptimizer):
fgraph
,
old_scan_node
,
old_scan_args
,
add_as_nitsots
fgraph
,
old_scan_node
,
old_scan_args
,
add_as_nitsots
)
)
new_scan_args
=
scan_a
rgs
(
new_scan_args
=
ScanA
rgs
(
new_scan_node
.
inputs
,
new_scan_node
.
inputs
,
new_scan_node
.
outputs
,
new_scan_node
.
outputs
,
new_scan_node
.
op
.
inputs
,
new_scan_node
.
op
.
inputs
,
...
@@ -944,13 +944,12 @@ class PushOutScanOutput(GlobalOptimizer):
...
@@ -944,13 +944,12 @@ class PushOutScanOutput(GlobalOptimizer):
old_scan_node
.
inputs
[
0
]
for
i
in
range
(
nb_new_outs
)
old_scan_node
.
inputs
[
0
]
for
i
in
range
(
nb_new_outs
)
]
]
# Create the scan_args corresponding to the new scan op to
# Create the `ScanArgs` corresponding to the new `Scan` `Op` to create
# create
new_scan_args
=
copy
.
copy
(
old_scan_args
)
new_scan_args
=
copy
.
copy
(
old_scan_args
)
new_scan_args
.
inner_out_nit_sot
.
extend
(
new_outputs_inner
)
new_scan_args
.
inner_out_nit_sot
.
extend
(
new_outputs_inner
)
new_scan_args
.
outer_in_nit_sot
.
extend
(
new_nitsots_initial_value
)
new_scan_args
.
outer_in_nit_sot
.
extend
(
new_nitsots_initial_value
)
# Create the
scan op from the scan_args
# Create the
`Scan` `Op` from the `ScanArgs`
new_scan_op
=
Scan
(
new_scan_op
=
Scan
(
new_scan_args
.
inner_inputs
,
new_scan_args
.
inner_outputs
,
new_scan_args
.
info
new_scan_args
.
inner_inputs
,
new_scan_args
.
inner_outputs
,
new_scan_args
.
info
)
)
...
@@ -1970,7 +1969,7 @@ def scan_merge_inouts(fgraph, node):
...
@@ -1970,7 +1969,7 @@ def scan_merge_inouts(fgraph, node):
# Do a first pass to merge identical external inputs.
# Do a first pass to merge identical external inputs.
# Equivalent inputs will be stored in inp_equiv, then a new
# Equivalent inputs will be stored in inp_equiv, then a new
# scan node created without duplicates.
# scan node created without duplicates.
a
=
scan_a
rgs
(
a
=
ScanA
rgs
(
node
.
inputs
,
node
.
outputs
,
node
.
op
.
inputs
,
node
.
op
.
outputs
,
node
.
op
.
info
node
.
inputs
,
node
.
outputs
,
node
.
op
.
inputs
,
node
.
op
.
outputs
,
node
.
op
.
info
)
)
...
@@ -2016,7 +2015,7 @@ def scan_merge_inouts(fgraph, node):
...
@@ -2016,7 +2015,7 @@ def scan_merge_inouts(fgraph, node):
if
not
isinstance
(
outputs
,
(
list
,
tuple
)):
if
not
isinstance
(
outputs
,
(
list
,
tuple
)):
outputs
=
[
outputs
]
outputs
=
[
outputs
]
na
=
scan_a
rgs
(
outer_inputs
,
outputs
,
op
.
inputs
,
op
.
outputs
,
op
.
info
)
na
=
ScanA
rgs
(
outer_inputs
,
outputs
,
op
.
inputs
,
op
.
outputs
,
op
.
info
)
remove
=
[
node
]
remove
=
[
node
]
else
:
else
:
na
=
a
na
=
a
...
...
aesara/scan/utils.py
浏览文件 @
a7840844
差异被折叠。
点击展开。
doc/extending/scan.rst
浏览文件 @
a7840844
...
@@ -276,12 +276,12 @@ by usage.
...
@@ -276,12 +276,12 @@ by usage.
Accessing/manipulating Scan's inputs and outputs by type
Accessing/manipulating Scan's inputs and outputs by type
--------------------------------------------------------
--------------------------------------------------------
Declared in ``utils.py``, the class ``
scan_a
rgs`` handles the
Declared in ``utils.py``, the class ``
ScanA
rgs`` handles the
parsing of the inputs and outputs (both inner and outer) to a format
parsing of the inputs and outputs (both inner and outer) to a format
that is easier to analyse and manipulate. Without this class,
that is easier to analyse and manipulate. Without this class,
analysing Scan's inputs and outputs often required convoluted logic
analysing Scan's inputs and outputs often required convoluted logic
which make for code that is hard to read and to maintain. Because of
which make for code that is hard to read and to maintain. Because of
this, you should favor using ``
scan_a
rgs`` when it is practical and
this, you should favor using ``
ScanA
rgs`` when it is practical and
appropriate to do so.
appropriate to do so.
The scan op also defines a few helper functions for this purpose, such as
The scan op also defines a few helper functions for this purpose, such as
...
...
tests/scan/test_utils.py
浏览文件 @
a7840844
...
@@ -5,7 +5,7 @@ import pytest
...
@@ -5,7 +5,7 @@ import pytest
import
aesara
import
aesara
from
aesara
import
tensor
as
aet
from
aesara
import
tensor
as
aet
from
aesara.scan.utils
import
map_variables
from
aesara.scan.utils
import
ScanArgs
,
map_variables
from
aesara.tensor.type
import
scalar
,
vector
from
aesara.tensor.type
import
scalar
,
vector
...
@@ -145,3 +145,15 @@ class TestMapVariables:
...
@@ -145,3 +145,15 @@ class TestMapVariables:
shared
.
update
=
shared
+
1
shared
.
update
=
shared
+
1
with
pytest
.
raises
(
NotImplementedError
):
with
pytest
.
raises
(
NotImplementedError
):
map_variables
(
self
.
replacer
,
[
t
])
map_variables
(
self
.
replacer
,
[
t
])
def
test_ScanArgs
():
scan_args
=
ScanArgs
.
create_empty
()
assert
scan_args
.
n_steps
is
None
for
name
in
scan_args
.
field_names
:
if
name
==
"n_steps"
:
continue
assert
len
(
getattr
(
scan_args
,
name
))
==
0
with
pytest
.
raises
(
TypeError
):
ScanArgs
.
from_node
(
aet
.
ones
(
2
)
.
owner
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论