Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
d24ce34c
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看板
提交
d24ce34c
编写于
9月 01, 2020
作者:
W
wangmin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug of bert_thor
上级
36977394
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
16 addition
and
7 deletion
+16
-7
model_zoo/official/nlp/bert_thor/README.md
model_zoo/official/nlp/bert_thor/README.md
+1
-1
model_zoo/official/nlp/bert_thor/pretrain_eval.py
model_zoo/official/nlp/bert_thor/pretrain_eval.py
+3
-2
model_zoo/official/nlp/bert_thor/run_pretrain.py
model_zoo/official/nlp/bert_thor/run_pretrain.py
+5
-1
model_zoo/official/nlp/bert_thor/src/bert_model.py
model_zoo/official/nlp/bert_thor/src/bert_model.py
+3
-2
model_zoo/official/nlp/bert_thor/src/fused_layer_norm.py
model_zoo/official/nlp/bert_thor/src/fused_layer_norm.py
+4
-1
未找到文件。
model_zoo/official/nlp/bert_thor/README.md
浏览文件 @
d24ce34c
...
...
@@ -201,7 +201,7 @@ step: 3000 Accuracy: [0.71377236]
| Loss Function | Softmax Cross Entropy |
| outputs | probability |
| Loss |1.5654222 |
| Speed | 2
69
ms/step(8pcs) |
| Speed | 2
75
ms/step(8pcs) |
| Total time | 14 mins |
| Parameters (M) | 330 |
| Checkpoint for Fine tuning | 4.5G(.ckpt file) |
...
...
model_zoo/official/nlp/bert_thor/pretrain_eval.py
浏览文件 @
d24ce34c
...
...
@@ -155,10 +155,11 @@ def MLM_eval():
res
=
net
.
eval
(
dataset
,
dataset_sink_mode
=
False
)
print
(
"=============================================================="
)
for
_
,
v
in
res
.
items
():
print
(
"Accuracy is: "
)
print
(
v
)
print
(
"Accuracy is: "
,
v
)
print
(
"=============================================================="
)
if
__name__
==
"__main__"
:
DEVICE_ID
=
1
os
.
environ
[
'DEVICE_ID'
]
=
str
(
DEVICE_ID
)
MLM_eval
()
model_zoo/official/nlp/bert_thor/run_pretrain.py
浏览文件 @
d24ce34c
...
...
@@ -26,7 +26,6 @@ from src.config import cfg
from
src.dataset
import
create_bert_dataset
from
src.lr_generator
import
get_bert_lr
,
get_bert_damping
from
src.model_thor
import
Model
from
src.thor_for_bert_arg
import
THOR
from
src.utils
import
LossCallBack
,
BertLearningRate
import
mindspore.common.dtype
as
mstype
import
mindspore.communication.management
as
D
...
...
@@ -66,10 +65,15 @@ def run_pretrain():
parser
.
add_argument
(
"--schema_dir"
,
type
=
str
,
default
=
""
,
help
=
"Schema path, it is better to use absolute path"
)
args_opt
=
parser
.
parse_args
()
if
args_opt
.
distribute
==
"true"
:
from
src.thor_for_bert_arg
import
THOR
else
:
from
src.thor_for_bert
import
THOR
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
args_opt
.
device_target
,
device_id
=
args_opt
.
device_id
,
save_graphs
=
False
)
context
.
set_context
(
reserve_class_name_in_scope
=
False
)
context
.
set_context
(
variable_memory_max_size
=
"30GB"
)
context
.
set_context
(
max_call_depth
=
3000
)
ckpt_save_dir
=
args_opt
.
save_checkpoint_path
if
args_opt
.
distribute
==
"true"
:
if
args_opt
.
device_target
==
'Ascend'
:
...
...
model_zoo/official/nlp/bert_thor/src/bert_model.py
浏览文件 @
d24ce34c
...
...
@@ -231,16 +231,17 @@ class EmbeddingPostprocessor(nn.Cell):
frequency
=
frequency
)
self
.
position_ids
=
Tensor
(
np
.
arange
(
seq
).
reshape
(
-
1
,
seq
).
astype
(
np
.
int32
))
self
.
layernorm
=
nn
.
LayerNorm
((
embedding_size
,))
self
.
add
=
P
.
TensorAdd
()
def
construct
(
self
,
token_type_ids
,
word_embeddings
):
"""construct of EmbeddingPostprocessor"""
output
=
word_embeddings
if
self
.
use_token_type
:
token_type_embeddings
,
_
=
self
.
token_type_embedding
(
token_type_ids
)
output
+=
token_type_embeddings
output
=
self
.
add
(
output
,
token_type_embeddings
)
if
not
self
.
use_relative_positions
:
position_embeddings
,
_
=
self
.
full_position_embedding
(
self
.
position_ids
)
output
+=
position_embeddings
output
=
self
.
add
(
output
,
position_embeddings
)
output
=
self
.
layernorm
(
output
)
output
=
self
.
dropout
(
output
)
return
output
...
...
model_zoo/official/nlp/bert_thor/src/fused_layer_norm.py
浏览文件 @
d24ce34c
...
...
@@ -101,6 +101,8 @@ class FusedLayerNorm(Cell):
self
.
batch_norm
=
P
.
BatchNorm
(
is_training
=
True
,
epsilon
=
1e-5
)
self
.
use_batch_norm
=
use_batch_norm
self
.
mul
=
P
.
Mul
()
self
.
add
=
P
.
TensorAdd
()
def
construct
(
self
,
input_x
):
"""construct of FusedLayerNorm"""
...
...
@@ -112,7 +114,8 @@ class FusedLayerNorm(Cell):
input_x
=
F
.
reshape
(
input_x
,
norm_shape
)
output
,
_
,
_
,
_
,
_
,
_
=
self
.
batch_norm
(
input_x
,
ones
,
zeros
,
None
,
None
)
output
=
F
.
reshape
(
output
,
shape_x
)
y
=
output
*
self
.
gamma
+
self
.
beta
y
=
self
.
mul
(
output
,
self
.
gamma
)
y
=
self
.
add
(
y
,
self
.
beta
)
else
:
y
,
_
,
_
=
self
.
layer_norm
(
input_x
,
self
.
gamma
,
self
.
beta
)
return
y
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录