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
98d5b727
Unverified
Commit
98d5b727
authored
Feb 08, 2023
by
Thomas Wang
Committed by
GitHub
Feb 08, 2023
Browse files
Update OPT conversion script to work for OPT-IML (#21519)
parent
fe616f35
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
src/transformers/models/opt/convert_opt_original_pytorch_checkpoint_to_pytorch.py
...opt/convert_opt_original_pytorch_checkpoint_to_pytorch.py
+21
-0
No files found.
src/transformers/models/opt/convert_opt_original_pytorch_checkpoint_to_pytorch.py
View file @
98d5b727
...
...
@@ -53,6 +53,27 @@ def load_checkpoint(checkpoint_path):
if
old_key
in
sd
:
sd
[
new_key
]
=
sd
.
pop
(
old_key
)
keys
=
list
(
sd
.
keys
())
for
key
in
keys
:
if
".qkj_proj."
in
key
:
value
=
sd
[
key
]
# We split QKV in seperate Q,K,V
q_name
=
key
.
replace
(
".qkv_proj."
,
".q_proj."
)
k_name
=
key
.
replace
(
".qkv_proj."
,
".k_proj."
)
v_name
=
key
.
replace
(
".qkv_proj."
,
".v_proj."
)
depth
=
value
.
shape
[
0
]
assert
depth
%
3
==
0
# `SequeuceParallelTransformerBlock` has QKV weight is separated in K,V,Q despite the naming:
# https://cs.github.com/facebookresearch/metaseq/blob/51871bd73cd04c038f239ea2a26db1d7f6b37927/metaseq/modules/sequence_parallel_transformer_layer.py#L97
k
,
v
,
q
=
torch
.
split
(
value
,
depth
//
3
,
dim
=
0
)
sd
[
q_name
]
=
q
sd
[
k_name
]
=
k
sd
[
v_name
]
=
v
del
sd
[
key
]
return
sd
...
...
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