Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3bc8cd31
提交
3bc8cd31
authored
6月 14, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix typos and add test to check if gradients are disabled in GPU CTC test
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
a67aa22b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
19 行删除
+18
-19
test_ctc.py
theano/gpuarray/tests/test_ctc.py
+18
-19
没有找到文件。
theano/gpuarray/tests/test_ctc.py
浏览文件 @
3bc8cd31
...
...
@@ -26,13 +26,13 @@ class TestCTC(unittest.TestCase):
inputs
=
[
t_activations
,
t_labels
,
t_activation_times
]
# Execute several tests for each test case
self
.
check_expected_values
(
*
input
s
,
expected_costs
,
expected_grads
)
self
.
check_expected_values
(
t_activations
,
t_labels
,
t_activation_time
s
,
expected_costs
,
expected_grads
)
self
.
compare_gpu_and_cpu_values
(
*
inputs
)
self
.
check_grads_disabled
(
*
inputs
)
self
.
run_gpu_optimization_with_grad
(
*
inputs
)
self
.
run_gpu_optimization_no_grad
(
*
inputs
)
def
setup_cpu_op
(
self
,
activations
,
labels
,
input_length
,
compute_grad
=
True
,
mode
=
mode_without_gpu
):
# Compute CTC costs and gradients on the CPU to compare with GPU
cpu_ctc_cost
=
ctc
(
activations
,
labels
,
input_length
)
outputs
=
[
cpu_ctc_cost
]
if
compute_grad
:
...
...
@@ -42,7 +42,6 @@ class TestCTC(unittest.TestCase):
return
theano
.
function
([],
outputs
,
mode
=
mode
)
def
setup_gpu_op
(
self
,
activations
,
labels
,
input_length
,
compute_grad
=
True
):
# Compute CTC costs and gradients on the CPU to compare with GPU
gpu_ctc_cost
=
gpu_ctc
(
activations
,
labels
,
input_length
)
outputs
=
[
gpu_ctc_cost
]
if
compute_grad
:
...
...
@@ -76,26 +75,26 @@ class TestCTC(unittest.TestCase):
utt
.
assert_allclose
(
cpu_grad
,
grad_from_gpu
)
utt
.
assert_allclose
(
cpu_cost
,
cost_from_gpu
)
def
check_grads_disabled
(
self
,
activations
,
labels
,
input_length
):
"""
Check if optimization to disable gradients is working
"""
gpu_ctc_cost
=
gpu_ctc
(
activations
,
labels
,
input_length
)
gpu_ctc_function
=
theano
.
function
([],
[
gpu_ctc_cost
])
for
node
in
gpu_ctc_function
.
maker
.
fgraph
.
apply_nodes
:
if
isinstance
(
node
.
op
,
GpuConnectionistTemporalClassification
):
assert
(
node
.
op
.
compute_grad
is
False
)
def
run_gpu_optimization_with_grad
(
self
,
activations
,
labels
,
input_length
):
cpu_train
=
self
.
setup_cpu_op
(
activations
,
labels
,
input_length
)
cpu_cost
,
cpu_grad
=
cpu_train
()
# Compile CPU function without optimization
# Compile CPU function with optimization
cpu_lifted_train
=
self
.
setup_cpu_op
(
activations
,
labels
,
input_length
,
mode
=
mode_with_gpu
)
# Check whether Op is lifted to the GPU
assert
self
.
has_only_gpu_op
(
cpu_lifted_train
)
gpu_cost
,
gpu_grad
=
cpu_lifted_train
()
# Transfer costs from GPU memory to host
cost_from_gpu
=
np
.
asarray
(
gpu_cost
)
# Transfer gradients from GPU memory to host
grad_from_gpu
=
np
.
asarray
(
gpu_grad
)
# Compare values from CPU and GPU Ops
utt
.
assert_allclose
(
cpu_cost
,
cost_from_gpu
)
utt
.
assert_allclose
(
cpu_grad
,
grad_from_gpu
)
def
run_gpu_optimization_no_grad
(
self
,
activations
,
labels
,
input_length
):
cpu_t
est
=
self
.
setup_cpu_op
(
activations
,
labels
,
input_length
,
compute_grad
=
False
)
cpu_cost
=
cpu_t
est
()
# Compile CPU function with
out
optimization
cpu_t
rain
=
self
.
setup_cpu_op
(
activations
,
labels
,
input_length
,
compute_grad
=
False
)
cpu_cost
=
cpu_t
rain
()
# Compile CPU function with optimization
cpu_lifted_test
=
self
.
setup_cpu_op
(
activations
,
labels
,
input_length
,
compute_grad
=
False
,
mode
=
mode_with_gpu
)
# Check whether Op is lifted to the GPU
assert
self
.
has_only_gpu_op
(
cpu_lifted_test
)
...
...
@@ -110,10 +109,10 @@ class TestCTC(unittest.TestCase):
has_gpu_instance
=
False
for
node
in
function
.
maker
.
fgraph
.
apply_nodes
:
if
isinstance
(
node
.
op
,
ConnectionistTemporalClassification
):
has_
g
pu_instance
=
True
has_
c
pu_instance
=
True
if
isinstance
(
node
.
op
,
GpuConnectionistTemporalClassification
):
has_
c
pu_instance
=
True
has_
g
pu_instance
=
True
return
has_gpu_instance
and
(
not
has_cpu_instance
)
# Test obtained from Torch tutorial at:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论