Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
Fairseq-S2T
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
xuchen
Fairseq-S2T
Commits
07f0ab14
Commit
07f0ab14
authored
Aug 10, 2021
by
xuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the device bug of the local attention
parent
8b97a50b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
10 行增加
和
11 行删除
+10
-11
egs/mustc/st/local/monitor.sh
+1
-1
fairseq/modules/local_multihead_attention.py
+9
-10
没有找到文件。
egs/mustc/st/local/monitor.sh
查看文件 @
07f0ab14
gpu_num
=
1
cmd
=
""
cmd
=
"
sh train.sh
"
while
:
do
...
...
fairseq/modules/local_multihead_attention.py
查看文件 @
07f0ab14
...
...
@@ -319,22 +319,21 @@ class LocalMultiheadAttention(nn.Module):
x2
=
torch
.
arange
(
-
1
,
src_len
-
1
,
1
)
.
view
(
1
,
-
1
)
dis
=
x2
-
x1
mask_diag
=
torch
.
abs
(
dis
)
>
hard_mask_window
mask_diag
=
mask_diag
.
unsqueeze
(
0
)
mask_diag
=
mask_diag
.
unsqueeze
(
0
)
.
to
(
attn_weights
.
device
)
attn_weights
=
attn_weights
.
masked_fill
(
mask_diag
,
float
(
"-inf"
))
if
self
.
multihead_gauss_mask_sigma
is
not
None
:
x1
=
torch
.
arange
(
-
1
,
src_len
-
1
,
1
)
.
view
(
-
1
,
1
)
x2
=
torch
.
arange
(
-
1
,
src_len
-
1
,
1
)
.
view
(
1
,
-
1
)
di
ag_growing
=
-
(
x1
-
x2
)
**
2
/
2.0
e_diag_gauss_mask
=
diag_growing
.
unsqueeze
(
0
)
.
repeat
(
self
.
num_heads
,
1
,
1
)
e_sigma_square
=
1
/
torch
.
square
(
self
.
multihead_gauss_mask_sigma
)
e_diag_gauss_mask_final
=
e_diag_gauss_mask
*
e_sigma_square
x1
=
torch
.
arange
(
-
1
,
src_len
-
1
,
1
)
.
view
(
-
1
,
1
)
.
to
(
attn_weights
.
device
)
x2
=
torch
.
arange
(
-
1
,
src_len
-
1
,
1
)
.
view
(
1
,
-
1
)
.
to
(
attn_weights
.
device
)
di
s_square
=
-
(
x1
-
x2
)
**
2
/
2.0
multihead_dis_square
=
dis_square
.
unsqueeze
(
0
)
.
repeat
(
self
.
num_heads
,
1
,
1
)
sigma_square
=
1
/
torch
.
square
(
self
.
multihead_gauss_mask_sigma
)
gauss_bias
=
multihead_dis_square
*
sigma_square
gauss_bias
=
torch
.
unsqueeze
(
gauss_bias
,
0
)
e_diag_gauss_mask_final
=
torch
.
unsqueeze
(
e_diag_gauss_mask_final
,
0
)
attn_weights
=
attn_weights
.
view
(
bsz
,
self
.
num_heads
,
tgt_len
,
src_len
)
multihead_mask_weight
=
torch
.
sigmoid
(
self
.
multihead_mask_weight
.
unsqueeze
(
0
))
attn_weights
=
(
1
-
multihead_mask_weight
)
*
attn_weights
+
multihead_mask_weight
*
e_diag_gauss_mask_final
attn_weights
=
(
1
-
multihead_mask_weight
)
*
attn_weights
+
multihead_mask_weight
*
gauss_bias
attn_weights
=
attn_weights
.
view
(
bsz
*
self
.
num_heads
,
tgt_len
,
src_len
)
if
attn_mask
is
not
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论