Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Shape Transformer RWKV
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolay Strohschen
Shape Transformer RWKV
Commits
d90b6609
Commit
d90b6609
authored
3 years ago
by
Moritz Ibing
Browse files
Options
Downloads
Patches
Plain Diff
Simple fix to pass full information to higher layers
parent
aa25ef26
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/generative_head/double_substitution_head.py
+8
-4
8 additions, 4 deletions
modules/generative_head/double_substitution_head.py
modules/generative_head/substitution_head.py
+5
-2
5 additions, 2 deletions
modules/generative_head/substitution_head.py
with
13 additions
and
6 deletions
modules/generative_head/double_substitution_head.py
+
8
−
4
View file @
d90b6609
...
...
@@ -51,6 +51,9 @@ class DoubleSubstitutionHead(nn.Module):
convolution_0
+=
[
nn
.
GELU
(),
BlockConvolution
(
head_dim
,
head_dim
,
8
)]
self
.
convolution_0
=
nn
.
Sequential
(
*
convolution_0
)
self
.
down_convolution_1
=
Convolution
(
head_dim
,
head_dim
,
8
)
self
.
down_convolution_0
=
Convolution
(
head_dim
,
head_dim
,
8
)
linear
=
[]
for
i
in
range
(
n_layer
-
1
):
linear
+=
[
nn
.
GELU
(),
nn
.
Linear
(
head_dim
,
head_dim
)]
...
...
@@ -102,16 +105,17 @@ class DoubleSubstitutionHead(nn.Module):
# add spatial decoding if available
if
self
.
spatial_encoding
is
not
None
:
emb_0
=
emb_0
+
self
.
spatial_encoding
(
pos
[:,
-
len_0
:])
emb_0
=
self
.
convolution_0
(
emb_0
[:,
:
mix_1
*
8
])
emb_1
=
torch
.
zeros
((
batch_size
,
torch
.
max
(
len_1
),
self
.
head_dim
),
dtype
=
torch
.
float
,
device
=
value
.
device
)
# substitute all mixed token embeddings of penultimate layer, with token embeddings of last layer
emb_1
[
val_1
==
2
]
=
emb_0
[:,
7
::
8
]
# [N, T1, C]
emb_1
=
self
.
convolution_1
(
emb_1
)
emb_1
[
val_1
==
2
]
=
self
.
down_convolution_0
(
emb_0
[:,
:
mix_1
*
8
])
# [N, T1, C]
emb_2
=
torch
.
zeros
((
batch_size
,
torch
.
max
(
len_2
),
self
.
head_dim
),
dtype
=
torch
.
float
,
device
=
value
.
device
)
# substitute all mixed token embeddings of third to last layer, with token embeddings of penultimate layer
emb_2
[
val_2
==
2
]
=
emb_1
[:,
7
::
8
]
# [N, T1, C]
emb_2
[
val_2
==
2
]
=
self
.
down_convolution_1
(
emb_1
)
# [N, T1, C]
emb_0
=
self
.
convolution_0
(
emb_0
[:,
:
mix_1
*
8
])
emb_1
=
self
.
convolution_1
(
emb_1
)
emb_2
=
self
.
convolution_2
(
emb_2
)
# create intermediate list to hold vectors
...
...
This diff is collapsed.
Click to expand it.
modules/generative_head/substitution_head.py
+
5
−
2
View file @
d90b6609
...
...
@@ -41,6 +41,8 @@ class SubstitutionHead(nn.Module):
convolution_0
+=
[
nn
.
GELU
(),
BlockConvolution
(
head_dim
,
head_dim
,
8
)]
self
.
convolution_0
=
nn
.
Sequential
(
*
convolution_0
)
self
.
down_convolution
=
Convolution
(
head_dim
,
head_dim
,
8
)
linear
=
[]
for
i
in
range
(
n_layer
-
1
):
linear
+=
[
nn
.
GELU
(),
nn
.
Linear
(
head_dim
,
head_dim
)]
...
...
@@ -90,11 +92,12 @@ class SubstitutionHead(nn.Module):
# add spatial decoding if available
if
self
.
spatial_encoding
is
not
None
:
emb_0
=
emb_0
+
self
.
spatial_encoding
(
pos
[:,
-
len_0
:])
emb_0
=
self
.
convolution_0
(
emb_0
[:,
:
mix_1
*
8
])
emb_1
=
torch
.
zeros
((
batch_size
,
torch
.
max
(
len_1
),
self
.
head_dim
),
dtype
=
torch
.
float
,
device
=
value
.
device
)
# substitite all mixed token embeddings of penultimate layer, with token embeddings of last layer
emb_1
[
val_1
==
2
]
=
emb_0
[:,
7
::
8
]
# [N, T1, C]
emb_1
[
val_1
==
2
]
=
self
.
down_convolution
(
emb_0
[:,
:
mix_1
*
8
])
# [N, T1, C]
emb_0
=
self
.
convolution_0
(
emb_0
[:,
:
mix_1
*
8
])
emb_1
=
self
.
convolution_1
(
emb_1
)
x_0
=
torch
.
zeros
((
batch_size
,
torch
.
max
(
mix_1
),
self
.
head_dim
),
device
=
value
.
device
)
...
...
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