Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SwissArmyTransformer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
thukeg
SwissArmyTransformer
Commits
2721c2fa
Commit
2721c2fa
authored
3 years ago
by
Ming Ding
Browse files
Options
Downloads
Patches
Plain Diff
fix shared crossattn bug
parent
233d9495
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SwissArmyTransformer/model/encoder_decoder_model.py
+12
-6
12 additions, 6 deletions
SwissArmyTransformer/model/encoder_decoder_model.py
with
12 additions
and
6 deletions
SwissArmyTransformer/model/encoder_decoder_model.py
+
12
−
6
View file @
2721c2fa
...
@@ -18,17 +18,23 @@ from .common_layers import CrossAttention, LayerNorm
...
@@ -18,17 +18,23 @@ from .common_layers import CrossAttention, LayerNorm
class
CrossAttentionMixin
(
BaseMixin
):
class
CrossAttentionMixin
(
BaseMixin
):
def
__init__
(
self
,
hidden_size
,
num_attention_heads
,
def
__init__
(
self
,
num_layers
,
hidden_size
,
num_attention_heads
,
attention_dropout_prob
,
output_dropout_prob
,
attention_dropout_prob
,
output_dropout_prob
,
init_method
,
enc_hidden_size
=
None
,
inner_hidden_size
=
None
,
output_layer_init_method
=
None
):
init_method
,
enc_hidden_size
=
None
,
inner_hidden_size
=
None
,
output_layer_init_method
=
None
):
super
().
__init__
()
super
().
__init__
()
self
.
cross_attention
=
CrossAttention
(
self
.
cross_attentions
=
torch
.
nn
.
ModuleList
(
[
CrossAttention
(
hidden_size
,
num_attention_heads
,
hidden_size
,
num_attention_heads
,
attention_dropout_prob
,
output_dropout_prob
,
attention_dropout_prob
,
output_dropout_prob
,
init_method
,
enc_hidden_size
=
enc_hidden_size
,
inner_hidden_size
=
inner_hidden_size
,
init_method
,
enc_hidden_size
=
enc_hidden_size
,
inner_hidden_size
=
inner_hidden_size
,
output_layer_init_method
=
output_layer_init_method
output_layer_init_method
=
output_layer_init_method
)
# Just copy args
)]
for
layer_id
in
range
(
num_layers
)
self
.
cross_ln
=
LayerNorm
(
hidden_size
,
1e-5
)
)
# Just copy args
self
.
cross_lns
=
torch
.
nn
.
ModuleList
(
[
LayerNorm
(
hidden_size
,
1e-5
)]
for
layer_id
in
range
(
num_layers
)
)
def
layer_forward
(
self
,
hidden_states
,
mask
,
layer_id
,
**
kw_args
):
def
layer_forward
(
self
,
hidden_states
,
mask
,
layer_id
,
**
kw_args
):
...
@@ -49,8 +55,8 @@ class CrossAttentionMixin(BaseMixin):
...
@@ -49,8 +55,8 @@ class CrossAttentionMixin(BaseMixin):
hidden_states
=
hidden_states
+
attention_output
hidden_states
=
hidden_states
+
attention_output
# Cross attention.
# Cross attention.
layernorm_output
=
self
.
cross_ln
(
hidden_states
)
layernorm_output
=
self
.
cross_ln
s
[
layer_id
]
(
hidden_states
)
cross_attn_output
=
self
.
cross_attention
(
cross_attn_output
=
self
.
cross_attention
s
[
layer_id
]
(
layernorm_output
,
layernorm_output
,
torch
.
ones
(
1
,
1
,
device
=
hidden_states
.
device
,
dtype
=
hidden_states
.
dtype
),
torch
.
ones
(
1
,
1
,
device
=
hidden_states
.
device
,
dtype
=
hidden_states
.
dtype
),
encoder_outputs
encoder_outputs
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment