Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f06146ae
提交
f06146ae
authored
11月 24, 2021
作者:
Ricardo
提交者:
Brandon T. Willard
12月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add SoftmaxGrad jax dispatch
上级
bafd9638
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
1 行删除
+24
-1
dispatch.py
aesara/link/jax/dispatch.py
+12
-1
test_jax.py
tests/link/test_jax.py
+12
-0
没有找到文件。
aesara/link/jax/dispatch.py
浏览文件 @
f06146ae
...
@@ -47,7 +47,7 @@ from aesara.tensor.extra_ops import (
...
@@ -47,7 +47,7 @@ from aesara.tensor.extra_ops import (
)
)
from
aesara.tensor.math
import
Dot
,
MaxAndArgmax
from
aesara.tensor.math
import
Dot
,
MaxAndArgmax
from
aesara.tensor.nlinalg
import
SVD
,
Det
,
Eig
,
Eigh
,
MatrixInverse
,
QRFull
from
aesara.tensor.nlinalg
import
SVD
,
Det
,
Eig
,
Eigh
,
MatrixInverse
,
QRFull
from
aesara.tensor.nnet.basic
import
LogSoftmax
,
Softmax
from
aesara.tensor.nnet.basic
import
LogSoftmax
,
Softmax
,
SoftmaxGrad
from
aesara.tensor.random.op
import
RandomVariable
from
aesara.tensor.random.op
import
RandomVariable
from
aesara.tensor.shape
import
Reshape
,
Shape
,
Shape_i
,
SpecifyShape
from
aesara.tensor.shape
import
Reshape
,
Shape
,
Shape_i
,
SpecifyShape
from
aesara.tensor.slinalg
import
Cholesky
,
Solve
from
aesara.tensor.slinalg
import
Cholesky
,
Solve
...
@@ -206,6 +206,17 @@ def jax_funcify_Softmax(op, **kwargs):
...
@@ -206,6 +206,17 @@ def jax_funcify_Softmax(op, **kwargs):
return
softmax
return
softmax
@jax_funcify.register
(
SoftmaxGrad
)
def
jax_funcify_SoftmaxGrad
(
op
,
**
kwargs
):
axis
=
op
.
axis
def
softmax_grad
(
dy
,
sm
):
dy_times_sm
=
dy
*
sm
return
dy_times_sm
-
jnp
.
sum
(
dy_times_sm
,
axis
=
axis
,
keepdims
=
True
)
*
sm
return
softmax_grad
@jax_funcify.register
(
LogSoftmax
)
@jax_funcify.register
(
LogSoftmax
)
def
jax_funcify_LogSoftmax
(
op
,
**
kwargs
):
def
jax_funcify_LogSoftmax
(
op
,
**
kwargs
):
axis
=
op
.
axis
axis
=
op
.
axis
...
...
tests/link/test_jax.py
浏览文件 @
f06146ae
...
@@ -34,6 +34,7 @@ from aesara.tensor.math import clip, cosh, erf, erfc, erfinv, gammaln, log
...
@@ -34,6 +34,7 @@ from aesara.tensor.math import clip, cosh, erf, erfc, erfinv, gammaln, log
from
aesara.tensor.math
import
max
as
aet_max
from
aesara.tensor.math
import
max
as
aet_max
from
aesara.tensor.math
import
maximum
,
prod
,
psi
,
sigmoid
,
softplus
from
aesara.tensor.math
import
maximum
,
prod
,
psi
,
sigmoid
,
softplus
from
aesara.tensor.math
import
sum
as
aet_sum
from
aesara.tensor.math
import
sum
as
aet_sum
from
aesara.tensor.nnet.basic
import
SoftmaxGrad
from
aesara.tensor.random.basic
import
RandomVariable
,
normal
from
aesara.tensor.random.basic
import
RandomVariable
,
normal
from
aesara.tensor.random.utils
import
RandomStream
from
aesara.tensor.random.utils
import
RandomStream
from
aesara.tensor.shape
import
Shape
,
Shape_i
,
SpecifyShape
,
reshape
from
aesara.tensor.shape
import
Shape
,
Shape_i
,
SpecifyShape
,
reshape
...
@@ -988,6 +989,17 @@ def test_logsoftmax(axis):
...
@@ -988,6 +989,17 @@ def test_logsoftmax(axis):
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
])
@pytest.mark.parametrize
(
"axis"
,
[
None
,
0
,
1
])
def
test_softmax_grad
(
axis
):
dy
=
matrix
(
"dy"
)
dy
.
tag
.
test_value
=
np
.
array
([[
1
,
1
,
1
],
[
0
,
0
,
0
]],
dtype
=
config
.
floatX
)
sm
=
matrix
(
"sm"
)
sm
.
tag
.
test_value
=
np
.
arange
(
6
,
dtype
=
config
.
floatX
)
.
reshape
(
2
,
3
)
out
=
SoftmaxGrad
(
axis
=
axis
)(
dy
,
sm
)
fgraph
=
FunctionGraph
([
dy
,
sm
],
[
out
])
compare_jax_and_py
(
fgraph
,
[
get_test_value
(
i
)
for
i
in
fgraph
.
inputs
])
@pytest.mark.xfail
(
@pytest.mark.xfail
(
version_parse
(
jax
.
__version__
)
>=
version_parse
(
"0.2.12"
),
version_parse
(
jax
.
__version__
)
>=
version_parse
(
"0.2.12"
),
reason
=
"Omnistaging cannot be disabled"
,
reason
=
"Omnistaging cannot be disabled"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论