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

Only offload if activation is on CUDA #2466

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions torchtune/training/_activation_offloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ def pack_tensor(activation: torch.Tensor) -> int:
num_bytes = get_num_bytes_tensor(activation)
tensor_id = get_tensor_id()

# only offload hefty bois if they're activations (our heuristic for that is to
# check if they're not params or buffers)!
if num_bytes >= self.min_tensor_size_bytes and (
not isinstance(activation, torch.nn.Parameter)
and not isinstance(activation, torch.nn.Buffer)
# only offload hefty bois if they're activations on CUDA (our heuristic
# for that is to check if they're not params or buffers)!
if (
activation.is_cuda
and num_bytes >= self.min_tensor_size_bytes
and (
not isinstance(activation, torch.nn.Parameter)
and not isinstance(activation, torch.nn.Buffer)
)
):
if self.use_streams:
# First, sync back and dereference previously offloaded tensors
Expand Down