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
fairscale
Commits
63f289f2
Unverified
Commit
63f289f2
authored
Jun 25, 2021
by
Sam Shleifer
Committed by
GitHub
Jun 25, 2021
Browse files
checkpoint_activations: use non blocking cpu transfer (#719)
parent
308f1057
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
fairscale/nn/checkpoint/checkpoint_activations.py
fairscale/nn/checkpoint/checkpoint_activations.py
+2
-2
No files found.
fairscale/nn/checkpoint/checkpoint_activations.py
View file @
63f289f2
...
@@ -248,7 +248,7 @@ class CheckpointFunction(torch.autograd.Function):
...
@@ -248,7 +248,7 @@ class CheckpointFunction(torch.autograd.Function):
if
parent_ctx_dict
[
"offload"
]:
if
parent_ctx_dict
[
"offload"
]:
ctx
.
fwd_device
=
tuple
(
x
.
device
for
x
in
tensor_inputs
)
ctx
.
fwd_device
=
tuple
(
x
.
device
for
x
in
tensor_inputs
)
ctx
.
grad_requirements
=
tuple
(
x
.
requires_grad
for
x
in
tensor_inputs
)
ctx
.
grad_requirements
=
tuple
(
x
.
requires_grad
for
x
in
tensor_inputs
)
tensor_inputs
=
tuple
(
x
.
cpu
(
)
for
x
in
tensor_inputs
)
tensor_inputs
=
tuple
(
x
.
to
(
"cpu"
,
non_blocking
=
True
)
for
x
in
tensor_inputs
)
else
:
else
:
ctx
.
fwd_device
,
ctx
.
grad_requirements
=
None
,
None
ctx
.
fwd_device
,
ctx
.
grad_requirements
=
None
,
None
...
@@ -277,7 +277,7 @@ class CheckpointFunction(torch.autograd.Function):
...
@@ -277,7 +277,7 @@ class CheckpointFunction(torch.autograd.Function):
tensor_inputs
:
Tuple
=
ctx
.
saved_tensors
tensor_inputs
:
Tuple
=
ctx
.
saved_tensors
tensor_inputs
=
torch_checkpoint
.
detach_variable
(
tensor_inputs
)
tensor_inputs
=
torch_checkpoint
.
detach_variable
(
tensor_inputs
)
if
ctx
.
fwd_device
is
not
None
:
if
ctx
.
fwd_device
is
not
None
:
tensor_inputs
=
tuple
(
t
.
to
(
ctx
.
fwd_device
[
i
])
for
i
,
t
in
enumerate
(
tensor_inputs
))
tensor_inputs
=
tuple
(
t
.
to
(
ctx
.
fwd_device
[
i
]
,
non_blocking
=
True
)
for
i
,
t
in
enumerate
(
tensor_inputs
))
for
i
,
need_grad
in
enumerate
(
ctx
.
grad_requirements
):
for
i
,
need_grad
in
enumerate
(
ctx
.
grad_requirements
):
tensor_inputs
[
i
].
requires_grad
=
need_grad
tensor_inputs
[
i
].
requires_grad
=
need_grad
inputs
=
unpack_non_tensors
(
tensor_inputs
,
ctx
.
packed_non_tensor_inputs
)
inputs
=
unpack_non_tensors
(
tensor_inputs
,
ctx
.
packed_non_tensor_inputs
)
...
...
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