Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
93368aac
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
93368aac
编写于
5月 09, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
差异文件
Merge develop
上级
9eec2c75
170ac721
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
33 deletion
+93
-33
paddle/fluid/operators/load_op.cc
paddle/fluid/operators/load_op.cc
+0
-13
paddle/fluid/platform/profiler.cc
paddle/fluid/platform/profiler.cc
+1
-1
python/paddle/fluid/tests/unittests/test_parallel_executor.py
...on/paddle/fluid/tests/unittests/test_parallel_executor.py
+92
-19
未找到文件。
paddle/fluid/operators/load_op.cc
浏览文件 @
93368aac
...
@@ -46,19 +46,6 @@ class LoadOp : public framework::OperatorBase {
...
@@ -46,19 +46,6 @@ class LoadOp : public framework::OperatorBase {
auto
*
tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
DeserializeFromStream
(
fin
,
tensor
,
*
dev_ctx
);
DeserializeFromStream
(
fin
,
tensor
,
*
dev_ctx
);
if
(
platform
::
is_gpu_place
(
place
))
{
// copy CPU to GPU
framework
::
LoDTensor
cpu_tensor
;
cpu_tensor
.
ShareDataWith
(
*
tensor
);
cpu_tensor
.
set_lod
(
tensor
->
lod
());
// reset tensor
out_var
->
Clear
();
tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
tensor
->
set_lod
(
cpu_tensor
.
lod
());
TensorCopy
(
cpu_tensor
,
place
,
*
dev_ctx
,
tensor
);
}
}
}
};
};
...
...
paddle/fluid/platform/profiler.cc
浏览文件 @
93368aac
...
@@ -463,7 +463,7 @@ void SetProfileListener() {
...
@@ -463,7 +463,7 @@ void SetProfileListener() {
std
::
mt19937
rng
;
std
::
mt19937
rng
;
rng
.
seed
(
std
::
random_device
()());
rng
.
seed
(
std
::
random_device
()());
std
::
uniform_int_distribution
<
std
::
mt19937
::
result_type
>
dist6
(
std
::
uniform_int_distribution
<
std
::
mt19937
::
result_type
>
dist6
(
1
,
std
::
numeric_limits
<
int64_t
>::
max
());
1
,
std
::
numeric_limits
<
std
::
mt19937
::
result_type
>::
max
());
profiler_lister_id
=
dist6
(
rng
);
profiler_lister_id
=
dist6
(
rng
);
}
}
int64_t
ListenerId
()
{
return
profiler_lister_id
;
}
int64_t
ListenerId
()
{
return
profiler_lister_id
;
}
...
...
python/paddle/fluid/tests/unittests/test_parallel_executor.py
浏览文件 @
93368aac
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
numpy
import
numpy
as
np
import
unittest
import
unittest
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
...
@@ -243,7 +243,7 @@ class TestParallelExecutorBase(unittest.TestCase):
...
@@ -243,7 +243,7 @@ class TestParallelExecutorBase(unittest.TestCase):
begin
=
time
.
time
()
begin
=
time
.
time
()
first_loss
,
=
run_executor
(
first_loss
,
=
run_executor
(
exe
=
exe
,
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
exe
=
exe
,
feed
=
feed_dict
,
fetch_list
=
[
loss
.
name
])
first_loss
=
n
umpy
.
array
(
first_loss
)
first_loss
=
n
p
.
array
(
first_loss
)
for
i
in
xrange
(
iter
):
for
i
in
xrange
(
iter
):
run_executor
(
exe
=
exe
,
feed
=
feed_dict
,
fetch_list
=
[])
run_executor
(
exe
=
exe
,
feed
=
feed_dict
,
fetch_list
=
[])
...
@@ -256,7 +256,7 @@ class TestParallelExecutorBase(unittest.TestCase):
...
@@ -256,7 +256,7 @@ class TestParallelExecutorBase(unittest.TestCase):
print
"%.4f Instance per second"
%
(
print
"%.4f Instance per second"
%
(
(
batch_size
*
iter
+
2
)
/
(
end
-
begin
))
(
batch_size
*
iter
+
2
)
/
(
end
-
begin
))
last_loss
=
n
umpy
.
array
(
last_loss
)
last_loss
=
n
p
.
array
(
last_loss
)
print
first_loss
,
last_loss
print
first_loss
,
last_loss
# self.assertGreater(first_loss[0], last_loss[0])
# self.assertGreater(first_loss[0], last_loss[0])
...
@@ -284,8 +284,8 @@ class TestMNIST(TestParallelExecutorBase):
...
@@ -284,8 +284,8 @@ class TestMNIST(TestParallelExecutorBase):
self
.
check_network_convergence
(
simple_fc_net
)
self
.
check_network_convergence
(
simple_fc_net
)
self
.
check_network_convergence
(
simple_fc_net
,
allow_op_delay
=
True
)
self
.
check_network_convergence
(
simple_fc_net
,
allow_op_delay
=
True
)
img
=
n
umpy
.
zeros
(
shape
=
[
32
,
784
],
dtype
=
'float32'
)
img
=
n
p
.
zeros
(
shape
=
[
32
,
784
],
dtype
=
'float32'
)
label
=
n
umpy
.
ones
(
shape
=
[
32
,
1
],
dtype
=
'int64'
)
label
=
n
p
.
ones
(
shape
=
[
32
,
1
],
dtype
=
'int64'
)
self
.
check_network_convergence
(
self
.
check_network_convergence
(
simple_fc_net
,
feed_dict
=
{
"image"
:
img
,
simple_fc_net
,
feed_dict
=
{
"image"
:
img
,
"label"
:
label
})
"label"
:
label
})
...
@@ -294,8 +294,8 @@ class TestMNIST(TestParallelExecutorBase):
...
@@ -294,8 +294,8 @@ class TestMNIST(TestParallelExecutorBase):
self
.
check_simple_fc_convergence
()
self
.
check_simple_fc_convergence
()
def
check_simple_fc_parallel_accuracy
(
self
):
def
check_simple_fc_parallel_accuracy
(
self
):
img
=
n
umpy
.
zeros
(
shape
=
[
32
,
784
],
dtype
=
'float32'
)
img
=
n
p
.
zeros
(
shape
=
[
32
,
784
],
dtype
=
'float32'
)
label
=
n
umpy
.
ones
(
shape
=
[
32
,
1
],
dtype
=
'int64'
)
label
=
n
p
.
ones
(
shape
=
[
32
,
1
],
dtype
=
'int64'
)
single_first_loss
,
single_last_loss
=
self
.
check_network_convergence
(
single_first_loss
,
single_last_loss
=
self
.
check_network_convergence
(
method
=
simple_fc_net
,
method
=
simple_fc_net
,
seed
=
1000
,
seed
=
1000
,
...
@@ -319,8 +319,8 @@ class TestMNIST(TestParallelExecutorBase):
...
@@ -319,8 +319,8 @@ class TestMNIST(TestParallelExecutorBase):
def
check_batchnorm_fc_convergence
(
self
):
def
check_batchnorm_fc_convergence
(
self
):
self
.
check_network_convergence
(
fc_with_batchnorm
)
self
.
check_network_convergence
(
fc_with_batchnorm
)
img
=
n
umpy
.
zeros
(
shape
=
[
32
,
784
],
dtype
=
'float32'
)
img
=
n
p
.
zeros
(
shape
=
[
32
,
784
],
dtype
=
'float32'
)
label
=
n
umpy
.
ones
(
shape
=
[
32
,
1
],
dtype
=
'int64'
)
label
=
n
p
.
ones
(
shape
=
[
32
,
1
],
dtype
=
'int64'
)
self
.
check_network_convergence
(
self
.
check_network_convergence
(
fc_with_batchnorm
,
feed_dict
=
{
"image"
:
img
,
fc_with_batchnorm
,
feed_dict
=
{
"image"
:
img
,
"label"
:
label
})
"label"
:
label
})
...
@@ -404,9 +404,6 @@ class ModelHyperParams(object):
...
@@ -404,9 +404,6 @@ class ModelHyperParams(object):
dropout
=
0.1
dropout
=
0.1
import
numpy
as
np
def
prepare_batch_input
(
insts
,
src_pad_idx
,
trg_pad_idx
,
n_head
):
def
prepare_batch_input
(
insts
,
src_pad_idx
,
trg_pad_idx
,
n_head
):
"""
"""
Pad the instances to the max sequence length in batch, and generate the
Pad the instances to the max sequence length in batch, and generate the
...
@@ -533,9 +530,8 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
...
@@ -533,9 +530,8 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
opt
.
minimize
(
loss
)
opt
.
minimize
(
loss
)
batch_size
=
32
batch_size
=
32
image
=
numpy
.
random
.
normal
(
size
=
(
batch_size
,
image
=
np
.
random
.
normal
(
size
=
(
batch_size
,
784
)).
astype
(
'float32'
)
784
)).
astype
(
'float32'
)
label
=
np
.
random
.
randint
(
0
,
10
,
(
batch_size
,
1
),
dtype
=
"int64"
)
label
=
numpy
.
random
.
randint
(
0
,
10
,
(
batch_size
,
1
),
dtype
=
"int64"
)
place
=
fluid
.
CUDAPlace
(
0
)
place
=
fluid
.
CUDAPlace
(
0
)
exe
=
fluid
.
Executor
(
place
)
exe
=
fluid
.
Executor
(
place
)
...
@@ -552,12 +548,12 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
...
@@ -552,12 +548,12 @@ class ParallelExecutorTestingDuringTraining(unittest.TestCase):
for
i
in
xrange
(
5
):
for
i
in
xrange
(
5
):
test_loss
,
=
test_exe
.
run
([
loss
.
name
],
feed
=
feed_dict
)
test_loss
,
=
test_exe
.
run
([
loss
.
name
],
feed
=
feed_dict
)
test_loss
=
n
umpy
.
array
(
test_loss
)
test_loss
=
n
p
.
array
(
test_loss
)
train_loss
,
=
train_exe
.
run
([
loss
.
name
],
feed
=
feed_dict
)
train_loss
,
=
train_exe
.
run
([
loss
.
name
],
feed
=
feed_dict
)
train_loss
=
n
umpy
.
array
(
train_loss
)
train_loss
=
n
p
.
array
(
train_loss
)
self
.
assertTrue
(
self
.
assertTrue
(
n
umpy
.
allclose
(
n
p
.
allclose
(
train_loss
,
test_loss
,
atol
=
1e-8
),
train_loss
,
test_loss
,
atol
=
1e-8
),
"Train loss: "
+
str
(
train_loss
)
+
"
\n
Test loss:"
+
"Train loss: "
+
str
(
train_loss
)
+
"
\n
Test loss:"
+
str
(
test_loss
))
str
(
test_loss
))
...
@@ -712,7 +708,7 @@ class TestCRFModel(unittest.TestCase):
...
@@ -712,7 +708,7 @@ class TestCRFModel(unittest.TestCase):
data
=
train_data
()
data
=
train_data
()
for
i
in
xrange
(
10
):
for
i
in
xrange
(
10
):
cur_batch
=
next
(
data
)
cur_batch
=
next
(
data
)
print
map
(
n
umpy
.
array
,
print
map
(
n
p
.
array
,
pe
.
run
(
feed
=
feeder
.
feed
(
cur_batch
),
pe
.
run
(
feed
=
feeder
.
feed
(
cur_batch
),
fetch_list
=
[
avg_cost
.
name
]))[
0
]
fetch_list
=
[
avg_cost
.
name
]))[
0
]
...
@@ -723,5 +719,82 @@ class TestCRFModel(unittest.TestCase):
...
@@ -723,5 +719,82 @@ class TestCRFModel(unittest.TestCase):
self
.
check_network_convergence
(
is_sparse
=
False
)
self
.
check_network_convergence
(
is_sparse
=
False
)
# test fetch all the variables of global_block
import
paddle.dataset.flowers
as
flowers
import
math
def
Lenet
(
data
,
class_dim
):
conv1
=
fluid
.
layers
.
conv2d
(
data
,
32
,
5
,
1
,
act
=
None
)
bn1
=
fluid
.
layers
.
batch_norm
(
conv1
,
act
=
'relu'
)
pool1
=
fluid
.
layers
.
pool2d
(
bn1
,
2
,
'max'
,
2
)
conv2
=
fluid
.
layers
.
conv2d
(
pool1
,
50
,
5
,
1
,
act
=
None
)
bn2
=
fluid
.
layers
.
batch_norm
(
conv2
,
act
=
'relu'
)
pool2
=
fluid
.
layers
.
pool2d
(
bn2
,
2
,
'max'
,
2
)
fc1
=
fluid
.
layers
.
fc
(
pool2
,
size
=
500
,
act
=
'relu'
)
fc2
=
fluid
.
layers
.
fc
(
fc1
,
size
=
class_dim
,
act
=
'softmax'
)
return
fc2
class
TestFetchOp
(
unittest
.
TestCase
):
def
parallel_exe
(
self
,
train_inputs
,
seed
):
main
=
fluid
.
Program
()
startup
=
fluid
.
Program
()
startup
.
random_seed
=
seed
with
fluid
.
program_guard
(
main
,
startup
):
data
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
3
,
224
,
224
],
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
out
=
Lenet
(
data
,
class_dim
=
102
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label
)
loss
=
fluid
.
layers
.
mean
(
loss
)
opt
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
0.1
,
momentum
=
0.9
,
regularization
=
fluid
.
regularizer
.
L2Decay
(
1e-4
))
opt
.
minimize
(
loss
)
# TODO(zcd): I found that onece the memory optimizer is open,
# parallel_exe doesn't fetch some variable, such as conv2d_0.b_0@GRAD,
# conv2d_1.b_0@GRAD. Those variables should not be pruned.
# fluid.memory_optimize(main)
place
=
fluid
.
CUDAPlace
(
0
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
startup
)
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
[
data
,
label
])
pe
=
fluid
.
ParallelExecutor
(
use_cuda
=
True
,
loss_name
=
loss
.
name
,
main_program
=
main
)
fetch_list
=
[]
all_vars
=
main
.
global_block
().
vars
for
k
,
v
in
all_vars
.
iteritems
():
if
'tmp'
not
in
k
and
k
[
0
]
is
not
'_'
or
v
.
persistable
:
fetch_list
.
append
(
k
)
for
data
in
train_inputs
:
ret
=
pe
.
run
(
fetch_list
,
feed
=
feeder
.
feed
(
data
))
for
i
in
range
(
len
(
fetch_list
)):
assert
not
math
.
isnan
(
np
.
sum
(
ret
[
i
]))
and
\
not
math
.
isinf
(
np
.
sum
(
ret
[
i
]))
def
test_update_sparse_parameter
(
self
):
tst_reader
=
paddle
.
batch
(
flowers
.
test
(
use_xmap
=
False
),
batch_size
=
16
)
tst_reader_iter
=
tst_reader
()
iters
=
3
train_inputs
=
[]
for
i
in
range
(
iters
):
train_inputs
.
append
(
tst_reader_iter
.
next
())
self
.
parallel_exe
(
train_inputs
,
seed
=
1
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录