Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
f0d571da
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f0d571da
编写于
8月 27, 2019
作者:
Y
yaopenghui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cost monitor
上级
9da0a7f4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
107 addition
and
1 deletion
+107
-1
paddle/fluid/train/custom_trainer/feed/executor/executor.h
paddle/fluid/train/custom_trainer/feed/executor/executor.h
+4
-0
paddle/fluid/train/custom_trainer/feed/monitor/auc_monitor.cc
...le/fluid/train/custom_trainer/feed/monitor/auc_monitor.cc
+1
-1
paddle/fluid/train/custom_trainer/feed/monitor/cost_monitor.cc
...e/fluid/train/custom_trainer/feed/monitor/cost_monitor.cc
+49
-0
paddle/fluid/train/custom_trainer/feed/monitor/cost_monitor.h
...le/fluid/train/custom_trainer/feed/monitor/cost_monitor.h
+53
-0
未找到文件。
paddle/fluid/train/custom_trainer/feed/executor/executor.h
浏览文件 @
f0d571da
...
@@ -37,6 +37,10 @@ public:
...
@@ -37,6 +37,10 @@ public:
virtual
bool
is_dump_all_model
()
{
virtual
bool
is_dump_all_model
()
{
return
false
;
return
false
;
}
}
// cost time millisecond
virtual
uint64_t
epoch_cost
()
const
{
return
0
;
}
protected:
protected:
::
paddle
::
framework
::
Scope
_scope
;
::
paddle
::
framework
::
Scope
_scope
;
};
};
...
...
paddle/fluid/train/custom_trainer/feed/monitor/auc_monitor.cc
浏览文件 @
f0d571da
...
@@ -44,6 +44,7 @@ void AucMonitor::add_data(int epoch_id, const Executor* executor, SampleInstance
...
@@ -44,6 +44,7 @@ void AucMonitor::add_data(int epoch_id, const Executor* executor, SampleInstance
bool
AucMonitor
::
need_compute_result
(
int
epoch_id
,
EpochAccessor
*
accessor
)
{
bool
AucMonitor
::
need_compute_result
(
int
epoch_id
,
EpochAccessor
*
accessor
)
{
CHECK
(
accessor
!=
nullptr
);
CHECK
(
accessor
!=
nullptr
);
uint64_t
epoch_time
=
accessor
->
epoch_timestamp
(
epoch_id
);
uint64_t
epoch_time
=
accessor
->
epoch_timestamp
(
epoch_id
);
CHECK
(
_compute_interval
!=
0
);
if
(
epoch_time
%
_compute_interval
!=
0
)
{
if
(
epoch_time
%
_compute_interval
!=
0
)
{
return
false
;
return
false
;
}
}
...
@@ -68,7 +69,6 @@ void AucMonitor::compute_result() {
...
@@ -68,7 +69,6 @@ void AucMonitor::compute_result() {
_auc
=
area
/
(
fp
*
tp
);
_auc
=
area
/
(
fp
*
tp
);
_mae
=
Monitor
::
_context_ptr
->
environment
->
all_reduce_ele
(
_local_abserr
)
/
(
fp
+
tp
);
_mae
=
Monitor
::
_context_ptr
->
environment
->
all_reduce_ele
(
_local_abserr
)
/
(
fp
+
tp
);
_rmse
=
sqrt
(
Monitor
::
_context_ptr
->
environment
->
all_reduce_ele
(
_local_sqrerr
)
/
(
fp
+
tp
));
_rmse
=
sqrt
(
Monitor
::
_context_ptr
->
environment
->
all_reduce_ele
(
_local_sqrerr
)
/
(
fp
+
tp
));
_rmse
=
sqrt
(
_rmse
/
(
fp
+
tp
));
_actual_ctr
=
tp
/
(
fp
+
tp
);
_actual_ctr
=
tp
/
(
fp
+
tp
);
_predicted_ctr
=
Monitor
::
_context_ptr
->
environment
->
all_reduce_ele
(
_local_pred
)
/
(
fp
+
tp
);
_predicted_ctr
=
Monitor
::
_context_ptr
->
environment
->
all_reduce_ele
(
_local_pred
)
/
(
fp
+
tp
);
_size
=
fp
+
tp
;
_size
=
fp
+
tp
;
...
...
paddle/fluid/train/custom_trainer/feed/monitor/cost_monitor.cc
0 → 100644
浏览文件 @
f0d571da
#include "paddle/fluid/train/custom_trainer/feed/monitor/cost_monitor.h"
namespace
paddle
{
namespace
custom_trainer
{
namespace
feed
{
int
CostMonitor
::
initialize
(
const
YAML
::
Node
&
config
,
std
::
shared_ptr
<
TrainerContext
>
context_ptr
)
{
Monitor
::
initialize
(
config
,
context_ptr
);
_compute_interval
=
3600
;
if
(
config
[
"compute_interval"
])
{
uint32_t
interval
=
config
[
"compute_interval"
].
as
<
uint32_t
>
();
if
(
interval
!=
3600
||
interval
!=
86400
)
{
LOG
(
FATAL
)
<<
" AucMonitor config compute_interval just support hour: 3600 or day: 86400. "
;
return
-
1
;
}
_compute_interval
=
interval
;
}
}
void
CostMonitor
::
add_data
(
int
epoch_id
,
const
Executor
*
executor
,
SampleInstance
*
instance
,
size_t
num
)
{
CHECK
(
executor
!=
nullptr
);
_total_time_ms
+=
executor
->
epoch_cost
();
_total_cnt
++
;
}
bool
CostMonitor
::
need_compute_result
(
int
epoch_id
,
EpochAccessor
*
accessor
)
{
CHECK
(
accessor
!=
nullptr
);
uint64_t
epoch_time
=
accessor
->
epoch_timestamp
(
epoch_id
);
CHECK
(
_compute_interval
!=
0
);
if
(
epoch_time
%
_compute_interval
!=
0
)
{
return
false
;
}
return
true
;
}
std
::
string
CostMonitor
::
format_result
()
{
char
buf
[
1024
];
snprintf
(
buf
,
1024
*
sizeof
(
char
),
"%s: Cost Time=%lu"
,
Monitor
::
_name
.
c_str
(),
_avg_time_ms
);
return
std
::
string
(
buf
);
}
}
// namespace feed
}
// namespace custom_trainer
}
// namespace paddle
paddle/fluid/train/custom_trainer/feed/monitor/cost_monitor.h
0 → 100644
浏览文件 @
f0d571da
#pragma once
#include <string>
#include <cmath> //std::lround
#include "paddle/fluid/train/custom_trainer/feed/monitor/monitor.h"
namespace
paddle
{
namespace
custom_trainer
{
namespace
feed
{
// cost time profile
class
CostMonitor
:
public
Monitor
{
public:
CostMonitor
()
:
_total_time_ms
(
0
),
_total_cnt
(
0
),
_avg_time_ms
(
0
)
{}
virtual
~
CostMonitor
()
{}
virtual
int
initialize
(
const
YAML
::
Node
&
config
,
std
::
shared_ptr
<
TrainerContext
>
context_ptr
)
override
;
//添加一项记录,统计内容Monitor自行从Executor按需获取
virtual
void
add_data
(
int
epoch_id
,
const
Executor
*
executor
,
SampleInstance
*
instance
,
size_t
num
);
//是否开始结果统计
virtual
bool
need_compute_result
(
int
epoch_id
,
EpochAccessor
*
accessor
);
//统计当前结果
virtual
void
compute_result
()
{
CHECK
(
_total_cnt
!=
0
);
_avg_time_ms
=
_total_time_ms
/
_total_cnt
;
}
//基于现有结果,输出格式化的统计信息
virtual
std
::
string
format_result
();
virtual
void
reset
()
{
_total_time_ms
=
0
;
_total_cnt
=
0
;
_avg_time_ms
=
0
;
}
protected:
std
::
string
_name
;
private:
uint64_t
_total_time_ms
;
uint64_t
_total_cnt
;
uint64_t
_avg_time_ms
;
uint32_t
_compute_interval
;
};
}
// namespace feed
}
// namespace custom_trainer
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录