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
cb0af126
Commit
cb0af126
authored
Sep 09, 2021
by
xuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the bug of the conformer
parent
31d0303e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
7 行删除
+16
-7
fairseq/modules/conformer_layer.py
+1
-1
fairseq/modules/convolution.py
+15
-6
没有找到文件。
fairseq/modules/conformer_layer.py
查看文件 @
cb0af126
...
...
@@ -83,7 +83,7 @@ class ConformerEncoderLayer(nn.Module):
self
.
conv_module
=
ConvolutionModule
(
self
.
embed_dim
,
args
.
cnn_module_kernel
,
self
.
activation_fn
)
self
.
final_norm
=
LayerNorm
(
self
.
embed_dim
)
else
:
self
.
conv_norm
=
Fals
e
self
.
conv_norm
=
Non
e
self
.
conv_module
=
None
self
.
final_norm
=
None
...
...
fairseq/modules/convolution.py
查看文件 @
cb0af126
...
...
@@ -9,6 +9,14 @@ from typing import Optional, Tuple
import
torch
from
torch
import
nn
from
fairseq.modules.layer_norm
import
LayerNorm
class
Swish
(
nn
.
Module
):
"""Construct an Swish object."""
def
forward
(
self
,
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
"""Return Swish activation function."""
return
x
*
torch
.
sigmoid
(
x
)
class
ConvolutionModule
(
nn
.
Module
):
...
...
@@ -16,7 +24,7 @@ class ConvolutionModule(nn.Module):
def
__init__
(
self
,
channels
:
int
,
kernel_size
:
int
=
15
,
activation
:
nn
.
Module
=
nn
.
ReLU
(),
activation
:
nn
.
Module
=
Swish
(),
norm
:
str
=
"batch_norm"
,
causal
:
bool
=
False
,
bias
:
bool
=
True
):
...
...
@@ -48,6 +56,7 @@ class ConvolutionModule(nn.Module):
assert
(
kernel_size
-
1
)
%
2
==
0
padding
=
(
kernel_size
-
1
)
//
2
self
.
lorder
=
0
self
.
depthwise_conv
=
nn
.
Conv1d
(
channels
,
channels
,
...
...
@@ -64,7 +73,7 @@ class ConvolutionModule(nn.Module):
self
.
norm
=
nn
.
BatchNorm1d
(
channels
)
else
:
self
.
use_layer_norm
=
True
self
.
norm
=
nn
.
LayerNorm
(
channels
)
self
.
norm
=
LayerNorm
(
channels
)
self
.
pointwise_conv2
=
nn
.
Conv1d
(
channels
,
...
...
@@ -74,7 +83,7 @@ class ConvolutionModule(nn.Module):
padding
=
0
,
bias
=
bias
,
)
self
.
activation
=
activation
self
.
activation
=
Swish
()
def
forward
(
self
,
...
...
@@ -109,14 +118,14 @@ class ConvolutionModule(nn.Module):
assert
(
x
.
size
(
2
)
>
self
.
lorder
)
new_cache
=
x
[:,
:,
-
self
.
lorder
:]
else
:
# It's better we just return None if no cache is requ
ri
ed,
# It's better we just return None if no cache is requ
ir
ed,
# However, for JIT export, here we just fake one tensor instead of
# None.
new_cache
=
torch
.
tensor
([
0.0
],
dtype
=
x
.
dtype
,
device
=
x
.
device
)
# GLU mechanism
x
=
self
.
pointwise_conv1
(
x
)
# (batch, 2*channel,
dim
)
x
=
nn
.
functional
.
glu
(
x
,
dim
=
1
)
# (batch, channel,
dim
)
x
=
self
.
pointwise_conv1
(
x
)
# (batch, 2*channel,
time
)
x
=
nn
.
functional
.
glu
(
x
,
dim
=
1
)
# (batch, channel,
time
)
# 1D Depthwise Conv
x
=
self
.
depthwise_conv
(
x
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论