Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
abde1a16
Unverified
提交
abde1a16
authored
12月 08, 2020
作者:
Dan F-M
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding JAX conversion for BatchedDot
BatchedDot only supports tensor3 fixing broadcasting behavior in BatchedDot adding test for TypeError on dimension mismatch removing extra tests
上级
b0b34b59
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
49 行增加
和
0 行删除
+49
-0
test_jax.py
tests/sandbox/test_jax.py
+36
-0
jaxify.py
theano/sandbox/jaxify.py
+13
-0
没有找到文件。
tests/sandbox/test_jax.py
浏览文件 @
abde1a16
...
@@ -816,6 +816,42 @@ def test_second():
...
@@ -816,6 +816,42 @@ def test_second():
compare_jax_and_py
(
fgraph
,
[
np
.
zeros
([
5
],
dtype
=
theano
.
config
.
floatX
),
5.0
])
compare_jax_and_py
(
fgraph
,
[
np
.
zeros
([
5
],
dtype
=
theano
.
config
.
floatX
),
5.0
])
def
test_jax_BatchedDot
():
# tensor3 . tensor3
a
=
tt
.
tensor3
(
"a"
)
a
.
tag
.
test_value
=
(
np
.
linspace
(
-
1
,
1
,
10
*
5
*
3
)
.
astype
(
theano
.
config
.
floatX
)
.
reshape
((
10
,
5
,
3
))
)
b
=
tt
.
tensor3
(
"b"
)
b
.
tag
.
test_value
=
(
np
.
linspace
(
1
,
-
1
,
10
*
3
*
2
)
.
astype
(
theano
.
config
.
floatX
)
.
reshape
((
10
,
3
,
2
))
)
out
=
tt
.
blas
.
BatchedDot
()(
a
,
b
)
fgraph
=
theano
.
gof
.
FunctionGraph
([
a
,
b
],
[
out
])
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
# A dimension mismatch should raise a TypeError for compatibility
inputs
=
[
get_test_value
(
a
)[:
-
1
],
get_test_value
(
b
)]
opts
=
theano
.
gof
.
Query
(
include
=
[
None
],
exclude
=
[
"cxx_only"
,
"BlasOpt"
])
jax_mode
=
theano
.
compile
.
mode
.
Mode
(
theano
.
sandbox
.
jax_linker
.
JAXLinker
(),
opts
)
theano_jax_fn
=
theano
.
function
(
fgraph
.
inputs
,
fgraph
.
outputs
,
mode
=
jax_mode
)
with
pytest
.
raises
(
TypeError
):
theano_jax_fn
(
*
inputs
)
# matrix . matrix
a
=
tt
.
matrix
(
"a"
)
a
.
tag
.
test_value
=
(
np
.
linspace
(
-
1
,
1
,
5
*
3
)
.
astype
(
theano
.
config
.
floatX
)
.
reshape
((
5
,
3
))
)
b
=
tt
.
matrix
(
"b"
)
b
.
tag
.
test_value
=
(
np
.
linspace
(
1
,
-
1
,
5
*
3
)
.
astype
(
theano
.
config
.
floatX
)
.
reshape
((
5
,
3
))
)
out
=
tt
.
blas
.
BatchedDot
()(
a
,
b
)
fgraph
=
theano
.
gof
.
FunctionGraph
([
a
,
b
],
[
out
])
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
def
test_shared
():
def
test_shared
():
a
=
theano
.
shared
(
np
.
array
([
1
,
2
,
3
],
dtype
=
theano
.
config
.
floatX
))
a
=
theano
.
shared
(
np
.
array
([
1
,
2
,
3
],
dtype
=
theano
.
config
.
floatX
))
...
...
theano/sandbox/jaxify.py
浏览文件 @
abde1a16
...
@@ -34,6 +34,7 @@ from theano.tensor.basic import (
...
@@ -34,6 +34,7 @@ from theano.tensor.basic import (
ScalarFromTensor
,
ScalarFromTensor
,
TensorFromScalar
,
TensorFromScalar
,
)
)
from
theano.tensor.blas
import
BatchedDot
from
theano.tensor.elemwise
import
CAReduce
,
DimShuffle
,
Elemwise
from
theano.tensor.elemwise
import
CAReduce
,
DimShuffle
,
Elemwise
from
theano.tensor.extra_ops
import
(
from
theano.tensor.extra_ops
import
(
Bartlett
,
Bartlett
,
...
@@ -1066,3 +1067,15 @@ def jax_funcify_Eye(op):
...
@@ -1066,3 +1067,15 @@ def jax_funcify_Eye(op):
return
jnp
.
eye
(
N
,
M
,
k
,
dtype
=
dtype
)
return
jnp
.
eye
(
N
,
M
,
k
,
dtype
=
dtype
)
return
eye
return
eye
@jax_funcify.register
(
BatchedDot
)
def
jax_funcify_BatchedDot
(
op
):
def
batched_dot
(
a
,
b
):
if
a
.
shape
[
0
]
!=
b
.
shape
[
0
]:
raise
TypeError
(
"Shapes must match in the 0-th dimension"
)
if
a
.
ndim
==
2
or
b
.
ndim
==
2
:
return
jnp
.
einsum
(
"n...j,nj...->n..."
,
a
,
b
)
return
jnp
.
einsum
(
"nij,njk->nik"
,
a
,
b
)
return
batched_dot
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论