Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
39bda72a
提交
39bda72a
authored
6月 20, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
6月 29, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove deprecation warning on softmax functions
上级
60bc3688
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
8 行增加
和
38 行删除
+8
-38
special.py
pytensor/tensor/special.py
+2
-34
models.py
tests/d3viz/models.py
+1
-1
test_special.py
tests/tensor/rewriting/test_special.py
+2
-2
test_rop.py
tests/test_rop.py
+3
-1
没有找到文件。
pytensor/tensor/special.py
浏览文件 @
39bda72a
import
warnings
from
textwrap
import
dedent
from
textwrap
import
dedent
import
numpy
as
np
import
numpy
as
np
...
@@ -483,25 +482,8 @@ class Softmax(COp):
...
@@ -483,25 +482,8 @@ class Softmax(COp):
return
(
4
,)
return
(
4
,)
UNSET_AXIS
=
object
()
def
softmax
(
c
,
axis
=
None
):
def
softmax
(
c
,
axis
=
UNSET_AXIS
):
if
axis
is
UNSET_AXIS
:
warnings
.
warn
(
"Softmax now accepts an axis argument. For backwards-compatibility it defaults to -1 when not specified, "
"but in the future the default will be `None`.
\n
To suppress this warning specify axis explicitly."
,
FutureWarning
,
)
axis
=
-
1
c
=
as_tensor_variable
(
c
)
c
=
as_tensor_variable
(
c
)
if
c
.
ndim
==
1
:
# TODO: Create Specific warning type that can be suppressed?
warnings
.
warn
(
"Softmax no longer converts a vector to a row matrix."
,
UserWarning
,
)
return
Softmax
(
axis
=
axis
)(
c
)
return
Softmax
(
axis
=
axis
)(
c
)
...
@@ -749,22 +731,8 @@ class LogSoftmax(COp):
...
@@ -749,22 +731,8 @@ class LogSoftmax(COp):
return
(
1
,)
return
(
1
,)
def
log_softmax
(
c
,
axis
=
UNSET_AXIS
):
def
log_softmax
(
c
,
axis
=
None
):
if
axis
is
UNSET_AXIS
:
warnings
.
warn
(
"logsoftmax now accepts an axis argument. For backwards-compatibility it defaults to -1 when not specified, "
"but in the future the default will be `None`.
\n
To suppress this warning specify axis explicitly."
,
FutureWarning
,
)
axis
=
-
1
c
=
as_tensor_variable
(
c
)
c
=
as_tensor_variable
(
c
)
if
c
.
ndim
==
1
:
# TODO: Create Specific warning type that can be suppressed?
warnings
.
warn
(
"Softmax no longer converts a vector to a row matrix."
,
UserWarning
,
)
return
LogSoftmax
(
axis
=
axis
)(
c
)
return
LogSoftmax
(
axis
=
axis
)(
c
)
...
...
tests/d3viz/models.py
浏览文件 @
39bda72a
...
@@ -25,7 +25,7 @@ class Mlp:
...
@@ -25,7 +25,7 @@ class Mlp:
wy
=
shared
(
self
.
rng
.
normal
(
0
,
1
,
(
nhiddens
,
noutputs
)))
wy
=
shared
(
self
.
rng
.
normal
(
0
,
1
,
(
nhiddens
,
noutputs
)))
by
=
shared
(
np
.
zeros
(
noutputs
),
borrow
=
True
)
by
=
shared
(
np
.
zeros
(
noutputs
),
borrow
=
True
)
y
=
softmax
(
at
.
dot
(
h
,
wy
)
+
by
)
y
=
softmax
(
at
.
dot
(
h
,
wy
)
+
by
,
axis
=-
1
)
self
.
inputs
=
[
x
]
self
.
inputs
=
[
x
]
self
.
outputs
=
[
y
]
self
.
outputs
=
[
y
]
...
...
tests/tensor/rewriting/test_special.py
浏览文件 @
39bda72a
...
@@ -72,7 +72,7 @@ class TestLogSoftmaxRewrites:
...
@@ -72,7 +72,7 @@ class TestLogSoftmaxRewrites:
"""
"""
x
=
matrix
(
"x"
)
x
=
matrix
(
"x"
)
y
=
log
(
softmax
(
x
))
y
=
log
(
softmax
(
x
,
axis
=-
1
))
g
=
pytensor
.
tensor
.
grad
(
y
.
sum
(),
x
)
g
=
pytensor
.
tensor
.
grad
(
y
.
sum
(),
x
)
softmax_grad_node
=
g
.
owner
softmax_grad_node
=
g
.
owner
...
@@ -96,7 +96,7 @@ def test_log_softmax_stabilization():
...
@@ -96,7 +96,7 @@ def test_log_softmax_stabilization():
mode
=
mode
.
including
(
"local_log_softmax"
,
"specialize"
)
mode
=
mode
.
including
(
"local_log_softmax"
,
"specialize"
)
x
=
matrix
()
x
=
matrix
()
y
=
softmax
(
x
)
y
=
softmax
(
x
,
axis
=-
1
)
z
=
log
(
y
)
z
=
log
(
y
)
fgraph
=
FunctionGraph
([
x
],
[
z
])
fgraph
=
FunctionGraph
([
x
],
[
z
])
...
...
tests/test_rop.py
浏览文件 @
39bda72a
...
@@ -272,7 +272,9 @@ class TestRopLop(RopLopChecker):
...
@@ -272,7 +272,9 @@ class TestRopLop(RopLopChecker):
self
.
check_mat_rop_lop
(
self
.
mx
.
sum
(
axis
=
1
),
(
self
.
mat_in_shape
[
0
],))
self
.
check_mat_rop_lop
(
self
.
mx
.
sum
(
axis
=
1
),
(
self
.
mat_in_shape
[
0
],))
def
test_softmax
(
self
):
def
test_softmax
(
self
):
self
.
check_rop_lop
(
pytensor
.
tensor
.
special
.
softmax
(
self
.
x
),
self
.
in_shape
)
self
.
check_rop_lop
(
pytensor
.
tensor
.
special
.
softmax
(
self
.
x
,
axis
=-
1
),
self
.
in_shape
)
def
test_alloc
(
self
):
def
test_alloc
(
self
):
# Alloc of the sum of x into a vector
# Alloc of the sum of x into a vector
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论