Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
f8c43c94
Unverified
Commit
f8c43c94
authored
Apr 17, 2023
by
Kunhao ZHENG
Committed by
GitHub
Apr 17, 2023
Browse files
Fix squeeze into torch 1.x compatible form in llama model (#22808)
fix-squeeze-tuple
parent
5269718c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
src/transformers/models/llama/modeling_llama.py
src/transformers/models/llama/modeling_llama.py
+2
-2
No files found.
src/transformers/models/llama/modeling_llama.py
View file @
f8c43c94
...
@@ -132,8 +132,8 @@ def rotate_half(x):
...
@@ -132,8 +132,8 @@ def rotate_half(x):
def
apply_rotary_pos_emb
(
q
,
k
,
cos
,
sin
,
position_ids
):
def
apply_rotary_pos_emb
(
q
,
k
,
cos
,
sin
,
position_ids
):
# The first two dimensions of cos and sin are always 1, so we can `squeeze` them.
# The first two dimensions of cos and sin are always 1, so we can `squeeze` them.
cos
=
cos
.
squeeze
(
(
0
,
1
)
)
# [seq_len, dim]
cos
=
cos
.
squeeze
(
1
).
squeeze
(
0
)
# [seq_len, dim]
sin
=
sin
.
squeeze
(
(
0
,
1
)
)
# [seq_len, dim]
sin
=
sin
.
squeeze
(
1
).
squeeze
(
0
)
# [seq_len, dim]
cos
=
cos
[
position_ids
].
unsqueeze
(
1
)
# [bs, 1, seq_len, dim]
cos
=
cos
[
position_ids
].
unsqueeze
(
1
)
# [bs, 1, seq_len, dim]
sin
=
sin
[
position_ids
].
unsqueeze
(
1
)
# [bs, 1, seq_len, dim]
sin
=
sin
[
position_ids
].
unsqueeze
(
1
)
# [bs, 1, seq_len, dim]
q_embed
=
(
q
*
cos
)
+
(
rotate_half
(
q
)
*
sin
)
q_embed
=
(
q
*
cos
)
+
(
rotate_half
(
q
)
*
sin
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment