Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dc8686bb
提交
dc8686bb
authored
5月 24, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make opt handle float16 and test it
上级
79ccac56
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
8 行删除
+17
-8
opt.py
theano/tensor/opt.py
+6
-4
test_opt.py
theano/tensor/tests/test_opt.py
+11
-4
没有找到文件。
theano/tensor/opt.py
浏览文件 @
dc8686bb
...
@@ -5717,11 +5717,13 @@ def local_opt_alloc(node):
...
@@ -5717,11 +5717,13 @@ def local_opt_alloc(node):
val
=
val
.
reshape
(
1
)[
0
]
val
=
val
.
reshape
(
1
)[
0
]
# check which type of op
# check which type of op
size
=
T
.
mul
(
*
shapes
)
size
=
T
.
mul
(
*
shapes
)
if
input
.
dtype
==
"float32"
:
if
input
.
dtype
in
[
"float16"
,
"float32"
]
:
# shapes are ints and normally int64.
# shapes are ints and normally int64.
# We don't want to have a float64 upcast here
# We don't want to have a float64 upcast
# if input is a float32.
# We don't want to downcast to float16
size
=
size
.
astype
(
input
.
dtype
)
# as we fear it could loose too much precision
# that will be amplified by the mul/pow below.
size
=
size
.
astype
(
'float32'
)
if
(
node
.
op
.
axis
is
None
or
if
(
node
.
op
.
axis
is
None
or
node
.
op
.
axis
==
tuple
(
range
(
input
.
ndim
))):
node
.
op
.
axis
==
tuple
(
range
(
input
.
ndim
))):
if
isinstance
(
node
.
op
,
T
.
Sum
):
if
isinstance
(
node
.
op
,
T
.
Sum
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
dc8686bb
...
@@ -5558,9 +5558,11 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -5558,9 +5558,11 @@ class T_local_sum_prod(unittest.TestCase):
class
T_local_opt_alloc
(
unittest
.
TestCase
):
class
T_local_opt_alloc
(
unittest
.
TestCase
):
dtype
=
'float32'
def
test_sum_upcast
(
self
):
def
test_sum_upcast
(
self
):
s
=
theano
.
tensor
.
lscalar
()
s
=
theano
.
tensor
.
lscalar
()
a
=
theano
.
tensor
.
alloc
(
np
.
asarray
(
5
,
dtype
=
'float32'
),
s
,
s
)
a
=
theano
.
tensor
.
alloc
(
np
.
asarray
(
5
,
dtype
=
self
.
dtype
),
s
,
s
)
orig
=
theano
.
config
.
warn_float64
orig
=
theano
.
config
.
warn_float64
theano
.
config
.
warn_float64
=
"raise"
theano
.
config
.
warn_float64
=
"raise"
try
:
try
:
...
@@ -5571,7 +5573,7 @@ class T_local_opt_alloc(unittest.TestCase):
...
@@ -5571,7 +5573,7 @@ class T_local_opt_alloc(unittest.TestCase):
def
test_prod_upcast
(
self
):
def
test_prod_upcast
(
self
):
s
=
theano
.
tensor
.
lscalar
()
s
=
theano
.
tensor
.
lscalar
()
a
=
theano
.
tensor
.
alloc
(
np
.
asarray
(
5
,
dtype
=
'float32'
),
s
,
s
)
a
=
theano
.
tensor
.
alloc
(
np
.
asarray
(
5
,
dtype
=
self
.
dtype
),
s
,
s
)
orig
=
theano
.
config
.
warn_float64
orig
=
theano
.
config
.
warn_float64
theano
.
config
.
warn_float64
=
"raise"
theano
.
config
.
warn_float64
=
"raise"
try
:
try
:
...
@@ -5587,11 +5589,16 @@ class T_local_opt_alloc(unittest.TestCase):
...
@@ -5587,11 +5589,16 @@ class T_local_opt_alloc(unittest.TestCase):
f
=
theano
.
function
([
s
],
a
.
sum
())
f
=
theano
.
function
([
s
],
a
.
sum
())
f
(
5
)
f
(
5
)
# test with user specified dtype
# test with user specified dtype
f
=
theano
.
function
([
s
],
a
.
sum
(
dtype
=
'float32'
))
f
=
theano
.
function
([
s
],
a
.
sum
(
dtype
=
self
.
dtype
))
f
(
5
)
f
(
5
)
# test only 1 axis summed
# test only 1 axis summed
f
=
theano
.
function
([
s
],
a
.
sum
(
axis
=
0
,
dtype
=
'float32'
))
f
=
theano
.
function
([
s
],
a
.
sum
(
axis
=
0
,
dtype
=
self
.
dtype
))
f
(
5
)
f
(
5
)
print
(
self
.
dtype
)
class
T_local_opt_alloc_f16
(
T_local_opt_alloc
):
dtype
=
'float16'
class
T_local_reduce
(
unittest
.
TestCase
):
class
T_local_reduce
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论