Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1f3b41c8
提交
1f3b41c8
authored
9月 27, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use Elemwise NumPy information to convert CAReduce nodes to JAX
上级
80d8a0ef
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
13 行删除
+31
-13
test_jax.py
tests/sandbox/test_jax.py
+7
-1
jaxify.py
theano/sandbox/jaxify.py
+24
-12
没有找到文件。
tests/sandbox/test_jax.py
浏览文件 @
1f3b41c8
...
@@ -518,9 +518,15 @@ def test_tensor_basics():
...
@@ -518,9 +518,15 @@ def test_tensor_basics():
# optimizations are turned on; however, when using JAX mode, it should
# optimizations are turned on; however, when using JAX mode, it should
# leave the expression alone.
# leave the expression alone.
out
=
y
.
dot
(
alpha
*
A
)
.
dot
(
x
)
+
beta
*
y
out
=
y
.
dot
(
alpha
*
A
)
.
dot
(
x
)
+
beta
*
y
fgraph
=
theano
.
gof
.
FunctionGraph
([
y
,
x
,
A
,
alpha
,
beta
],
[
out
])
fgraph
=
theano
.
gof
.
FunctionGraph
([
y
,
x
,
A
,
alpha
,
beta
],
[
out
])
_
=
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
out
=
tt
.
maximum
(
y
,
x
)
fgraph
=
theano
.
gof
.
FunctionGraph
([
y
,
x
],
[
out
])
_
=
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
out
=
tt
.
max
(
y
)
fgraph
=
theano
.
gof
.
FunctionGraph
([
y
],
[
out
])
_
=
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
_
=
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
...
...
theano/sandbox/jaxify.py
浏览文件 @
1f3b41c8
...
@@ -528,28 +528,40 @@ def jax_funcify_FunctionGraph(fgraph):
...
@@ -528,28 +528,40 @@ def jax_funcify_FunctionGraph(fgraph):
@jax_funcify.register
(
CAReduce
)
@jax_funcify.register
(
CAReduce
)
def
jax_funcify_CAReduce
(
op
):
def
jax_funcify_CAReduce
(
op
):
def
careduce
(
x
):
axis
=
op
.
axis
axis
=
op
.
axis
op_nfunc_spec
=
getattr
(
op
,
"nfunc_spec"
,
None
)
scalar_nfunc_spec
=
getattr
(
op
.
scalar_op
,
"nfunc_spec"
,
None
)
scalar_op_name
=
getattr
(
op
.
scalar_op
,
"name"
,
None
)
scalar_op_identity
=
getattr
(
op
.
scalar_op
,
"identity"
,
None
)
acc_dtype
=
getattr
(
op
,
"acc_dtype"
,
None
)
def
careduce
(
x
):
nonlocal
axis
,
op_nfunc_spec
,
scalar_nfunc_spec
,
scalar_op_name
,
scalar_op_identity
,
acc_dtype
if
axis
is
None
:
if
axis
is
None
:
axis
=
list
(
range
(
x
.
ndim
))
axis
=
list
(
range
(
x
.
ndim
))
to_reduce
=
reversed
(
sorted
(
axis
))
if
acc_dtype
is
None
:
if
hasattr
(
op
,
"acc_dtype"
)
and
op
.
acc_dtype
is
not
None
:
acc_dtype
=
op
.
acc_dtype
else
:
acc_dtype
=
x
.
dtype
.
type
acc_dtype
=
x
.
dtype
.
type
if
op_nfunc_spec
:
jax_op
=
getattr
(
jnp
,
op_nfunc_spec
[
0
])
return
jax_op
(
x
,
axis
=
axis
)
.
astype
(
acc_dtype
)
# The Theano `Op` didn't tell us which NumPy equivalent to use (or
# there isn't one), so we use this fallback approach
if
scalar_nfunc_spec
:
scalar_fn_name
=
scalar_nfunc_spec
[
0
]
elif
scalar_op_name
:
scalar_fn_name
=
scalar_op_name
to_reduce
=
reversed
(
sorted
(
axis
))
if
to_reduce
:
if
to_reduce
:
if
getattr
(
op
.
scalar_op
,
"name"
,
None
):
jax_op
=
getattr
(
jax
.
lax
,
op
.
scalar_op
.
name
)
elif
getattr
(
op
.
scalar_op
,
"nfunc_spec"
,
None
):
# In this case, we need to use the `jax.lax` function (if there
# In this case, we need to use the `jax.lax` function (if there
# is one), and not the `jnp` version.
# is one), and not the `jnp` version.
jax_op
=
getattr
(
jax
.
lax
,
op
.
scalar_op
.
nfunc_spec
[
0
])
jax_op
=
getattr
(
jax
.
lax
,
scalar_fn_name
)
init_value
=
jnp
.
array
(
scalar_op_identity
,
dtype
=
acc_dtype
)
init_value
=
jnp
.
array
(
op
.
scalar_op
.
identity
,
dtype
=
acc_dtype
)
return
jax
.
lax
.
reduce
(
x
,
init_value
,
jax_op
,
to_reduce
)
.
astype
(
acc_dtype
)
return
jax
.
lax
.
reduce
(
x
,
init_value
,
jax_op
,
to_reduce
)
.
astype
(
acc_dtype
)
else
:
else
:
return
x
return
x
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论