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
0d98466d
Commit
0d98466d
authored
Sep 18, 2023
by
Geoffrey Yu
Browse files
protect necessary tensors by moving them to cpu memory
parent
bc49758a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
6 deletions
+32
-6
openfold/utils/loss.py
openfold/utils/loss.py
+32
-6
No files found.
openfold/utils/loss.py
View file @
0d98466d
...
...
@@ -2079,7 +2079,10 @@ class AlphaFoldMultimerLoss(AlphaFoldLoss):
ca_idx
=
rc
.
atom_order
[
"CA"
]
pred_ca_pos
=
out
[
"final_atom_positions"
][...,
ca_idx
,
:]
# [bsz, nres, 3]
pred_ca_mask
=
out
[
"final_atom_mask"
][...,
ca_idx
].
to
(
dtype
=
pred_ca_pos
.
dtype
)
# [bsz, nres]
pred_ca_pos
=
pred_ca_pos
.
detach
().
to
(
'cpu'
)
pred_ca_mask
=
pred_ca_mask
.
detach
().
to
(
'cpu'
)
print
(
f
"@@@@@@@ line 2082 pred_ca_pos isinf:
{
torch
.
isinf
(
pred_ca_pos
).
any
()
}
isnan:
{
torch
.
isnan
(
pred_ca_pos
).
any
()
}
"
)
print
(
f
"@@@@@@@@ line 2083 pred_ca_mask isinf:
{
torch
.
isinf
(
pred_ca_mask
).
any
()
}
isnan:
{
torch
.
isnan
(
pred_ca_mask
).
any
()
}
"
)
true_ca_poses
=
[
l
[
"all_atom_positions"
][...,
ca_idx
,
:]
for
l
in
labels
]
# list([nres, 3])
...
...
@@ -2095,6 +2098,7 @@ class AlphaFoldMultimerLoss(AlphaFoldLoss):
per_asym_residue_index
[
int
(
cur_asym_id
)]
=
torch
.
masked_select
(
batch
[
"residue_index"
],
asym_mask
)
if
permutate_chains
:
anchor_gt_asym
,
anchor_pred_asym
=
get_least_asym_entity_or_longest_length
(
batch
)
torch
.
cuda
.
empty_cache
()
print
(
f
"anchor_gt_asym:
{
anchor_gt_asym
}
anchor_pred_asym:
{
anchor_pred_asym
}
"
)
anchor_gt_idx
=
int
(
anchor_gt_asym
)
-
1
...
...
@@ -2105,25 +2109,46 @@ class AlphaFoldMultimerLoss(AlphaFoldLoss):
cur_asym_id
=
torch
.
unique
(
batch
[
"asym_id"
][
ent_mask
])
entity_2_asym_list
[
int
(
cur_ent_id
)]
=
cur_asym_id
asym_mask
=
(
batch
[
"asym_id"
]
==
anchor_pred_asym
).
bool
()
anchor_residue_idx
=
per_asym_residue_index
[
int
(
anchor_pred_asym
)]
anchor_true_pos
=
torch
.
index_select
(
true_ca_poses
[
anchor_gt_idx
],
1
,
anchor_residue_idx
)
anchor_pred_pos
=
pred_ca_pos
[
0
][
asym_mask
[
0
]]
anchor_true_pos
=
torch
.
squeeze
(
anchor_true_pos
,
0
)
print
(
f
"@@@@@@@ line 2115 pred_ca_pos isinf:
{
torch
.
isinf
(
pred_ca_pos
).
any
()
}
asym_mask isnan:
{
torch
.
isnan
(
pred_ca_pos
).
any
()
}
"
)
print
(
f
"@@@@@@@ line 2116 pred_ca_mask isinf:
{
torch
.
isinf
(
pred_ca_mask
).
any
()
}
pred_ca_mask isnan:
{
torch
.
isnan
(
pred_ca_mask
).
any
()
}
"
)
pred_ca_pos
=
torch
.
squeeze
(
pred_ca_pos
,
0
)
asym_mask
=
torch
.
squeeze
(
asym_mask
,
0
)
asym_mask
=
asym_mask
.
detach
().
to
(
'cpu'
)
pred_ca_mask
=
torch
.
squeeze
(
pred_ca_mask
,
0
)
print
(
f
"@@@@@@@ line 2120 pred_ca_pos isinf:
{
torch
.
isinf
(
pred_ca_pos
).
any
()
}
asym_mask isnan:
{
torch
.
isnan
(
pred_ca_pos
).
any
()
}
"
)
print
(
f
"@@@@@@@ line 2121 pred_ca_mask isinf:
{
torch
.
isinf
(
pred_ca_mask
).
any
()
}
pred_ca_mask isnan:
{
torch
.
isnan
(
pred_ca_mask
).
any
()
}
"
)
anchor_pred_pos
=
pred_ca_pos
[
asym_mask
]
anchor_true_mask
=
torch
.
index_select
(
true_ca_masks
[
anchor_gt_idx
],
1
,
anchor_residue_idx
)
anchor_pred_mask
=
pred_ca_mask
[
0
][
asym_mask
[
0
]]
anchor_pred_mask
=
pred_ca_mask
[
asym_mask
]
anchor_pred_mask
=
torch
.
unsqueeze
(
anchor_pred_mask
,
0
)
anchor_pred_mask
=
anchor_pred_mask
.
to
(
anchor_true_mask
.
device
)
pred_ca_pos
=
torch
.
unsqueeze
(
pred_ca_pos
,
0
)
pred_ca_mask
=
torch
.
unsqueeze
(
pred_ca_mask
,
0
)
input_mask
=
(
anchor_true_mask
*
anchor_pred_mask
).
bool
()
anchor_pred_pos
=
anchor_pred_pos
.
to
(
anchor_true_pos
.
device
)
r
,
x
=
get_optimal_transform
(
anchor_pred_pos
,
anchor_true_pos
[
0
]
,
mask
=
input_mask
[
0
]
anchor_pred_pos
,
anchor_true_pos
,
mask
=
torch
.
squeeze
(
input_mask
,
0
)
)
del
input_mask
# just to save memory
del
anchor_pred_mask
del
anchor_true_mask
gc
.
collect
()
aligned_true_ca_poses
=
[
ca
.
to
(
r
.
dtype
)
@
r
+
x
for
ca
in
true_ca_poses
]
# apply transforms
del
true_ca_poses
gc
.
collect
()
pred_ca_pos
=
pred_ca_pos
.
to
(
anchor_true_mask
.
device
)
pred_ca_mask
=
pred_ca_mask
.
to
(
anchor_true_mask
.
device
)
del
anchor_true_mask
gc
.
collect
()
torch
.
cuda
.
empty_cache
()
align
=
greedy_align
(
batch
,
per_asym_residue_index
,
...
...
@@ -2140,6 +2165,7 @@ class AlphaFoldMultimerLoss(AlphaFoldLoss):
del
pred_ca_pos
,
pred_ca_mask
del
anchor_pred_pos
,
anchor_true_pos
gc
.
collect
()
torch
.
cuda
.
empty_cache
()
print
(
f
"finished multi-chain permutation and final align is
{
align
}
"
)
else
:
align
=
list
(
enumerate
(
range
(
len
(
labels
))))
...
...
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