Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4e2fc615
提交
4e2fc615
authored
2月 04, 2022
作者:
Rémi Louf
提交者:
Brandon T. Willard
2月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add JAX conversion for CheckAndRaiseOp
上级
e69f2d0a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
0 行删除
+28
-0
dispatch.py
aesara/link/jax/dispatch.py
+16
-0
test_jax.py
tests/link/test_jax.py
+12
-0
没有找到文件。
aesara/link/jax/dispatch.py
浏览文件 @
4e2fc615
...
@@ -14,6 +14,7 @@ from aesara.configdefaults import config
...
@@ -14,6 +14,7 @@ from aesara.configdefaults import config
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.fg
import
FunctionGraph
from
aesara.ifelse
import
IfElse
from
aesara.ifelse
import
IfElse
from
aesara.link.utils
import
fgraph_to_python
from
aesara.link.utils
import
fgraph_to_python
from
aesara.raise_op
import
CheckAndRaise
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.scalar.math
import
Erf
,
Erfc
,
Erfinv
,
Psi
from
aesara.scalar.math
import
Erf
,
Erfc
,
Erfinv
,
Psi
...
@@ -575,6 +576,21 @@ def jax_funcify_IfElse(op, **kwargs):
...
@@ -575,6 +576,21 @@ def jax_funcify_IfElse(op, **kwargs):
return
ifelse
return
ifelse
@jax_funcify.register
(
CheckAndRaise
)
def
jax_funcify_CheckAndRaise
(
op
,
**
kwargs
):
raise
NotImplementedError
(
f
"""This exception is raised because you tried to convert an aesara graph with a `CheckAndRaise` Op (message: {op.msg}) to JAX.
JAX uses tracing to jit-compile functions, and assertions typically
don't do well with tracing. The appropriate workaround depends on what
you intended to do with the assertions in the first place.
Note that all assertions can be removed from the graph by adding
`local_remove_all_assert` to the rewrites."""
)
@jax_funcify.register
(
Subtensor
)
@jax_funcify.register
(
Subtensor
)
def
jax_funcify_Subtensor
(
op
,
**
kwargs
):
def
jax_funcify_Subtensor
(
op
,
**
kwargs
):
...
...
tests/link/test_jax.py
浏览文件 @
4e2fc615
...
@@ -17,6 +17,7 @@ from aesara.graph.op import Op, get_test_value
...
@@ -17,6 +17,7 @@ from aesara.graph.op import Op, get_test_value
from
aesara.graph.optdb
import
OptimizationQuery
from
aesara.graph.optdb
import
OptimizationQuery
from
aesara.ifelse
import
ifelse
from
aesara.ifelse
import
ifelse
from
aesara.link.jax
import
JAXLinker
from
aesara.link.jax
import
JAXLinker
from
aesara.raise_op
import
assert_op
from
aesara.scalar.basic
import
Composite
from
aesara.scalar.basic
import
Composite
from
aesara.scan.basic
import
scan
from
aesara.scan.basic
import
scan
from
aesara.tensor
import
basic
as
at
from
aesara.tensor
import
basic
as
at
...
@@ -770,6 +771,17 @@ def test_jax_ifelse():
...
@@ -770,6 +771,17 @@ def test_jax_ifelse():
compare_jax_and_py
(
x_fg
,
[
get_test_value
(
i
)
for
i
in
x_fg
.
inputs
])
compare_jax_and_py
(
x_fg
,
[
get_test_value
(
i
)
for
i
in
x_fg
.
inputs
])
def
test_jax_checkandraise
():
p
=
scalar
()
p
.
tag
.
test_value
=
0
res
=
assert_op
(
p
,
p
<
1.0
)
res_fg
=
FunctionGraph
([
p
],
[
res
])
with
pytest
.
raises
(
NotImplementedError
):
compare_jax_and_py
(
res_fg
,
[
1.0
])
def
test_jax_CAReduce
():
def
test_jax_CAReduce
():
a_at
=
vector
(
"a"
)
a_at
=
vector
(
"a"
)
a_at
.
tag
.
test_value
=
np
.
r_
[
1
,
2
,
3
]
.
astype
(
config
.
floatX
)
a_at
.
tag
.
test_value
=
np
.
r_
[
1
,
2
,
3
]
.
astype
(
config
.
floatX
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论