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
OpenDAS
OpenFold
Commits
423e7ecf
"vscode:/vscode.git/clone" did not exist on "d797b4ba0e38c75a167fb2ac2b84efac144c8b71"
Commit
423e7ecf
authored
Jun 27, 2022
by
Gustaf Ahdritz
Browse files
Fix typo
parent
a7c4159d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
openfold/utils/import_weights.py
openfold/utils/import_weights.py
+13
-6
No files found.
openfold/utils/import_weights.py
View file @
423e7ecf
...
@@ -52,14 +52,14 @@ class Param:
...
@@ -52,14 +52,14 @@ class Param:
stacked
:
bool
=
False
stacked
:
bool
=
False
def
_
process_translation
s
_dict
(
d
,
top_layer
=
True
):
def
process_translation_dict
(
d
,
top_layer
=
True
):
flat
=
{}
flat
=
{}
for
k
,
v
in
d
.
items
():
for
k
,
v
in
d
.
items
():
if
type
(
v
)
==
dict
:
if
type
(
v
)
==
dict
:
prefix
=
_NPZ_KEY_PREFIX
if
top_layer
else
""
prefix
=
_NPZ_KEY_PREFIX
if
top_layer
else
""
sub_flat
=
{
sub_flat
=
{
(
prefix
+
"/"
.
join
([
k
,
k_prime
])):
v_prime
(
prefix
+
"/"
.
join
([
k
,
k_prime
])):
v_prime
for
k_prime
,
v_prime
in
_
process_translation
s
_dict
(
for
k_prime
,
v_prime
in
process_translation_dict
(
v
,
top_layer
=
False
v
,
top_layer
=
False
).
items
()
).
items
()
}
}
...
@@ -122,9 +122,7 @@ def assign(translation_dict, orig_weights):
...
@@ -122,9 +122,7 @@ def assign(translation_dict, orig_weights):
raise
raise
def
import_jax_weights_
(
model
,
npz_path
,
version
=
"model_1"
):
def
generate_translation_dict
(
model
,
version
):
data
=
np
.
load
(
npz_path
)
#######################
#######################
# Some templates
# Some templates
#######################
#######################
...
@@ -431,8 +429,17 @@ def import_jax_weights_(model, npz_path, version="model_1"):
...
@@ -431,8 +429,17 @@ def import_jax_weights_(model, npz_path, version="model_1"):
"logits"
:
LinearParams
(
model
.
aux_heads
.
tm
.
linear
)
"logits"
:
LinearParams
(
model
.
aux_heads
.
tm
.
linear
)
}
}
return
translations
def
import_jax_weights_
(
model
,
npz_path
,
version
=
"model_1"
):
data
=
np
.
load
(
npz_path
)
translations
=
generate_translation_dict
(
model
,
version
)
# Flatten keys and insert missing key prefixes
# Flatten keys and insert missing key prefixes
flat
=
_
process_translation
s
_dict
(
translations
)
flat
=
process_translation_dict
(
translations
)
# Sanity check
# Sanity check
keys
=
list
(
data
.
keys
())
keys
=
list
(
data
.
keys
())
...
...
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