Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6557682b
提交
6557682b
authored
5月 19, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
5月 23, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow Blockwise to compile C inner thunks
上级
261aaf37
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
2 行删除
+22
-2
blockwise.py
pytensor/tensor/blockwise.py
+22
-2
没有找到文件。
pytensor/tensor/blockwise.py
浏览文件 @
6557682b
...
...
@@ -16,6 +16,7 @@ from pytensor.graph.replace import (
_vectorize_not_needed
,
vectorize_graph
,
)
from
pytensor.link.c.op
import
COp
from
pytensor.scalar
import
ScalarType
from
pytensor.tensor
import
as_tensor_variable
from
pytensor.tensor.shape
import
shape_padleft
...
...
@@ -43,7 +44,18 @@ def _vectorize_node_perform(
"""
storage_map
=
{
var
:
[
None
]
for
var
in
core_node
.
inputs
+
core_node
.
outputs
}
core_thunk
=
core_node
.
op
.
make_thunk
(
core_node
,
storage_map
,
None
,
[],
impl
=
impl
)
try
:
core_thunk
=
core_node
.
op
.
make_thunk
(
core_node
,
storage_map
,
None
,
[],
impl
=
impl
)
except
NotImplementedError
:
if
impl
==
"c"
:
# Try again with py impl
core_thunk
=
core_node
.
op
.
make_thunk
(
core_node
,
storage_map
,
None
,
[],
impl
=
"py"
)
else
:
raise
single_in
=
len
(
core_node
.
inputs
)
==
1
core_input_storage
=
[
storage_map
[
inp
]
for
inp
in
core_node
.
inputs
]
core_output_storage
=
[
storage_map
[
out
]
for
out
in
core_node
.
outputs
]
...
...
@@ -128,7 +140,7 @@ def _check_runtime_broadcast_core(numerical_inputs, batch_bcast_patterns, batch_
)
class
Blockwise
(
Op
):
class
Blockwise
(
C
Op
):
"""Generalizes a core `Op` to work with batched dimensions.
TODO: Dispatch JAX (should be easy with the vectorize macro)
...
...
@@ -483,6 +495,14 @@ class Blockwise(Op):
else
:
return
self
.
name
def
c_code
(
self
,
*
args
,
**
kwargs
):
# Blockwise is a C_Op just so we can propagate compilation mode to the inner Op.
# It doesn't itself have a C implementation yet.
raise
NotImplementedError
()
def
c_code_cache_version
(
self
):
return
(
-
1
,)
@_vectorize_node.register
(
Op
)
def
vectorize_node_fallback
(
op
:
Op
,
node
:
Apply
,
*
bached_inputs
)
->
Apply
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论