Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
4815dcbb
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4815dcbb
编写于
8月 18, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 18, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4517 The teacher use fp16 calculations to imporve the performance of tinybert on gpu
Merge pull request !4517 from hanhuifeng/tinybert_gpu_perf
上级
e7df19a5
9e2b38c9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
14 deletion
+17
-14
model_zoo/official/nlp/tinybert/run_general_distill.py
model_zoo/official/nlp/tinybert/run_general_distill.py
+2
-5
model_zoo/official/nlp/tinybert/run_task_distill.py
model_zoo/official/nlp/tinybert/run_task_distill.py
+2
-5
model_zoo/official/nlp/tinybert/scripts/run_distribute_gd_for_gpu.sh
...fficial/nlp/tinybert/scripts/run_distribute_gd_for_gpu.sh
+1
-0
model_zoo/official/nlp/tinybert/src/tinybert_model.py
model_zoo/official/nlp/tinybert/src/tinybert_model.py
+12
-4
未找到文件。
model_zoo/official/nlp/tinybert/run_general_distill.py
浏览文件 @
4815dcbb
...
...
@@ -87,13 +87,10 @@ def run_general_distill():
enable_loss_scale
=
True
if
args_opt
.
device_target
==
"GPU"
:
if
bert_teacher_net_cfg
.
compute_type
!=
mstype
.
float32
:
logger
.
warning
(
'GPU only support fp32 temporarily, run with fp32.'
)
bert_teacher_net_cfg
.
compute_type
=
mstype
.
float32
if
bert_student_net_cfg
.
compute_type
!=
mstype
.
float32
:
logger
.
warning
(
'
GPU only support fp32 temporarily, run with fp
32.'
)
logger
.
warning
(
'
Compute about the student only support float32 temporarily, run with float
32.'
)
bert_student_net_cfg
.
compute_type
=
mstype
.
float32
# B
oth the forward and b
ackward of the network are calculated using fp32,
# Backward of the network are calculated using fp32,
# and the loss scale is not necessary
enable_loss_scale
=
False
...
...
model_zoo/official/nlp/tinybert/run_task_distill.py
浏览文件 @
4815dcbb
...
...
@@ -285,13 +285,10 @@ if __name__ == '__main__':
enable_loss_scale
=
True
if
args_opt
.
device_target
==
"GPU"
:
if
td_teacher_net_cfg
.
compute_type
!=
mstype
.
float32
:
logger
.
warning
(
'GPU only support fp32 temporarily, run with fp32.'
)
td_teacher_net_cfg
.
compute_type
=
mstype
.
float32
if
td_student_net_cfg
.
compute_type
!=
mstype
.
float32
:
logger
.
warning
(
'
GPU only support fp32 temporarily, run with fp
32.'
)
logger
.
warning
(
'
Compute about the student only support float32 temporarily, run with float
32.'
)
td_student_net_cfg
.
compute_type
=
mstype
.
float32
# B
oth the forward and b
ackward of the network are calculated using fp32,
# Backward of the network are calculated using fp32,
# and the loss scale is not necessary
enable_loss_scale
=
False
...
...
model_zoo/official/nlp/tinybert/scripts/run_distribute_gd_for_gpu.sh
浏览文件 @
4815dcbb
...
...
@@ -37,4 +37,5 @@ mpirun --allow-run-as-root -n $RANK_SIZE \
--save_ckpt_path
=
""
\
--data_dir
=
$DATA_DIR
\
--schema_dir
=
$SCHEMA_DIR
\
--enable_data_sink
=
False
\
--load_teacher_ckpt_path
=
$TEACHER_CKPT_PATH
>
log.txt 2>&1 &
model_zoo/official/nlp/tinybert/src/tinybert_model.py
浏览文件 @
4815dcbb
...
...
@@ -24,6 +24,7 @@ from mindspore.ops import operations as P
from
mindspore.ops
import
composite
as
C
from
mindspore.common.tensor
import
Tensor
from
mindspore.common.parameter
import
Parameter
from
mindspore
import
context
from
.fused_layer_norm
import
FusedLayerNorm
...
...
@@ -250,11 +251,16 @@ class BertOutput(nn.Cell):
weight_init
=
TruncatedNormal
(
initializer_range
)).
to_float
(
compute_type
)
self
.
dropout
=
nn
.
Dropout
(
1
-
dropout_prob
)
self
.
add
=
P
.
TensorAdd
()
if
compute_type
==
mstype
.
float16
:
self
.
layernorm
=
FusedLayerNorm
((
out_channels
,),
use_batch_norm
=
enable_fused_layernorm
).
to_float
(
compute_type
)
self
.
is_gpu
=
context
.
get_context
(
'device_target'
)
==
"GPU"
if
self
.
is_gpu
:
self
.
layernorm
=
nn
.
LayerNorm
((
out_channels
,)).
to_float
(
mstype
.
float32
)
self
.
compute_type
=
compute_type
else
:
self
.
layernorm
=
nn
.
LayerNorm
((
out_channels
,)).
to_float
(
compute_type
)
if
compute_type
==
mstype
.
float16
:
self
.
layernorm
=
FusedLayerNorm
((
out_channels
,),
use_batch_norm
=
enable_fused_layernorm
).
to_float
(
compute_type
)
else
:
self
.
layernorm
=
nn
.
LayerNorm
((
out_channels
,)).
to_float
(
compute_type
)
self
.
cast
=
P
.
Cast
()
...
...
@@ -264,6 +270,8 @@ class BertOutput(nn.Cell):
output
=
self
.
dropout
(
output
)
output
=
self
.
add
(
input_tensor
,
output
)
output
=
self
.
layernorm
(
output
)
if
self
.
is_gpu
:
output
=
self
.
cast
(
output
,
self
.
compute_type
)
return
output
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录