Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5fa5c9ba
提交
5fa5c9ba
authored
5月 07, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
5月 09, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Speedup python implementation of Blockwise
上级
51cda52b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
61 行增加
和
21 行删除
+61
-21
op.py
pytensor/graph/op.py
+27
-14
op.py
pytensor/link/c/op.py
+12
-6
blockwise.py
pytensor/tensor/blockwise.py
+0
-0
test_blockwise.py
tests/tensor/test_blockwise.py
+22
-1
没有找到文件。
pytensor/graph/op.py
浏览文件 @
5fa5c9ba
...
@@ -502,7 +502,7 @@ class Op(MetaObject):
...
@@ -502,7 +502,7 @@ class Op(MetaObject):
self
,
self
,
node
:
Apply
,
node
:
Apply
,
storage_map
:
StorageMapType
,
storage_map
:
StorageMapType
,
compute_map
:
ComputeMapType
,
compute_map
:
ComputeMapType
|
None
,
no_recycling
:
list
[
Variable
],
no_recycling
:
list
[
Variable
],
debug
:
bool
=
False
,
debug
:
bool
=
False
,
)
->
ThunkType
:
)
->
ThunkType
:
...
@@ -513,25 +513,38 @@ class Op(MetaObject):
...
@@ -513,25 +513,38 @@ class Op(MetaObject):
"""
"""
node_input_storage
=
[
storage_map
[
r
]
for
r
in
node
.
inputs
]
node_input_storage
=
[
storage_map
[
r
]
for
r
in
node
.
inputs
]
node_output_storage
=
[
storage_map
[
r
]
for
r
in
node
.
outputs
]
node_output_storage
=
[
storage_map
[
r
]
for
r
in
node
.
outputs
]
node_compute_map
=
[
compute_map
[
r
]
for
r
in
node
.
outputs
]
if
debug
and
hasattr
(
self
,
"debug_perform"
):
if
debug
and
hasattr
(
self
,
"debug_perform"
):
p
=
node
.
op
.
debug_perform
p
=
node
.
op
.
debug_perform
else
:
else
:
p
=
node
.
op
.
perform
p
=
node
.
op
.
perform
@is_thunk_type
if
compute_map
is
None
:
def
rval
(
p
=
p
,
@is_thunk_type
i
=
node_input_storage
,
def
rval
(
o
=
node_output_storage
,
p
=
p
,
n
=
node
,
i
=
node_input_storage
,
cm
=
node_compute_map
,
o
=
node_output_storage
,
):
n
=
node
,
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
):
for
entry
in
cm
:
return
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
entry
[
0
]
=
True
return
r
else
:
node_compute_map
=
[
compute_map
[
r
]
for
r
in
node
.
outputs
]
@is_thunk_type
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
,
cm
=
node_compute_map
,
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
for
entry
in
cm
:
entry
[
0
]
=
True
return
r
rval
.
inputs
=
node_input_storage
rval
.
inputs
=
node_input_storage
rval
.
outputs
=
node_output_storage
rval
.
outputs
=
node_output_storage
...
...
pytensor/link/c/op.py
浏览文件 @
5fa5c9ba
...
@@ -39,7 +39,7 @@ class COp(Op, CLinkerOp):
...
@@ -39,7 +39,7 @@ class COp(Op, CLinkerOp):
self
,
self
,
node
:
Apply
,
node
:
Apply
,
storage_map
:
StorageMapType
,
storage_map
:
StorageMapType
,
compute_map
:
ComputeMapType
,
compute_map
:
ComputeMapType
|
None
,
no_recycling
:
Collection
[
Variable
],
no_recycling
:
Collection
[
Variable
],
)
->
CThunkWrapperType
:
)
->
CThunkWrapperType
:
"""Create a thunk for a C implementation.
"""Create a thunk for a C implementation.
...
@@ -86,11 +86,17 @@ class COp(Op, CLinkerOp):
...
@@ -86,11 +86,17 @@ class COp(Op, CLinkerOp):
)
)
thunk
,
node_input_filters
,
node_output_filters
=
outputs
thunk
,
node_input_filters
,
node_output_filters
=
outputs
@is_cthunk_wrapper_type
if
compute_map
is
None
:
def
rval
():
rval
=
is_cthunk_wrapper_type
(
thunk
)
thunk
()
for
o
in
node
.
outputs
:
else
:
compute_map
[
o
][
0
]
=
True
cm_entries
=
[
compute_map
[
o
]
for
o
in
node
.
outputs
]
@is_cthunk_wrapper_type
def
rval
(
thunk
=
thunk
,
cm_entries
=
cm_entries
):
thunk
()
for
entry
in
cm_entries
:
entry
[
0
]
=
True
rval
.
thunk
=
thunk
rval
.
thunk
=
thunk
rval
.
cthunk
=
thunk
.
cthunk
rval
.
cthunk
=
thunk
.
cthunk
...
...
pytensor/tensor/blockwise.py
浏览文件 @
5fa5c9ba
差异被折叠。
点击展开。
tests/tensor/test_blockwise.py
浏览文件 @
5fa5c9ba
...
@@ -12,10 +12,11 @@ from pytensor.gradient import grad
...
@@ -12,10 +12,11 @@ from pytensor.gradient import grad
from
pytensor.graph
import
Apply
,
Op
from
pytensor.graph
import
Apply
,
Op
from
pytensor.graph.replace
import
vectorize_node
from
pytensor.graph.replace
import
vectorize_node
from
pytensor.raise_op
import
assert_op
from
pytensor.raise_op
import
assert_op
from
pytensor.tensor
import
diagonal
,
log
,
ones_like
,
scalar
,
tensor
,
vector
from
pytensor.tensor
import
diagonal
,
dmatrix
,
log
,
ones_like
,
scalar
,
tensor
,
vector
from
pytensor.tensor.blockwise
import
Blockwise
,
vectorize_node_fallback
from
pytensor.tensor.blockwise
import
Blockwise
,
vectorize_node_fallback
from
pytensor.tensor.nlinalg
import
MatrixInverse
from
pytensor.tensor.nlinalg
import
MatrixInverse
from
pytensor.tensor.rewriting.blas
import
specialize_matmul_to_batched_dot
from
pytensor.tensor.rewriting.blas
import
specialize_matmul_to_batched_dot
from
pytensor.tensor.signal
import
convolve1d
from
pytensor.tensor.slinalg
import
(
from
pytensor.tensor.slinalg
import
(
Cholesky
,
Cholesky
,
Solve
,
Solve
,
...
@@ -484,6 +485,26 @@ def test_batched_mvnormal_logp_and_dlogp(mu_batch_shape, cov_batch_shape, benchm
...
@@ -484,6 +485,26 @@ def test_batched_mvnormal_logp_and_dlogp(mu_batch_shape, cov_batch_shape, benchm
benchmark
(
fn
,
*
test_values
)
benchmark
(
fn
,
*
test_values
)
def
test_small_blockwise_performance
(
benchmark
):
a
=
dmatrix
(
shape
=
(
7
,
128
))
b
=
dmatrix
(
shape
=
(
7
,
20
))
out
=
convolve1d
(
a
,
b
,
mode
=
"valid"
)
fn
=
pytensor
.
function
([
a
,
b
],
out
,
trust_input
=
True
)
assert
isinstance
(
fn
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
,
Blockwise
)
rng
=
np
.
random
.
default_rng
(
495
)
a_test
=
rng
.
normal
(
size
=
a
.
type
.
shape
)
b_test
=
rng
.
normal
(
size
=
b
.
type
.
shape
)
np
.
testing
.
assert_allclose
(
fn
(
a_test
,
b_test
),
[
np
.
convolve
(
a_test
[
i
],
b_test
[
i
],
mode
=
"valid"
)
for
i
in
range
(
a_test
.
shape
[
0
])
],
)
benchmark
(
fn
,
a_test
,
b_test
)
def
test_cop_with_params
():
def
test_cop_with_params
():
matrix_assert
=
Blockwise
(
core_op
=
assert_op
,
signature
=
"(x1,x2),()->(x1,x2)"
)
matrix_assert
=
Blockwise
(
core_op
=
assert_op
,
signature
=
"(x1,x2),()->(x1,x2)"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论