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

[WIP] Accelerate training by replacing DataContainer object scatter #1236

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 3 additions & 6 deletions mmcv/parallel/_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Open-MMLab. All rights reserved.
import torch
from torch.cuda import comm
from torch.nn.parallel._functions import _get_stream


Expand All @@ -16,16 +17,12 @@ def scatter(input, devices, streams=None):
]
return outputs
elif isinstance(input, torch.Tensor):
output = input.contiguous()
# TODO: copy to a pinned buffer first (if copying from CPU)
stream = streams[0] if output.numel() > 0 else None
if devices != [-1]:
with torch.cuda.device(devices[0]), torch.cuda.stream(stream):
output = output.cuda(devices[0], non_blocking=True)
output = comm.scatter(input, devices, None, 0, streams)[0]
else:
# unsqueeze the first dimension thus the tensor's shape is the
# same as those scattered with GPU.
output = output.unsqueeze(0)
output = input.contiguous().unsqueeze(0)
return output
else:
raise Exception(f'Unknown type {type(input)}.')
Expand Down