Skip to content
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
7 changes: 7 additions & 0 deletions colossalai/utils/multi_tensor_apply/multi_tensor_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class MultiTensorApply(object):
"""
Apply an operation to a list of tensors efficiently.
Move tensors to CUDA if they are on CPU.

Args:
chunk_size (int): Size of a chunk.
Expand Down Expand Up @@ -32,4 +33,10 @@ def check_avail(self):
def __call__(self, op, noop_flag_buffer, tensor_lists, *args):
self.check_avail()

# Move tensors to GPU if not already on GPU
for i, tensor_list in enumerate(tensor_lists):
for j, tensor in enumerate(tensor_list):
if tensor.device.type == "cpu":
tensor_lists[i][j] = tensor.to("cuda")

return op(self.chunk_size, noop_flag_buffer, tensor_lists, *args)