Skip to content

Instantly share code, notes, and snippets.

@sailfish009
Created October 14, 2024 10:32
Show Gist options
  • Save sailfish009/518054b476232ae221f13206b0abca6f to your computer and use it in GitHub Desktop.
Save sailfish009/518054b476232ae221f13206b0abca6f to your computer and use it in GitHub Desktop.
AttributeError: 'int' object has no attribute 'type'
https://github.com/open-mmlab/mmdetection/issues/10720
from torch import Tensor
from torch.nn.parallel._functions import _get_stream
from packaging import version
def scatter(input: Union[List, Tensor],
devices: List,
@@ -72,7 +74,10 @@ def forward(target_gpus: List[int], input: Union[List, Tensor]) -> tuple:
streams = None
if input_device == -1 and target_gpus != [-1]:
# Perform CPU to GPU copies in a background stream
streams = [_get_stream(device) for device in target_gpus]
if version.parse(torch.__version__) >= version.parse('2.1.0'):
streams = [_get_stream(torch.device("cuda", device)) for device in target_gpus]
else:
streams = [_get_stream(device) for device in target_gpus]
outputs = scatter(input, target_gpus, streams)
# Synchronize with the copy stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment