Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpointing: Avoid assigning tensor storage with different device #4836

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions deepspeed/runtime/activation_checkpointing/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ def get_partitioned_activations_for_backward(args, inputs, contiguous_checkpoint
num_non_fp_tensors += 1
continue

arg.data = inp.data
arg.data = torch.empty([], device=arg.device).data
arg.saved_data = inp.data

new_args.append(arg)
i = arg_index - num_non_fp_tensors

Expand Down Expand Up @@ -472,7 +474,8 @@ def get_cpu_activations_for_backward(args, inputs):
new_args.append(arg)
continue

arg.data = inp.data
arg.data = torch.empty([], device=arg.device).data
arg.saved_data = inp.data
new_args.append(arg)

return new_args
Expand Down Expand Up @@ -628,6 +631,12 @@ def backward(ctx, *grads):

global cuda_device, transport_stream, PARTITION_ACTIVATIONS

# Rebuild deepspeed_saved_tensors
for t in ctx.deepspeed_saved_tensors:
if t is not None and hasattr(t, 'saved_data') and t.saved_data is not None:
t.data = t.saved_data.to(t.device)
t.saved_data = None

if PARTITION_ACTIVATIONS:
# with get_accelerator().stream(transport_stream):
inputs = gather_partitioned_activations(ctx.deepspeed_saved_tensors,
Expand Down