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
c17f8035
Commit
c17f8035
authored
3 years ago
by
duzx16
Browse files
Options
Downloads
Patches
Plain Diff
Delete unused code
parent
4e0e9674
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/t5_model.py
+2
-5
2 additions, 5 deletions
SwissArmyTransformer/model/t5_model.py
with
2 additions
and
5 deletions
SwissArmyTransformer/model/t5_model.py
+
2
−
5
View file @
c17f8035
...
@@ -95,7 +95,7 @@ class T5AttentionMixin(BaseMixin):
...
@@ -95,7 +95,7 @@ class T5AttentionMixin(BaseMixin):
relative_buckets
+=
torch
.
where
(
is_small
,
relative_position
,
relative_postion_if_large
)
relative_buckets
+=
torch
.
where
(
is_small
,
relative_position
,
relative_postion_if_large
)
return
relative_buckets
return
relative_buckets
def
compute_bias
(
self
,
query_length
,
key_length
,
cross_attention
=
False
):
def
compute_bias
(
self
,
query_length
,
key_length
):
"""
Compute binned relative position bias
"""
"""
Compute binned relative position bias
"""
context_position
=
torch
.
arange
(
query_length
,
dtype
=
torch
.
long
)[:,
None
]
context_position
=
torch
.
arange
(
query_length
,
dtype
=
torch
.
long
)[:,
None
]
memory_position
=
torch
.
arange
(
key_length
,
dtype
=
torch
.
long
)[
None
,
:]
memory_position
=
torch
.
arange
(
key_length
,
dtype
=
torch
.
long
)[
None
,
:]
...
@@ -107,10 +107,7 @@ class T5AttentionMixin(BaseMixin):
...
@@ -107,10 +107,7 @@ class T5AttentionMixin(BaseMixin):
)
)
relative_position_bucket
=
relative_position_bucket
.
to
(
self
.
relative_attention_bias
.
weight
.
device
)
relative_position_bucket
=
relative_position_bucket
.
to
(
self
.
relative_attention_bias
.
weight
.
device
)
# shape (query_length, key_length, num_heads)
# shape (query_length, key_length, num_heads)
if
cross_attention
:
values
=
self
.
relative_attention_bias
(
relative_position_bucket
)
values
=
self
.
cross_relative_attention_bias
(
relative_position_bucket
)
else
:
values
=
self
.
relative_attention_bias
(
relative_position_bucket
)
values
=
values
.
permute
([
2
,
0
,
1
]).
unsqueeze
(
0
)
# shape (1, num_heads, query_length, key_length)
values
=
values
.
permute
([
2
,
0
,
1
]).
unsqueeze
(
0
)
# shape (1, num_heads, query_length, key_length)
return
values
return
values
...
...
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