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
ceef010a
Commit
ceef010a
authored
Aug 26, 2022
by
Gustaf Ahdritz
Browse files
Add offloading sanity checks
parent
4b410596
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
1 deletion
+11
-1
openfold/model/evoformer.py
openfold/model/evoformer.py
+5
-1
openfold/model/structure_module.py
openfold/model/structure_module.py
+3
-0
openfold/model/template.py
openfold/model/template.py
+3
-0
No files found.
openfold/model/evoformer.py
View file @
ceef010a
...
...
@@ -12,8 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
import
sys
import
torch
import
torch.nn
as
nn
from
typing
import
Tuple
,
Sequence
,
Optional
...
...
@@ -208,6 +208,7 @@ class EvoformerBlockCore(nn.Module):
if
(
_offload_inference
and
inplace_safe
):
del
m
,
z
assert
(
sys
.
getrefcount
(
input_tensors
[
1
])
==
2
)
input_tensors
[
1
]
=
input_tensors
[
1
].
cpu
()
torch
.
cuda
.
empty_cache
()
m
,
z
=
input_tensors
...
...
@@ -218,6 +219,7 @@ class EvoformerBlockCore(nn.Module):
if
(
_offload_inference
and
inplace_safe
):
del
m
,
z
assert
(
sys
.
getrefcount
(
input_tensors
[
0
])
==
2
)
input_tensors
[
0
]
=
input_tensors
[
0
].
cpu
()
input_tensors
[
1
]
=
input_tensors
[
1
].
to
(
opm
.
device
)
m
,
z
=
input_tensors
...
...
@@ -300,6 +302,8 @@ class EvoformerBlockCore(nn.Module):
if
(
_offload_inference
and
inplace_safe
):
device
=
z
.
device
del
m
,
z
assert
(
sys
.
getrefcount
(
input_tensors
[
0
])
==
2
)
assert
(
sys
.
getrefcount
(
input_tensors
[
1
])
==
2
)
input_tensors
[
0
]
=
input_tensors
[
0
].
to
(
device
)
input_tensors
[
1
]
=
input_tensors
[
1
].
to
(
device
)
m
,
z
=
input_tensors
...
...
openfold/model/structure_module.py
View file @
ceef010a
...
...
@@ -15,6 +15,7 @@
from
functools
import
reduce
import
importlib
import
math
import
sys
from
operator
import
mul
import
torch
...
...
@@ -307,6 +308,7 @@ class InvariantPointAttention(nn.Module):
b
=
self
.
linear_b
(
z
[
0
])
if
(
_offload_inference
):
assert
(
sys
.
getrefcount
(
z
[
0
])
==
2
)
z
[
0
]
=
z
[
0
].
cpu
()
# [*, H, N_res, N_res]
...
...
@@ -651,6 +653,7 @@ class StructureModule(nn.Module):
z_reference_list
=
None
if
(
_offload_inference
):
assert
(
sys
.
getrefcount
(
evoformer_output_dict
[
"pair"
])
==
2
)
evoformer_output_dict
[
"pair"
]
=
evoformer_output_dict
[
"pair"
].
cpu
()
z_reference_list
=
[
z
]
z
=
None
...
...
openfold/model/template.py
View file @
ceef010a
...
...
@@ -14,6 +14,7 @@
# limitations under the License.
from
functools
import
partial
import
math
import
sys
from
typing
import
Optional
,
List
import
torch
...
...
@@ -471,6 +472,8 @@ def embed_templates_offload(
_mask_trans
=
model
.
config
.
_mask_trans
,
)
assert
(
sys
.
getrefcount
(
t
)
==
2
)
pair_embeds_cpu
.
append
(
t
.
cpu
())
del
t
...
...
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