Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
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
S2T
Commits
ca4271f2
Commit
ca4271f2
authored
Aug 22, 2023
by
xuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use inf instead of 1e8 or 1e-8
parent
976237ec
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
10 行增加
和
10 行删除
+10
-10
fairseq/modules/espnet_multihead_attention.py
+5
-5
fairseq/modules/pds_layer.py
+1
-1
fairseq/modules/s2t_transformer_layer.py
+1
-1
fairseq/modules/s2t_transformer_s2_layer.py
+1
-1
fairseq/modules/transformer_layer.py
+1
-1
fairseq/modules/transformer_s2_layer.py
+1
-1
没有找到文件。
fairseq/modules/espnet_multihead_attention.py
查看文件 @
ca4271f2
...
@@ -64,9 +64,9 @@ class ESPNETMultiHeadedAttention(nn.Module):
...
@@ -64,9 +64,9 @@ class ESPNETMultiHeadedAttention(nn.Module):
if
kwargs
.
get
(
"cal_localness"
,
False
)
and
not
self
.
encoder_decoder_attention
:
if
kwargs
.
get
(
"cal_localness"
,
False
)
and
not
self
.
encoder_decoder_attention
:
self
.
cal_localness
=
True
self
.
cal_localness
=
True
self
.
localness_window
=
kwargs
.
get
(
"localness_window"
,
0.1
)
self
.
localness_window
=
kwargs
.
get
(
"localness_window"
,
0.1
)
if
kwargs
.
get
(
"cal_entropy"
,
False
):
if
kwargs
.
get
(
"cal_entropy"
,
False
):
# and self.encoder_decoder_attention:
self
.
cal_entropy
=
True
self
.
cal_entropy
=
True
if
kwargs
.
get
(
"cal_topk_cross_attn_weights"
,
False
)
and
self
.
encoder_decoder_attention
:
if
kwargs
.
get
(
"cal_topk_cross_attn_weights"
,
False
)
:
self
.
cal_topk
=
True
self
.
cal_topk
=
True
self
.
weights_topk
=
kwargs
.
get
(
"topk_cross_attn_weights"
,
1
)
self
.
weights_topk
=
kwargs
.
get
(
"topk_cross_attn_weights"
,
1
)
if
kwargs
.
get
(
"cal_monotonic_cross_attn_weights"
,
False
)
and
self
.
encoder_decoder_attention
:
if
kwargs
.
get
(
"cal_monotonic_cross_attn_weights"
,
False
)
and
self
.
encoder_decoder_attention
:
...
@@ -74,7 +74,7 @@ class ESPNETMultiHeadedAttention(nn.Module):
...
@@ -74,7 +74,7 @@ class ESPNETMultiHeadedAttention(nn.Module):
def
dump
(
self
,
fstream
,
info
):
def
dump
(
self
,
fstream
,
info
):
if
self
.
cal_localness
:
if
self
.
cal_localness
:
print
(
"
%
s window size:
%
f localness:
%.2
f"
%
(
info
,
self
.
localness_window
,
self
.
localness
),
file
=
fstream
)
print
(
"
%
s window size:
%
.2
f localness:
%.4
f"
%
(
info
,
self
.
localness_window
,
self
.
localness
),
file
=
fstream
)
if
self
.
cal_entropy
:
if
self
.
cal_entropy
:
print
(
"
%
s Entropy:
%.2
f"
%
(
info
,
self
.
entropy
),
file
=
fstream
)
print
(
"
%
s Entropy:
%.2
f"
%
(
info
,
self
.
entropy
),
file
=
fstream
)
...
@@ -119,8 +119,8 @@ class ESPNETMultiHeadedAttention(nn.Module):
...
@@ -119,8 +119,8 @@ class ESPNETMultiHeadedAttention(nn.Module):
if
mask
is
not
None
:
if
mask
is
not
None
:
scores
=
scores
.
masked_fill
(
scores
=
scores
.
masked_fill
(
mask
.
unsqueeze
(
1
)
.
unsqueeze
(
2
)
.
to
(
bool
),
mask
.
unsqueeze
(
1
)
.
unsqueeze
(
2
)
.
to
(
bool
),
-
1e8
if
scores
.
dtype
==
torch
.
float32
else
-
1e4
#
-1e8 if scores.dtype == torch.float32 else -1e4
#
float("-inf"), # (batch, head, time1, time2)
float
(
"-inf"
),
# (batch, head, time1, time2)
)
)
# self.attn = torch.softmax(scores, dim=-1) # (batch, head, time1, time2)
# self.attn = torch.softmax(scores, dim=-1) # (batch, head, time1, time2)
...
...
fairseq/modules/pds_layer.py
查看文件 @
ca4271f2
...
@@ -286,7 +286,7 @@ class PDSTransformerEncoderLayer(nn.Module):
...
@@ -286,7 +286,7 @@ class PDSTransformerEncoderLayer(nn.Module):
# the attention weight (before softmax) for some padded element in query
# the attention weight (before softmax) for some padded element in query
# will become -inf, which results in NaN in model parameters
# will become -inf, which results in NaN in model parameters
if
attn_mask
is
not
None
:
if
attn_mask
is
not
None
:
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
1e8
)
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
float
(
'inf'
)
)
# whether to use macaron style
# whether to use macaron style
if
self
.
macaron_norm
is
not
None
:
if
self
.
macaron_norm
is
not
None
:
...
...
fairseq/modules/s2t_transformer_layer.py
查看文件 @
ca4271f2
...
@@ -252,7 +252,7 @@ class S2TTransformerEncoderLayer(nn.Module):
...
@@ -252,7 +252,7 @@ class S2TTransformerEncoderLayer(nn.Module):
# the attention weight (before softmax) for some padded element in query
# the attention weight (before softmax) for some padded element in query
# will become -inf, which results in NaN in model parameters
# will become -inf, which results in NaN in model parameters
if
attn_mask
is
not
None
:
if
attn_mask
is
not
None
:
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
1e8
)
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
float
(
'inf'
)
)
# whether to use macaron style
# whether to use macaron style
if
self
.
macaron_norm
is
not
None
:
if
self
.
macaron_norm
is
not
None
:
...
...
fairseq/modules/s2t_transformer_s2_layer.py
查看文件 @
ca4271f2
...
@@ -315,7 +315,7 @@ class S2TTransformerS2EncoderLayer(nn.Module):
...
@@ -315,7 +315,7 @@ class S2TTransformerS2EncoderLayer(nn.Module):
# the attention weight (before softmax) for some padded element in query
# the attention weight (before softmax) for some padded element in query
# will become -inf, which results in NaN in model parameters
# will become -inf, which results in NaN in model parameters
if
attn_mask
is
not
None
:
if
attn_mask
is
not
None
:
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
1e8
)
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
float
(
'inf'
)
)
# whether to use macaron style
# whether to use macaron style
if
self
.
macaron_norm
is
not
None
:
if
self
.
macaron_norm
is
not
None
:
...
...
fairseq/modules/transformer_layer.py
查看文件 @
ca4271f2
...
@@ -188,7 +188,7 @@ class TransformerEncoderLayer(nn.Module):
...
@@ -188,7 +188,7 @@ class TransformerEncoderLayer(nn.Module):
# will become -inf, which results in NaN in model parameters
# will become -inf, which results in NaN in model parameters
if
attn_mask
is
not
None
:
if
attn_mask
is
not
None
:
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
1e8
if
x
.
dtype
==
torch
.
float32
else
-
1e4
attn_mask
.
to
(
torch
.
bool
),
-
float
(
'inf'
)
# -
1e8 if x.dtype == torch.float32 else -1e4
)
)
residual
=
x
residual
=
x
...
...
fairseq/modules/transformer_s2_layer.py
查看文件 @
ca4271f2
...
@@ -241,7 +241,7 @@ class TransformerS2EncoderLayer(nn.Module):
...
@@ -241,7 +241,7 @@ class TransformerS2EncoderLayer(nn.Module):
# will become -inf, which results in NaN in model parameters
# will become -inf, which results in NaN in model parameters
if
attn_mask
is
not
None
:
if
attn_mask
is
not
None
:
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
=
attn_mask
.
masked_fill
(
attn_mask
.
to
(
torch
.
bool
),
-
1e8
if
x
.
dtype
==
torch
.
float32
else
-
1e4
attn_mask
.
to
(
torch
.
bool
),
-
float
(
'inf'
)
# -
1e8 if x.dtype == torch.float32 else -1e4
)
)
residual
=
x
residual
=
x
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论