Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0e595433
提交
0e595433
authored
11月 04, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix float16/cast handling and add/fix tests
上级
12c78b33
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
32 行增加
和
7 行删除
+32
-7
elemwise.py
theano/gpuarray/elemwise.py
+4
-5
test_elemwise.py
theano/gpuarray/tests/test_elemwise.py
+22
-1
basic.py
theano/scalar/basic.py
+5
-0
test_basic.py
theano/scalar/tests/test_basic.py
+1
-1
没有找到文件。
theano/gpuarray/elemwise.py
浏览文件 @
0e595433
...
@@ -108,9 +108,8 @@ class GpuElemwise(HideC, Elemwise):
...
@@ -108,9 +108,8 @@ class GpuElemwise(HideC, Elemwise):
# load in float16 and cast to float32 and do the reverse for
# load in float16 and cast to float32 and do the reverse for
# the output.
# the output.
scalar_op
=
self
.
scalar_op
scalar_op
=
self
.
scalar_op
if
isinstance
(
scalar_op
,
Composite
):
if
isinstance
(
scalar_op
,
(
scalar
.
Cast
,
Composite
)):
s
=
scalar_op
.
clone_float32
()
scalar_op
=
scalar_op
.
clone_float32
()
scalar_op
=
s
fake_node
=
scalar_op
.
make_node
(
*
scal_v_ins
)
fake_node
=
scalar_op
.
make_node
(
*
scal_v_ins
)
scal_v_out
=
fake_node
.
outputs
scal_v_out
=
fake_node
.
outputs
assert
len
(
scal_v_out
)
==
len
(
node
.
outputs
)
assert
len
(
scal_v_out
)
==
len
(
node
.
outputs
)
...
@@ -119,8 +118,8 @@ class GpuElemwise(HideC, Elemwise):
...
@@ -119,8 +118,8 @@ class GpuElemwise(HideC, Elemwise):
inps
,
outs
,
inps
,
outs
,
dict
(
fail
=
'return;'
))
dict
(
fail
=
'return;'
))
if
isinstance
(
scalar_op
,
Composite
):
# If the following assert fail, then we need to update the
# Other op like cast should handle float16 themself
.
# code handler above
.
assert
'npy_float16'
not
in
kop
assert
'npy_float16'
not
in
kop
support_code
=
""
support_code
=
""
...
...
theano/gpuarray/tests/test_elemwise.py
浏览文件 @
0e595433
...
@@ -52,7 +52,8 @@ def test_elemwise_pow():
...
@@ -52,7 +52,8 @@ def test_elemwise_pow():
assert_allclose
(
out
,
expected_out
)
assert_allclose
(
out
,
expected_out
)
def
test_composite_elemwise_float16
():
class
test_float16
():
def
test_composite_elemwise_float16
(
self
):
w
=
theano
.
tensor
.
bvector
()
w
=
theano
.
tensor
.
bvector
()
x
=
theano
.
tensor
.
vector
(
dtype
=
'float16'
)
x
=
theano
.
tensor
.
vector
(
dtype
=
'float16'
)
y
=
theano
.
tensor
.
fvector
()
y
=
theano
.
tensor
.
fvector
()
...
@@ -74,6 +75,26 @@ def test_composite_elemwise_float16():
...
@@ -74,6 +75,26 @@ def test_composite_elemwise_float16():
o
=
tensor
.
switch
(
v
,
tensor
.
mul
(
w
,
x
,
y
),
z
)
o
=
tensor
.
switch
(
v
,
tensor
.
mul
(
w
,
x
,
y
),
z
)
theano
.
function
([
v
,
w
,
x
,
y
,
z
],
o
,
mode
=
mode_with_gpu
)
theano
.
function
([
v
,
w
,
x
,
y
,
z
],
o
,
mode
=
mode_with_gpu
)
def
test_cast_float16
(
self
):
f16
=
theano
.
tensor
.
vector
(
dtype
=
'float16'
)
f32
=
theano
.
tensor
.
fvector
()
f
=
theano
.
function
([
f16
,
f32
],
[
f16
.
astype
(
'float32'
),
f32
.
astype
(
'float16'
),
f32
.
astype
(
'float64'
)],
mode
=
mode_with_gpu
)
d1
=
numpy
.
random
.
rand
(
4
)
.
astype
(
'float16'
)
d2
=
numpy
.
random
.
rand
(
5
)
.
astype
(
'float32'
)
res
=
f
(
d1
,
d2
)
assert
res
[
0
]
.
dtype
==
"float32"
assert
res
[
1
]
.
dtype
==
"float16"
assert
res
[
2
]
.
dtype
==
"float64"
assert_allclose
(
d1
,
res
[
0
])
assert_allclose
(
d2
,
res
[
1
])
assert_allclose
(
d2
,
res
[
2
])
class
test_GpuDimShuffle
(
test_elemwise
.
test_DimShuffle
):
class
test_GpuDimShuffle
(
test_elemwise
.
test_DimShuffle
):
op
=
GpuDimShuffle
op
=
GpuDimShuffle
...
...
theano/scalar/basic.py
浏览文件 @
0e595433
...
@@ -2220,6 +2220,11 @@ class Cast(UnaryScalarOp):
...
@@ -2220,6 +2220,11 @@ class Cast(UnaryScalarOp):
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
o_type
.
dtype
)
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
o_type
.
dtype
)
def
clone_float32
(
self
):
if
self
.
o_type
==
float16
:
return
identity
return
self
def
make_new_inplace
(
self
,
output_types_preference
=
None
,
name
=
None
):
def
make_new_inplace
(
self
,
output_types_preference
=
None
,
name
=
None
):
"""
"""
This op.__init__ fct don't have the same parameter as other scalar op.
This op.__init__ fct don't have the same parameter as other scalar op.
...
...
theano/scalar/tests/test_basic.py
浏览文件 @
0e595433
...
@@ -93,7 +93,7 @@ class test_composite(unittest.TestCase):
...
@@ -93,7 +93,7 @@ class test_composite(unittest.TestCase):
y
=
float16
()
y
=
float16
()
z
=
float16
()
z
=
float16
()
c
=
switch
(
v
,
mul
(
w
,
x
,
y
),
z
)
c
=
Composite
([
v
,
w
,
x
,
y
,
z
],
[
switch
(
v
,
mul
(
w
,
x
,
y
),
z
)]
)
assert
has_f16
(
c
)
assert
has_f16
(
c
)
nc
=
c
.
clone_float32
()
nc
=
c
.
clone_float32
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论