Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
5215efd3
O
oneflow
项目概览
Oneflow-Inc
/
oneflow
上一次同步 2 年多
通知
13
Star
2733
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oneflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5215efd3
编写于
3月 12, 2018
作者:
X
Xinqi Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
try entropy as indecision
Former-commit-id: 503bafaeffec27e685c5b6bcb2c2e353ba79a9a6
上级
74e4ea27
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
54 addition
and
6 deletion
+54
-6
oneflow/core/auto_placement/df_demo.cpp
oneflow/core/auto_placement/df_demo.cpp
+32
-6
oneflow/core/auto_placement/df_func.cpp
oneflow/core/auto_placement/df_func.cpp
+19
-0
oneflow/core/auto_placement/df_func.h
oneflow/core/auto_placement/df_func.h
+3
-0
未找到文件。
oneflow/core/auto_placement/df_demo.cpp
浏览文件 @
5215efd3
...
...
@@ -106,6 +106,17 @@ Tensor CalcDeviceMemConsumed(const Tensor& chain_node_prob,
regst_duration_copies
.
at
(
1
),
chain_graph
));
}
Tensor
CalcTransportation
(
const
Tensor
&
chain_node_prob
,
const
DemoChainGraph
&
chain_graph
)
{
auto
chain_node_prob_copies
=
Clone
(
chain_node_prob
,
2
);
Tensor
edge_src_prob
=
ColIndexReduce
(
chain_node_prob_copies
.
at
(
0
),
chain_graph
.
edge_id2src_chain_node_id
());
Tensor
edge_dst_prob
=
ColIndexReduce
(
chain_node_prob_copies
.
at
(
1
),
chain_graph
.
edge_id2dst_chain_node_id
());
Tensor
edge_prob
=
Mul
(
Tensor
(
0.5
),
Abs
(
Sub
(
edge_src_prob
,
edge_dst_prob
)));
return
MatrixRowSum
(
edge_prob
);
}
Tensor
CalcDeviceMemII
(
const
Tensor
&
chain_node_placement
,
const
DemoChainGraph
&
chain_graph
,
double
mem_size_per_device
)
{
...
...
@@ -153,6 +164,21 @@ std::function<double()> MakeFlation(int keep) {
return
MakeFlation
(
keep
,
0.005
);
}
Tensor
SqrtIndecision
(
const
Tensor
&
input
)
{
return
Sub
(
MatrixColSum
(
Sqrt
(
input
)),
Tensor
(
1
));
}
Tensor
EntropyIndecision
(
const
Tensor
&
input
)
{
const
auto
&
input_copies
=
Clone
(
input
,
2
);
return
MatrixColSum
(
Minus
(
Mul
(
input_copies
.
at
(
0
),
Log
(
input_copies
.
at
(
1
)))));
}
Tensor
SquareIndecision
(
const
Tensor
&
input
)
{
const
auto
&
input_copies
=
Clone
(
input
,
2
);
return
MatrixColSum
(
Mul
(
input_copies
.
at
(
0
),
Sub
(
Tensor
(
1
),
input_copies
.
at
(
1
))));
}
void
AutoPlacementMemoryDemo
()
{
std
::
random_device
rd
{};
std
::
mt19937
gen
{
rd
()};
...
...
@@ -172,11 +198,12 @@ void AutoPlacementMemoryDemo() {
Tensor
fw_prob
;
const
auto
&
chain_node_id2name
=
chain_graph
.
chain_node_id2chain_node_name
();
double
bugo
=
2
;
double
rethink_threshold
=
2
0
;
double
rethink_threshold
=
1
0
;
Tensor
decision_ratio
(
Shape
({
fw_node_num
}),
[
&
](
int64_t
index
)
{
return
1
+
fw_node_num
*
0.5
/
(
index
+
1
);
});
std
::
function
<
double
()
>
MemFlation
=
MakeFlation
(
100
);
int64_t
mem_keep
=
100
;
std
::
function
<
double
()
>
MemFlation
=
MakeFlation
(
mem_keep
);
FOR_RANGE
(
int
,
step
,
0
,
100000
)
{
double
lr
=
0.01
;
if
(
step
%
(
static_cast
<
int
>
(
bugo
+=
0.05
)))
{
...
...
@@ -191,8 +218,7 @@ void AutoPlacementMemoryDemo() {
Tensor
normalized_dev_mem
=
Mul
(
Tensor
(
2.5
*
MemFlation
()),
Sqrt
(
dev_mem
));
Tensor
fw_indecision
=
Mul
(
Sub
(
MatrixColSum
(
Sqrt
(
fw_prob_copies
.
at
(
1
))),
Tensor
(
1
)),
decision_ratio
);
Mul
(
SqrtIndecision
(
fw_prob_copies
.
at
(
1
)),
decision_ratio
);
Tensor
indecision
=
Sum
(
fw_indecision
);
Tensor
balance
=
ADD
(
indecision
,
ADD
(
AvgAbsDeviation
(
normalized_dev_mem
),
AvgAbsDeviation
(
computation_ii
)));
...
...
@@ -248,8 +274,8 @@ void AutoPlacementMemoryDemo() {
std
::
cout
<<
std
::
endl
;
}
if
(
indecision
.
At
(
0
)
<
rethink_threshold
)
{
MemFlation
=
MakeFlation
(
100
);
rethink_threshold
-=
1
;
MemFlation
=
MakeFlation
(
mem_keep
);
rethink_threshold
-=
(
rethink_threshold
>
2
)
?
1
:
0.0
1
;
const
auto
&
edge_id2src_id
=
chain_graph
.
edge_id2src_chain_node_id
();
const
auto
&
edge_id2dst_id
=
chain_graph
.
edge_id2dst_chain_node_id
();
auto
old_fw_var
=
fw_var
.
buffer
();
...
...
oneflow/core/auto_placement/df_func.cpp
浏览文件 @
5215efd3
...
...
@@ -197,6 +197,25 @@ Tensor _Exp(const std::string& caller, const Tensor& input) {
});
}
Tensor
_Log
(
const
std
::
string
&
caller
,
const
Tensor
&
input
)
{
std
::
shared_ptr
<
Buffer
>
out
(
new
Buffer
(
input
.
buffer
()));
FOR_RANGE
(
int
,
i
,
0
,
out
->
Size
())
{
double
&
x
=
out
->
At
(
i
);
x
=
std
::
log
(
x
);
}
DEFINE_RUN_TIME_CNT_BOX
();
return
Tensor
(
out
,
[
=
](
const
Buffer
&
out_diff
)
{
SET_FW_CALLER
();
RUN_ONLY_ONE_TIME
();
Buffer
input_diff
(
out_diff
);
FOR_RANGE
(
int
,
i
,
0
,
input_diff
.
Size
())
{
double
&
diff
=
input_diff
.
At
(
i
);
diff
/=
input
.
At
(
i
);
}
input
.
HandleDiff
(
input_diff
);
});
}
Tensor
_Tanh
(
const
std
::
string
&
caller
,
const
Tensor
&
input
)
{
std
::
shared_ptr
<
Buffer
>
out
(
new
Buffer
(
input
.
buffer
()));
FOR_RANGE
(
int
,
i
,
0
,
out
->
Size
())
{
out
->
At
(
i
)
=
std
::
tanh
(
input
.
At
(
i
));
}
...
...
oneflow/core/auto_placement/df_func.h
浏览文件 @
5215efd3
...
...
@@ -42,6 +42,9 @@ Tensor _Abs(const std::string& caller, const Tensor& input);
Tensor
_Exp
(
const
std
::
string
&
caller
,
const
Tensor
&
input
);
#define Exp(...) _Exp(__LOC__, __VA_ARGS__)
Tensor
_Log
(
const
std
::
string
&
caller
,
const
Tensor
&
input
);
#define Log(...) _Log(__LOC__, __VA_ARGS__)
Tensor
_Tanh
(
const
std
::
string
&
caller
,
const
Tensor
&
input
);
#define Tanh(...) _Tanh(__LOC__, __VA_ARGS__)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录