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
Uni-Core
Commits
a44b9c68
Unverified
Commit
a44b9c68
authored
Mar 09, 2023
by
Ziyao Li
Committed by
GitHub
Mar 09, 2023
Browse files
pass arg to switch ckp on/off (#22)
parent
ee13d84f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
unicore/utils.py
unicore/utils.py
+3
-2
No files found.
unicore/utils.py
View file @
a44b9c68
...
@@ -296,6 +296,7 @@ def eval_bool(x, default=False):
...
@@ -296,6 +296,7 @@ def eval_bool(x, default=False):
def
checkpoint_sequential
(
def
checkpoint_sequential
(
functions
,
functions
,
input
,
input
,
enabled
=
True
,
):
):
def
wrap_tuple
(
a
):
def
wrap_tuple
(
a
):
return
(
a
,)
if
type
(
a
)
is
not
tuple
else
a
return
(
a
,)
if
type
(
a
)
is
not
tuple
else
a
...
@@ -313,7 +314,7 @@ def checkpoint_sequential(
...
@@ -313,7 +314,7 @@ def checkpoint_sequential(
is_grad_enabled
=
torch
.
is_grad_enabled
()
is_grad_enabled
=
torch
.
is_grad_enabled
()
if
is_grad_enabled
:
if
enabled
and
is_grad_enabled
:
for
func
in
functions
:
for
func
in
functions
:
input
=
torch
.
utils
.
checkpoint
.
checkpoint
(
get_wrap_exec
(
func
),
*
input
)
input
=
torch
.
utils
.
checkpoint
.
checkpoint
(
get_wrap_exec
(
func
),
*
input
)
else
:
else
:
...
@@ -433,4 +434,4 @@ def validate_with_ema(trainer, ema=False):
...
@@ -433,4 +434,4 @@ def validate_with_ema(trainer, ema=False):
yield
yield
finally
:
finally
:
trainer
.
_wrapped_model
=
_wrapped_model
trainer
.
_wrapped_model
=
_wrapped_model
\ No newline at end of file
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