Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e09e2b1e
提交
e09e2b1e
authored
11月 16, 2020
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Return the correct output for multi-output inputs in a JAXified graph
上级
99f08ee3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
2 行删除
+34
-2
test_jax.py
tests/sandbox/test_jax.py
+8
-0
jaxify.py
theano/sandbox/jaxify.py
+26
-2
没有找到文件。
tests/sandbox/test_jax.py
浏览文件 @
e09e2b1e
...
@@ -281,6 +281,14 @@ def test_jax_basic_multiout():
...
@@ -281,6 +281,14 @@ def test_jax_basic_multiout():
out_fg
=
theano
.
gof
.
FunctionGraph
([
x
],
outs
)
out_fg
=
theano
.
gof
.
FunctionGraph
([
x
],
outs
)
compare_jax_and_py
(
out_fg
,
[
X
.
astype
(
tt
.
config
.
floatX
)],
assert_fn
=
assert_fn
)
compare_jax_and_py
(
out_fg
,
[
X
.
astype
(
tt
.
config
.
floatX
)],
assert_fn
=
assert_fn
)
# Test that a single output of a multi-output `Op` can be used as input to
# another `Op`
x
=
tt
.
dvector
()
mx
,
amx
=
theano
.
tensor
.
MaxAndArgmax
([
0
])(
x
)
out
=
mx
*
amx
out_fg
=
theano
.
gof
.
FunctionGraph
([
x
],
[
out
])
compare_jax_and_py
(
out_fg
,
[
np
.
r_
[
1
,
2
]])
@pytest.mark.skip
(
reason
=
"Not fully implemented, yet."
)
@pytest.mark.skip
(
reason
=
"Not fully implemented, yet."
)
def
test_jax_scan
():
def
test_jax_scan
():
...
...
theano/sandbox/jaxify.py
浏览文件 @
e09e2b1e
...
@@ -93,10 +93,13 @@ incsubtensor_ops = (IncSubtensor, AdvancedIncSubtensor1)
...
@@ -93,10 +93,13 @@ incsubtensor_ops = (IncSubtensor, AdvancedIncSubtensor1)
def
compose_jax_funcs
(
out_node
,
fgraph_inputs
,
memo
=
None
):
def
compose_jax_funcs
(
out_node
,
fgraph_inputs
,
memo
=
None
):
"""Compose JAX implementations of node operations.
"""Compose JAX implementations of node operations.
This function walks the graph given by the `Apply` node, `out_node`, and
creates JAX JIT-able functions for its input and output variables.
Parameters
Parameters
----------
----------
out_node:
Node
out_node:
theano.gof.graph.Apply
The
output node
.
The
node for which we want to construct a JAX JIT-able function
.
fgraph_inputs: List[Variable]
fgraph_inputs: List[Variable]
The inputs--in a `FunctionGraph` sense--to `out_node`.
The inputs--in a `FunctionGraph` sense--to `out_node`.
memo: Mapping (Optional)
memo: Mapping (Optional)
...
@@ -116,9 +119,13 @@ def compose_jax_funcs(out_node, fgraph_inputs, memo=None):
...
@@ -116,9 +119,13 @@ def compose_jax_funcs(out_node, fgraph_inputs, memo=None):
jax_return_func
=
jax_funcify
(
out_node
.
op
)
jax_return_func
=
jax_funcify
(
out_node
.
op
)
# We create a list of JAX-able functions that produce the values of each
# input variable for `out_node`.
input_funcs
=
[]
input_funcs
=
[]
for
i
in
out_node
.
inputs
:
for
i
in
out_node
.
inputs
:
if
i
in
fgraph_inputs
:
if
i
in
fgraph_inputs
:
# This input is a top-level input (i.e. an input to the
# `FunctionGraph` in which this `out_node` resides)
idx
=
fgraph_inputs
.
index
(
i
)
idx
=
fgraph_inputs
.
index
(
i
)
i_dtype
=
getattr
(
i
,
"dtype"
,
None
)
i_dtype
=
getattr
(
i
,
"dtype"
,
None
)
...
@@ -129,6 +136,7 @@ def compose_jax_funcs(out_node, fgraph_inputs, memo=None):
...
@@ -129,6 +136,7 @@ def compose_jax_funcs(out_node, fgraph_inputs, memo=None):
input_f
=
jax_inputs_func
input_f
=
jax_inputs_func
elif
i
.
owner
is
None
:
elif
i
.
owner
is
None
:
# This input is something like a `theano.gof.graph.Constant`
i_dtype
=
getattr
(
i
,
"dtype"
,
None
)
i_dtype
=
getattr
(
i
,
"dtype"
,
None
)
i_data
=
i
.
data
i_data
=
i
.
data
...
@@ -141,8 +149,24 @@ def compose_jax_funcs(out_node, fgraph_inputs, memo=None):
...
@@ -141,8 +149,24 @@ def compose_jax_funcs(out_node, fgraph_inputs, memo=None):
input_f
=
jax_data_func
input_f
=
jax_data_func
else
:
else
:
# This input is the output of another node, so we need to
# generate a JAX-able function for its subgraph
input_f
=
compose_jax_funcs
(
i
.
owner
,
fgraph_inputs
,
memo
)
input_f
=
compose_jax_funcs
(
i
.
owner
,
fgraph_inputs
,
memo
)
if
i
.
owner
.
nout
>
1
:
# This input is one of multiple outputs from the `i.owner`
# node, and we need to determine exactly which one it is and
# create a JAX-able function that returns only it.
out_idx
=
i
.
owner
.
outputs
.
index
(
i
)
(
out_fn
,)
=
input_f
def
jax_multiout_func
(
*
inputs
,
out_idx
=
out_idx
,
out_fn
=
out_fn
):
return
out_fn
(
*
inputs
)[
out_idx
]
input_f
=
jax_multiout_func
assert
callable
(
input_f
)
input_funcs
.
append
(
input_f
)
input_funcs
.
append
(
input_f
)
if
not
isinstance
(
jax_return_func
,
Sequence
):
if
not
isinstance
(
jax_return_func
,
Sequence
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论