Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PARL
提交
1f185137
P
PARL
项目概览
PaddlePaddle
/
PARL
通知
67
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PARL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1f185137
编写于
3月 23, 2020
作者:
Z
zenghsh3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine naming
上级
7fa307a6
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
22 addition
and
20 deletion
+22
-20
deepes/include/paddle/es_agent.h
deepes/include/paddle/es_agent.h
+3
-3
deepes/include/torch/es_agent.h
deepes/include/torch/es_agent.h
+9
-9
deepes/scripts/build.sh
deepes/scripts/build.sh
+3
-1
deepes/src/paddle/es_agent.cc
deepes/src/paddle/es_agent.cc
+7
-7
未找到文件。
deepes/include/paddle/es_agent.h
浏览文件 @
1f185137
...
...
@@ -78,8 +78,10 @@ class ESAgent {
std
::
shared_ptr
<
PaddlePredictor
>
get_predictor
();
private:
int64_t
_calculate_param_size
();
std
::
shared_ptr
<
PaddlePredictor
>
_predictor
;
std
::
shared_ptr
<
PaddlePredictor
>
_sampl
e
_predictor
;
std
::
shared_ptr
<
PaddlePredictor
>
_sampl
ing
_predictor
;
bool
_is_sampling_agent
;
std
::
shared_ptr
<
SamplingMethod
>
_sampling_method
;
std
::
shared_ptr
<
Optimizer
>
_optimizer
;
...
...
@@ -89,8 +91,6 @@ class ESAgent {
// malloc memory of noise and neg_gradients in advance.
float
*
_noise
;
float
*
_neg_gradients
;
int64_t
_calculate_param_size
();
};
}
...
...
deepes/include/torch/es_agent.h
浏览文件 @
1f185137
...
...
@@ -51,7 +51,7 @@ public:
_sampling_method
->
load_config
(
*
_config
);
_optimizer
=
std
::
make_shared
<
SGDOptimizer
>
(
_config
->
optimizer
().
base_lr
());
// Origin agent can't be used to sample, so keep it same with _model for evaluating.
_sampl
ed
_model
=
model
;
_sampl
ing
_model
=
model
;
_param_size
=
_calculate_param_size
();
_noise
=
new
float
[
_param_size
];
...
...
@@ -70,7 +70,7 @@ public:
new_agent
->
_model
=
_model
;
std
::
shared_ptr
<
T
>
new_model
=
_model
->
clone
();
new_agent
->
_sampl
ed
_model
=
new_model
;
new_agent
->
_sampl
ing
_model
=
new_model
;
new_agent
->
_is_sampling_agent
=
true
;
new_agent
->
_sampling_method
=
_sampling_method
;
...
...
@@ -89,7 +89,7 @@ public:
* if _is_sampling_agent is false, will use the original model without added noise.
*/
torch
::
Tensor
predict
(
const
torch
::
Tensor
&
x
)
{
return
_sampl
ed
_model
->
forward
(
x
);
return
_sampl
ing
_model
->
forward
(
x
);
}
/**
...
...
@@ -139,19 +139,19 @@ public:
return
false
;
}
auto
sampl
ed_params
=
_sampled
_model
->
named_parameters
();
auto
sampl
ing_params
=
_sampling
_model
->
named_parameters
();
auto
params
=
_model
->
named_parameters
();
int
key
=
_sampling_method
->
sampling
(
_noise
,
_param_size
);
sampling_key
.
add_key
(
key
);
int64_t
counter
=
0
;
for
(
auto
&
param
:
sampl
ed
_params
)
{
torch
::
Tensor
sampl
ed
_tensor
=
param
.
value
().
view
({
-
1
});
for
(
auto
&
param
:
sampl
ing
_params
)
{
torch
::
Tensor
sampl
ing
_tensor
=
param
.
value
().
view
({
-
1
});
std
::
string
param_name
=
param
.
key
();
torch
::
Tensor
tensor
=
params
.
find
(
param_name
)
->
view
({
-
1
});
auto
sampl
ed_tensor_a
=
sampled
_tensor
.
accessor
<
float
,
1
>
();
auto
sampl
ing_tensor_a
=
sampling
_tensor
.
accessor
<
float
,
1
>
();
auto
tensor_a
=
tensor
.
accessor
<
float
,
1
>
();
for
(
int64_t
j
=
0
;
j
<
tensor
.
size
(
0
);
++
j
)
{
sampl
ed
_tensor_a
[
j
]
=
tensor_a
[
j
]
+
_noise
[
counter
+
j
];
sampl
ing
_tensor_a
[
j
]
=
tensor_a
[
j
]
+
_noise
[
counter
+
j
];
}
counter
+=
tensor
.
size
(
0
);
}
...
...
@@ -161,7 +161,7 @@ public:
private:
std
::
shared_ptr
<
T
>
_sampl
ed
_model
;
std
::
shared_ptr
<
T
>
_sampl
ing
_model
;
std
::
shared_ptr
<
T
>
_model
;
bool
_is_sampling_agent
;
std
::
shared_ptr
<
SamplingMethod
>
_sampling_method
;
...
...
deepes/scripts/build.sh
浏览文件 @
1f185137
...
...
@@ -14,7 +14,9 @@ if [ $1 = "paddle" ]; then
fi
# Initialization model
if
[
!
-d
./demo/paddle/cartpole_init_model]
;
then
unzip ./demo/paddle/cartpole_init_model.zip
-d
./demo/paddle/
fi
FLAGS
=
" -DWITH_PADDLE=ON"
elif
[
$1
=
"torch"
]
;
then
...
...
deepes/src/paddle/es_agent.cc
浏览文件 @
1f185137
...
...
@@ -42,7 +42,7 @@ ESAgent::ESAgent(
_is_sampling_agent
=
false
;
_predictor
=
predictor
;
// Original agent can't be used to sample, so keep it same with _predictor for evaluating.
_sampl
e
_predictor
=
predictor
;
_sampl
ing
_predictor
=
predictor
;
_config
=
std
::
make_shared
<
DeepESConfig
>
();
load_proto_conf
(
config_path
,
*
_config
);
...
...
@@ -60,20 +60,20 @@ ESAgent::ESAgent(
}
std
::
shared_ptr
<
ESAgent
>
ESAgent
::
clone
()
{
std
::
shared_ptr
<
PaddlePredictor
>
new_sampl
e
_predictor
=
_predictor
->
Clone
();
std
::
shared_ptr
<
PaddlePredictor
>
new_sampl
ing
_predictor
=
_predictor
->
Clone
();
std
::
shared_ptr
<
ESAgent
>
new_agent
=
std
::
make_shared
<
ESAgent
>
();
float
*
n
ew_n
oise
=
new
float
[
_param_size
];
float
*
noise
=
new
float
[
_param_size
];
new_agent
->
_predictor
=
_predictor
;
new_agent
->
_sampl
e_predictor
=
new_sample
_predictor
;
new_agent
->
_sampl
ing_predictor
=
new_sampling
_predictor
;
new_agent
->
_is_sampling_agent
=
true
;
new_agent
->
_sampling_method
=
_sampling_method
;
new_agent
->
_param_names
=
_param_names
;
new_agent
->
_param_size
=
_param_size
;
new_agent
->
_noise
=
n
ew_n
oise
;
new_agent
->
_noise
=
noise
;
return
new_agent
;
}
...
...
@@ -126,7 +126,7 @@ bool ESAgent::add_noise(SamplingKey& sampling_key) {
int64_t
counter
=
0
;
for
(
std
::
string
param_name
:
_param_names
)
{
std
::
unique_ptr
<
Tensor
>
sample_tensor
=
_sampl
e
_predictor
->
GetMutableTensor
(
param_name
);
std
::
unique_ptr
<
Tensor
>
sample_tensor
=
_sampl
ing
_predictor
->
GetMutableTensor
(
param_name
);
std
::
unique_ptr
<
const
Tensor
>
tensor
=
_predictor
->
GetTensor
(
param_name
);
int64_t
tensor_size
=
ShapeProduction
(
tensor
->
shape
());
for
(
int64_t
j
=
0
;
j
<
tensor_size
;
++
j
)
{
...
...
@@ -140,7 +140,7 @@ bool ESAgent::add_noise(SamplingKey& sampling_key) {
std
::
shared_ptr
<
PaddlePredictor
>
ESAgent
::
get_predictor
()
{
return
_sampl
e
_predictor
;
return
_sampl
ing
_predictor
;
}
int64_t
ESAgent
::
_calculate_param_size
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录