Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
79a4bc1e
提交
79a4bc1e
authored
1月 02, 2026
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
1月 02, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clone inner graphs of Ops that will be mutated during compilation
上级
ef0950a9
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
44 行增加
和
6 行删除
+44
-6
builders.py
pytensor/compile/builders.py
+1
-1
fg.py
pytensor/graph/fg.py
+6
-2
op.py
pytensor/scan/op.py
+1
-1
optimize.py
pytensor/tensor/optimize.py
+1
-1
test_compile_ops.py
tests/link/numba/test_compile_ops.py
+35
-1
没有找到文件。
pytensor/compile/builders.py
浏览文件 @
79a4bc1e
...
@@ -872,7 +872,7 @@ class OpFromGraph(Op, HasInnerGraph):
...
@@ -872,7 +872,7 @@ class OpFromGraph(Op, HasInnerGraph):
def
clone
(
self
):
def
clone
(
self
):
res
=
copy
(
self
)
res
=
copy
(
self
)
res
.
fgraph
=
res
.
fgraph
.
clone
()
res
.
fgraph
=
res
.
fgraph
.
clone
(
clone_inner_graphs
=
True
)
return
res
return
res
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
...
...
pytensor/graph/fg.py
浏览文件 @
79a4bc1e
...
@@ -838,9 +838,13 @@ class FunctionGraph(MetaObject):
...
@@ -838,9 +838,13 @@ class FunctionGraph(MetaObject):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
f
"FunctionGraph({', '.join(graph_as_string(self.inputs, self.outputs))})"
return
f
"FunctionGraph({', '.join(graph_as_string(self.inputs, self.outputs))})"
def
clone
(
self
,
check_integrity
=
True
)
->
"FunctionGraph"
:
def
clone
(
self
,
check_integrity
=
True
,
clone_inner_graphs
:
bool
=
False
)
->
"FunctionGraph"
:
"""Clone the graph."""
"""Clone the graph."""
return
self
.
clone_get_equiv
(
check_integrity
)[
0
]
return
self
.
clone_get_equiv
(
check_integrity
,
clone_inner_graphs
=
clone_inner_graphs
)[
0
]
def
clone_get_equiv
(
def
clone_get_equiv
(
self
,
check_integrity
:
bool
=
True
,
attach_feature
:
bool
=
True
,
**
kwargs
self
,
check_integrity
:
bool
=
True
,
attach_feature
:
bool
=
True
,
**
kwargs
...
...
pytensor/scan/op.py
浏览文件 @
79a4bc1e
...
@@ -1521,7 +1521,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
...
@@ -1521,7 +1521,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
def
clone
(
self
)
->
"Scan"
:
def
clone
(
self
)
->
"Scan"
:
res
=
copy
(
self
)
res
=
copy
(
self
)
res
.
fgraph
=
res
.
fgraph
.
clone
()
res
.
fgraph
=
res
.
fgraph
.
clone
(
clone_inner_graphs
=
True
)
return
res
return
res
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
,
impl
=
None
):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
,
impl
=
None
):
...
...
pytensor/tensor/optimize.py
浏览文件 @
79a4bc1e
...
@@ -211,7 +211,7 @@ class ScipyWrapperOp(Op, HasInnerGraph):
...
@@ -211,7 +211,7 @@ class ScipyWrapperOp(Op, HasInnerGraph):
def
clone
(
self
):
def
clone
(
self
):
copy_op
=
copy
(
self
)
copy_op
=
copy
(
self
)
copy_op
.
fgraph
=
self
.
fgraph
.
clone
()
copy_op
.
fgraph
=
self
.
fgraph
.
clone
(
clone_inner_graphs
=
True
)
return
copy_op
return
copy_op
def
prepare_node
(
def
prepare_node
(
...
...
tests/link/numba/test_compile_ops.py
浏览文件 @
79a4bc1e
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
from
pytensor
import
OpFromGraph
,
config
,
function
,
ifelse
from
pytensor
import
Mode
,
OpFromGraph
,
config
,
function
,
ifelse
,
scan
from
pytensor
import
tensor
as
pt
from
pytensor
import
tensor
as
pt
from
pytensor.compile
import
ViewOp
from
pytensor.compile
import
ViewOp
from
pytensor.graph
import
vectorize_graph
from
pytensor.graph
import
vectorize_graph
from
pytensor.raise_op
import
assert_op
from
pytensor.raise_op
import
assert_op
from
pytensor.scalar
import
Add
from
pytensor.scalar
import
Add
from
pytensor.scan.op
import
Scan
from
pytensor.tensor
import
dmatrix
,
dtensor3
,
matrix
from
pytensor.tensor
import
dmatrix
,
dtensor3
,
matrix
from
pytensor.tensor.blockwise
import
Blockwise
,
BlockwiseWithCoreShape
from
pytensor.tensor.elemwise
import
Elemwise
from
pytensor.tensor.elemwise
import
Elemwise
from
pytensor.tensor.slinalg
import
Cholesky
from
tests.link.numba.test_basic
import
compare_numba_and_py
from
tests.link.numba.test_basic
import
compare_numba_and_py
...
@@ -197,3 +200,34 @@ def test_check_and_raise():
...
@@ -197,3 +200,34 @@ def test_check_and_raise():
out
=
assert_op
(
x
.
sum
(),
np
.
array
(
True
))
out
=
assert_op
(
x
.
sum
(),
np
.
array
(
True
))
compare_numba_and_py
([
x
],
out
,
[
x_test_value
])
compare_numba_and_py
([
x
],
out
,
[
x_test_value
])
def
test_ofg_with_inner_scan_rewrite
():
# Regression test where inner scan would be mutated when compiling outer OFG
ys
=
pt
.
tensor
(
"ys"
,
shape
=
(
5
,
3
,
3
))
xs
=
scan
(
lambda
y
:
pt
.
linalg
.
cholesky
(
y
),
sequences
=
[
ys
],
return_updates
=
False
,
mode
=
Mode
(
optimizer
=
None
),
)
xs_ofg
=
OpFromGraph
([
ys
],
[
xs
])(
ys
)
fn
=
function
([
ys
],
xs_ofg
,
mode
=
"NUMBA"
)
# Check that we have a BlockwiseWithCoreShape in the inner Scan
fn_ofg_op
=
fn
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
isinstance
(
fn_ofg_op
,
OpFromGraph
)
fn_scan_op
=
fn_ofg_op
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
isinstance
(
fn_scan_op
,
Scan
)
fn_cholesky_op
=
fn_scan_op
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
isinstance
(
fn_cholesky_op
,
BlockwiseWithCoreShape
)
assert
isinstance
(
fn_cholesky_op
.
core_op
,
Cholesky
)
# Check original Ops aren't modified
ofg_op
=
xs_ofg
.
owner
.
op
assert
isinstance
(
ofg_op
,
OpFromGraph
)
scan_op
=
ofg_op
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
isinstance
(
scan_op
,
Scan
)
cholesky_op
=
scan_op
.
fgraph
.
outputs
[
0
]
.
owner
.
op
assert
isinstance
(
cholesky_op
,
Blockwise
)
assert
isinstance
(
cholesky_op
.
core_op
,
Cholesky
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论