Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c98f144f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c98f144f
编写于
2月 05, 2021
作者:
C
Chengmo
提交者:
GitHub
2月 05, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add truncated gaussian random (#30922)
add truncated gaussian random
上级
4a8b8b45
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
0 deletion
+42
-0
paddle/fluid/distributed/table/common_dense_table.cc
paddle/fluid/distributed/table/common_dense_table.cc
+2
-0
paddle/fluid/distributed/table/depends/initializers.h
paddle/fluid/distributed/table/depends/initializers.h
+37
-0
paddle/fluid/distributed/table/depends/large_scale_kv.h
paddle/fluid/distributed/table/depends/large_scale_kv.h
+3
-0
未找到文件。
paddle/fluid/distributed/table/common_dense_table.cc
浏览文件 @
c98f144f
...
...
@@ -29,6 +29,8 @@ void CommonDenseTable::create_initializer(const std::string& attr,
initializers_
[
name
]
=
new
FillConstantInitializer
(
slices
);
}
else
if
(
slices
[
0
]
==
"uniform_random"
)
{
initializers_
[
name
]
=
new
UniformInitializer
(
slices
);
}
else
if
(
slices
[
0
]
==
"truncated_gaussian_random"
)
{
initializers_
[
name
]
=
new
TruncatedGaussianInitializer
(
slices
);
}
else
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"%s can not be supported"
,
name
));
...
...
paddle/fluid/distributed/table/depends/initializers.h
浏览文件 @
c98f144f
...
...
@@ -16,6 +16,7 @@
#include <functional>
#include <memory>
#include <random>
#include <string>
#include <utility>
#include <vector>
...
...
@@ -23,6 +24,8 @@
#include "paddle/fluid/framework/generator.h"
#include "paddle/fluid/operators/truncated_gaussian_random_op.h"
namespace
paddle
{
namespace
distributed
{
...
...
@@ -108,6 +111,40 @@ class GaussianInitializer : public Initializer {
std
::
normal_distribution
<
float
>
dist_
;
};
class
TruncatedGaussianInitializer
:
public
Initializer
{
public:
explicit
TruncatedGaussianInitializer
(
const
std
::
vector
<
std
::
string
>
&
attrs
)
{
name_
=
attrs
[
0
];
seed_
=
static_cast
<
unsigned
int
>
(
std
::
stoi
(
attrs
[
1
]));
mean_
=
std
::
stof
(
attrs
[
2
]);
std_
=
std
::
stof
(
attrs
[
3
]);
std
::
uniform_real_distribution
<
float
>
dist_
(
std
::
numeric_limits
<
float
>::
min
(),
1.0
);
random_engine_
=
framework
::
GetCPURandomEngine
(
seed_
);
}
float
GetValue
()
override
{
paddle
::
operators
::
TruncatedNormal
<
float
>
truncated_normal
(
mean_
,
std_
);
float
value
=
truncated_normal
(
dist_
(
*
random_engine_
));
return
value
;
}
void
GetValue
(
float
*
value
,
int
numel
)
{
paddle
::
operators
::
TruncatedNormal
<
float
>
truncated_normal
(
mean_
,
std_
);
for
(
int
x
=
0
;
x
<
numel
;
++
x
)
{
value
[
x
]
=
truncated_normal
(
dist_
(
*
random_engine_
));
}
}
private:
float
std_
;
float
mean_
;
std
::
shared_ptr
<
std
::
mt19937_64
>
random_engine_
;
std
::
uniform_real_distribution
<
float
>
dist_
;
};
class
FillConstantInitializer
:
public
Initializer
{
public:
explicit
FillConstantInitializer
(
const
std
::
vector
<
std
::
string
>
&
attrs
)
{
...
...
paddle/fluid/distributed/table/depends/large_scale_kv.h
浏览文件 @
c98f144f
...
...
@@ -134,6 +134,9 @@ class ValueBlock {
}
else
if
(
slices
[
0
]
==
"uniform_random"
)
{
initializers_
.
emplace_back
(
std
::
make_shared
<
UniformInitializer
>
(
slices
));
}
else
if
(
slices
[
0
]
==
"truncated_gaussian_random"
)
{
initializers_
.
emplace_back
(
std
::
make_shared
<
TruncatedGaussianInitializer
>
(
slices
));
}
else
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"%s can not be supported"
,
attr
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录