Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5a61625a
提交
5a61625a
authored
5月 07, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
5月 11, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix scan_checkpoints with padded sequences
上级
db734614
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
9 行删除
+14
-9
checkpoints.py
pytensor/scan/checkpoints.py
+8
-6
test_checkpoints.py
tests/scan/test_checkpoints.py
+6
-3
没有找到文件。
pytensor/scan/checkpoints.py
浏览文件 @
5a61625a
import
pytensor.tensor.basic
as
ptb
from
pytensor.scan.basic
import
scan
from
pytensor.tensor.basic
import
Join
from
pytensor.tensor.math
import
ceil
,
eq
from
pytensor.tensor.math
import
ceil
,
eq
,
neq
from
pytensor.tensor.subtensor
import
set_subtensor
...
...
@@ -130,16 +130,18 @@ def scan_checkpoints(
# Since padding could be an empty tensor, Join returns a view of s.
join
=
Join
(
view
=
0
)
for
i
,
s
in
enumerate
(
sequences
):
n
=
s
.
shape
[
0
]
%
save_every_N
z
=
ptb
.
zeros
((
n
,
s
.
shape
[
1
:]),
dtype
=
s
.
dtype
)
sequences
[
i
]
=
join
(
0
,
[
s
,
z
])
overshoots_by
=
s
.
shape
[
0
]
%
save_every_N
overshoots
=
neq
(
overshoots_by
,
0
)
n
=
(
save_every_N
-
overshoots_by
)
*
overshoots
z
=
ptb
.
zeros
((
n
,
*
s
.
shape
[
1
:]),
dtype
=
s
.
dtype
)
sequences
[
i
]
=
join
(
0
,
s
,
z
)
# Establish the input variables of the outer scan
o_sequences
=
[
s
.
reshape
(
[
s
.
shape
[
0
]
/
save_every_N
,
save_every_N
]
[
s
.
shape
[
0
]
/
/
save_every_N
,
save_every_N
]
+
[
s
.
shape
[
i
]
for
i
in
range
(
1
,
s
.
ndim
)],
s
.
ndim
+
1
,
ndim
=
s
.
ndim
+
1
,
)
for
s
in
sequences
]
...
...
tests/scan/test_checkpoints.py
浏览文件 @
5a61625a
...
...
@@ -5,7 +5,7 @@ from pytensor.compile.function import function
from
pytensor.gradient
import
grad
from
pytensor.scan.basic
import
scan
from
pytensor.scan.checkpoints
import
scan_checkpoints
from
pytensor.tensor.basic
import
ones_like
from
pytensor.tensor.basic
import
arange
,
ones_like
from
pytensor.tensor.type
import
iscalar
,
vector
...
...
@@ -13,15 +13,18 @@ class TestScanCheckpoint:
def
setup_method
(
self
):
self
.
k
=
iscalar
(
"k"
)
self
.
A
=
vector
(
"A"
)
seq
=
arange
(
self
.
k
,
dtype
=
"float32"
)
+
1
result
,
_
=
scan
(
fn
=
lambda
prior_result
,
A
:
prior_result
*
A
,
fn
=
lambda
s
,
prior_result
,
A
:
prior_result
*
A
/
s
,
outputs_info
=
ones_like
(
self
.
A
),
sequences
=
[
seq
],
non_sequences
=
self
.
A
,
n_steps
=
self
.
k
,
)
result_check
,
_
=
scan_checkpoints
(
fn
=
lambda
prior_result
,
A
:
prior_result
*
A
,
fn
=
lambda
s
,
prior_result
,
A
:
prior_result
*
A
/
s
,
outputs_info
=
ones_like
(
self
.
A
),
sequences
=
[
seq
],
non_sequences
=
self
.
A
,
n_steps
=
self
.
k
,
save_every_N
=
100
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论