Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0d953806
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2307
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
提交
0d953806
编写于
9月 05, 2019
作者:
G
gavin1332
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not transpose weight in dist_arcface_classification algorithm, without affect performance.
test=develop test=document_preview
上级
2be9036f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
13 deletion
+11
-13
python/paddle/fluid/layers/dist_algo.py
python/paddle/fluid/layers/dist_algo.py
+4
-4
python/paddle/fluid/tests/unittests/dist_arcface_classification.py
...ddle/fluid/tests/unittests/dist_arcface_classification.py
+7
-9
未找到文件。
python/paddle/fluid/layers/dist_algo.py
浏览文件 @
0d953806
...
...
@@ -151,7 +151,6 @@ class DistributedClassifier(object):
dtype
=
x
.
dtype
,
in_dim
=
flatten_dim
,
param_attr
=
param_attr
,
transpose_weight
=
True
,
use_bias
=
False
)
# normalize x
...
...
@@ -169,12 +168,12 @@ class DistributedClassifier(object):
nshards
=
self
.
nranks
,
shard_id
=
self
.
rank_id
,
ignore_value
=-
1
)
# TODO check necessary
shard_label
.
stop_gradient
=
True
# normalize weight
weight_l2
=
ops
.
sqrt
(
nn
.
reduce_sum
(
nn
.
square
(
weight
),
dim
=
1
))
norm_weight
=
nn
.
elementwise_div
(
weight
,
weight_l2
,
axis
=
0
)
norm_weight
=
nn
.
transpose
(
norm_weight
,
perm
=
[
1
,
0
])
weight_l2
=
ops
.
sqrt
(
nn
.
reduce_sum
(
nn
.
square
(
weight
),
dim
=
0
))
norm_weight
=
nn
.
elementwise_div
(
weight
,
weight_l2
,
axis
=
1
)
shard_cos
=
nn
.
mul
(
norm_x_all
,
norm_weight
,
x_num_col_dims
=
1
)
...
...
@@ -183,6 +182,7 @@ class DistributedClassifier(object):
shard_one_hot
=
nn
.
one_hot
(
shard_label
,
depth
=
self
.
shard_dim
,
allow_out_of_range
=
True
)
# TODO check necessary
shard_one_hot
.
stop_gradient
=
True
diff
=
(
margin_cos
-
shard_cos
)
*
shard_one_hot
...
...
python/paddle/fluid/tests/unittests/dist_arcface_classification.py
浏览文件 @
0d953806
...
...
@@ -23,7 +23,6 @@ from dist_classification_base import DistClassificationRunner
from
test_dist_collective_base
import
runtime_main
# TODO(gavin1332) check whether it is necessary to transpose weight
class
DistArcfaceClassificationRunner
(
DistClassificationRunner
):
@
classmethod
def
add_other_arguments
(
cls
,
parser
):
...
...
@@ -33,15 +32,15 @@ class DistArcfaceClassificationRunner(DistClassificationRunner):
def
__init__
(
self
,
args
):
super
(
DistArcfaceClassificationRunner
,
self
).
__init__
(
args
)
np
.
random
.
seed
(
1024
)
self
.
param_value
=
np
.
random
.
rand
(
self
.
args
.
class_num
,
self
.
args
.
feature_size
)
self
.
param_value
=
np
.
random
.
rand
(
self
.
args
.
feature_size
,
self
.
args
.
class_num
)
def
local_classify_subnet
(
self
,
feature
,
label
):
args
=
self
.
args
weight
=
layers
.
create_parameter
(
dtype
=
feature
.
dtype
,
shape
=
[
args
.
class_num
,
args
.
feature_size
],
shape
=
[
args
.
feature_size
,
args
.
class_num
],
default_initializer
=
NumpyArrayInitializer
(
self
.
param_value
),
is_bias
=
False
)
...
...
@@ -52,9 +51,8 @@ class DistArcfaceClassificationRunner(DistClassificationRunner):
norm_feature
=
layers
.
elementwise_div
(
feature
,
feature_l2
,
axis
=
0
)
# normalize weight
weight_l2
=
layers
.
sqrt
(
layers
.
reduce_sum
(
layers
.
square
(
weight
),
dim
=
1
))
norm_weight
=
layers
.
elementwise_div
(
weight
,
weight_l2
,
axis
=
0
)
norm_weight
=
layers
.
transpose
(
norm_weight
,
perm
=
[
1
,
0
])
weight_l2
=
layers
.
sqrt
(
layers
.
reduce_sum
(
layers
.
square
(
weight
),
dim
=
0
))
norm_weight
=
layers
.
elementwise_div
(
weight
,
weight_l2
,
axis
=
1
)
cos
=
layers
.
mul
(
norm_feature
,
norm_weight
)
...
...
@@ -76,8 +74,8 @@ class DistArcfaceClassificationRunner(DistClassificationRunner):
args
=
self
.
args
shard_dim
=
(
args
.
class_num
+
args
.
nranks
-
1
)
//
args
.
nranks
shard_start
=
shard_dim
*
args
.
rank
rank_param_value
=
self
.
param_value
[
shard_start
:(
shard_start
+
shard_dim
),
:
]
rank_param_value
=
self
.
param_value
[
:,
shard_start
:(
shard_start
+
shard_dim
)
]
cost
=
layers
.
dist_algo
.
_distributed_arcface_classify
(
x
=
feature
,
label
=
label
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录